/* Auteur: Nicolas JANEY */
/* nicolas.janey@univ-fcomte.fr */
/* Fevrier 2002 */
/* L'animation en OpenGL */
#include <stdio.h>
#include <math.h>
#include <GL/glut.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include "ModuleCouleurs.h"
#include "ModuleMenus.h"
#include "ModuleManipulateur.h"
#include "ModuleReshape.h"
static float r1 = 0.0F;
static int anim = 1;
void myinit(void) {
GLfloat mat_shininess[] = { 50.0 };
GLfloat light0_position[] = { 1.0,1.0,1.0,0.0 };
GLfloat light1_position[] = { -1.0,1.0,1.0,0.0 };
GLfloat light2_position[] = { 1.0,-1.0,1.0,0.0 };
glMaterialfv(GL_FRONT,GL_SPECULAR,couleurBlanc());
glMaterialfv(GL_FRONT,GL_SHININESS,mat_shininess);
glLightfv(GL_LIGHT0,GL_DIFFUSE,couleurRouge());
glLightfv(GL_LIGHT1,GL_DIFFUSE,couleurVert());
glLightfv(GL_LIGHT2,GL_DIFFUSE,couleurBleu());
glLightfv(GL_LIGHT0,GL_POSITION,light0_position);
glLightfv(GL_LIGHT1,GL_POSITION,light1_position);
glLightfv(GL_LIGHT2,GL_POSITION,light2_position);
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);
}
void display(void) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
manipulateurSouris();
manipulateurClavier();
glRotatef(r1,0.0F,1.0F,0.0F);
float rx = 1.3*(1.0F-fabs(r1-180.0F)/180.0F);
glScalef(1.0F+rx,1.0F,1.0F);
glutSolidTorus(2.7, 7.0,24,36);
glPopMatrix();
glFlush();
glutSwapBuffers();
}
void idle(void) {
r1 += 1.0F ;
if ( r1 >= 360.0F )
r1 = 0.0F;
glutPostRedisplay() ;
}
void key(unsigned char key,int x,int y) {
if ( keyManipulateur(key,x,y) )
glutPostRedisplay();
else
switch ( key ) {
case 32 : anim = !anim ;
glutIdleFunc((anim) ? idle : NULL);
glutPostRedisplay();
break ; }
}
int main(int argc,char **argv) {
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_RGBA|GLUT_DEPTH|GLUT_DOUBLE);
glutInitWindowSize(400,200);
glutInitWindowPosition(50,50);
glutCreateWindow("Un tore en rotation");
myinit();
creationMenuBasique();
setParametresOrthoBasique(-12.0,12.0,-12.0,12.0,-500.0,500.0);
setManipulateurDistance(1.0F);
glutReshapeFunc(reshapeOrthoBasique);
glutKeyboardFunc(key);
glutSpecialFunc(specialBasique);
glutMotionFunc(motionBasique);
glutMouseFunc(sourisBasique);
glutIdleFunc(idle);
glutDisplayFunc(display);
glutMainLoop();
return(0);
}