/* $Id: bounce.c,v 3.0 1998/02/14 18:42:29 brianp Exp $ */
/*
* Bouncing ball demo. Color index mode only!
*
* This program is in the public domain
*
* Brian Paul
*/
/* Conversion to GLUT by Mark J. Kilgard */
/*
* $Log: bounce.c,v $
* Revision 3.0 1998/02/14 18:42:29 brianp
* initial rev
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <GL/glut.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include "ModuleManipulateur.h"
#include "ModuleCouleurs.h"
#include "ModuleMenus.h"
#include "ModuleReshape.h"
#define COS(X) cos((X)*3.14159/180.0)
#define SIN(X) sin((X)*3.14159/180.0)
GLuint Ball;
GLenum Mode;
GLfloat Zrot = 0.0F,Zstep = 6.0F;
GLfloat Xpos = 0.0F,Ypos = 1.0F;
GLfloat Xvel = 0.2F,Yvel = 0.0F;
GLfloat Xmin=-4.0F,Xmax=4.0F;
GLfloat Ymin=-3.8F,Ymax=4.0F;
GLfloat G = -0.1F;
GLuint make_ball(void) {
GLuint list;
GLfloat a,b;
GLfloat da = 18.0,db = 18.0;
GLfloat radius = 1.0;
GLuint color;
GLfloat x,y,z;
list = glGenLists(1);
glNewList(list,GL_COMPILE);
color = 0;
for(a=-90.0;a+da<=90.0;a+=da) {
glBegin(GL_QUAD_STRIP);
for(b=0.0;b<=360.0;b+=db) {
if(color) {
glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,couleurRouge()) ;}
else {
glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,couleurBlanc()); }
x =(float)(COS(b) * COS(a));
y =(float)(SIN(b) * COS(a));
z =(float) SIN(a);
glVertex3f(x,y,z);
glNormal3f(x,y,z);
x =(float)(radius * COS(b) * COS(a+da));
y =(float)(radius * SIN(b) * COS(a+da));
z =(float)(radius * SIN(a+da));
glVertex3f(x,y,z);
glNormal3f(x,y,z);
color = 1-color; }
glEnd(); }
glEndList();
return list;
}
void display(void){
GLint i;
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glPushMatrix();
manipulateurSouris();
manipulateurClavier();
glMaterialfv(GL_FRONT,GL_DIFFUSE,couleurCyan()) ;
glBegin(GL_LINES);
for(i=-5;i<=5;i++) {
glVertex2i(i,-5);
glVertex2i(i,5);}
for(i=-5;i<=5;i++) {
glVertex2i(-5,i);
glVertex2i(5,i);}
for(i=-5;i<=5;i++) {
glVertex2i(i,-5);
glVertex2f(i*1.15F,-5.9F);}
glVertex2f(-5.3F,-5.35F);
glVertex2f(5.3F,-5.35F);
glVertex2f(-5.75,-5.9F);
glVertex2f(5.75,-5.9F);
glEnd();
glPushMatrix();
glTranslatef(Xpos,Ypos,0.0);
glScalef(2.0,2.0,2.0);
glRotatef(8.0,0.0,0.0,1.0);
glRotatef(90.0,1.0,0.0,0.0);
glRotatef(Zrot,0.0,0.0,1.0);
glCallList(Ball);
glPopMatrix();
glPopMatrix();
glFlush();
glutSwapBuffers();
}
static void idle(void){
static float vel0 = -100.0;
Zrot += Zstep;
Xpos += Xvel;
if(Xpos>=Xmax) {
Xpos = Xmax;
Xvel = -Xvel;
Zstep = -Zstep; }
if(Xpos<=Xmin) {
Xpos = Xmin;
Xvel = -Xvel;
Zstep = -Zstep; }
Ypos += Yvel;
Yvel += G;
if(Ypos<Ymin) {
Ypos = Ymin;
if(vel0==-100.0)
vel0 =(float) fabs(Yvel);
Yvel = vel0; }
glutPostRedisplay() ;
}
void init() {
Ball = make_ball();
glEnable(GL_LIGHTING) ;
glEnable(GL_LIGHT0) ;
glEnable(GL_DEPTH_TEST) ;
glEnable(GL_NORMALIZE) ;
glDepthFunc(GL_DEPTH) ;
glShadeModel(GL_FLAT);
}
int main(int argc,char **argv) {
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_RGBA|GLUT_DEPTH|GLUT_DOUBLE);
glutInitWindowSize(250,250);
glutInitWindowPosition(50,50);
glutCreateWindow("Une balle rebondissante");
init();
creationMenuBasique();
setParametresOrthoBasique(-6.0,6.0,-6.0,6.0,-500.0,500.0);
setManipulateurDistance(1.0F);
glutReshapeFunc(reshapeOrthoBasique);
glutIdleFunc(idle);
glutKeyboardFunc(keyBasique);
glutSpecialFunc(specialBasique);
glutMotionFunc(motionBasique);
glutMouseFunc(sourisBasique);
glutDisplayFunc(display);
glutMainLoop();
return(0);
}