//MouseMotion // Drawing polyline // glutMotionFunc(onDrag); // mouse drag event call back // void onDrag(int x, int y_inv) // T. Kosaka CS TNCT 2001 #include #include #include #include "drawShape2D.h" void userdraw(void); void display(void) { glClear( GL_COLOR_BUFFER_BIT); userdraw(); glutSwapBuffers(); } int NumberofPoints=1; point2D_t PointBuffer[4096]={{0,0}}; int drag=0; point2D_t CurrentPoint; void onMouseButton(int button, int state, int x, int y_inv) { int y=480-y_inv-1; // device coordinate -> view coordinate switch (button) { case GLUT_LEFT_BUTTON: if (state == GLUT_UP && NumberofPoints!=4096) { PointBuffer[NumberofPoints].x=x; PointBuffer[NumberofPoints].y=y; NumberofPoints++; drag=0; } break; case GLUT_MIDDLE_BUTTON: // do nothing break; case GLUT_RIGHT_BUTTON: // do nothing break; default: break; } } //マウスがドラッグされた時に呼び出される関数 void onDrag(int x, int y_inv) { int y=480-y_inv-1; // device coordinate -> view coordinate drag=1; CurrentPoint.x=x; CurrentPoint.y=y; } void userdraw(void) { int i; color_t white={1.,1.,1.}; color_t cyan={0.,1.,1.}; setColor(white); if (1