L'exécutable

Le source : DeplacementCamera-1.cpp

/* Auteur: Nicolas JANEY                         */
/* nicolas.janey@univ-fcomte.fr                  */
/* Octobre 2008                                  */
/* Un programme OpenGL de deplacement au clavier */
/* d'une camera au sein d'une scene              */

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

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

#include "Scene.h"

/* Variables globales                           */

static int l = 1;

static float px = 0.0F;
static float py = 0.5F;
static float pz = 0.0F;
static float ouv = 60.0F;

/* Fonction executee lors d'un changement       */
/* de la taille de la fenetre OpenGL            */
/* Configuration d'une camera de visualisation  */
/* en projection en perspective                 */

void reshape(int tx,int ty) {
  /* Configuration du viewport d'affichage      */
  glViewport(0,0,tx,ty);
  /* Choix et configuration de la camera        */
  /* de visualisation                           */
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  gluPerspective(ouv,(double) tx/ty,0.1,100.0);
  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();
}

/* Fonction executee lors d'un rafraichissement */
/* de la fenetre de dessin                      */

void display(void) {
  glClearColor(0.6F,0.6F,0.6F,1.0F) ;
  glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT) ;
  glPushMatrix();
  gluLookAt(px,py,pz,
            px,py,pz+1.0,
            0.0,1.0,0.0);
  /* Affichage de la scene                      */
  scene(1);
  glPopMatrix();
  glFlush();
  glutSwapBuffers();
  int error = glGetError();
  if ( error != GL_NO_ERROR )
    printf("Attention, erreur OpenGL %d\n",error);
}

/* Fonction executee lors de la frappe          */
/* d'une touche alphanumerique du clavier       */

void keyboard(unsigned char key,int x,int y) {
  switch ( key ) {
    case 0x0D : l = !l ;
                glutPostRedisplay();
                break;
    case 0x1B : exit(0); }
}

/* Fonction executee lors de la frappe          */
/* d'une touche non alphanumerique du clavier   */

void special(int key,int x,int y) {
  switch ( key ) {
    case GLUT_KEY_UP      : pz += 0.1F;
                            glutPostRedisplay();
                            break;
    case GLUT_KEY_DOWN    : pz -= 0.1F;
                            glutPostRedisplay();
                            break; }
}

/* Fonction principale                          */

int main(int argc,char **argv) {
  glutInit(&argc,argv);
  glutInitDisplayMode(GLUT_RGBA|GLUT_DOUBLE|GLUT_DEPTH);
  glutInitWindowSize(450,200); 
  glutInitWindowPosition(50,50); 
  glutCreateWindow("Deplacement de camera");
  glutReshapeFunc(reshape);
  glutKeyboardFunc(keyboard);
  glutSpecialFunc(special);
  glutDisplayFunc(display);
  glutMainLoop();
  return(0);
}

RETOUR