Le source : TD-MouvementHelicoidal.cpp
/* Auteur: Nicolas JANEY */
/* nicolas.janey@univ-fcomte.fr */
/* Janvier 2004 */
/* Une sphere en deplacement */
/* sur une trajectoire helicoidale */
#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 int img =1;
static float coul[] = { 1.0F,1.0F,1.0F,1.0F };
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(int img) {
glPushMatrix();
float y;
if ( img < 1800 ) {
glRotatef((float) -img,0.0F,1.0F,0.0F);
y = 5.0F -(float) img/180; }
else {
y = -5.0F +(float) (img-1800)/100; }
glTranslatef(0.0F,y,-3.0F);
glutSolidSphere(1.0,24,24);
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 <= 300 ; i++ ) {
float a = i*2*M_PI/60;
float x = 3.0F*sin(a);
float y = 5.0F-(float) i/30;
float z = -3.0F*cos(a);
glVertex3f(x,y,z); }
glEnd(); }
scene(img);
glPopMatrix();
glFlush();
glutSwapBuffers();
}
void idle(void) {
img ++;
if ( img > 2800 )
img = 0;
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(); }
}
int main(int argc,char **argv) {
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_RGBA|GLUT_DEPTH|GLUT_DOUBLE);
glutInitWindowSize(280,250);
glutInitWindowPosition(50,50);
glutCreateWindow("Un mouvement helicoidal");
myinit();
creationMenuBasique();
setParametresOrthoBasique(-7.0F,7.0F,-7.0F,7.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);
}