//withMouse2 // mouse operation for object motion // T. Kosaka CS TNCT 16Aug2002 #include #include #include #include "GLDrawingtool3D.h" #ifndef M_PI #define M_PI 3.141592653589793 #endif GLfloat light0pos[] = { 500.0, 500.0, 1500.0, 0.0 }; // x,y,z,d GLfloat White[] = { 1.0, 1.0, 1.0, 1.0 }; // R,G,B,A GLfloat Black[] = { 0.0, 0.0, 0.0, 1.0 }; // R,G,B,A GLfloat Brown[] = { 0.3, 0.25, 0.0, 1.0 }; // R,G,B,A GLfloat Gray[] = { 0.4, 0.4, 0.4, 1.0 }; // R,G,B,A GLfloat CupColor[] = { 0.7, 0.7, 0.9, 1.0 }; // R,G,B,A GLfloat TeapotColor[] = { 0.7, 0.7, 0.4, 1.0 }; // R,G,B,A GLfloat TableColor[] = { 0.5, 0.4, 0.0, 1.0 }; // R,G,B,A GLfloat Red[] = { 1.0, 0.0, 0.0, 1.0 }; // R,G,B,A GLfloat Shine[] = { 100.0}; //0.0(large highlight) ... 128.0(small highlight) void userdraw(void); void display(void) { glClear( GL_COLOR_BUFFER_BIT); glClear(GL_DEPTH_BUFFER_BIT); // depth check userdraw(); glutSwapBuffers(); } ////////////////////////////////////////////////////////////////// point3D_t p0,p1; int active=0; // 0:nothing 1:press 2:draging 3:release void onMouseButton(int button, int state, int x_got, int y_got) { if (button==GLUT_LEFT_BUTTON) { if (state==GLUT_DOWN) { p0.x=x_got-320; // device coordinate -> view coordinate p0.y=240-y_got-1; // device coordinate -> view coordinate if (p0.x!=0 || p0.y!=0) { active=1; } } else { active=3; } } } void onDrag(int x_got, int y_got) { p1.x=x_got-320; // device coordinate -> view coordinate p1.y=240-y_got-1; // device coordinate -> view coordinate active=2; } ////////////////////////////////////////////////////////////////// void myInitView(void) { static float leyetmp=700.0; static float leye; static float rottmp=0.5;//rot[rad] static float rot; float alpha; if (active==2) { leye=leyetmp-(p1.y-p0.y); rot=rottmp-0.01*(p1.x-p0.x); if (1300.