Fichier source : ParametrageCameraB.cpp
static double px = 0.0;
static double py = 0.0;
static double pz = 10.0;
/* Fonction executee lors d'un rafraichissement */
/* de la fenetre de dessin */
static void display(void) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
const GLfloat light0_position[] = { 0.0,0.0,10.0,1.0 };
glPolygonMode(GL_FRONT_AND_BACK,(affichage) ? GL_FILL : GL_LINE);
glPushMatrix();
switch (version) {
case 0 :
glLightfv(GL_LIGHT0,GL_POSITION,light0_position);
gluLookAt(px,py,pz,0.0,0.0,0.0,0.0,1.0,0.0);
break;
case 1 :
gluLookAt(px,py,pz,0.0,0.0,0.0,0.0,1.0,0.0);
glLightfv(GL_LIGHT0,GL_POSITION,light0_position);
break; }
scene();
glPopMatrix();
glFlush();
glutSwapBuffers();
int error = glGetError();
if ( error != GL_NO_ERROR )
printf("Erreur OpenGL: %d\n",error);
}
/* Fonction executee lors d'un changement */
/* de la taille de la fenetre OpenGL */
/* -> Ajustement de la camera de visualisation */
static void reshape(int tx,int ty) {
glViewport(0,0,tx,ty);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
double ratio =(double) tx/ty;
if ( ratio >= 1.0 )
gluPerspective(80.0,ratio,1.0,20.0);
else
gluPerspective(80.0/ratio,ratio,1.0,20.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
/* Fonction executee lors de la frappe */
/* d'une touche speciale du clavier */
static void special(int key,int x,int y) {
switch ( key ) {
case GLUT_KEY_UP :
py += 0.1;
glutPostRedisplay();
break;
case GLUT_KEY_DOWN :
py -= 0.1;
glutPostRedisplay();
break;
case GLUT_KEY_LEFT :
px -= 0.1;
glutPostRedisplay();
break;
case GLUT_KEY_RIGHT :
px += 0.1;
glutPostRedisplay();
break;
case GLUT_KEY_PAGE_UP :
pz -= 0.1;
glutPostRedisplay();
break;
case GLUT_KEY_PAGE_DOWN :
pz += 0.1;
glutPostRedisplay();
break;
case GLUT_KEY_F1 :
px = 0.0;
py = 0.0;
pz = 10.0;
glutPostRedisplay();
break; }
}