//cube with CLASS // showing cube0 ..... cube5 // T. Kosaka CS TNCT 7Aug2002 #include #include #include #include "CGCore3D.h" void userdraw(void); void display(void) { glClear( GL_COLOR_BUFFER_BIT); userdraw(); glutSwapBuffers(); } ////////////////////////////////////////////////////////////////// void makeCube(C_Polyhedron &cube,float size,C_Color color,opticalAttribute_t attr) { float vertex0[][3]={// coordinates of the vertices of the cube {1,1,1},{1,1,-1},{-1,1,-1},{-1,1,1}, {1,-1,1},{1,-1,-1},{-1,-1,-1},{-1,-1,1} }; int vertexnumber[][4]={// every face has four vertices and showing vertex numbers {0,1,2,3},{0,4,5,1},{1,5,6,2}, {2,6,7,3},{3,7,4,0},{7,6,5,4} }; C_Vertex vertex[8]; C_Face face[6]; C_Color Cyan(0,1,1); int i; for (i=0;i<8;i++) { vertex[i].x=size*vertex0[i][0]; vertex[i].y=size*vertex0[i][1]; vertex[i].z=size*vertex0[i][2]; } for (i=0;i<6;i++) face[i].createFace(vertexnumber[i],4); cube.createPolyhedron(vertex,8,face,6,color,attr); } void userdraw(void) { static int tick=0; int disp=(tick/200)%2; static C_Polyhedron cube; float phi=0.5; // for tilting float theta=-0.5; // for tilting C_Vector ViewVector(0,0,1); C_Vector LightVector(0,1,0); C_Scene myScene; if (tick==0) { opticalAttribute_t attr; C_Color Cyan(0,1,1); attr.kspe=0.7; // specular reflection coefficient attr.kdif=0.6; // diffuse reflection coefficient attr.kamb=0.4; // ambient light coefficient makeCube(cube,100,Cyan,attr); } myScene.drawAxes(); myScene.initializeTMatrix(); myScene.setRotationY(0.02*tick); if (disp==0) myScene.drawPolyhedronWire(cube); else myScene.drawPolyhedronSurface(cube); tick++; } int main(int argc, char **argv) { glutInit(&argc,argv); glutInitDisplayMode ( GLUT_DOUBLE | GLUT_RGB ); glutInitWindowPosition(100,100); glutInitWindowSize(640,480); glutCreateWindow ("cube"); glClearColor(0.0, 0.0, 0.0, 0.0); gluOrtho2D(-320., 320., -240.0, 240.0); // Define the dimensions of the Orthographic Viewing Volume glutIdleFunc(display); // idle event call back glutDisplayFunc(display); glutMainLoop(); return 0; }