//cube // Demonstration of Rotation Transformation // Culling back face of the three dimentional object // This enables the OpenGL system to draw quickly. // T. Kosaka CS TNCT 2001 #include #include #include #include "GLDrawingtool3D.h" #ifndef M_PI #define M_PI 3.141592653589793 #endif void userdraw(void); void display(void) { glClear( GL_COLOR_BUFFER_BIT); glClear(GL_DEPTH_BUFFER_BIT); // depth check userdraw(); glutSwapBuffers(); } void userdraw(void) { static int tick=0; int disp=(tick/200)%10; int tickindisp=tick%200; float k1=tickindisp/200.; float k2; int i,j; myInitView(0); color_t color[]= { { 1.0, 0.0, 0.0 }, /* Red */ { 0.0, 0.9, 0.0 }, /* Green */ { 0.0, 0.0, 1.0 }, /* Blue */ { 0.7, 0.7, 0.0 }, /* Brown */ { 1.0, 0.0, 1.0 }, /* Magenta */ { 0.0, 0.8, 0.8 } /* Dark Cyan @*/ }; polyhedron_t cube={ 8, //number of vertices of the cube { {50,50,50},{50,50,-50},{-50,50,-50},{-50,50,50}, {50,-50,50},{50,-50,-50},{-50,-50,-50},{-50,-50,50} }, // coordinates of the vertices of the cube 6, // number of faces of the cube { {4,{0,1,2,3}},{4,{0,4,5,1}},{4,{1,5,6,2}}, {4,{2,6,7,3}},{4,{3,7,4,0}},{4,{7,6,5,4}} } // every face has four vertices and showing vertex numbers }; point3D_t pntbuff[8]; switch(disp) { case 0: glRotatef(k1*360.0, 1.0, 0.0, 0.0); //angle[deg],x,y,z break; case 1: glRotatef(k1*360.0, 0.0, 1.0, 0.0); //angle[deg],x,y,z break; case 2: glRotatef(k1*360.0, 0.0, 0.0, 1.0); //angle[deg],x,y,z break; case 3: glTranslatef(k1*200.0, 0.0, 0.0); break; case 4: glRotatef(k1*360.0, 0.0, 1.0, 0.0); // Matrix A glTranslatef(200.0, 0.0, 0.0); // Matrix B // Then the composit matrix is A*B break; case 5: glRotatef(k1*360.0, 0.0, 1.0, 0.0); // Matrix A glTranslatef(200.0, 0.0, 0.0); // Matrix B glRotatef(k1*360.0, 0.0, 0.0, 1.0); // Matrix C // Then the composit matrix is A*B*C break; case 6: glRotatef(k1*360.0, 0.0, 1.0, 0.0); // Matrix A glTranslatef(200.0, 0.0, 0.0); // Matrix B glRotatef(k1*360.0, 0.0, 0.0, 1.0); // Matrix C k2=1.+0.3*sin(4*M_PI*k1); glScalef(k2,k2,k2); // Matrix D // Then the composit matrix is A*B*C*D break; case 7: glTranslatef((1.-k1)*200.0, 0.0, 0.0); break; case 8: glTranslatef(50.0, 0.0, 50.0); // Matrix A glRotatef(k1*360.0, 0.0, 1.0, 0.0); // Matrix B glTranslatef(-50.0, 0.0, -50.0); // Matrix C // Then the composit matrix is A*B*C break; case 9: glTranslatef(-50.0, 0.0, -50.0); // Matrix A glRotatef(k1*360.0, 0.0, 1.0, 0.0); // Matrix B glTranslatef(50.0, 0.0, 50.0); // Matrix C // Then the composit matrix is A*B*C break; default: break; } glEnable(GL_CULL_FACE); // Cull back face glCullFace(GL_BACK); // Cull back face for (i=0;i