/* Variables globales */
static float r0 = 0.0F;
static float rx = 0.0F;
static int affichageTrajectoire = 0;
static int rotationElectrons = 1;
static int mode = 1;
static float positionAngulaire = 0.0F;
static float delta = 3.0F;
/* Scene dessinee */
static void electron(float inclinaison,float positionAngulaire,int trajectoire) {
glPushMatrix();
glRotatef(inclinaison,0.0F,0.0F,1.0F);
if ( trajectoire ) {
glPushMatrix();
glRotatef(90.0F,1.0F,0.0F,0.0F);
glutSolidTorus(0.05,7.0,24,90);
glPopMatrix(); }
glRotatef(positionAngulaire,1.0F,0.0F,0.0F);
glTranslatef(0.0F,7.0F,0.0F);
glutSolidSphere(0.5,36,36);
glPopMatrix();
}
static void scene(void) {
glPushMatrix();
glPushMatrix();
glTranslatef(0.0F,1.0F,0.0F);
glutSolidSphere(1.0,36,36);
glPopMatrix();
glPushMatrix();
glTranslatef(0.0F,-1.0F,0.0F);
glutSolidSphere(1.0,36,36);
glPopMatrix();
glPushMatrix();
glTranslatef(1.732F,0.0F,0.0F);
glutSolidSphere(1.0,36,36);
glPopMatrix();
glPushMatrix();
glTranslatef(-1.732F,0.0F,0.0F);
glutSolidSphere(1.0,36,36);
glPopMatrix();
electron(45.0F,positionAngulaire,affichageTrajectoire);
electron(-45.0F,positionAngulaire+180.0F,affichageTrajectoire);
glPopMatrix();
}
/* Fonction executee lors d'un rafraichissement */
/* de la fenetre de dessin */
static void display(void) {
glClearColor(0.5F,0.5F,0.5F,0.5F);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
const GLfloat light0_position[] = { 0.0,0.0,0.0,1.0 };
const GLfloat light1_position[] = { -1.0,1.0,1.0,0.0 };
const GLfloat light2_position[] = { 1.0,-1.0,1.0,0.0 };
glLightfv(GL_LIGHT0,GL_POSITION,light0_position);
glLightfv(GL_LIGHT1,GL_POSITION,light1_position);
glLightfv(GL_LIGHT2,GL_POSITION,light2_position);
glPushMatrix();
glRotatef(rx,1.0F,0.0F,0.0F);
glRotatef(r0,1.0F,1.0F,1.0F);
glPolygonMode(GL_FRONT_AND_BACK,(mode) ? GL_FILL : GL_LINE);
scene();
glPopMatrix();
glFlush();
glutSwapBuffers();
int error = glGetError();
if ( error != GL_NO_ERROR )
printf("Attention erreur %d\n",error);
}
/* Fonction executee lorsqu'aucun evenement */
/* n'est en file d'attente */
static void idle(void) {
r0 += 1.0F;
if ( rotationElectrons )
positionAngulaire += delta;
glutPostRedisplay();
}
/* Fonction executee lors de l'appui */
/* d'une touche alphanumerique du clavier */
static void keyboard(unsigned char key,int x,int y) {
switch (key) {
case 43 :
{ delta += 0.5F; }
break;
case 45 :
{ delta -= 0.5F; }
break;
case 0x0D :
{ static int anim = 0;
anim = !anim;
glutIdleFunc(( anim ) ? idle : NULL); }
break;
case 0x20 :
{ affichageTrajectoire = !affichageTrajectoire;
glutPostRedisplay(); }
break;
case 0x1B :
exit(0);
break; }
}
static void special(int code,int x,int y) {
switch (code) {
case GLUT_KEY_PAGE_DOWN :
{ rx += 1.0F ;
glutPostRedisplay(); }
break;
case GLUT_KEY_PAGE_UP :
{ rx -= 1.0F ;
glutPostRedisplay(); }
break; }
}
static void mouse(int button,int state,int x,int y) {
switch(button) {
case GLUT_LEFT_BUTTON :
if ( state == GLUT_UP )
rotationElectrons = !rotationElectrons;
glutPostRedisplay();
break;
case GLUT_RIGHT_BUTTON :
if ( state == GLUT_UP )
mode = !mode;
glutPostRedisplay();
break; }
}