/***************************************************************************** Main Program for CS480 Programming Assignment 2 ****************************************************************************** Author: Stan Sclaroff Boston University Computer Science Dept. February 15, 1995 ****************************************************************************** Description: This is the main program for the transformer program assignment. It opens a GL window in double buffer mode, and opens a slider menu for controlling the transforms. The user interface is through a separate slider menu which controls the rotation, translation, scaling, shearing, bending of a shape that's been defined as a polyline. There are also three main buttons on the slider menu: RESET SLIDERS: sets sliders all to default values and redraw. PLAY: This button is provided for you to play your animation. QUIT: This button allows you to exit. In addition, there are separate reset buttons for each slider. ****************************************************************************** Comments: This program has an optional command-line argument for specifying a polyline text file. For instance, typing animate figure.poly will load in the polylines contained in the text file "figure.poly" ******************************************************************************/ #include #include #include #include #include #include "forms.h" #include "menu.h" #include "draw.h" /* global variables !!! These are used by the menu call backs */ Polyline *figure; /* the polyline figure drawn */ Frame *frame; /* the rectangular clipping frame */ long winid; /* the drawing window id */ /* these globals are for the sliders themselves */ float slider_values[NUM_SLIDERS] = {0.0,0.0,0.0,100.0,100.0, 0.0,0.0,0.0,0.0}; /* the slider default values */ float slider_default_values[NUM_SLIDERS] = {0.0,0.0,0.0,100.0,100.0, 0.0,0.0,0.0,0.0}; /* the slider min/max values */ float slider_min_values[NUM_SLIDERS] = {0.0, -SCREEN_WIDTH/2,-SCREEN_HEIGHT/2, 0.0,0.0, -5.0,-5.0, -5.0,-5.0}; float slider_max_values[NUM_SLIDERS] = {360.0, SCREEN_WIDTH/2,SCREEN_HEIGHT/2, SCREEN_WIDTH,SCREEN_HEIGHT, 5.0,5.0, 5.0,5.0}; /* the animation tool's main program */ main(argc, argv) int argc; char **argv; { int i,j; float w,h,min_x,min_y,max_x,max_y,x,y; Device event; Screencoord mouse_pos[2]; /* a polyline file can be specified as an input argument */ if(argc > 1) figure = read_polyline_file(argv[1],YELLOW); /* if none is provided, use default: a box */ else figure = read_polyline_file("box.poly",YELLOW); /* failed to open a polyline file, so close up */ if(figure == 0) exit(EXIT_SUCCESS); /* create the clipping frame */ frame = create_frame((float)FRAME_XMIN,(float)FRAME_YMIN,(float)FRAME_XMAX,(float)FRAME_YMAX,RED); /* open the menu forms: slider window */ create_the_forms(); /* open the GL graphics window */ winid = open_window(SCREEN_WIDTH,SCREEN_HEIGHT,"Animation Window"); /* set up the sliders on the slider menu and then activate them */ setup_sliders(); activate_forms(); /* first time around draw twice: once to the front buffer and then once to the back buffer...this buffer switching happens automatically */ redraw(winid,figure,slider_values,frame); redraw(winid,figure,slider_values,frame); /* the inner loop: let the slider menu take control */ do fl_check_forms(); while(TRUE); } /* the call back routine for playing an animation */ /* this routine gets called every time the "play" button */ /* on the menu is pressed */ #define T_STEP 0.1 #define TOLERANCE 0.001 #define DAMPING_FACTOR 0.04 #define AMPLITUDE 5.0 void playCB(obj,arg) FL_OBJECT *obj; long arg; { float theta,val,t,dt,d_theta,vale; int i; for(i=0;iTOLERANCE;t+=dt,theta+=d_theta) { val = AMPLITUDE*cos(t)*exp(-t*t*DAMPING_FACTOR); slider_values[BEND_Y] = val; slider_values[TRANSLATE_Y] += val; redraw(winid,figure,slider_values,frame); } } /* the call back routine for quiting the program */ /* gets called when the quit button is pushed */ void quitCB(obj,arg) FL_OBJECT *obj; long arg; { /* cleanup */ free_polyline(figure); free_frame(frame); close_window(winid); exit(EXIT_SUCCESS); } /* this routine sets up the sliders default and min/max values */ void setup_sliders() { int i; /* set each slider's default value and min/max */ for(i=0;i