L'exécutable

Le source : CubesParFacettes.cpp

/* Auteur: Nicolas JANEY            */
/* nicolas.janey@univ-fcomte.fr     */
/* Septembre 2005                   */
/* 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.75F,0.75F,0.75F,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,couleurBlanc()) ;
  float dir1[4] = { -1.0F,1.0F,1.0F,0.0F };
  glLightfv(GL_LIGHT1,GL_POSITION,dir1) ;
  glLightfv(GL_LIGHT1,GL_DIFFUSE,couleurBlanc()) ;
  float dir2[4] = { 0.0F,-1.0F,1.0F,0.0F };
  glLightfv(GL_LIGHT2,GL_POSITION,dir2) ;
  glLightfv(GL_LIGHT2,GL_DIFFUSE,couleurBlanc()) ;
}

void idle(void) {
  anglex += 0.10F;
  angley += 0.11F;
  anglez += 0.12F;
  glutPostRedisplay();
}

void key(unsigned char key,int x,int y) {
  static int aff = 1;
  static int anim = 1;
  if ( keyManipulateur(key,x,y) )
    glutPostRedisplay();
    else
    switch ( key ) {
      case 'a'    : anim = !anim;
                    glutIdleFunc((anim) ? idle : NULL);
                    break;
      case ' '    : switchAffichagePlan();
                    glutPostRedisplay();
                    break;
      case 0x0D   : aff = !aff;
                    glPolygonMode(GL_FRONT_AND_BACK,
                                  (aff) ? GL_FILL : GL_LINE);
                    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 par facettes"); 
  myinit(); 
  creationMenuBasique();
  setParametresOrthoBasique(-3.5F,3.5F,-3.5F,3.5F,-5.0,5.0);
  setManipulateurDistance(1.0F);
  glutReshapeFunc(reshapeOrthoBasique);
  glutKeyboardFunc(key);
  glutSpecialFunc(specialBasique);
  glutMotionFunc(motionBasique);
  glutMouseFunc(sourisBasique);
  glutIdleFunc(idle);
  glutDisplayFunc(display);
  glutMainLoop();
  return(0);
}

Les modules utilitaires : Modules.zip

RETOUR