L'exécutable

ZB08.gif (4335 octets) ZB08.gif (4335 octets)

ZB08.gif (4335 octets) ZB08.gif (4335 octets)

Le source: DeformationsVisualisation.cpp

/* Auteur: Nicolas JANEY         */
/* nicolas.janey@univ-fcomte.fr  */
/* Fevrier 2002                  */
/* Les deformations liees        */
/* a la visualisation            */
/* en perspective                */

#include <stdio.h>
#include <stdlib.h>

#include <GL/glut.h>
#include <GL/gl.h>
#include <GL/glu.h>

#include "ModuleCouleurs.h"
#include "ModuleManipulateur.h"
#include "ModuleMenus.h"

static int ww ;
static int hh ;
static float ouverture = 1.0F ;
static float fact = 1.0F ;

void projection(void) {
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  gluPerspective(30.0*ouverture*fact,(double) ww/hh,0.1,100.0);
  glMatrixMode(GL_MODELVIEW);
  glTranslatef(0.0F,0.0F,-10.0F/ouverture);  
  setManipulateurDistance(10.0F/ouverture);
}

void glutSolidBox(float dx,float dy,float dz,int n) {
  glPushMatrix();
  glBegin(GL_QUADS);
  { for ( int i = 0 ; i < n ; i++ ) {
      float xi = -dx/2+i*dx/n;
      float xf = xi+dx/n;
      for ( int j = 0 ; j < n ; j++ ) {
        float yi = -dy/2+j*dy/n;
        float yf = yi+dy/n;
        glNormal3f(0.0F,0.0F,1.0F);
        glVertex3f(xi,yi,dz/2);
        glVertex3f(xi,yf,dz/2);
        glVertex3f(xf,yf,dz/2);
        glVertex3f(xf,yi,dz/2);
        glNormal3f(0.0F,0.0F,-1.0F);
        glVertex3f(xi,yi,-dz/2);
        glVertex3f(xi,yf,-dz/2);
        glVertex3f(xf,yf,-dz/2);
        glVertex3f(xf,yi,-dz/2); } } }
  { for ( int i = 0 ; i < n ; i++ ) {
      float xi = -dx/2+i*dx/n;
      float xf = xi+dx/n;
      for ( int j = 0 ; j < n ; j++ ) {
        float zi = -dz/2+j*dz/n;
        float zf = zi+dz/n;
        glNormal3f(0.0F,1.0F,0.0F);
        glVertex3f(xi,dy/2,zi);
        glVertex3f(xi,dy/2,zf);
        glVertex3f(xf,dy/2,zf);
        glVertex3f(xf,dy/2,zi);
        glNormal3f(0.0F,-1.0F,0.0F);
        glVertex3f(xi,-dy/2,zi);
        glVertex3f(xi,-dy/2,zf);
        glVertex3f(xf,-dy/2,zf);
        glVertex3f(xf,-dy/2,zi); } } }
  { for ( int i = 0 ; i < n ; i++ ) {
      float yi = -dy/2+i*dy/n;
      float yf = yi+dy/n;
      for ( int j = 0 ; j < n ; j++ ) {
        float zi = -dz/2+j*dz/n;
        float zf = zi+dz/n;
        glNormal3f(1.0F,0.0F,0.0F);
        glVertex3f(dx/2,yi,zi);
        glVertex3f(dx/2,yi,zf);
        glVertex3f(dx/2,yf,zf);
        glVertex3f(dx/2,yf,zi);
        glNormal3f(-1.0F,0.0F,0.0F);
        glVertex3f(-dx/2,yi,zi);
        glVertex3f(-dx/2,yi,zf);
        glVertex3f(-dx/2,yf,zf);
        glVertex3f(-dx/2,yf,zi); } } }
  glEnd();
  glPopMatrix();
}

void display(void) {   
  glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
  glPushMatrix();
  projection();
  glPushMatrix();
  manipulateurSouris();
  manipulateurClavier();
  glPushMatrix();
  glTranslatef(-1.9F,1.4F,0.0F) ;
  glRotatef(30.0F,0.0F,1.0F,1.0F);
  glMaterialfv(GL_FRONT,GL_DIFFUSE,couleurJaune());
  glutSolidBox(1.7F,1.6F,1.2F,30);
  glPopMatrix();
  glPushMatrix();
  glTranslatef(1.9F,1.4F,0.0F) ;
  glRotatef(25.0F,1.0F,0.0F,0.0F);
  glMaterialfv(GL_FRONT,GL_DIFFUSE,couleurRouge());
  glutSolidTorus(0.4,0.7,36,36);
  glPopMatrix();
  glPushMatrix();
  glTranslatef(1.9F,-1.4F,0.0F) ;
  glMaterialfv(GL_FRONT,GL_DIFFUSE,couleurBleu());
  glutSolidSphere(1.1,36,36);
  glPopMatrix();
  glPushMatrix();
  glTranslatef(-1.9F,-1.4F,0.0F) ;
  glRotatef(40.0F,1.0F,1.0F,0.0F);
  glMaterialfv(GL_FRONT,GL_DIFFUSE,couleurVert());
  glutSolidCone(1.0,1.5,36,36);
  glPopMatrix();
  glPopMatrix();
  glPopMatrix();
  glFlush();
  glutSwapBuffers();
}

void myinit(void) {
  glShadeModel(GL_SMOOTH);
  glDepthFunc(GL_LESS) ;
  glEnable(GL_DEPTH_TEST);
  glEnable(GL_LIGHTING);
  glEnable(GL_LIGHT0);
  glEnable(GL_AUTO_NORMAL);
  glEnable(GL_NORMALIZE);
  glLightfv(GL_LIGHT0,GL_SPECULAR,couleurBlanc());
  glMaterialfv(GL_FRONT,GL_SPECULAR,couleurBlanc());
  glMaterialf(GL_FRONT,GL_SHININESS,50);
}

void reshape(int w, int h) { 
  glViewport(0,0,w,h);
  ww = w ;
  hh = h ;
}

void key(unsigned char key,int x,int y) {
  if ( keyManipulateur(key,x,y) )
    glutPostRedisplay();
    else
    switch ( key ) {
      case 'o'  : fact *= 1.02F;
                  glutPostRedisplay();
                  break;
      case 'O'  : fact /= 1.02F;
                  glutPostRedisplay();
                  break;
      case 45   : ouverture *= 1.02F ;
                  glutPostRedisplay();
                  break;
      case 43   : ouverture /= 1.02F ;
                  glutPostRedisplay();
                  break; }
}

int main(int argc,char **argv) {
  glutInit(&argc,argv);
  glutInitDisplayMode(GLUT_RGBA|GLUT_DEPTH|GLUT_DOUBLE);
  glutInitWindowSize(280,210); 
  glutInitWindowPosition(50,50); 
  glutCreateWindow("Deformation liee a la perspective"); 
  myinit(); 
  creationMenuBasique();
  glutKeyboardFunc(key);
  glutSpecialFunc(specialBasique);
  glutMotionFunc(motionBasique);
  glutMouseFunc(sourisBasique);
  glutReshapeFunc(reshape);
  glutDisplayFunc(display);
  glutMainLoop();
  return(0);
}

Les modules utilitaires : Modules.zip

RETOUR