/* Auteur: Nicolas JANEY */
/* nicolas.janey@univ-fcomte.fr */
/* Fevrier 2003 */
/* Fonctions de dessin de cube */
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <GL/glut.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include "ModuleCouleurs.h"
#include "ModuleManipulateur.h"
#include "ModuleMenus.h"
#include "ModuleReshape.h"
#include "ModuleAxes.h"
static float anglex = 0.0F;
static float angley = 0.0F;
static float anglez = 0.0F;
void glutSolidCubeSansNormales(float c){
c /= 2.0F;
glPushMatrix();
glBegin(GL_QUADS);
glVertex3f(-c,c,-c);
glVertex3f(-c,-c,-c);
glVertex3f(c,-c,-c);
glVertex3f(c,c,-c);
glVertex3f(c,c,c);
glVertex3f(-c,c,c);
glVertex3f(-c,-c,c);
glVertex3f(c,-c,c);
glVertex3f(-c,c,-c);
glVertex3f(-c,-c,-c);
glVertex3f(-c,-c,c);
glVertex3f(-c,c,c);
glVertex3f(c,c,c);
glVertex3f(c,-c,c);
glVertex3f(c,-c,-c);
glVertex3f(c,c,-c);
glVertex3f(-c,-c,c);
glVertex3f(-c,-c,-c);
glVertex3f(c,-c,-c);
glVertex3f(c,-c,c);
glVertex3f(c,c,c);
glVertex3f(c,c,-c);
glVertex3f(-c,c,-c);
glVertex3f(-c,c,c);
glEnd();
glPopMatrix();
}
void glutSolidCubeAvecNormales(float c){
c /= 2.0F;
glPushMatrix();
glNormal3f(0.0F,0.0F,1.0F);
glBegin(GL_QUADS);
glNormal3f(0.0F,0.0F,-1.0F);
glVertex3f(c,c,-c);
glVertex3f(c,-c,-c);
glVertex3f(-c,-c,-c);
glVertex3f(-c,c,-c);
glNormal3f(0.0F,0.0F,1.0F);
glVertex3f(c,c,c);
glVertex3f(-c,c,c);
glVertex3f(-c,-c,c);
glVertex3f(c,-c,c);
glNormal3f(-1.0F,0.0F,0.0F);
glVertex3f(-c,c,-c);
glVertex3f(-c,-c,-c);
glVertex3f(-c,-c,c);
glVertex3f(-c,c,c);
glNormal3f(1.0F,0.0F,0.0F);
glVertex3f(c,c,c);
glVertex3f(c,-c,c);
glVertex3f(c,-c,-c);
glVertex3f(c,c,-c);
glNormal3f(0.0F,-1.0F,0.0F);
glVertex3f(-c,-c,c);
glVertex3f(-c,-c,-c);
glVertex3f(c,-c,-c);
glVertex3f(c,-c,c);
glNormal3f(0.0F,1.0F,0.0F);
glVertex3f(c,c,c);
glVertex3f(c,c,-c);
glVertex3f(-c,c,-c);
glVertex3f(-c,c,c);
glEnd();
glPopMatrix();
}
void display(void) {
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glPushMatrix();
manipulateurSouris();
manipulateurClavier();
axes();
glPushMatrix();
glTranslatef(1.7F,1.7F,0.0F) ;
glRotatef(anglex,1.0F,0.0F,0.0F);
glRotatef(angley,0.0F,1.0F,0.0F);
glRotatef(anglez,0.0F,0.0F,1.0F);
glutSolidCubeAvecNormales(1.6F) ;
glPopMatrix();
glPushMatrix();
glTranslatef(-1.7F,-1.7F,0.0F) ;
glRotatef(angley,0.0F,1.0F,0.0F);
glRotatef(anglez,0.0F,0.0F,1.0F);
glRotatef(anglex,1.0F,0.0F,0.0F);
glutSolidCubeAvecNormales(1.6F) ;
glPopMatrix();
glPushMatrix();
glTranslatef(-1.7F,1.7F,0.0F) ;
glRotatef(anglez,0.0F,0.0F,1.0F);
glRotatef(anglex,1.0F,0.0F,0.0F);
glRotatef(angley,0.0F,1.0F,0.0F);
glutSolidCubeSansNormales(1.6F) ;
glPopMatrix();
glPushMatrix();
glTranslatef(1.7F,-1.7F,0.0F) ;
glRotatef(angley,0.0F,1.0F,0.0F);
glRotatef(anglex,1.0F,0.0F,0.0F);
glRotatef(anglez,0.0F,0.0F,1.0F);
glutSolidCubeSansNormales(1.6F) ;
glPopMatrix();
glPopMatrix();
glFlush();
glutSwapBuffers();
}
void myinit (void) {
glClearColor(0.5F,0.5F,0.5F,0.0F);
glShadeModel(GL_SMOOTH);
glEnable(GL_NORMALIZE);
glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_LIGHT1);
glEnable(GL_LIGHT2);
float dir0[4] = { 1.0F,1.0F,1.0F,0.0F };
glLightfv(GL_LIGHT0,GL_POSITION,dir0) ;
glLightfv(GL_LIGHT0,GL_DIFFUSE,couleurVert()) ;
float dir1[4] = { -1.0F,1.0F,1.0F,0.0F };
glLightfv(GL_LIGHT1,GL_POSITION,dir1) ;
glLightfv(GL_LIGHT1,GL_DIFFUSE,couleurBleu()) ;
float dir2[4] = { 0.0F,-1.0F,1.0F,0.0F };
glLightfv(GL_LIGHT2,GL_POSITION,dir2) ;
glLightfv(GL_LIGHT2,GL_DIFFUSE,couleurRouge()) ;
}
void key(unsigned char key,int x,int y) {
static int aff = 1;
if ( keyManipulateur(key,x,y) )
glutPostRedisplay();
else
switch ( key ) {
case ' ' : switchAffichagePlan();
glutPostRedisplay();
break;
case 0x0D : aff = !aff;
glPolygonMode(GL_FRONT_AND_BACK,(aff) ? GL_FILL : GL_LINE);
glutPostRedisplay(); }
}
void idle(void) {
anglex += 1.0F;
angley += 1.1F;
anglez += 1.2F;
glutPostRedisplay();
}
int main(int argc,char **argv) {
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_RGBA|GLUT_DEPTH|GLUT_DOUBLE);
glutInitWindowSize(250,250);
glutInitWindowPosition(50,50);
glutCreateWindow("Cubes");
myinit();
creationMenuBasique();
setParametresOrthoBasique(-3.5F,3.5F,-3.5F,3.5F,-500.0,500.0);
setManipulateurDistance(1.0F);
glutReshapeFunc(reshapeOrthoBasique);
glutKeyboardFunc(key);
glutSpecialFunc(specialBasique);
glutMotionFunc(motionBasique);
glutMouseFunc(sourisBasique);
glutIdleFunc(idle);
glutDisplayFunc(display);
glutMainLoop();
return(0);
}