//polyhedron // Demonstration of shading and lighting with moving dodecahedron and icosahedron // flat shading // 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.15, 0.15, 0.15, 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(); } static void makeDodecahedron(polyhedron_t &dodecahedron,float size) { // size : an edge length of the dodecahedron float theta=2.0/5.0*M_PI;// 2 Pi/5 a central angle of the pentagon float alpha=3.0/5.0*M_PI;// an interior angle of the pentagon float r0; // a radius of an inscribed circle float r1; // a radius of a circumscribed circle float s1; // a length of a diagonal line of the pentagon float r2; // a radius of a circumscribed circle of the pentagon whose edge length is equal to s1 float h1,h2,h; // heights of the dodecahedron float r[4],th0[4],ha[4]; int i,j,k; float th; face_t face[]={ {5,{0,1,2,3,4}},{5,{0,5,10,6,1}},{5,{1,6,11,7,2}}, {5,{2,7,12,8,3}},{5,{3,8,13,9,4}},{5,{4,9,14,5,0}}, {5,{10,15,16,11,6}},{5,{11,16,17,12,7}},{5,{12,17,18,13,8}}, {5,{13,18,19,14,9}},{5,{14,19,15,10,5}},{5,{15,19,18,17,16}} }; // every face has five vertices and showing vertex numbers vector3D_t vecbuff[4]; dodecahedron.NumberofVertices=20; r1=size/(2.0*sin(theta/2.0)); r0=r1*cos(theta/2.0); s1=2.0*size*sin(alpha/2.0); r2=s1/(2.0*sin(theta/2.0)); h1=sqrt(size*size-(r2-r1)*(r2-r1)); h2=sqrt((r0+r1)*(r0+r1)-(r2-r0)*(r2-r0)); h=h1+h2; r[0]=r1; th0[0]=0.0; ha[0]=h-0.5*h; r[1]=r2; th0[1]=0.0; ha[1]=h2-0.5*h; r[2]=r2; th0[2]=0.2*M_PI; ha[2]=h1-0.5*h; r[3]=r1; th0[3]=0.2*M_PI; ha[3]=0.0-0.5*h; for (i = 0; i<4; i++){ for (j = 0; j<5; j++){ th=0.4*M_PI*(float)j+th0[i]; k=5*i+j; dodecahedron.pnt[k].z=-r[i]*sin(th); dodecahedron.pnt[k].x=r[i]*cos(th); dodecahedron.pnt[k].y=ha[i]; } } dodecahedron.NumberofFaces=12; for (i = 0; i