/* Auteur: Nicolas JANEY */ /* nicolas.janey@univ-fcomte.fr */ /* Novembre 2007 */ /* Module de dessin des spheres */ #include #include #include #include #include #include "ModuleSpheres.h" #ifndef M_PI #define M_PI 3.14159265358979323846264338327950288 #endif void mySolidSphere(float rayon,int nlat,int nlon) { for ( int i = 0 ; i < nlat ; i++ ) { float a1 = -M_PI/2.0F + i*M_PI/nlat ; float a2 = a1 + M_PI/nlat ; float cs1 = cos(a1); float cs2 = cos(a2); float sn1 = sin(a1); float sn2 = sin(a2); glBegin(GL_QUAD_STRIP); for ( int j = 0 ; j <= nlon ; j++ ) { float a = j*2*M_PI/nlon; float x1 = cs1*cos(a); float z1 = cs1*sin(a); float x2 = cs2*cos(a); float z2 = cs2*sin(a); glNormal3f(x1,sn1,z1); glVertex3f(rayon*x1,rayon*sn1,rayon*z1); glNormal3f(x2,sn2,z2); glVertex3f(rayon*x2,rayon*sn2,rayon*z2); } glEnd(); } }