 
    
Le source: SchemaReflexion.cpp
/* Auteur: Nicolas JANEY         */
    /* nicolas.janey@univ-fcomte.fr  */
    /* Janvier 2002                  */
    /* Schema du calcul de l'angle   */
    /* de reflexion                  */
    
    #include <stdio.h>
    #include <math.h>
    #include <stdlib.h>
    
    #include <GL/glut.h>
    #include <GL/gl.h>
    #include <GL/glu.h>
    
    #include "ModuleCouleurs.h"
    #include "ModuleFleche.h"
    #include "ModuleDessinArc.h"
    #include "ModuleMatriceVecteur.h"
    #include "ModuleFont.h"
    #include "ModuleManipulateur.h"
    #include "ModuleMenus.h"
    #include "ModuleReshape.h"
    
    static vecteur p = { -9.0F,9.0F,0.0F,1.0F } ;
    static vecteur r ;
    static vecteur i ;
    static vecteur n = { 0.0F,1.0F,0.0F } ;
    static float thetai ;
    static int f1;
    static int f2;
    
    void myinit(void) {
      GLfloat light_position0[] = { 1.0F,0.0F,1.0F,0.0F };
      GLfloat light_position1[] = { -1.0F,0.0F,1.0F,0.0F };
      glLightfv(GL_LIGHT0,GL_AMBIENT,couleurNoir());
      glLightfv(GL_LIGHT0,GL_DIFFUSE,couleurBlanc());
      glLightfv(GL_LIGHT1,GL_DIFFUSE,couleurBlanc());
      glLightfv(GL_LIGHT0,GL_SPECULAR,couleurNoir());
      glLightfv(GL_LIGHT0,GL_POSITION,light_position0);
      glLightfv(GL_LIGHT1,GL_POSITION,light_position1);
      glEnable(GL_LIGHT0);
      glEnable(GL_LIGHT1);
      glEnable(GL_AUTO_NORMAL);
      glEnable(GL_NORMALIZE);
      glDepthFunc(GL_LESS);
      glEnable(GL_ALPHA_TEST);
      glEnable(GL_BLEND);
      glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
      glLightModeli(GL_LIGHT_MODEL_TWO_SIDE,GL_TRUE);
    }
    
    void reflexion(vecteur p) {
      glColor4fv(couleurRouge()) ;
      r[0] = -p[0] ;
      r[1] = p[1] ;
      r[2] = -p[2] ;
      normalise(r) ;
      i[0] = p[0] ;
      i[1] = p[1] ;
      i[2] = p[2] ;
      normalise(i) ;
      thetai = acos(produitScalaire(r,n))*180.0F/3.14159F ;
      flecheEnVolume(10*r[0],10*r[1],10*r[2],0.35F,1.5F,0.07F);
      traceAngleFleche(n,r,30,7.0F,1,2,8.0F,0.5F) ;
      vecteur pint;
      positionIntermediaire(n,r,7.0F,pint);
      placeFontCursor(pint[0],pint[1],pint[2]) ;
      deplacementCursor(0,-10,0) ;
      simpleBitmapOutput(1,SYMBOL,"q") ; 
      deplacementCursor(7,-8,0) ;
      simpleBitmapOutput(1,REGULAR6x10,"r") ; 
      placeFontCursor(5*r[0],5*r[1],5*r[2]) ;
      deplacementCursor(5,15,0) ;
      simpleBitmapOutput(1,REGULAR8x13,"R") ; 
      deplacementCursor(2,10,0) ;
      simpleBitmapOutput(1,DESSIN,"TF") ;
    }
    
    void displayRayons(void) {
      reflexion(p);
      glPushMatrix();
      glMaterialfv(GL_FRONT,GL_DIFFUSE,couleurJaune()) ;
      glPushMatrix();
      glTranslatef(p[0],p[1],p[2]) ;
      glEnable(GL_LIGHTING);
      glEnable(GL_CULL_FACE);
      glutSolidSphere(0.5,10,10);
      glDisable(GL_CULL_FACE);
      glDisable(GL_LIGHTING);
      glPopMatrix();
      glColor4fv(couleurJaune()) ;
      placeFontCursor(i[0]*5,i[1]*5,i[2]*5) ;
      deplacementCursor(-15,15,0) ;
      simpleBitmapOutput(1,REGULAR8x13,"I") ; 
      deplacementCursor(-18,10,0) ;
      simpleBitmapOutput(1,DESSIN,"TF") ;
      flecheEnVolume(i[0]*10,i[1]*10,i[2]*10,0.35F,1.5F,0.07F);
      traceAngleFleche(n,i,30,7.0F,1,2,8.0F,0.5F) ;
      vecteur pint;
      positionIntermediaire(n,i,7.0F,pint);
      placeFontCursor(pint[0],pint[1],pint[2]) ;
      deplacementCursor(0,-10,0) ;
      simpleBitmapOutput(1,SYMBOL,"q") ; 
      deplacementCursor(7,-8,0) ;
      simpleBitmapOutput(1,REGULAR6x10,"i") ; 
      glColor4fv(couleurJaune(0.3F)) ;
      segmentEnVolume(p[0],p[1],p[2],0.07F);
      glColor4fv(couleurMagenta()) ;
      placeFontCursor(0.0F,8.0F,0.0F) ;
      deplacementCursor(10,0,0) ;
      simpleBitmapOutput(1,REGULAR8x13,"N") ; 
      deplacementCursor(7,-5,0) ;
      simpleBitmapOutput(1,DESSIN,"TF") ;
      flecheEnVolume(0.0F,10.0F,0.0F,0.35F,1.5F,0.07F);
      glPopMatrix();
    }
    
    void display(void) {
      glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
      glEnable(GL_DEPTH_TEST);
      glPushMatrix() ;
      glTranslatef(0.0F,-2.0F,0.0F);
      manipulateurSouris();
      manipulateurClavier();
      displayRayons() ;
      glEnable(GL_LIGHTING);
      glPushMatrix();
      glMaterialfv(GL_FRONT,GL_DIFFUSE,couleurBlanc(0.5F)) ;
      glScalef(16.0F,0.0001F,14.0F) ;
      glEnable(GL_CULL_FACE);
      glutSolidCube(1.0) ;
      glDisable(GL_CULL_FACE);
      glPopMatrix();
      glDisable(GL_LIGHTING);
      glPopMatrix() ;
      glDisable(GL_DEPTH_TEST);
      glFlush();
      glutSwapBuffers() ;
      glutPostWindowRedisplay(f2);
    }
    
    void key2(unsigned char key,int x,int y) {
      switch ( key ) {
        case '1'  : p[0] -= 0.2F ;
                    glutPostWindowRedisplay(f1);
                    break;
        case '4'  : p[0] += 0.2F ;
                    glutPostWindowRedisplay(f1);
                    break;
        case '2'  : p[1] -= 0.2F ;
                    glutPostWindowRedisplay(f1);
                    break;
        case '5'  : p[1] += 0.2F ;
                    glutPostWindowRedisplay(f1);
                    break;
        case '3'  : p[2] -= 0.2F ;
                    glutPostWindowRedisplay(f1);
                    break;
        case '6'  : p[2] += 0.2F ;
                    glutPostWindowRedisplay(f1);
                    break;
        case 0x1B : exit(0);
                    break; }
    }
    
    void key(unsigned char key,int x,int y) {
      if ( keyManipulateur(key,x,y) )
        glutPostWindowRedisplay(f1);
        else
        key2(key,x,y);
    }
    
    void special(int key,int x,int y) {
      if ( specialManipulateur(key,x,y) ) {
        glutPostWindowRedisplay(f1); }
    }
    
    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();
      float pos = 1.0F;
      glColor4fv(couleurJaune());
      placeFontCursor(5.0F,-pos*20.0F,0.0F) ;
      simpleBitmapOutput(1,REGULAR8x13,"INCIDENT     : %6.3f %6.3f %6.3f",i[0],i[1],i[2]) ;
      pos += 1.0F;
      glColor4fv(couleurMagenta());
      placeFontCursor(5.0F,-pos*20.0F,0.0F) ;
      simpleBitmapOutput(1,REGULAR8x13,"NORMALE      : %6.3f %6.3f %6.3f",n[0],n[1],n[2]) ;
      pos += 1.0F;
      glColor4fv(couleurRouge());
      placeFontCursor(5.0F,-pos*20.0F,0.0F) ;
      simpleBitmapOutput(1,REGULAR8x13,"REFLEXION    : %6.3f %6.3f %6.3f",r[0],r[1],r[2]) ;
      pos += 1.0F;
      glColor4fv(couleurJaune());
      placeFontCursor(5.0F,-pos*20.0F,0.0F) ;
      simpleBitmapOutput(1,REGULAR8x13,"THETA I      :  %6.3f degres",thetai) ;
      pos += 1.0F;
      glColor4fv(couleurRouge());
      placeFontCursor(5.0F,-pos*20.0F,0.0F) ;
      simpleBitmapOutput(1,REGULAR8x13,"THETA R      :  %6.3f degres",thetai) ;
      glPopMatrix();
      glutSwapBuffers();
    }
    
    int main(int argc,char **argv) {
      glutInit(&argc,argv);
      glutInitDisplayMode(GLUT_RGBA|GLUT_DEPTH|GLUT_DOUBLE);
      glutInitWindowPosition(50,50); 
      glutInitWindowSize(310,250); 
      f1 = glutCreateWindow("Schéma réflexion");
      myinit(); 
      creationMenuBasique();
      setParametresOrthoBasique(-10.0,10.0,-10.0,10.0,-500.0,500.0);
      setManipulateurDistance(1.0F);
      setManipulateurClavierAngle(25.0F,15.0F,0.0F);
      glutReshapeFunc(reshapeOrthoBasique);
      glutKeyboardFunc(key);
      glutSpecialFunc(specialBasique);
      glutDisplayFunc(display);
      glutMotionFunc(motionBasique);
      glutMouseFunc(sourisBasique);
      glutInitWindowSize(360,110);
      glutInitWindowPosition(60,340);
      glutInitDisplayMode(GLUT_RGBA|GLUT_DEPTH|GLUT_DOUBLE);
      f2 = glutCreateWindow("Valeurs");
      creationMenuBasique();
      glutDisplayFunc(display2);
      glutReshapeFunc(reshape2);
      glutKeyboardFunc(key2);
      glutSpecialFunc(special);
      glutMainLoop();
      return(0);
    }