//icosahedron // showing icosahedron rotating // T. Kosaka CS TNCT 2001 // icosahedron // showing icosahedron rotating // T. Kosaka CS TNCT 7Aug2002 #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 makeIcosahedron(polyhedron_t &icosahedron,float size) { // size : an edge length of the icosahedron float r1,r2,h1,h2,h3; float th0[2],h[2]; int i,j,k; float th; face_t face[]={ {3,{0,1,2}},{3,{0,2,3}},{3,{0,3,4}},{3,{0,4,5}},{3,{0,5,1}}, {3,{1,6,2}},{3,{2,7,3}},{3,{3,8,4}},{3,{4,9,5}},{3,{5,10,1}}, {3,{2,6,7}},{3,{3,7,8}},{3,{4,8,9}},{3,{5,9,10}},{3,{1,10,6}}, {3,{6,11,7}},{3,{7,11,8}},{3,{8,11,9}},{3,{9,11,10}},{3,{10,11,6}} }; // every face has five vertices and showing vertex numbers icosahedron.NumberofVertices=12; r1=size*0.5/tan(0.2*M_PI); // a radius of an inscribed circle of the triangle r2=size*0.5/sin(0.2*M_PI); // a radius of a circumscribed circle of the triangle h1=sqrt(size*size-r2*r2); // height of vertex 1 h2=h1+sqrt(3.0/4.0*size*size-(r2-r1)*(r2-r1));// height of vertex 1 h3=h1+h2; // height of the icosahedron icosahedron.pnt[0].z=0.0; icosahedron.pnt[0].x=0.0; icosahedron.pnt[0].y=h3-h3/2; icosahedron.pnt[11].z=0.0; icosahedron.pnt[11].x=0.0; icosahedron.pnt[11].y=0.0-h3/2; th0[0]=0.0; h[0]=h2; th0[1]=0.2*M_PI; h[1]=h1; for (i = 0; i<2; i++){ for (j = 0; j<5; j++){ th=0.4*M_PI*(float)j+th0[i]; k=5*i+j+1; icosahedron.pnt[k].z=-r2*sin(th); icosahedron.pnt[k].x=r2*cos(th); icosahedron.pnt[k].y=h[i]-h3/2; } } icosahedron.NumberofFaces=20; for (i = 0; i