//providedObjects // introduction of the objects provided by GLU and GLUT library // 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 Cyan[] = { 0.0, 1.0, 1.0, 1.0 }; // R,G,B,A GLfloat Gray[] = { 0.3, 0.3, 0.3, 1.0 }; // R,G,B,A GLfloat Red[] = { 1.0, 0.0, 0.0, 1.0 }; // R,G,B,A GLfloat Shine[] = { 20.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(); } ////////////////////////////////////////////////////////////////// void userdraw(void) { static int tick=0; int mode=(tick/100)%2; float interval=35; if (mode) { myInitView(0); } else { myInitView(1); glMaterialfv(GL_FRONT, GL_AMBIENT, Gray); //Attribute glMaterialfv(GL_FRONT, GL_DIFFUSE, Cyan); glMaterialfv(GL_FRONT, GL_SPECULAR, White); glMaterialfv(GL_FRONT, GL_SHININESS, Shine); glShadeModel(GL_SMOOTH); } glRotatef(2*tick,0,1,0); //cube glPushMatrix(); glTranslatef(200,0,0); glRotatef(10*tick,0,1,0); if (mode) glutWireCube(60); else glutSolidCube(60); glPopMatrix(); glRotatef(interval,0,1,0); //Tetrahedron glPushMatrix(); glTranslatef(200,0,0); glRotatef(10*tick,0,1,0); glScalef(50,50,50); if (mode) glutWireTetrahedron(); else glutSolidTetrahedron(); glPopMatrix(); glRotatef(interval,0,1,0); //Octahedron glPushMatrix(); glTranslatef(200,0,0); glRotatef(10*tick,0,1,0); glScalef(50,50,50); if (mode) glutWireOctahedron(); else glutSolidOctahedron(); glPopMatrix(); glRotatef(interval,0,1,0); //Dodecahedron glPushMatrix(); glTranslatef(200,0,0); glRotatef(10*tick,0,1,0); glScalef(25,25,25); if (mode) glutWireDodecahedron(); else glutSolidDodecahedron(); glPopMatrix(); glRotatef(interval,0,1,0); //Icosahedron glPushMatrix(); glTranslatef(200,0,0); glRotatef(10*tick,0,1,0); glScalef(40,40,40); if (mode) glutWireIcosahedron(); else glutSolidIcosahedron(); glPopMatrix(); glRotatef(interval,0,1,0); //Sphere glPushMatrix(); glTranslatef(200,0,0); glRotatef(10*tick,0,1,0); if (mode) glutWireSphere(40,36,18); else glutSolidSphere(40,36,18); glPopMatrix(); glRotatef(interval,0,1,0); //Torus glPushMatrix(); glTranslatef(200,0,0); glRotatef(10*tick,0,1,0); if (mode) glutWireTorus(15,30,16,40); else glutSolidTorus(15,30,16,40); glPopMatrix(); glRotatef(interval,0,1,0); //Teapot glPushMatrix(); glTranslatef(200,0,0); glRotatef(10*tick,0,1,0); if (mode) glutWireTeapot(50); else glutSolidTeapot(50); glPopMatrix(); glRotatef(interval,0,1,0); //Cylinder glPushMatrix(); glTranslatef(200,0,0); glRotatef(10*tick,0,1,0); { GLUquadricObj *qobj=gluNewQuadric(); if (mode) gluQuadricDrawStyle(qobj,GLU_LINE); else gluQuadricDrawStyle(qobj,GLU_FILL); gluCylinder(qobj,20.1,30.1,50,20,10); } glPopMatrix(); glRotatef(interval,0,1,0); //Cone glPushMatrix(); glTranslatef(200,0,0); glRotatef(10*tick,0,1,0); if (mode) glutWireCone(50,40,20,10); else glutSolidCone(50,40,20,10); glPopMatrix(); tick++; } int main(int argc, char **argv) { glutInit(&argc,argv); glutInitDisplayMode ( GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); // depth check glutInitWindowPosition(100,100); glutInitWindowSize(640,480); glutCreateWindow ("cube"); glClearColor(0.0, 0.0, 0.0, 0.0); glViewport(0,0,640,480); glutIdleFunc(display); // idle event call back glutDisplayFunc(display); glEnable(GL_DEPTH_TEST); // depth check (OpenGL inner Z-Buffer) glutMainLoop(); return 0; }