// torus with class // face z-sorting to draw faces // In the case of a red torus, no face z-sorting technique is used and // failed to complete the torus. // T. Kosaka CS TNCT 2001 #include #include #include #include "CGCore3D.h" #ifndef M_PI #define M_PI 3.141592653589793 #endif void userdraw(void); void display(void) { glClear( GL_COLOR_BUFFER_BIT); userdraw(); glutSwapBuffers(); } ////////////////////////////////////////////////////////////////// static void makeTorus(C_Smoothpolyhedron &torus,float r0,float r1,int NumCclEdge,int NumRngEdge,C_Color color,opticalAttribute_t attr) { // r0 : radius of the circle // r1 : radius of the ring // NumCclEdge : number of segments along the circle // NumRngEdge : number of segments along the ring int NumberVertices; //多面体を構成する頂点の数 C_Vertex *Vertex; //多面体を構成する頂点の座標 C_Vector *NormalVector; //各擬似頂点位置の法線ベクトル int NumberFaces; //多面体を構成する面の数 C_Face *Face; //多面体を構成する面の定義 float circleangle; float ringangle; int i,j,k; C_Vertex unitx(1,0,0); C_Vertex vec; C_Matrix mat,mat1,mat2,mat3; NumberVertices=NumCclEdge*NumRngEdge; Vertex=new C_Vertex[NumberVertices]; NormalVector=new C_Vector[NumberVertices]; mat1.setScale(r0,r0,r0); mat2.setTranslation(r1,0,0); mat=mat2*mat1; for(j=0;j