Projections orthographique et en perspective
Projection en perspective avec rapprochement de la scène
Projection en perspective : très grosses déformations
#include <windows.h> #include <stdio.h> #include <stdlib.h> #include <GL/gl.h> #include <GL/glu.h> #include "GL/glaux.h" static int proj = 0 ; static int ww ; static int hh ; static float anglex = 0.0F ; static float angley = 0.0F ; static float zoomPersp = 1.0F ; static float zoomParal = 1.0F ; static float ouverture = 1.0F ; void projection(void) { if ( proj ) { glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(60.0*ouverture,(double) ww/hh,0.5,200.0); glMatrixMode(GL_MODELVIEW); glTranslatef(0.0F,0.0F,-5.0F*zoomPersp); } else { glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(-2.5*zoomParal,2.5*zoomParal,-2.5*zoomParal*(double) hh/ww,2.5*zoomParal*(double) hh/ww,-25,25); glMatrixMode(GL_MODELVIEW); glTranslatef(0.0F,0.0F,-5.0F); } } void CALLBACK display(void) { glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); glPushMatrix(); glColor3f(1.0F,1.0F,1.0F); projection(); glPushMatrix(); glRotatef(anglex,1.0F,0.0F,0.0F); glRotatef(angley,0.0F,1.0F,0.0F); glTranslatef(-1.0F,0.0F,0.0F) ; float jaune[] = { 1.0F,1.0F,0.0F }; glMaterialfv(GL_FRONT,GL_DIFFUSE,jaune); auxSolidCube(2.0); glTranslatef(2.0F,0.0F,0.0F) ; float bleu[] = { 0.0F,0.0F,1.0F }; glMaterialfv(GL_FRONT,GL_DIFFUSE,bleu); auxSolidSphere(1.3); glPopMatrix(); glPopMatrix(); glFlush(); auxSwapBuffers() ; } void CALLBACK myinit(void) { glShadeModel(GL_SMOOTH); glDepthFunc(GL_LESS) ; glEnable(GL_DEPTH_TEST); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); } void CALLBACK myReshape(int w, int h) { glViewport(0,0,w,h); ww = w ; hh = h ; } void CALLBACK keyo(void) { ouverture *= 1.01F ; ouverture *= 1.01F ; } void CALLBACK keyO(void) { ouverture /= 1.01F ; ouverture /= 1.01F ; } void CALLBACK keyz(void) { zoomPersp *= 1.01F ; zoomParal *= 1.01F ; } void CALLBACK keyZ(void) { zoomPersp /= 1.01F ; zoomParal /= 1.01F ; } void CALLBACK keyP(void) { proj++; proj %= 2; } void CALLBACK keyp(void) { proj++; proj %= 2; } void CALLBACK up(void) { anglex++ ; } void CALLBACK down(void) { anglex-- ; } void CALLBACK left(void) { angley++ ; } void CALLBACK right(void) { angley-- ; } void main(void) { auxInitDisplayMode(AUX_DOUBLE|AUX_RGBA|AUX_DEPTH); auxInitPosition(0,0,200,200); auxInitWindow("Visualisations"); myinit(); auxKeyFunc(AUX_O,keyO); auxKeyFunc(AUX_o,keyo); auxKeyFunc(AUX_P,keyP); auxKeyFunc(AUX_p,keyp); auxKeyFunc(AUX_Z,keyZ); auxKeyFunc(AUX_z,keyz); auxKeyFunc(AUX_UP,up) ; auxKeyFunc(AUX_DOWN,down) ; auxKeyFunc(AUX_LEFT,left) ; auxKeyFunc(AUX_RIGHT,right) ; auxReshapeFunc(myReshape); auxMainLoop(display); }
RETOUR