/* Auteur: Nicolas JANEY */ /* nicolas.janey@univ-fcomte.fr */ /* Septembre 2005 */ /* Animation d'une mouette stylisee */ #include #include #include #include #include #include "ModuleCouleurs.h" #include "ModuleMenus.h" #include "ModuleReshape.h" #include "ModuleManipulateur.h" static int image = 0; static int mode = 0; void myinit(void) { GLfloat shinines[] = { 50.0 }; GLfloat l_pos[] = { 1.0,1.0,1.0,0.0 }; glClearColor(0.5F,0.5F,1.0F,1.0F) ; glMaterialfv(GL_FRONT,GL_SPECULAR,couleurBlanc()); glMaterialfv(GL_FRONT,GL_SHININESS,shinines); glLightfv(GL_LIGHT0,GL_POSITION,l_pos); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glEnable(GL_AUTO_NORMAL); glEnable(GL_NORMALIZE); glDepthFunc(GL_LESS); glEnable(GL_DEPTH_TEST); } void aileDroite(float a1,float a2) { glPushMatrix(); glTranslatef(0.75F,0.0F,0.0F); glRotatef(a1,0.0F,0.0F,1.0F); glTranslatef(1.0F,0.0F,0.0F); glPushMatrix(); glScalef(2.0F,0.1F,0.5F); glutSolidSphere(1.0,18,18); glPopMatrix(); glTranslatef(2.0F,0.0F,0.0F); glRotatef(a2,0.0F,0.0F,1.0F); glTranslatef(0.9F,0.0F,0.0F); glPushMatrix(); glScalef(1.0F,0.1F,0.5F); glutSolidSphere(1.0,18,18); glPopMatrix(); glPopMatrix(); } void aileGauche(float a1,float a2) { glPushMatrix(); glTranslatef(-0.75F,0.0F,0.0F); glRotatef(-a1,0.0F,0.0F,1.0F); glTranslatef(-1.0F,0.0F,0.0F); glPushMatrix(); glScalef(2.0F,0.1F,0.5F); glutSolidSphere(1.0,18,18); glPopMatrix(); glTranslatef(-2.0F,0.0F,0.0F); glRotatef(-a2,0.0F,0.0F,1.0F); glTranslatef(-0.9F,0.0F,0.0F); glPushMatrix(); glScalef(1.0F,0.1F,0.5F); glutSolidSphere(1.0,18,18); glPopMatrix(); glPopMatrix(); } void mouette() { float a1 =(float) 25.0*cos(image/180.0F); float a2 =(float) -40.0*cos((image+90)/180.0F); glPushMatrix(); glTranslatef(0.0F,-a1/100.0F,0.0F); glPushMatrix(); glScalef(0.75F,0.5F,1.5F); glutSolidSphere(1.0,18,18); glPopMatrix(); aileDroite(a1,a2); aileGauche(a1,a2); glPopMatrix(); } void idle(void) { image++; glutPostRedisplay(); } void display(void) { glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); glPolygonMode(GL_FRONT_AND_BACK,(mode) ? GL_LINE : GL_FILL); glPushMatrix(); manipulateurSouris(); manipulateurClavier(); mouette(); glPopMatrix(); glFlush(); glutSwapBuffers(); } void key(unsigned char key,int x,int y) { if ( keyManipulateur(key,x,y) ) glutPostRedisplay(); else switch ( key ) { case 0x0D : { static int anim = 1; anim = ! anim; glutIdleFunc((anim) ? idle : NULL); } break; case ' ' : mode = !mode; glutPostRedisplay(); break; } } int main(int argc,char **argv) { glutInit(&argc,argv); glutInitDisplayMode(GLUT_RGBA|GLUT_DEPTH|GLUT_DOUBLE); glutInitWindowSize(350,200); glutInitWindowPosition(50,50); glutCreateWindow("Une mouette"); myinit(); creationMenuBasique(); setParametresOrthoBasique(-2.5,2.5,-2.5,2.5,-50.0,50.0); setManipulateurDistance(1.0F); glutReshapeFunc(reshapeOrthoBasique); glutIdleFunc(idle); glutKeyboardFunc(key); glutSpecialFunc(specialBasique); glutMotionFunc(motionBasique); glutMouseFunc(sourisBasique); glutDisplayFunc(display); glutMainLoop(); return(0); }