Le source : SceneAnimeeRotationOz.cpp
/* Auteur: Nicolas JANEY */
/* nicolas.janey@univ-fcomte.fr */
/* Septembre 2005 */
/* Modelisation OpenGL d'une scene */
/* animee composee de cubes */
#include <stdio.h>
#include <math.h>
#include <GL/glut.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include "ModuleCouleurs.h"
#include "ModuleAxes.h"
#include "ModuleManipulateur.h"
#include "ModuleMenus.h"
#include "ModuleReshape.h"
static int n = 7 ;
static float angle = 0;
static float inc = 0.05F;
void myinit(void) {
GLfloat light_position0[] = { 0.0F,0.0F,1.0F,0.0F };
GLfloat light_position1[] = { 0.0F,0.0F,1.0F,0.0F };
glLightfv(GL_LIGHT0,GL_AMBIENT,couleurNoir());
glLightfv(GL_LIGHT0,GL_DIFFUSE,couleurBlanc());
glLightfv(GL_LIGHT1,GL_DIFFUSE,couleurBlanc());
glLightfv(GL_LIGHT0,GL_SPECULAR,couleurNoir());
glLightfv(GL_LIGHT0,GL_POSITION,light_position0);
glLightfv(GL_LIGHT1,GL_POSITION,light_position1);
glEnable(GL_LIGHT0);
glEnable(GL_LIGHT1);
glDepthFunc(GL_LESS);
glEnable(GL_AUTO_NORMAL);
glEnable(GL_NORMALIZE);
glEnable(GL_ALPHA_TEST);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
glLightModeli(GL_LIGHT_MODEL_TWO_SIDE,GL_TRUE);
setManipulateurClavierAngle(35.0F,20.0F,0.0F);
glEnable(GL_DEPTH_TEST);
}
void wireScene(int n) {
glPushMatrix();
for ( int i = 0 ; i < n ; i++ ) {
glPushMatrix();
glRotatef((360.0F*i)/n,0.0F,0.0F,1.0F);
glTranslatef(3.0F,0.0F,0.0F);
glutWireCube(1.0);
glPopMatrix(); }
glPopMatrix();
}
void solidScene(int n) {
glEnable(GL_LIGHTING);
glEnable(GL_CULL_FACE);
glPushMatrix();
for ( int i = 0 ; i < n ; i++ ) {
glPushMatrix();
glRotatef((360.0F*i)/n,0.0F,0.0F,1.0F);
glTranslatef(3.0F,0.0F,0.0F);
glutSolidCube(1.0);
glPopMatrix(); }
glPopMatrix();
glDisable(GL_LIGHTING);
glDisable(GL_CULL_FACE);
}
void scene(int n) {
glPushMatrix();
glPushMatrix();
glColor4fv(couleurRouge()) ;
wireScene(n);
glPopMatrix();
glPushMatrix();
glMaterialfv(GL_FRONT,GL_DIFFUSE,couleurRouge(0.5F)) ;
solidScene(n);
glPopMatrix();
glPopMatrix();
}
void display(void) {
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glPushMatrix() ;
manipulateurSouris();
manipulateurClavier();
axes();
glRotatef(angle,0.0F,0.0F,1.0F);
scene(n);
glPopMatrix();
glFlush();
glutSwapBuffers();
}
void idle(void) {
angle += inc;
glutPostRedisplay();
}
void key(unsigned char key,int x,int y) {
if ( keyManipulateur(key,x,y) )
glutPostRedisplay();
else
switch ( key ) {
case 45 : n--;
if ( n < 1 )
n = 1;
glutPostRedisplay();
break;
case 43 : n++;
glutPostRedisplay();
break;
case ' ' : inc = -inc;
break;
case 'a' :
case 'A' : inc *= 1.01F;
break;
case 'd' :
case 'D' : inc /= 1.01F;
break;
case 0x0D : { static int anim = 1;
anim = !anim;
glutIdleFunc((anim) ? idle : NULL); } }
}
int main(int argc,char **argv) {
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_RGBA|GLUT_DEPTH|GLUT_DOUBLE);
glutInitWindowSize(300,200);
glutInitWindowPosition(50,50);
glutCreateWindow("n cubes animés");
myinit();
creationMenuBasique();
setParametresOrthoBasique(-4.0,4.0,-4.0,4.0,-50.0,50.0);
setManipulateurDistance(1.0F);
glutReshapeFunc(reshapeOrthoBasique);
glutKeyboardFunc(key);
glutSpecialFunc(specialBasique);
glutMotionFunc(motionBasique);
glutMouseFunc(sourisBasique);
glutIdleFunc(idle);
glutDisplayFunc(display);
glutMainLoop();
return(0);
}