//torussphere // Demonstration of shading and lighting with moving sphere and torus // mesh models // smooth shading // T. Kosaka CS TNCT 16Aug2002 #include #include #include #include "GLDrawingtool3D.h" #ifndef M_PI #define M_PI 3.141592653589793 #endif 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.2, 0.2, 0.2, 1.0 }; // R,G,B,A GLfloat Red[] = { 1.0, 0.0, 0.0, 1.0 }; // R,G,B,A GLfloat Shine[] = { 20.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 makeSphereGL(smoothpolyhedron_t &sphere,float r) { // r : radius of the sphere float latitude; float longitude; int NumLatEdge=18; int NumLngEdge=32; int i,j,k; vector3D_t unitz={0,0,1,1}; vector3D_t unityn={0,1,0,1}; vector3D_t unitys={0,-1,0,1}; matrix3D_t mat; vector3D_t vecbuff[4]; sphere.NumberofVertices=1+(NumLatEdge-1)*NumLngEdge+1; sphere.NormalVector[0]=unityn; sphere.pnt[0]=Vector2Point(r*sphere.NormalVector[0]); for(i=1;i