Le source : TP-ToleOndulante.cpp
/* Auteur: Nicolas JANEY */
/* nicolas.janey@univ-fcomte.fr */
/* Fevrier 2003 */
/* Animation d'un maillage de facettes */
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <GL/glut.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include "ModuleMenus.h"
#include "ModuleReshape.h"
#include "ModuleManipulateur.h"
#include "ModuleCouleurs.h"
#ifndef M_PI
#define M_PI 3.14159
#endif
static int mode = 2;
static int disc = 100;
static float d = 0.0F;
static float larg = 20.0F;
static float fact = 1.0F;
static float factz = 1.0F;
void myinit(void) {
GLfloat shinines[] = { 50.0F };
glClearColor(0.5F,0.5F,0.8F,1.0F) ;
glMaterialfv(GL_FRONT,GL_DIFFUSE,couleurBlanc());
glMaterialfv(GL_FRONT,GL_SPECULAR,couleurGrisFonce());
glMaterialfv(GL_FRONT,GL_SHININESS,shinines);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_LIGHT1);
glEnable(GL_LIGHT2);
float dir0[4] = { 1.0F,1.0F,1.0F,0.0F };
glLightfv(GL_LIGHT0,GL_POSITION,dir0) ;
glLightfv(GL_LIGHT0,GL_DIFFUSE,couleurVert()) ;
float dir1[4] = { -1.0F,1.0F,1.0F,0.0F };
glLightfv(GL_LIGHT1,GL_POSITION,dir1) ;
glLightfv(GL_LIGHT1,GL_DIFFUSE,couleurBleu()) ;
float dir2[4] = { 0.0F,-1.0F,1.0F,0.0F };
glLightfv(GL_LIGHT2,GL_POSITION,dir2) ;
glLightfv(GL_LIGHT2,GL_DIFFUSE,couleurRouge()) ;
glEnable(GL_AUTO_NORMAL);
glEnable(GL_NORMALIZE);
glDepthFunc(GL_LESS);
glEnable(GL_DEPTH_TEST);
}
void display(void) {
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glPushMatrix();
manipulateurSouris();
manipulateurClavier();
switch ( mode ) {
case 0 : glPolygonMode(GL_FRONT_AND_BACK,GL_POINT);
break;
case 1 : glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);
break;
case 2 : glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
break; }
for ( int j = 0 ; j < 10 ; j++ ) {
glBegin(GL_QUAD_STRIP);
for ( int i = 0 ; i <= disc ; i++ ) {
float x = i*larg/disc - larg/2.0F;
float z = factz*sin(fact*x+d);
glNormal3f(-factz*fact*cos(fact*x+d),0.0F,1.0F);
glVertex3f(x,-4.0F+j,z);
glVertex3f(x,-5.0F+j,z);}
glEnd(); }
glPopMatrix();
glFlush();
glutSwapBuffers();
}
void key(unsigned char key,int x,int y) {
if ( keyManipulateur(key,x,y) )
glutPostRedisplay();
else
switch ( key ) {
case 43 : fact *= 1.1F;
glutPostRedisplay() ;
break ;
case 45 : fact /= 1.1F;
glutPostRedisplay() ;
break ;
case 'c' : factz *= 1.1F;
glutPostRedisplay() ;
break ;
case 'C' : factz /= 1.1F;
glutPostRedisplay() ;
break ;
case 'a' : disc++ ;
glutPostRedisplay() ;
break ;
case 'A' : disc-- ;
if ( disc < 3 )
disc = 3;
glutPostRedisplay() ;
break ;
case ' ' : mode = (mode+1)%3 ;
glutPostRedisplay() ;
break ; }
}
void idle(void) {
d -=0.05;
glutPostRedisplay();
}
int main(int argc,char **argv) {
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_RGBA|GLUT_DEPTH|GLUT_DOUBLE);
glutInitWindowSize(450,300);
glutInitWindowPosition(50,50);
glutCreateWindow("Animation d'un maillage de facettes");
myinit();
creationMenuBasique();
setParametresOrthoBasique(-10.0,10.0,-10.0,10.0,-500.0,500.0);
setManipulateurDistance(1.0F);
glutReshapeFunc(reshapeOrthoBasique);
glutKeyboardFunc(key);
glutIdleFunc(idle);
glutSpecialFunc(specialBasique);
glutMotionFunc(motionBasique);
glutMouseFunc(sourisBasique);
glutDisplayFunc(display);
glutMainLoop();
return(0);
}