L'exécutable

 

Le source : TP-Cameras.cpp

/* Auteur: Nicolas JANEY              */
/* nicolas.janey@univ-fcomte.fr       */
/* Avril 2001                         */
/* Utilisation des cameras en OpenGL  */

#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 "ModuleMenus.h"

static float anglex = 0.0F ;
static int scene = 0 ;
static int width ;
static int height ;

void wireCylindre(float r,float h,int n,int m) {
  glPushMatrix();
  GLUquadricObj *qobj = gluNewQuadric();
  gluQuadricDrawStyle(qobj,GLU_LINE);
  gluCylinder(qobj,r,r,h,n,m);
  gluDeleteQuadric(qobj);  
  glPopMatrix();
}

void display(void) {
  glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
  glPushMatrix();
  glTranslatef(3.0f,3.0f,0.0f);
  glRotatef(anglex,1.0F,0.0F,0.0F) ;
  glutWireCube(2.0);
  glPopMatrix();
  glPushMatrix();
  glTranslatef(-3.0f,3.0f,0.0f);
  glRotatef(anglex,1.0F,0.0F,0.0F) ;
  glutWireSphere(1.0,18,18);
  glPopMatrix();
  glPushMatrix();
  glTranslatef(3.0f,-3.0f,0.0f);
  glRotatef(anglex,1.0F,0.0F,0.0F) ;
  wireCylindre(1.0,2.0,18,18);
  glPopMatrix();
  glPushMatrix();
  glTranslatef(-3.0f,-3.0f,0.0f);
  glRotatef(anglex,1.0F,0.0F,0.0F) ;
  glutWireCone(1.0,2.0,18,18);
  glPopMatrix();
  glFlush();
  glutSwapBuffers();
}

void myinit (void) {
  glClearColor(0.5F,0.5F,0.5F,0.0F);
  glColor4fv(couleurBlanc());
  glEnable(GL_DEPTH_TEST);
}

void reshape(int w, int h) {
  glViewport(0,0,w,h);
  width = w;
  height = h;
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  gluPerspective(30,(double) w/h,5.0,40.0);
  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();
  switch ( scene ) {
    case 0 : glTranslatef(0.0f,0.0f,-20.0f);
             break;
    case 1 : glRotatef(-90.0f,0.0f,1.0f,0.0f);
             glTranslatef(-20.0f,0.0f,0.0f);
             break;
    case 2 : glRotatef(90.0f,1.0f,0.0f,0.0f);
             glTranslatef(0.0f,-20.0f,0.0f);
             break;
    case 3 : glRotatef(-45.0f,0.0f,1.0f,0.0f);
             glTranslatef(-20.0f,0.0f,-20.0f);
             break;
    case 4 : glRotatef(45.0f,1.0f,0.0f,0.0f);
             glTranslatef(0.0f,-20.0f,-20.0f);
             break;
    case 5 : glRotatef(-90.0f,-1.0f,1.0f,0.0f);
             glTranslatef(-20.0f,-20.0f,0.0f);
             break;
    case 6 : glRotatef(180.0f,-0.325f,-0.325f,-0.888f);
             glTranslatef(-20.0f,-20.0f,-20.0f);
             break;
    case 7 : glRotatef(-54.7356f,-1.0f,1.0f,0.0f);
             glTranslatef(-20.0f,-20.0f,-20.0f);
             break;
    case 8 : gluLookAt(20.0,20.0,20.0,0.0,0.0,0.0,0.0,1.0,0.0);
             break; }
}

void key(unsigned char key,int x,int y) {
  switch ( key) {
    case 0x0D : scene = (scene+1) % 9 ;
                reshape(width,height);
                glutPostRedisplay();
                break ;
    case 0x1B : exit(0) ;
                break; }
}

void idle(void) {
  anglex++ ;
  glutPostRedisplay() ;
}

int main(int argc,char **argv) {
  glutInit(&argc,argv);
  glutInitDisplayMode(GLUT_RGBA|GLUT_DEPTH|GLUT_DOUBLE);
  glutInitWindowSize(300,300); 
  glutInitWindowPosition(50,50); 
  glutCreateWindow("Camera pour la perspective"); 
  myinit(); 
  creationMenuBasique();
  glutKeyboardFunc(key);
  glutIdleFunc(idle);
  glutReshapeFunc(reshape);
  glutDisplayFunc(display);
  glutMainLoop();
  return(0);
}

Les modules utilitaires : Modules.zip

RETOUR