//polyhedron (dancing dodecahedron and icosahedron) // the order of drawing objects // T. Kosaka CS TNCT 2001 #include #include #include #include "drawtools3D.h" #ifndef M_PI #define M_PI 3.141592653589793 #endif void userdraw(void); void display(void) { glClear( GL_COLOR_BUFFER_BIT); userdraw(); glutSwapBuffers(); } ////////////////////////////////////////////////////////////////// void drawcharX(float x,float y) { drawLine(x,y,x+10,y+12);drawLine(x,y+12,x+10,y); } void drawcharY(float x,float y) { drawLine(x+5,y,x+5,y+7);drawLine(x,y+12,x+5,y+7);drawLine(x+10,y+12,x+5,y+7); } void drawcharZ(float x,float y) { drawLine(x,y+12,x+10,y+12);drawLine(x+10,y+12,x,y);drawLine(x,y,x+10,y); } void drawAxes(matrix3D_t view) { #define HALFAXIS 220 #define HALFAXIS1 (HALFAXIS-10) point3D_t axes[14]={ {-HALFAXIS,0,0},{HALFAXIS,0,0},{HALFAXIS1,5,0},{HALFAXIS1,0,0},{0,0,0}, {0,-HALFAXIS,0},{0,HALFAXIS,0},{0,HALFAXIS1,5},{0,HALFAXIS1,0},{0,0,0}, {0,0,-HALFAXIS},{0,0,HALFAXIS},{5,0,HALFAXIS1},{0,0,HALFAXIS1} }; vector3D_t vec[14]; int i; for (i=0;i<14;i++) { vec[i]=Point2Vector(axes[i]); vec[i]=view*vec[i]; } drawPolyline(vec,14); drawcharX(vec[1].v[0],vec[1].v[1]); drawcharY(vec[6].v[0],vec[6].v[1]); drawcharZ(vec[11].v[0]-14,vec[11].v[1]); } ////////////////////////////////////////////////////////////////// typedef struct { int NumberofVertices; //in the face short int pnt[32]; } face_t; typedef struct { int NumberofVertices; //of the object point3D_t pnt[100]; int NumberofFaces; //of the object face_t fc[32]; } polyhedron_t; 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 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