📄 animdemo.c
字号:
/* The example program demonstrates the use of animation controls. An animation control is a picture ring which automatically advances through its pictures. The rate at which the pictures are displayed and the size and position of the each picture is configurable through the animation control's attributes. This program uses the animate.fp instrument driver to create the animation controls. Animation controls can be used for animated instructions, flashing warnings, etc...*/ #include <cvirte.h> /* Needed if linking in external compiler; harmless otherwise */#include <ansi_c.h>#include <userint.h>#include "toolbox.h" /* for TWO_PI */#include "animdemo.h"#include "animate.h"#define NUM_WORLD_STEPS 144 /* number steps in the world's path */#define NUM_ROCKET_STEPS 63 /* number of steps in the rockets path */ /* Note: an animation path is an optional string which specifies how to move and size the animation control for each displayed frame. See the function panel help for the Attribute Value parameter of the AnimateCtrl_SetAttribute() function for a description of the path format. */ void GenerateRocketPath(void);void GenerateWorldPath(int xCenter, int yCenter, int radius, int width, int height, double minZRatio, double maxZRatio, int numSteps, char *pathBuffer);int thePanel;char threeDeePath[NUM_WORLD_STEPS * 30]; /* space for an animation path string */char twoDeePath[NUM_WORLD_STEPS * 30]; /* space for an animation path string */char rocketPath[NUM_ROCKET_STEPS * 30]; /* space for an animation path string */int main (int argc, char *argv[]){ if (InitCVIRTE (0, argv, 0) == 0) /* Needed if linking in external compiler; harmless otherwise */ return -1; /* out of memory */ thePanel = LoadPanel (0, "animdemo.uir", PANEL); /* Create and configure the animation control for the rotating CVI world */ AnimateCtrl_ConvertFromPictRing(thePanel, PANEL_WORLD_PICTRING); AnimateCtrl_SetAttribute (thePanel, PANEL_WORLD_PICTRING, ATTR_ANIMATE_FRAME_INTERVAL, 0.04); GenerateWorldPath(110, 90, 85, 126, 126, 0.01, 1.5, NUM_WORLD_STEPS, threeDeePath); GenerateWorldPath(110, 90, 85, 126, 126, 1.0, 1.0, NUM_WORLD_STEPS, twoDeePath); AnimateCtrl_SetAttribute (thePanel, PANEL_WORLD_PICTRING, ATTR_ANIMATE_PATH, twoDeePath); /* the path describes how to move and size the animation control */ /* Create and configure the animation control for the rocket. Note: the rocket images were loaded from icon (.ico) files. Therefore they can have a transparent background color (on Windows only). */ AnimateCtrl_ConvertFromPictRing(thePanel, PANEL_ROCKET_PICTRING); AnimateCtrl_SetAttribute (thePanel, PANEL_ROCKET_PICTRING, ATTR_ANIMATE_FRAME_INTERVAL, 0.05); GenerateRocketPath(); AnimateCtrl_SetAttribute (thePanel, PANEL_ROCKET_PICTRING, ATTR_ANIMATE_PATH, rocketPath); /* the path describes how to move and size the animation control */ AnimateCtrl_SetAttribute (thePanel, PANEL_ROCKET_PICTRING, ATTR_ANIMATE_ENABLED, 0); /* wait for launch button to start */ AnimateCtrl_SetAttribute (thePanel, PANEL_ROCKET_PICTRING, ATTR_ANIMATE_STOP_AT_PATH_END, 1); /* wait for launch button when done */ DisplayPanel (thePanel); RunUserInterface (); DiscardPanel (thePanel); return 0;}/************************************************************************************/ /* This function does nothing. It is included to show where you could add any special per-frame processing if desired. */int CVICALLBACK AnimateWorldCallback (int panel, int control, int event, void *callbackData, int eventData1, int eventData2){ switch (event) { case EVENT_ANIMATE_PRE_FRAME: /* received before a frame is displayed, eventData1 == oldFrameIndex, eventData2 == newFrameIndex */ break; case EVENT_ANIMATE_POST_FRAME: /* received after a frame is displayed, eventData1 == oldFrameIndex, eventData2 == newFrameIndex */ break; } return 0;}/************************************************************************************/int CVICALLBACK QuitCallback (int panel, int control, int event, void *callbackData, int eventData1, int eventData2){ switch (event) { case EVENT_COMMIT: QuitUserInterface(0); /* the stop button was pressed, quit the program */ break; } return 0;}/************************************************************************************/int CVICALLBACK LaunchCallback (int panel, int control, int event, void *callbackData, int eventData1, int eventData2){ switch (event) { case EVENT_COMMIT: /* start the rocket, the animation control will disable itself when it reached the end of its path (see main) */ AnimateCtrl_SetAttribute (thePanel, PANEL_ROCKET_PICTRING, ATTR_ANIMATE_ENABLED, 1); break; } return 0;}/************************************************************************************/int CVICALLBACK PathSwitchCallback (int panel, int control, int event, void *callbackData, int eventData1, int eventData2){ int value; switch (event) { case EVENT_COMMIT: GetCtrlVal(panel, control, &value); if (value) AnimateCtrl_SetAttribute (thePanel, PANEL_WORLD_PICTRING, ATTR_ANIMATE_PATH, threeDeePath); else AnimateCtrl_SetAttribute (thePanel, PANEL_WORLD_PICTRING, ATTR_ANIMATE_PATH, twoDeePath); break; } return 0;}/************************************************************************************/ /* generates a circular path string with optional scaling to simulate 3d motion */void GenerateWorldPath(int xCenter, int yCenter, int radius, int width, int height, double minZRatio, double maxZRatio, int numSteps, char *pathBuffer){ double radians, zRatio; int index, z, x, y; int T, L, H, W; /* top, width, height, width */ *pathBuffer = 0; for (index = 0; index < numSteps; index++) { radians = TWO_PI * index / numSteps; x = radius * cos(radians); y = radius * sin(radians); z = x + radius; zRatio = minZRatio + (maxZRatio - minZRatio) * z / (2 * radius); L = x + xCenter; T = y + yCenter; H = height * zRatio; W = width * zRatio; pathBuffer += sprintf(pathBuffer, "(T=%d, L=%d, H=%d, W=%d) ", T, L, H, W); }} /************************************************************************************/ /* Generates a diagonal path string with a small amount of acceleration. */void GenerateRocketPath(void){ int index; int x = -32, y = 350; /* start off bottom left edge */ double vX = .8, vY = -1; double accel = 1.1; char *path = rocketPath; for (index = 0; index < NUM_ROCKET_STEPS; index++) { path += sprintf(path, "(T=%d, L=%d) ", y, x); x += vX; y += vY; vX = Min(9, vX * accel); vY = Max(-8, vY * accel); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -