//hitKey // Drawing a circle at the position of the pointer when key 'A' is hit. // Drawing a square at the position of the pointer when key 'B' is hit. // glutKeyboardFunc(onKeyboard); // keyboard event call back // void onKeyboard(unsigned char key, int x, int y_inv) // T. Kosaka CS TNCT 2001 #include #include #include #include "drawShape2D.h" #ifndef M_PI #define M_PI 3.141592653589793 #endif void userdraw(void); void display(void) { glClear( GL_COLOR_BUFFER_BIT); userdraw(); glutSwapBuffers(); } unsigned int GlobalTick=1000; point2D_t CurrentPoint; int circle; void onKeyboard(unsigned char key, int x, int y_inv) { int y=480-y_inv-1; // device coordinate -> view coordinate switch (key) { case 'A': case 'a': GlobalTick=10; CurrentPoint.x=x; CurrentPoint.y=y; circle=1; break; case 'B': case 'b': GlobalTick=10; CurrentPoint.x=x; CurrentPoint.y=y; circle=0; break; default: break; } } void userdraw(void) { float r; int num; int i; color_t cyan={0.,1.,1.}; point2D_t p[600]; if (GlobalTick<400) { r=GlobalTick; if (circle==1) { num=GlobalTick/20+30; } else { num=4; } for (i=0;i