L'exécutable

Algo23.gif (9617 octets) Algo23.gif (9617 octets)

Le source: Voxels.cpp

/* Auteur: Nicolas JANEY             */
/* nicolas.janey@univ-fcomte.fr      */
/* Avril 2001                        */
/* Illustration d'une decomposition  */
/* de l'espace en voxels pour une    */
/* utilisation dans un algorithme    */
/* de lancer de rayons               */

#include <stdio.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"

static int aff = 0 ;

void myinit(void) {
  GLfloat light_position0[] = { 1.0F,1.0F,1.0F,0.0F };
  glLightfv(GL_LIGHT0,GL_AMBIENT,couleurNoir());
  glLightfv(GL_LIGHT0,GL_DIFFUSE,couleurBlanc());
  glLightfv(GL_LIGHT0,GL_SPECULAR,couleurBlanc());
  glLightfv(GL_LIGHT0,GL_POSITION,light_position0);
  glEnable(GL_LIGHT0);
  glEnable(GL_AUTO_NORMAL);
  glEnable(GL_NORMALIZE);
  glEnable(GL_DEPTH_TEST);
  glDepthFunc(GL_LESS);
}

void display(void) {
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  glPushMatrix() ;
  manipulateurSouris();
  manipulateurClavier();
  glRotatef(10.0F,1.0,0.0,0.0);
  glRotatef(15.0F,0.0,1.0,0.0);
  glRotatef(0.0F,0.0,0.0,1.0);
  glColor4fv(couleurBlanc()) ;
  glBegin(GL_LINES) ;
  for ( int x = -6 ; x <= 6 ; x += 4 )
    for ( int y = -6 ; y <= 6 ; y += 4 ) {
      glVertex3i(x,y,-6) ;
      glVertex3i(x,y,6) ;
      glVertex3i(x,-6,y) ;
      glVertex3i(x,6,y) ;
      glVertex3i(-6,x,y) ;
      glVertex3i(6,x,y) ; }
  glEnd() ;
  glEnable(GL_LIGHTING);
  if ( aff == 1 ) {
    glPushMatrix();
    glTranslatef(3.0F,2.0F,1.0F);
    glMaterialfv(GL_FRONT,GL_DIFFUSE,couleurRouge()) ;
    glRotatef(10,1.0,0.0,0.0);
    glRotatef(20,0.0,1.0,0.0);
    glRotatef(30,0.0,0.0,1.0);
    glutSolidSphere(1.3,30,30) ;
    glPopMatrix();
    glPushMatrix();
    glTranslatef(-3.0F,4.0F,-3.0F);
    glMaterialfv(GL_FRONT,GL_DIFFUSE,couleurVert()) ;
    glRotatef(-10,1.0,0.0,0.0);
    glRotatef(-20,0.0,1.0,0.0);
    glRotatef(60,0.0,0.0,1.0);
    glutSolidCube(1.0) ;
    glPopMatrix();
    glPushMatrix();
    glTranslatef(-0.0F,-4.0F,-2.0F);
    glMaterialfv(GL_FRONT,GL_DIFFUSE,couleurBleu()) ;
    glRotatef(10,1.0,0.0,0.0);
    glRotatef(20,0.0,1.0,0.0);
    glRotatef(60,0.0,0.0,1.0);
    glutSolidCone(1.9,2.0,30,30) ;
    glPopMatrix();
    glPushMatrix();
    glTranslatef(-2.0F,-4.0F,-4.0F);
    glMaterialfv(GL_FRONT,GL_DIFFUSE,couleurJaune()) ;
    glRotatef(10,1.0,0.0,0.0);
    glRotatef(20,0.0,1.0,0.0);
    glRotatef(60,0.0,0.0,1.0);
    glutSolidTorus(0.8,1.6,30,30) ;
    glPopMatrix();
    glPushMatrix();
    glTranslatef(4.0F,-1.0F,-4.0F);
    glMaterialfv(GL_FRONT,GL_DIFFUSE,couleurMagenta()) ;
    glRotatef(10,1.0,0.0,0.0);
    glRotatef(20,0.0,1.0,0.0);
    glRotatef(60,0.0,0.0,1.0);
    glutSolidTeapot(1.5) ;
    glPopMatrix();
    glPushMatrix();
    glTranslatef(-3.0F,3.0F,4.0F);
    glMaterialfv(GL_FRONT,GL_DIFFUSE,couleurCyan()) ;
    glRotatef(10,1.0,0.0,0.0);
    glRotatef(60,0.0,1.0,0.0);
    glRotatef(60,0.0,0.0,1.0);
    glutSolidCone(0.8,2.5,30,30) ;
    glPopMatrix(); }
  glDisable(GL_LIGHTING);
  glPopMatrix() ;
  glFlush();
  glutSwapBuffers() ;
}

void key(unsigned char key,int x,int y) {
  if ( keyManipulateur(key,x,y) )
    glutPostRedisplay();
    else
    switch ( key ) {
      case 0x0D   : aff = 1-aff ;
                    glutPostRedisplay();
                    break ; }
}

int main(int argc,char **argv) {
  glutInit(&argc,argv);
  glutInitDisplayMode(GLUT_RGBA|GLUT_DEPTH|GLUT_DOUBLE);
  glutInitWindowSize(300,300); 
  glutInitWindowPosition(50,50); 
  glutCreateWindow("Décomposition en voxels"); 
  myinit(); 
  creationMenuBasique();
  setParametresOrthoBasique(-11.0,11.0,-11.0,11.0,-50.0,50.0);
  setManipulateurDistance(1.0F);
  glutReshapeFunc(reshapeOrthoBasique);
  glutKeyboardFunc(key);
  glutSpecialFunc(specialBasique);
  glutMotionFunc(motionBasique);
  glutMouseFunc(sourisBasique);
  glutDisplayFunc(display);
  glutMainLoop();
  return(0);
}

Les modules utilitaires : Modules.zip

WB01624_.gif (281 octets) RETOUR