/* Auteur: Nicolas JANEY */ /* nicolas.janey@univ-fcomte.fr */ /* Septembre 2008 */ /* Simulation d'un accelerateur de particules */ /* avec cubes modelises par facettes */ #include #include #include #include #include /* Variables et constantes globales */ static const float blanc[] = { 1.0F,1.0F,1.0F,1.0F }; static const float rouge[] = { 1.0F,0.0F,0.0F,1.0F }; static const float vert[] = { 0.0F,1.0F,0.0F,1.0F }; static const float bleu[] = { 0.0F,0.0F,1.0F,1.0F }; static int n = 10; /* Fonction d'initialisation des parametres */ /* OpenGL ne changeant pas au cours de la vie */ /* du programme */ void init(void) { const GLfloat mat_shininess[] = { 50.0 }; glMaterialfv(GL_FRONT,GL_SPECULAR,blanc); glMaterialfv(GL_FRONT,GL_SHININESS,mat_shininess); glLightfv(GL_LIGHT0,GL_DIFFUSE,rouge); glLightfv(GL_LIGHT1,GL_DIFFUSE,vert); glLightfv(GL_LIGHT2,GL_DIFFUSE,bleu); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glEnable(GL_LIGHT1); glEnable(GL_LIGHT2); glDepthFunc(GL_LESS); glEnable(GL_DEPTH_TEST); glEnable(GL_NORMALIZE); glEnable(GL_AUTO_NORMAL); glEnable(GL_CULL_FACE); } /* Scene dessinee */ void box2(float tx,float ty,float tz) { glPushMatrix(); glScalef(tx,ty,tz); glutSolidCube(1.0); glPopMatrix(); } void box(float tx,float ty,float tz) { tx /= 2.0F; ty /= 2.0F; tz /= 2.0F; glPushMatrix(); glBegin(GL_QUADS); glNormal3f(1.0F,0.0F,0.0F); glVertex3f(tx,-ty,-tz); glVertex3f(tx,ty,-tz); glVertex3f(tx,ty,tz); glVertex3f(tx,-ty,tz); glNormal3f(-1.0F,0.0F,0.0F); glVertex3f(-tx,-ty,tz); glVertex3f(-tx,ty,tz); glVertex3f(-tx,ty,-tz); glVertex3f(-tx,-ty,-tz); glNormal3f(0.0F,1.0F,0.0F); glVertex3f(tx,ty,tz); glVertex3f(tx,ty,-tz); glVertex3f(-tx,ty,-tz); glVertex3f(-tx,ty,tz); glNormal3f(0.0F,-1.0F,0.0F); glVertex3f(-tx,-ty,tz); glVertex3f(-tx,-ty,-tz); glVertex3f(tx,-ty,-tz); glVertex3f(tx,-ty,tz); glNormal3f(0.0F,0.0F,1.0F); glVertex3f(-tx,ty,tz); glVertex3f(-tx,-ty,tz); glVertex3f(tx,-ty,tz); glVertex3f(tx,ty,tz); glNormal3f(0.0F,0.0F,-1.0F); glVertex3f(tx,-ty,-tz); glVertex3f(-tx,-ty,-tz); glVertex3f(-tx,ty,-tz); glVertex3f(tx,ty,-tz); glEnd(); glPopMatrix(); } void scene(int n) { double a = 2*3.14159/n; double cs = 1.0-cos(a); double sn = sin(a); double d = 10*sqrt(cs*cs+sn*sn); glPushMatrix(); for( int i=0 ; i