Le source : TD-Animation1c.cpp
/* Auteur: Nicolas JANEY */
/* nicolas.janey@univ-fcomte.fr */
/* Janvier 2004 */
/* Des spheres en deplacement */
/* sur une trajectoire circulaire */
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <GL/glut.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include "ModuleManipulateur.h"
#include "ModuleMenus.h"
#include "ModuleReshape.h"
#include "ModuleAxes.h"
static int mode = 0;
#ifndef M_PI
#define M_PI 3.14159
#endif
static float a = 0.0F;
static float coul[] = { 1.0F,1.0F,1.0F,1.0F };
static int anim = 1;
void myinit(void) {
glClearColor(0.8F,0.8F,0.8F,0.0);
glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glDepthFunc(GL_LESS);
glShadeModel(GL_SMOOTH);
glEnable(GL_AUTO_NORMAL);
glEnable(GL_NORMALIZE);
}
void scene(float a) {
glPushMatrix();
glRotatef(a,0.0F,0.0F,1.0F);
glTranslatef(3.0F,0.0F,0.0F);
glutSolidSphere(1.0,36,36);
glPopMatrix();
}
void display(void) {
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glPushMatrix();
manipulateurSouris();
manipulateurClavier();
if ( mode ) {
axes();
int i;
glBegin(GL_LINE_LOOP);
for ( i = 0 ; i < 60 ; i++ ) {
float a = i*2*M_PI/60;
float x = 3.0F*cos(a);
float y = 3.0F*sin(a);
glVertex2f(x,y); }
glEnd(); }
scene(a);
glPopMatrix();
glFlush();
glutSwapBuffers();
}
void idle(void) {
static float pas = 1.0F;
a += pas;
if ( ( a >= 360.0F ) || ( a <= 0.0F ) )
pas = -pas;
printf("%f %f\n",a,pas);
glutPostRedisplay();
}
void key(unsigned char key,int x,int y) {
static int anim = 1;
if ( keyManipulateur(key,x,y) )
glutPostRedisplay();
else
switch ( key ) {
case 0x1B : exit(0);
break;
case ' ' : mode = !mode;
glutPostRedisplay();
case 0x0D : anim = !anim;
glutIdleFunc((anim) ? idle : NULL); }
}
int main(int argc,char **argv) {
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_RGBA|GLUT_DEPTH|GLUT_DOUBLE);
glutInitWindowSize(250,200);
glutInitWindowPosition(50,50);
glutCreateWindow("Une animation");
myinit();
creationMenuBasique();
setParametresOrthoBasique(-5.0F,5.0F,-5.0F,5.0F,-100.0F,100.0F);
setManipulateurDistance(1.0F);
glutReshapeFunc(reshapeOrthoBasique);
glutKeyboardFunc(key);
glutSpecialFunc(specialBasique);
glutMotionFunc(motionBasique);
glutMouseFunc(sourisBasique);
glutIdleFunc(idle);
glutDisplayFunc(display);
glutMainLoop();
return(0);
}