/* Auteur: Nicolas JANEY */ /* nicolas.janey@univ-fcomte.fr */ /* Decembre 2004 */ /* Animation de camera via le clavier */ #include #include #include #include #include #include "ModuleCouleurs.h" #include "ModuleMenus.h" #include "ModuleFont.h" static int mode = 1; static int f1; static int f2; void myinit(void) { GLfloat shinines[] = { 100.0F }; glClearColor(0.5F,0.5F,1.0F,1.0F) ; glMaterialfv(GL_FRONT,GL_DIFFUSE,couleurBlanc()); glMaterialfv(GL_FRONT,GL_SPECULAR,couleurBlanc()); glMaterialfv(GL_FRONT,GL_SHININESS,shinines); glLightfv(GL_LIGHT0,GL_DIFFUSE,couleurGrisMoyen()); glLightfv(GL_LIGHT0,GL_SPECULAR,couleurRouge()); glLightfv(GL_LIGHT1,GL_DIFFUSE,couleurGrisMoyen()); glLightfv(GL_LIGHT1,GL_SPECULAR,couleurVert()); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glEnable(GL_LIGHT1); glDepthFunc(GL_LESS); glEnable(GL_DEPTH_TEST); glEnable(GL_AUTO_NORMAL); glEnable(GL_NORMALIZE); } void scene(void) { GLfloat pos0[] = { 1.0F,1.0F,1.0F,0.0F }; GLfloat pos1[] = { 1.0F,-1.0F,-1.0F,0.0F }; glLightfv(GL_LIGHT0,GL_POSITION,pos0); glLightfv(GL_LIGHT1,GL_POSITION,pos1); glPushMatrix(); switch ( mode ) { case 0 : { for ( int i = -75 ; i <= 75 ; i += 50 ) for ( int j = -75 ; j <= 75 ; j += 50 ) for ( int k = -75 ; k <= 75 ; k += 50 ) { glPushMatrix(); glTranslatef(i,j,k); glRotatef(30.0F,1.0F,1.0F,1.0F); glutSolidSphere(15,24,24); glPopMatrix(); } } break; case 1 : glutSolidSphere(100.0F,72,72); break; } glPopMatrix(); } static float px = 1000.0F ; static int fw ; static int fh ; void redisplay(void) { glutPostWindowRedisplay(f1); glutPostWindowRedisplay(f2); } void reshape(int w,int h) { glViewport(0,0,w,h); fw = w; fh = h; } void display(void) { glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(13.0*1000.0/px, fw/(float)fh, px-110.0F,px+110.0F); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(px,0.0F,0.0F, 0.0F,0.0F,0.0F, 0.0F,1.0F,0.0F); scene(); glFlush(); glutSwapBuffers(); } void special(int k,int x,int y) { switch ( k ) { case GLUT_KEY_DOWN : px += 2.0F; if ( px > 1000.0F ) px = 1000.0F; redisplay(); break; case GLUT_KEY_UP : px -= 2.0F; if ( px < 120.0F ) px = 120.0F; redisplay(); break; } } void key(unsigned char k,int x,int y) { switch ( k ) { case 0x1B : exit(0); break; case 0x0D : mode = !mode; redisplay(); } } void reshape2(int w,int h) { glViewport(0,0,w,h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0,w,-h,0,-1.0,1.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); } void display2() { glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT); glClearColor(0.0F,0.0F,0.0F,1.0F) ; glPushMatrix(); glColor4fv(couleurBlanc()); float pos = 1.0F; placeFontCursor(5.0F,-pos*20.0F,0.0F) ; simpleBitmapOutput(1,REGULAR8x13,"Position en x : %4.0f",px) ; pos += 1.0F; placeFontCursor(5.0F,-pos*20.0F,0.0F) ; simpleBitmapOutput(1,REGULAR8x13,"Angle d'ouverture : %8.3f degres",13000.0F/px) ; glPopMatrix(); glutSwapBuffers(); } int main(int argc,char **argv) { glutInit(&argc,argv); glutInitDisplayMode(GLUT_RGBA|GLUT_DEPTH|GLUT_DOUBLE); glutInitWindowSize(250,250); glutInitWindowPosition(50,50); f1 = glutCreateWindow("Animation de caméra"); myinit(); creationMenuBasique(); glutReshapeFunc(reshape); glutKeyboardFunc(key); glutSpecialFunc(special); glutDisplayFunc(display); glutInitWindowSize(360,50); glutInitWindowPosition(60,330); glutInitDisplayMode(GLUT_RGBA|GLUT_DEPTH|GLUT_DOUBLE); f2 = glutCreateWindow("Valeurs"); creationMenuBasique(); glutDisplayFunc(display2); glutReshapeFunc(reshape2); glutKeyboardFunc(key); glutSpecialFunc(special); glutMainLoop(); return(0); }