// J-Building0 with mouse operation // T. Kosaka CS TNCT 25Aug2003 #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 LightBlue[] = { 0.8, 0.8, 1.0, 1.0 }; // R,G,B,A GLfloat Gray[] = { 0.4, 0.4, 0.4, 1.0 }; // R,G,B,A GLfloat LightGray[] = { 0.9, 0.9, 0.9, 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 diptmp=0.70;//dip[rad] static float dip; static float rottmp=0.5;//rot[rad] static float rot; if (active==2) { dip=diptmp-0.003*(p1.y-p0.y); rot=rottmp-0.003*(p1.x-p0.x); if (0.4999*M_PI