// TRANSFORMATIONS HIERARCHIQUES // UNE BRANCHE #include /* glut.h includes gl.h and glu.h */ #include "glut.h" int NumeroDImage=0; void setup(void) { // set the background color glClearColor(0.05f, 0.05f, 0.95f, 1.0f); } void rect() { glRectf(0.0, -0.05, 0.5, 0.05); } void DessineObjet1() { glColor3f( 1., 0.25, 0.25); rect(); } void DessineObjet2() { glColor3f( 0.25, 1., 0.25); rect(); } void DessineObjet3() { glColor3f( 1., 1., 1.); rect(); } void FonctionAppelleeToutesLes33Millisecondes(int value) { printf( "NumeroDImage = %d\n", NumeroDImage); NumeroDImage += 1; glutPostRedisplay(); glutTimerFunc( 33, FonctionAppelleeToutesLes33Millisecondes, 1); } void AnimeObjet1() { int Indice; Indice = NumeroDImage % 100; if (Indice < 50) { glRotatef( Indice - 25, 0. , 0., 1.); } else { glRotatef( 75 - Indice, 0. , 0., 1.); } } void AnimeObjet2() { int Indice; Indice = NumeroDImage % 100; if (Indice < 50) { glRotatef( Indice - 25, 0. , 0., 1.); } else { glRotatef( 75 - Indice, 0. , 0., 1.); } } void AnimeObjet3() { int Indice; Indice = (NumeroDImage*7) % 100; if (Indice < 50) { glRotatef( Indice - 25, 0. , 0., 1.); } else { glRotatef( 75 - Indice, 0. , 0., 1.); } } void DuRepereGlobalAObjet1() { glTranslatef( -0.7, -0.0, 0); AnimeObjet1(); } void DeObjet1AObjet2() { glTranslatef( 0.5, 0., 0.); AnimeObjet2(); } void DeObjet2AObjet3() { glTranslatef( 0.5, 0., 0.); AnimeObjet3(); } void Affichage(int value) { printf("Affichage\n"); glClear(GL_COLOR_BUFFER_BIT); glPushMatrix(); // ESSAYER SANS CA!!! DuRepereGlobalAObjet1(); // glRotatef( 10., 0., 0., 1.); // MOUVEMENT DE L'OBJET 1 DessineObjet1(); DeObjet1AObjet2(); // glRotatef( 45., 0., 0., 1.); // MOUVEMENT DE L'OBJET 2 DessineObjet2(); DeObjet2AObjet3(); // glRotatef( 45., 0., 0., 1.); // MOUVEMENT DE L'OBJET 3 DessineObjet3(); glPopMatrix(); // ESSAYER SANS CA!!! glFlush(); glutSwapBuffers(); } int main(int argc, char** argv) { glutInit(&argc,argv); glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGBA); glutInitWindowSize(512,512); glutInitWindowPosition(10,50); glutCreateWindow("rect"); setup(); glutDisplayFunc( Affichage); glutTimerFunc( 33, FonctionAppelleeToutesLes33Millisecondes, 1); glutMainLoop(); }