#include <windows.h> #include <GL/gl.h> #include <GL/glu.h> #include <GL/glaux.h> #include <stdio.h> #include <stdlib.h> #include <math.h> static float anglex = 0.0F ; static int scene = 0 ; static int width ; static int height ; void CALLBACK 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) ; auxWireCube(2); glPopMatrix(); glPushMatrix(); glTranslatef(-3.0f,3.0f,0.0f); glRotatef(anglex,1.0F,0.0F,0.0F) ; auxWireSphere(1); glPopMatrix(); glPushMatrix(); glTranslatef(3.0f,-3.0f,0.0f); glRotatef(anglex,1.0F,0.0F,0.0F) ; auxWireCylinder(1,2); glPopMatrix(); glPushMatrix(); glTranslatef(-3.0f,-3.0f,0.0f); glRotatef(anglex,1.0F,0.0F,0.0F) ; auxWireCone(1,2); glPopMatrix(); glFlush(); auxSwapBuffers(); } void myinit (void) { glClearColor(0.5F,0.5F,0.5F,0.0F); glColor3f(1.0F,1.0F,1.0F); glEnable(GL_DEPTH_TEST); } void CALLBACK myReshape(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 CALLBACK enter(void) { scene = (scene+1) % 9 ; myReshape(width,height); } void CALLBACK idle(void) { anglex++ ; display(); } void main(void) { auxInitDisplayMode(AUX_DOUBLE|AUX_RGBA|AUX_DEPTH); auxInitPosition (0,0,300,300); auxInitWindow("Camera pour la perspective") ; myinit(); auxKeyFunc(AUX_RETURN,enter) ; auxIdleFunc(idle); auxReshapeFunc(myReshape); auxMainLoop(display); }
RETOUR