/* Auteur: Nicolas JANEY */
/* nicolas.janey@univ-fcomte.fr */
/* Janvier 2004 */
/* Des spheres en deplacement */
/* sur une trajectoire en huit */
#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"
#ifndef M_PI
#define M_PI 3.14159
#endif
static int n = 21;
static float r = 1.0F;
static float rc = 12.0F;
static float init = 0.0F;
static float d = 1.0F;
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 n,float r,float rc) {
float l = 720.0F;
float dist = l/n;
glPushMatrix();
for ( int i = 0 ; i < n ; i++ ) {
glPushMatrix();
float pos = init+i*dist;
if ( pos > l )
pos -= l;
if ( pos < 360 )
glTranslatef(rc,0.0F,0.0F);
else {
pos = (180-pos);
glTranslatef(-rc,0.0F,0.0F); }
glRotatef(pos,0.0F,0.0F,1.0F);
glTranslatef(-rc,0.0F,0.0F);
glutSolidSphere(r,36,36);
glPopMatrix(); }
glPopMatrix();
}
void display(void) {
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glPushMatrix();
manipulateurSouris();
manipulateurClavier();
int i;
glBegin(GL_LINE_LOOP);
for ( i = 0 ; i < 60 ; i++ ) {
float a = i*2*M_PI/60;
float x = rc+rc*cos(a);
float y = rc*sin(a);
glVertex2f(x,y); }
glEnd();
glBegin(GL_LINE_LOOP);
for ( i = 0 ; i < 60 ; i++ ) {
float a = i*2*M_PI/60;
float x = -rc+rc*cos(a);
float y = rc*sin(a);
glVertex2f(x,y); }
glEnd();
scene(n,r,rc);
glPopMatrix();
glFlush();
glutSwapBuffers();
}
void idle(void) {
float l = 720.0F;
init += d;
if ( init > l )
init -= l;
glutPostRedisplay();
}
void key(unsigned char key,int x,int y) {
static int anim = 1;
if ( keyManipulateur(key,x,y) )
glutPostRedisplay();
else
switch ( key ) {
case 'r' : rc *= 1.01F;
glutPostRedisplay();
break;
case 'R' : rc /= 1.01F;
glutPostRedisplay();
break;
case 'a' : r *= 1.01F;
glutPostRedisplay();
break;
case 'A' : r /= 1.01F;
glutPostRedisplay();
break;
case 'v' : d *= 1.01F;
glutPostRedisplay();
break;
case 'V' : d /= 1.01F;
glutPostRedisplay();
break;
case 45 : n--;
if ( n < 1 )
n = 1;
glutPostRedisplay();
break;
case 43 : n++;
glutPostRedisplay();
break;
case ' ' : anim = !anim;
glutIdleFunc((anim) ? idle : NULL); }
}
int main(int argc,char **argv) {
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_RGBA|GLUT_DEPTH|GLUT_DOUBLE);
glutInitWindowSize(350,200);
glutInitWindowPosition(50,50);
glutCreateWindow("Un huit anime");
myinit();
creationMenuBasique();
setParametresOrthoBasique(-15.0F,15.0F,-15.0F,15.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);
}