home *** CD-ROM | disk | FTP | other *** search
/ ftp.hitl.washington.edu / ftp.hitl.washington.edu.tar / ftp.hitl.washington.edu / pub / people / habib / kodak / Vrml2_Viewer.cpp~ < prev    next >
Text File  |  2000-04-18  |  86KB  |  2,349 lines

  1. // By Habib Abi-Rached
  2. // 3 March 1998. 
  3. // Using Glut / OpenGl
  4.  
  5.  
  6. #include <stdio.h>
  7. #include <iostream.h>  
  8. #include <stdlib.h>
  9. #include <string.h>
  10. #include <math.h>       /* for cos(), sin(), and sqrt() */
  11. #include <GL/glut.h>
  12. #include "variables.h"
  13. #include "f-gen.h"
  14. #include "trackball.h"
  15. #include "mirror.h"
  16. #include <windows.h>  // WinUnix
  17. #include <mmsystem.h> // WinUnix
  18. #include "interface.h"
  19. #include <malloc.h>
  20.  
  21. #define DimX 400
  22. #define DimY 150
  23. #define DimZ 400
  24.  
  25. extern void Draw_Vrml(Type_Transform *, int numlist);
  26. extern Type_Transform * Read_Vrml_File(char *);
  27. extern "C" unsigned char * read_JPEG_file (char *, unsigned char *, int *, int *);
  28. void
  29. inline buildmf()
  30. {
  31.    mf[0][0] = m[0][0];
  32.    mf[0][1] = m[0][1];
  33.    mf[0][2] = m[0][2];
  34.    mf[0][3] = m[0][3];
  35.  
  36.    mf[1][0] = m[1][0];
  37.    mf[1][1] = m[1][1];
  38.    mf[1][2] = m[1][2];
  39.    mf[1][3] = m[1][3];
  40.  
  41.    mf[2][0] = m[2][0];
  42.    mf[2][1] = m[2][1];
  43.    mf[2][2] = m[2][2];
  44.    mf[2][3] = m[2][3];
  45.  
  46.    mf[3][0] = m[3][0];
  47.    mf[3][1] = m[3][1];
  48.    mf[3][2] = m[3][2];
  49.    mf[3][3] = m[3][3];
  50. }
  51. void  
  52. glerror()
  53. {
  54.   GLenum errCode;
  55.    errCode = glGetError();
  56.    cout << gluErrorString(errCode) << endl;
  57. }
  58. void
  59. inputdollar (char phrase[70]) 
  60. {  
  61.    char mot[20] ;
  62.    char blanc [2];
  63.    blanc[0] = ' ';
  64.    strcpy (phrase,""); /* pour vider input car on va lui faire un strcat. */
  65.    printf ("---> ");
  66.    while (blanc[0] == ' ')
  67.    {
  68.     scanf ("%s",mot);
  69.     scanf ("%1c",blanc);
  70.     strcat (phrase,mot);
  71.     strncat (phrase,blanc,1);
  72.     
  73.    }
  74.    
  75. }
  76.  
  77. void
  78. inline
  79. showMessage(GLfloat x, GLfloat y, GLfloat z, char *message)
  80. {
  81.          glPushMatrix();
  82.          // glDisable(GL_LIGHTING);
  83.          glRasterPos3f(x,y,z);
  84.          //glScalef(.02, .02, .02); 
  85.          
  86.          while (*message) {
  87.                     //glutStrokeCharacter(GLUT_STROKE_ROMAN, *message);
  88.                     glutBitmapCharacter(GLUT_BITMAP_8_BY_13, *message);
  89.                     message++;
  90.          }
  91.          glPopMatrix();
  92.          if (FLAG_TOGGLE_MENU1) {
  93.              glEnable(GL_LIGHTING);
  94.          }
  95. }
  96. /*________________________trouver____________________________________*/
  97. /* c'est une fct qui calcul la moyenne */
  98. /* d'un tableau TABC et le min et le   */
  99. /* et le max du meme TABC et renvoie   */
  100. /* ces 3 valeurs en renvoyant une struc*/
  101. inline
  102. struct bmm trouver (float *tabc,int dim[1])
  103. { int i;
  104.   int local_dim = dim[0];
  105.   struct bmm bmm2;
  106.   bmm2.bar=0;
  107.   bmm2.min=tabc[0];
  108.   bmm2.max=tabc[0];
  109.   for (i=0; i<dim[0]; i++)
  110.   {
  111.       if (tabc[i] != NaN) {
  112.             bmm2.bar = bmm2.bar + tabc [i];
  113.             if (tabc[i]<bmm2.min) bmm2.min = tabc[i];
  114.             if (tabc[i]>bmm2.max) bmm2.max = tabc[i];
  115.       }
  116.       else local_dim = local_dim -1;
  117.   }
  118.   bmm2.bar = bmm2.bar/local_dim;
  119.   return bmm2;
  120. }
  121. /*_____________________trouver_bar_min_max_________________________
  122. /* c'est une fct qui calcul le bar, max et min */
  123. /* de 3 tableaux: xc, yc, zc.                  
  124. //ftrouver_bar_min_max_sig
  125. void
  126. trouver_bar_min_max_sig(float *xc,float *yc, float* zc,int dim[1])
  127. { struct bmm bmm1[i];
  128.   
  129.   bmm1[i]=trouver (xc,dim);
  130.   xmax = bmm1[i].max;
  131.   xbar = bmm1[i].bar;
  132.   xmin = bmm1[i].min;
  133.   bmm1[i]=trouver (yc,dim);
  134.   ymax = bmm1[i].max;
  135.   ybar = bmm1[i].bar;
  136.   ymin = bmm1[i].min;
  137.   bmm1[i]=trouver (zc,dim);
  138.   zmax = bmm1[i].max;
  139.   zbar = bmm1[i].bar;
  140.   zmin = bmm1[i].min;
  141.  
  142.     // Calculating sigma and taking care of NaN.
  143.     sigx = sigy = sigz = 0;
  144.     int dimx, dimy, dimz; // to take care of NaN.
  145.     dimx = dimy = dimz = dim[0];
  146.     for (int i=0; i< dim[0]; i++){
  147.             if (xc[i] != NaN)
  148.                 sigx = sigx + (xbar - xc[i]) * (xbar - xc[i]);
  149.             else dimx = dimx -1;
  150.  
  151.             if (yc[i] != NaN)
  152.                 sigy = sigy + (ybar - yc[i]) * (ybar - yc[i]);
  153.             else (dimy = dimy -1);
  154.  
  155.             if (zc[i] != NaN)
  156.                 sigz = sigz + (zbar - zc[i]) * (zbar - zc[i]);
  157.             else (dimz = dimz -1);
  158.     }
  159.     sigx = sigx/dimx;
  160.     sigy = sigy/dimy;
  161.     sigz = sigz/dimz;
  162.  
  163.     sigx = sqrt (sigx);    
  164.     sigy = sqrt (sigy);    
  165.     sigz = sqrt (sigz);    
  166.  
  167.     // Normalizing sigma so that when we scale it keeps the smallest axes fix.
  168.     if ((sigx<sigy) && (sigx<sigz)) sig_min = sigx;
  169.     else     
  170.              if ((sigy<sigx) && (sigy<sigz)) sig_min = sigy;
  171.              else sig_min = sigz;
  172.     
  173.     sig_x_n = sigx/sig_min;
  174.     sig_y_n = sigy/sig_min;
  175.     sig_z_n = sigz/sig_min;
  176.  
  177.     // Calculating delta.
  178.     deltax = fabs(xmax - xmin);
  179.     deltay = fabs(ymax - ymin);
  180.     deltaz = fabs(zmax - zmin);
  181.  
  182.     // Normalizing sigma so that when we scale it keeps the smallest axes fix.
  183.     if ((deltax<deltay) && (deltax<deltaz)) delta_min = deltax;
  184.     else     
  185.              if ((deltay<deltax) && (deltay<deltaz)) delta_min = deltay;
  186.              else delta_min = deltaz;
  187.  
  188.     deltax_n = deltax/delta_min;
  189.     deltay_n = deltay/delta_min;
  190.     deltaz_n = deltaz/delta_min;
  191.  
  192.     // Calculating xmin_e ... for some extraneous uses...
  193.     xmin_e = xmin - 0.3*deltax;
  194.     ymin_e = ymin - 0.3*deltay;
  195.     zmin_e = zmin - 0.3*deltaz;
  196.     xmax_e = xmax + 0.3*deltax;
  197.     ymax_e = ymax + 0.3*deltay;
  198.     zmax_e = zmax + 0.3*deltaz;
  199.  
  200.     cout << "xmax=" << xmax << "  ymax=" << ymax << "  zmax=" << zmax << endl;
  201.     cout << "xmin=" << xmin << "  ymin=" << ymin << "  zmin=" << zmin << endl;
  202.     cout << "xbar=" << xbar << "  ybar=" << ybar << "  zbar=" << zbar << endl;
  203.     cout << "sigx="<< sigx << "  sigy=" << sigy << "  sigz=" << sigz << endl;
  204.     cout << "sig_x_n="<< sig_x_n << "  sig_y_n=" << sig_y_n << "  sig_z_n=" << sig_z_n << endl;
  205.     cout << "xmax-xmin=" << xmax - xmin << "  ymax-ymin=" << ymax - ymin << " zmax-zmin=" << zmax - zmin << endl;
  206.     cout << "deltax=" << deltax << "  deltay="<<  deltay << "  deltaz=" << deltaz << endl;
  207.     cout << "deltax_n=" << deltax_n << "  deltay_n="<<  deltay_n << "  deltaz_n=" << deltaz_n << endl;
  208.   
  209. }*/
  210.  
  211. void
  212. inline
  213. draw_axes()
  214. {
  215.          void dvertical_adjx();
  216.          glBegin(GL_LINES);
  217.          glColor3f (0.2f,0.2f,1.0f);
  218.          glVertex3f (0.0f, 0.0f, 0.0f);
  219.          glVertex3f (deltax, 0.0f, 0.0f);
  220.          glEnd();
  221.          showMessage(deltax,0,0, string3);
  222.          glBegin(GL_LINES);
  223.          glColor3f (0.15f,0.7f,0.15f);
  224.          glVertex3f (0.0f, 0.0f, 0.0f);
  225.          glVertex3f (0.0f, deltay, 0.0f);    
  226.          glEnd();
  227.          showMessage(0,deltay,0, string2);
  228.          glBegin(GL_LINES);
  229.          glColor3f (1.0f,0.2f,0.2f);
  230.          glVertex3f (0, 0, 0);
  231.          glVertex3f (0.0, 0.0, deltaz);
  232.          glEnd();      
  233.          showMessage(0,0,deltaz, string1);
  234. }
  235.  
  236. void
  237. inline
  238. draw_box()
  239. {
  240.          glBegin(GL_LINES);
  241.          glColor3f (0.45f,0.45f,0.45f);
  242.          glVertex3f (xmin,ymax,zmax);
  243.          glVertex3f (xmax,ymax,zmax);
  244.          glEnd();
  245.  
  246.          glBegin(GL_LINES);
  247.          glColor3f (0.45f,0.45f,0.45f);
  248.          glVertex3f (xmax,ymax,zmax);
  249.          glVertex3f (xmax,ymin,zmax);
  250.          glEnd();
  251.  
  252.          glBegin(GL_LINES);
  253.          glColor3f (0.45f,0.45f,0.45f);
  254.          // glColor3f (0.5,0,0);
  255.          glVertex3f (xmax,ymin,zmax);
  256.          glVertex3f (xmin,ymin,zmax);
  257.          glEnd();
  258.  
  259.          glBegin(GL_LINES);
  260.          glColor3f (0.45f,0.45f,0.45f);
  261.          // glColor3f (0.0,0.5,0.0);
  262.          glVertex3f (xmin,ymin,zmax);
  263.          glVertex3f (xmin,ymax,zmax);
  264.          glEnd();
  265.  
  266.          glBegin(GL_LINES);
  267.          glColor3f (0.45f,0.45f,0.45f);
  268.          // glColor3f (0,0,0.8);
  269.          glVertex3f (xmin,ymax,zmax);
  270.          glVertex3f (xmin,ymax,zmin);
  271.          glEnd();
  272.  
  273.          glBegin(GL_LINES);
  274.          glColor3f (0.45f,0.45f,0.45f);
  275.          //glColor3f (0,0,0.8);
  276.          glVertex3f (xmax,ymax,zmax);
  277.          glVertex3f (xmax,ymax,zmin);
  278.          glEnd();
  279.  
  280.          glBegin(GL_LINES);
  281.          glColor3f (0.45f,0.45f,0.45f);
  282.          //glColor3f (0,0,0.8);
  283.          glVertex3f (xmax,ymin,zmax);
  284.          glVertex3f (xmax,ymin,zmin);
  285.          glEnd();
  286.  
  287.          glBegin(GL_LINES);
  288.          glColor3f (0.45f,0.45f,0.45f);
  289.          //glColor3f (0,0,0.8);
  290.          glVertex3f (xmin,ymin,zmax);
  291.          glVertex3f (xmin,ymin,zmin);
  292.          glEnd();
  293.  
  294.          glBegin(GL_LINES);
  295.          glColor3f (0.45f,0.45f,0.45f);
  296.          //glColor3f (0.0,0.5,0.0);
  297.          glVertex3f (xmin,ymax,zmin);
  298.          glVertex3f (xmin,ymin,zmin);
  299.          glEnd();
  300.  
  301.          glBegin(GL_LINES);
  302.          glColor3f (0.45f,0.45f,0.45f);
  303.          //glColor3f (0.5,0,0);
  304.          glVertex3f (xmin,ymin,zmin);
  305.          glVertex3f (xmax,ymin,zmin);
  306.          glEnd();
  307.  
  308.          glBegin(GL_LINES);
  309.          glColor3f (0.45f,0.45f,0.45f);
  310.          //glColor3f (0.0,0.5,0.0);
  311.          glVertex3f (xmax,ymin,zmin);
  312.          glVertex3f (xmax,ymax,zmin);
  313.          glEnd();
  314.  
  315.          glBegin(GL_LINES);
  316.          glColor3f (0.45f,0.45f,0.45f);
  317.          //glColor3f (0.5,0,0);
  318.          glVertex3f (xmax,ymax,zmin);
  319.          glVertex3f (xmin,ymax,zmin);
  320.          glEnd();
  321.  
  322.  
  323. }
  324.  
  325. void
  326. inline
  327. recalcModelView(void) //frecalcmodelview
  328. {
  329.     void init();
  330.    // GLfloat m[4][4]; Global variable because used after.
  331.    glMatrixMode(GL_MODELVIEW);
  332.    glPopMatrix();
  333.    glPushMatrix();
  334.  
  335.     if (LIGHTS_FIX_WITH_CAMERA) {
  336.     glLightfv(GL_LIGHT0, GL_POSITION, lightZeroPosition);
  337.     glLightfv(GL_LIGHT1, GL_POSITION, lightOnePosition);
  338.     glLightfv(GL_LIGHT0, GL_DIFFUSE, lightZeroColor);
  339.     glLightfv(GL_LIGHT1, GL_DIFFUSE, lightOneColor);// Because light is affected by the scale.
  340.     glLightfv(GL_LIGHT0, GL_AMBIENT, ambi);
  341.     glLightfv(GL_LIGHT1, GL_AMBIENT, ambi);
  342.     }
  343.    double scalex, scaley, scalez;
  344.    // build_rotmatrix(m, curquat);
  345.  
  346.    // I moved this block to interface because the rotation should be done as soon as we move the mouse.
  347.    //rotate the 3D up,lk,hor system.
  348.    /*lk_rt = mult_matrix_vector(m,lk);   // lk is (0,0,1)      lk_rt  is the lk  after the quaternion rotation
  349.    up_rt  = mult_matrix_vector(m,up );   // up  is (0,1,0)     up_rt  is up      after the quaternion rotation.
  350.    hor_rt = mult_matrix_vector(m,hor);   // hor is (1,0,0)     hor_rt is hor     after the quaternion rotation.*/
  351.  
  352.    //up_rt  = vectoriel (hor_rt,lk_rt);                           
  353.    // The translation is done in the interface mode.
  354.  
  355.    // Translate lk_tr in the Z direction.
  356.    gluLookAt(eye.x,eye.y,eye.z,   // eye is at (... 
  357.             eye.x+lk_rt.x,eye.y+lk_rt.y,eye.z+lk_rt.z,      // looking to 
  358.                 up_rt.x,up_rt.y,up_rt.z);      // up is in positive Y direction */
  359.  
  360.    // We should normalize scaling in order to maintain the same lenth for the smaller axes.
  361.     if (SCALE_SIGMA)  {
  362.              scalex = 1/sigx;
  363.              scaley = 1/sigy;
  364.              scalez = 1/sigz;
  365.     }
  366.  
  367.     // We should normalize scaling in order to maintain the same lenth for the smaller axes.
  368.     if (SCALE_MIDDLE)  {
  369.              scalex = 1/deltax;
  370.              scaley = 1/deltay;
  371.              scalez = 1/deltaz;
  372.     }
  373.     else {
  374.              scalex = 1;  
  375.              scaley = 1;
  376.              scalez = 1;
  377.     }
  378.  
  379.     // Translate the origin ONLY IF INDICATED OTHERWHISE PUT IT IN 0,0,0
  380.              // 
  381.     if (TRANSLATE_TO_GRAVITY) glTranslatef (-xbar*scalex,-ybar*scaley,-zbar*scalez); 
  382.     if (TRANSLATE_TO_MIDDLE ) glTranslatef (-(xmin+xmax)*scalex/2,-(ymin+ymax)*scaley/2,-(zmin+zmax)*scalez/2); 
  383.  
  384.  
  385.     // SCALE ONLY IF REQUESTED OTHERWISE DO NOT SCALE (1,1,1).
  386.   glScalef (scalex, scaley, scalez);
  387.   newModel = 0;
  388.   if (!LIGHTS_FIX_WITH_CAMERA) {
  389.       glLightfv(GL_LIGHT0, GL_POSITION, lightZeroPosition);
  390.     glLightfv(GL_LIGHT1, GL_POSITION, lightOnePosition);
  391.     glLightfv(GL_LIGHT0, GL_DIFFUSE, lightZeroColor);
  392.     glLightfv(GL_LIGHT1, GL_DIFFUSE, lightOneColor);// Because light is affected by the scale.
  393.     glLightfv(GL_LIGHT0, GL_AMBIENT, ambi);
  394.     glLightfv(GL_LIGHT1, GL_AMBIENT, ambi);
  395.   }
  396. }
  397. void
  398. inline
  399. recalcModelViewOtherCars(void) //frecalcmodelviewothercars
  400. {
  401.     void init();
  402.    glMatrixMode(GL_MODELVIEW);
  403.    glPopMatrix();
  404.    glPushMatrix();
  405.  
  406.    // Translate lk_tr in the Z direction.
  407.    gluLookAt(eye.x,eye.y,eye.z,   // eye is at (... 
  408.             eye.x+lk_rt.x,eye.y+lk_rt.y,eye.z+lk_rt.z,      // looking to 
  409.                 up_rt.x,up_rt.y,up_rt.z);      // up is in positive Y direction */
  410.  
  411. }
  412. void
  413. inline
  414. recalcModelView_Car(void) //frecalcmodelview
  415. {
  416.     void init();
  417.    // GLfloat m[4][4]; Global variable because used after.
  418.    glMatrixMode(GL_MODELVIEW);
  419.    glPopMatrix();
  420.    glPushMatrix();
  421.  
  422.     if (LIGHTS_FIX_WITH_CAMERA) {
  423.       glLightfv(GL_LIGHT0, GL_POSITION, lightZeroPosition);
  424.     glLightfv(GL_LIGHT1, GL_POSITION, lightOnePosition);
  425.     glLightfv(GL_LIGHT2, GL_POSITION, light2Position);
  426.     glLightfv(GL_LIGHT3, GL_POSITION, light3Position);
  427.     glLightfv(GL_LIGHT0, GL_DIFFUSE, lightZeroColor_Car);
  428.     glLightfv(GL_LIGHT1, GL_DIFFUSE, lightOneColor_Car); // Because light is affected by the scale.
  429.     glLightfv(GL_LIGHT2, GL_DIFFUSE, lightZeroColor_Car);
  430.     glLightfv(GL_LIGHT3, GL_DIFFUSE, lightOneColor_Car); // Because light is affected by the scale.
  431.  
  432.     }
  433.    double scalex, scaley, scalez;
  434.    // build_rotmatrix(m, curquat);
  435.  
  436.    // I moved this block to interface because the rotation should be done as soon as we move the mouse.
  437.    //rotate the 3D up,lk,hor system.
  438.    /* lk_rt = mult_matrix_vector(m,lk);   // lk is (0,0,1)      lk_rt  is the lk  after the quaternion rotation
  439.    up_rt  = mult_matrix_vector(m,up ); // up  is (0,1,0)     up_rt  is up      after the quaternion rotation.
  440.    hor_rt = mult_matrix_vector(m,hor); // hor is (1,0,0)     hor_rt is hor     after the quaternion rotation.*/
  441.  
  442.    //up_rt  = vectoriel (hor_rt,lk_rt);                           
  443.    // The translation is done in the interface mode.
  444.  
  445.    // Translate lk_tr in the Z direction.
  446.    gluLookAt(eyec.x,eyec.y,eyec.z,   // eye is at (... 
  447.             eyec.x+lkc_rt.x,eyec.y+lkc_rt.y,eyec.z+lkc_rt.z,      // looking to 
  448.                 upc_rt.x,upc_rt.y,upc_rt.z);      // up is in positive Y direction */
  449.  
  450.    // We should normalize scaling in order to maintain the same lenth for the smaller axes.
  451.     if (SCALE_SIGMA)  {
  452.              scalex = 1/sigx;
  453.              scaley = 1/sigy;
  454.              scalez = 1/sigz;
  455.     }
  456.  
  457.     // We should normalize scaling in order to maintain the same lenth for the smaller axes.
  458.     if (SCALE_MIDDLE)  {
  459.              scalex = 1/deltax;
  460.              scaley = 1/deltay;
  461.              scalez = 1/deltaz;
  462.     }
  463.     else {
  464.              scalex = 1;  
  465.              scaley = 1;
  466.              scalez = 1;
  467.     }
  468.  
  469.     // Translate the origin ONLY IF INDICATED OTHERWHISE PUT IT IN 0,0,0
  470.              // 
  471.     if (TRANSLATE_TO_GRAVITY) glTranslatef (-xbar*scalex,-ybar*scaley,-zbar*scalez); 
  472.     if (TRANSLATE_TO_MIDDLE ) glTranslatef (-(xmin+xmax)*scalex/2,-(ymin+ymax)*scaley/2,-(zmin+zmax)*scalez/2); 
  473.  
  474.  
  475.     // SCALE ONLY IF REQUESTED OTHERWISE DO NOT SCALE (1,1,1).
  476.   glScalef (scalex, scaley, scalez);
  477.   newModel = 0;
  478.   if (!LIGHTS_FIX_WITH_CAMERA) {
  479.       glLightfv(GL_LIGHT0, GL_POSITION, lightZeroPosition);
  480.     glLightfv(GL_LIGHT1, GL_POSITION, lightOnePosition);
  481.     glLightfv(GL_LIGHT2, GL_POSITION, light2Position);
  482.     glLightfv(GL_LIGHT3, GL_POSITION, light3Position);
  483.     glLightfv(GL_LIGHT0, GL_DIFFUSE, lightZeroColor_Car);
  484.     glLightfv(GL_LIGHT1, GL_DIFFUSE, lightOneColor_Car); // Because light is affected by the scale.
  485.     glLightfv(GL_LIGHT2, GL_DIFFUSE, lightZeroColor_Car);
  486.     glLightfv(GL_LIGHT3, GL_DIFFUSE, lightOneColor_Car); // Because light is affected by the scale.
  487.   }
  488. }
  489.  
  490.  
  491. void
  492. inline
  493. recalcModelView_axes(void)
  494. {
  495.    GLdouble m[4][4];
  496.    glMatrixMode(GL_MODELVIEW);
  497.    glPopMatrix();
  498.    glPushMatrix();
  499.    build_rotmatrix(m, curquat);
  500.    gluLookAt(eye.x,eye.y,eye.z,               // eye is at (... 
  501.                         0,0,0,             // looking to 
  502.                         up.x,up.y,up.z);   // up is in positive Y direction     
  503.    // rotate
  504.    buildmf();
  505.    glMultMatrixf(&mf[0][0]);
  506.  
  507.     // SCALE ONLY IF REQUESTED OTHERWISE DO NOT SCALE (1,1,1).
  508.     if (SCALE_SIGMA)   glScalef (1/sigx,1/sigy,1/sigz); // normalized scaling.
  509.     else  
  510.         if (SCALE_MIDDLE)  glScalef (1/deltax,1/deltay,1/deltaz);
  511.         else
  512.             glScalef (1,1,1);
  513.  
  514.   newModel = 0;
  515. }
  516. void
  517. inline
  518. recalcModelViewVehicleCentric()
  519. {
  520.    // GLfloat m[4][4]; Global variable because used after.
  521.    glMatrixMode(GL_MODELVIEW);
  522.    glPopMatrix();
  523.    glPushMatrix(); 
  524.  
  525.   glLightfv(GL_LIGHT0, GL_POSITION, lightZeroPosition);
  526.   glLightfv(GL_LIGHT1, GL_POSITION, lightOnePosition);
  527.   glLightfv(GL_LIGHT2, GL_POSITION, light2Position);
  528.   glLightfv(GL_LIGHT3, GL_POSITION, light3Position);
  529.  
  530.   // Translating.
  531.   glTranslatef(TRANSLATE_X, TRANSLATE_Y,0.0);
  532.  
  533.   /* Rotating.
  534.   build_rotmatrix(m, curquat_top_view);
  535.   buildmf();
  536.   glMultMatrixf(&mf[0][0]); */
  537.  
  538.   gluLookAt(Geye.x, Geye.y, Geye.z, // eye is at (... 
  539.                         eyec.x, eyec.y, eyec.z,      // looking to 
  540.                         Gup.x, Gup.y, Gup.z);      // up is in positive Y direction */
  541. }
  542. void
  543. inline
  544. recalcModelViewTOPVIEW()
  545. {
  546.     void init();
  547.    // GLfloat m[4][4]; Global variable because used after.
  548.    glMatrixMode(GL_MODELVIEW);
  549.    glPopMatrix();
  550.    glPushMatrix(); 
  551.    
  552.    // double scalex, scaley, scalez;
  553.  
  554.        glLightfv(GL_LIGHT0, GL_POSITION, lightZeroPosition);
  555.     glLightfv(GL_LIGHT1, GL_POSITION, lightOnePosition);
  556.     glTranslatef((LEFT + RIGHT)/2.0,(BOTTOM + TOP)/2.0,0.0);
  557.     glTranslatef(-(LEFT + RIGHT)/2.0,-(BOTTOM + TOP)/2.0,0.0);    
  558.     build_rotmatrix(m, curquat_top_view);
  559.  
  560.    // eye_tr = mult_matrix_vector(m,eye);
  561.    /* gluLookAt(eye_tr.x,eye_tr.y,eye_tr.z,   // eye is at (... 
  562.                         0,0,0,      // looking to 
  563.                         up.x,up.y,up.z);      // up is in positive Y direction */
  564.  
  565.    buildmf();
  566.    glTranslatef(TRANSLATE_X, TRANSLATE_Y,0.0);
  567.    glMultMatrixf(&mf[0][0]);
  568.  
  569.   gluLookAt(0,0,100,    // eye is at (... 
  570.                         0,0,0,      // looking to 
  571.                         0,1,0);      // up is in positive Y direction */
  572.  
  573.    
  574.    //glTranslatef(-(LEFT + RIGHT)/2.0,-(BOTTOM + TOP)/2.0,0.0);    
  575.  
  576.    // Draw the position of the camera (eye).
  577.    glPointSize (3);
  578.    glBegin(GL_LINES);
  579.    glColor3f(1.0, 1.0, 1.0); 
  580.    glVertex3f(eye.x,eye.y,eye.z);
  581.    glColor3f(1.0, 1.0, 1.0); 
  582.    glVertex3f(eye.x + 400*lk_rt.x,eye.y+ 400*lk_rt.y, eye.z+400*lk_rt.z);
  583.    glColor3f(1.0, 1.0, 1.0); 
  584.    glVertex3f(eye.x,eye.y,eye.z);
  585.    glColor3f(1.0, 1.0, 1.0); 
  586.    glVertex3f(eye.x + 200*up_rt.x,eye.y+ 200*up_rt.y, eye.z+200*up_rt.z);
  587.    glColor3f(1.0, 1.0, 1.0); 
  588.    glEnd();
  589.    // Draw the position of mirror_eye.
  590.    glPointSize (3);
  591.    glBegin(GL_LINES);
  592.    glColor3f(1.0, 1.0, 1.0); 
  593.    glVertex3f(eye_mirror.x,eye_mirror.y,eye_mirror.z);
  594.    glColor3f(1.0, 1.0, 1.0); 
  595.    glVertex3f(m1[FLAG_SELECTED_MIRROR].cr.x,m1[FLAG_SELECTED_MIRROR].cr.y,m1[FLAG_SELECTED_MIRROR].cr.z);
  596.    glColor3f(1.0, 1.0, 1.0); 
  597.    glEnd();    
  598.     // rotate
  599.     //glMultMatrixf(&m[0][0]);
  600.     // init();
  601.  
  602.  
  603.  
  604. }
  605.  
  606. inline 
  607. void
  608. recalcboundingboxTOPVIEW()
  609.    glMatrixMode(GL_PROJECTION);/* set up projection transform */
  610.    glPopMatrix();
  611.    glLoadIdentity();
  612.    glOrtho (LEFT,RIGHT, BOTTOM,TOP, NEAR2,FAR2);
  613.    glPushMatrix();
  614. }
  615. inline 
  616. void
  617. recalcboundingboxVehicleCentric()
  618.    glMatrixMode(GL_PROJECTION);/* set up projection transform */
  619.    glPopMatrix();
  620.    glLoadIdentity();
  621.    glOrtho (LEFT,RIGHT, BOTTOM,TOP, NEAR2,FAR2);
  622.    glPushMatrix();
  623. }
  624. inline
  625. void
  626. recalcboundingbox() //frecalcboundingbox
  627. {
  628.    glMatrixMode(GL_PROJECTION);/* set up projection transform */
  629.    glPopMatrix();
  630.    glLoadIdentity();
  631.    if (FLAG_ORTHO_PERSP)
  632.       gluPerspective( /* field of view in degree */ cam_angle,  
  633.                  /* aspect blen, ratio */      aspect_ratio,
  634.                /* Z near */                  2.0, 
  635.                /* Z far */                   2000.0);
  636.    else 
  637.       glOrtho (LEFT,RIGHT, BOTTOM,TOP, NEAR2,FAR2);
  638.    glPushMatrix();
  639. }
  640. inline
  641. void
  642. recalcboundingbox_mirror(int i) //frecalcboundingbox
  643. {
  644.    glMatrixMode(GL_PROJECTION);/* set up projection transform */
  645.    glPopMatrix();
  646.    glLoadIdentity();
  647.    /* glFrustum (-100,100,1,100,-100,20000); 
  648.    glFrustum (m1[i].c1.x, m1[i].c3.x,
  649.                 m1[i].c3.y, m1[i].c1.y,
  650.                   calculer_distance_entre_2_plans_paralelles(m1[i].nl,
  651.                                                          m1[i].cr,
  652.                                                          eye_mirror), 2000);  */
  653. html   //look at the hard paper called (mirror perspective) in your hard folder of VC++ Project Render.
  654.    double OD=longueur(eye_mirror,m1[i].cr);
  655.    struct point ODv = vect(m1[i].cr,eye_mirror);
  656.    gluPerspective( /* field of view in degree */ 
  657.       calc_angle_entre_2_vecteurs_def_par_3_pts (eye_mirror,interpoler(m1[i].c1,m1[i].c4),interpoler(m1[i].c2,m1[i].c3)),  
  658.           html /* aspect ratio A'B' / m1[i].height*/   scalairv(m1[i].nl,ODv)*m1[i].width/OD/m1[i].height,
  659.                /* Z near */                  OD, 
  660.                /* Z far */                   500.0);
  661.    glPushMatrix();
  662. }
  663. void
  664. inline
  665. recalcModelView_mirror(int i) //frecalcmodelview
  666. {
  667.    // GLdouble m[4][4]; Global variable because used after.
  668.    glMatrixMode(GL_MODELVIEW);
  669.    glPopMatrix();
  670.    // glLoadIdentity();
  671.    glPushMatrix();
  672.    double scalex, scaley, scalez;
  673.  
  674.  /*  gluPerspective( /* field of view in degree (mirror angle)  asin(vectoriel(
  675.                  /* aspect blen, ratio       1.0,
  676.                /* Z near                  longueur(eye_mirror,m1[i].cr), 
  677.                /* Z far                   4000.0); */
  678.  
  679.    gluLookAt(eye_mirror.x,eye_mirror.y,eye_mirror.z,   // eye is at (... 
  680.                         m1[i].cr.x,m1[i].cr.y,m1[i].cr.z,      // looking to 
  681.                         m1[i].up.x,m1[i].up.y,m1[i].up.z);      // up is in positive Y direction 
  682. }
  683. void
  684. inline
  685. texture_map_gods_eye(int i)
  686. {
  687.    // Render what the mirror is seeing and create the texture map
  688.    // But do not display it yet, it only creates it in TEX_BUF buffer.
  689.    glViewport(0,0, TEX_WIDTH, TEX_HEIGHT);
  690.    recalcboundingboxTOPVIEW();
  691.    recalcModelViewTOPVIEW();
  692.    glCallList(9); // City.
  693.    glTranslatef (eyec.x,eyec.y,eyec.z); 
  694.    glRotatef (2*acos(curquatc[0])*180.0/3.15169,curquatc[1], curquatc[2],curquatc[3]); 
  695.    glScalef( car_scale_factor , -car_scale_factor , car_scale_factor);
  696.    glCallList(19);//Vehicle
  697.   for (iti=0; iti<10; iti++) { // For each car
  698.       if (RouteNum[iti]){
  699.         recalcModelViewTOPVIEW();
  700.         glTranslatef (    CarLocationRec[iti][IndexCarLocRec[iti]].x,                     CarLocationRec[iti][IndexCarLocRec[iti]].y,       CarLocationRec[iti][IndexCarLocRec[iti]].z);
  701.         glRotatef (2*acos(CarLocationRec[iti][IndexCarLocRec[iti]].quat[0])*180.0/3.15169,CarLocationRec[iti][IndexCarLocRec[iti]].quat[1], CarLocationRec[iti][IndexCarLocRec[iti]].quat[2],CarLocationRec[iti][IndexCarLocRec[iti]].quat[3]);
  702.         glScalef(car_scale_factor, -car_scale_factor, car_scale_factor);
  703.         glCallList(19); // render car.
  704.       }
  705.   }
  706.    glFlush();
  707.  
  708.    // reads the GL_Back buffer into the texture.
  709.    glReadBuffer(GL_BACK);
  710.     
  711.    /* glCopyTexImage2D (GL_TEXTURE_2D, 0,  
  712.             GL_RGB, 0, 0, 128, 128, 0);  */ // very slow
  713.    glReadPixels (0,0, TEX_WIDTH,TEX_HEIGHT, GL_RGB, GL_UNSIGNED_BYTE,TEX_BUF[i][0][0]); // image[0][0]); //
  714.  
  715.    glBindTexture(GL_TEXTURE_2D, texName[i]);
  716.    glTexImage2D(  GL_TEXTURE_2D,    // target
  717.                      0,                // level
  718.                      //0, 0,                              // xoffset, yoffset
  719.                      GL_RGB, // format
  720.                      TEX_WIDTH, TEX_HEIGHT,             // Width, Height
  721.                      //im_width[0], im_height[0],
  722.                      0, // border
  723.                      GL_RGB,           // format
  724.                      GL_UNSIGNED_BYTE, // type
  725.                      //image);
  726.                      TEX_BUF[i][0][0]);        // GLvoid *pixels */ 
  727.    glViewport(0,0,W, H);
  728. }
  729.  
  730. int
  731. calculate_closer_sensor (float x, float y, float z)
  732. {
  733.     float toul,toul2;
  734.     int   closer = 0;
  735.     toul = (x-sensors_W[0].x)*(x-sensors_W[0].x) +
  736.            (y-sensors_W[0].y)*(y-sensors_W[0].y) +
  737.            (z-sensors_W[0].z)*(z-sensors_W[0].z);
  738.     for (int wo = 1; wo<8; wo++){
  739.         toul2 =       (x-sensors_W[wo].x)*(x-sensors_W[wo].x) +
  740.                       (y-sensors_W[wo].y)*(y-sensors_W[wo].y) +
  741.                       (z-sensors_W[wo].z)*(z-sensors_W[wo].z)  ;
  742.         if (toul > toul2  ){
  743.             toul = toul2;
  744.             closer = wo;
  745.         }
  746.     }
  747.     return closer;
  748. }
  749.         
  750.  
  751. // based on my mouse rotation, it calulates Geye_V which is the God's
  752. // eye in the vehicle coord system (eyec, lkc_rt, upc_rt, horc_rt)
  753. void
  754. inline
  755. Calculate_Geye_in_Vehicle_coord(){
  756.     // Geye_V is the God's eye in the vehicle coord system (eyec, lkc_rt, upc_rt, horc_rt)
  757.     Geye_V.x = Geye_V.z=0;
  758.     Geye_V.y = GeyeHIGHT; // Original position of the Gods eye, in the Vehicle
  759.                           // coordinate system (eyec, lkc_rt, upc_rt, horc_rt)
  760.     Gup_V.z=-1;            // Original up position of the Gods eye, in the Vehicle
  761.     Gup_V.y=Gup_V.x=0;    // coordinate system (eyec, lkc_rt, upc_rt, horc_rt)
  762.     
  763.     build_rotmatrix(m, curquat_Geye);
  764.     Geye_V = mult_matrix_vector(m,Geye_V);  
  765.     Gup_V  = mult_matrix_vector(m, Gup_V);  
  766. }
  767.  
  768. // Geye is in the World Absolute coordinate system (000, 001, 010, 100).
  769. void 
  770. inline
  771. Calculate_Geye_in_Worlds_coord(){
  772.    Geye.x = Geye_V.x * horc_rt.x  +  Geye_V.y * upc_rt.x  +  Geye_V.z * lkc_rt.x;
  773.    Geye.y = Geye_V.x * horc_rt.y  +  Geye_V.y * upc_rt.y  +  Geye_V.z * lkc_rt.y;
  774.    Geye.z = Geye_V.x * horc_rt.z  +  Geye_V.y * upc_rt.z  +  Geye_V.z * lkc_rt.z;
  775.    Geye   = add_vect_to_pt (Geye , eyec);
  776.  
  777.    Gup.x = Gup_V.x * horc_rt.x  +  Gup_V.y * upc_rt.x  +  Gup_V.z * lkc_rt.x;
  778.    Gup.y = Gup_V.x * horc_rt.y  +  Gup_V.y * upc_rt.y  +  Gup_V.z * lkc_rt.y;
  779.    Gup.z = Gup_V.x * horc_rt.z  +  Gup_V.y * upc_rt.z  +  Gup_V.z * lkc_rt.z;
  780.  
  781.    /*Gup.x  = -lkc_rt.x;
  782.      Gup.y  = -lkc_rt.y;
  783.      Gup.z  = -lkc_rt.z; */
  784. }
  785.  
  786. void
  787. Calculate_Sensors_W(){
  788.     for (int wa=0; wa<8; wa++){
  789.    sensors_W[wa].x = sensors_V[wa].x * horc_rt.x  +  sensors_V[wa].y * upc_rt.x  +  sensors_V[wa].z * lkc_rt.x;
  790.    sensors_W[wa].y = sensors_V[wa].x * horc_rt.y  +  sensors_V[wa].y * upc_rt.y  +  sensors_V[wa].z * lkc_rt.y;
  791.    sensors_W[wa].z = sensors_V[wa].x * horc_rt.z  +  sensors_V[wa].y * upc_rt.z  +  sensors_V[wa].z * lkc_rt.z;
  792.    sensors_W[wa]   = add_vect_to_pt (sensors_W[wa] , eyec);
  793.     }
  794. }
  795.  
  796. void
  797. renderBlueBox()
  798. {
  799.  glutSolidCube(2.0);
  800. }
  801.  
  802. void
  803. renderRedBox()
  804. {
  805.  glutSolidCube(2.0);
  806. }
  807.  
  808. void 
  809. inline
  810. texture_map_sensors_godseye(int i)
  811. {
  812.     Calculate_Geye_in_Vehicle_coord();
  813.     Calculate_Geye_in_Worlds_coord();
  814.     Calculate_Sensors_W();
  815.     int closer_sensor;
  816.    // Render what the mirror is seeing and create the texture map
  817.    // But do not display it yet, it only creates it in TEX_BUF buffer.
  818.    glViewport(0,0, TEX_WIDTH, TEX_HEIGHT);
  819.    recalcboundingboxVehicleCentric();
  820.    recalcModelViewVehicleCentric();
  821.    // Draws the warning flashing lines on the gods eye display.
  822.    for (int ro=0; ro<10; ro++){
  823.      if (RouteNum[ro]){
  824.         if ( (CarLocationRec[ro][IndexCarLocRec[ro]].x - eyec.x) * 
  825.                 (CarLocationRec[ro][IndexCarLocRec[ro]].x - eyec.x) +
  826.                 (CarLocationRec[ro][IndexCarLocRec[ro]].y - eyec.y) * 
  827.                 (CarLocationRec[ro][IndexCarLocRec[ro]].y - eyec.y) +
  828.                 (CarLocationRec[ro][IndexCarLocRec[ro]].z - eyec.z) * 
  829.                 (CarLocationRec[ro][IndexCarLocRec[ro]].z - eyec.z) 
  830.                 < 25 * 25 ) {// if cars are distante more then 30 units then
  831.             closer_sensor = calculate_closer_sensor(CarLocationRec[ro][IndexCarLocRec[ro]].x, CarLocationRec[ro][IndexCarLocRec[ro]].y, CarLocationRec[ro][IndexCarLocRec[ro]].z);
  832.             recalcModelViewVehicleCentric();
  833.             glTranslatef (sensors_W[closer_sensor].x, sensors_W[closer_sensor].y, sensors_W[closer_sensor].z);
  834.             renderRedBox();
  835.             PlaySound ("boom.wav",NULL,SND_ASYNC); //WinUnin
  836.            }
  837.         else
  838.            if ( (CarLocationRec[ro][IndexCarLocRec[ro]].x - eyec.x) * 
  839.                 (CarLocationRec[ro][IndexCarLocRec[ro]].x - eyec.x) +
  840.                 (CarLocationRec[ro][IndexCarLocRec[ro]].y - eyec.y) * 
  841.                 (CarLocationRec[ro][IndexCarLocRec[ro]].y - eyec.y) +
  842.                 (CarLocationRec[ro][IndexCarLocRec[ro]].z - eyec.z) * 
  843.                 (CarLocationRec[ro][IndexCarLocRec[ro]].z - eyec.z) 
  844.                 < 40 * 40 ) {// if cars are distante more then 30 units then
  845.                 closer_sensor = calculate_closer_sensor(CarLocationRec[ro][IndexCarLocRec[ro]].x, CarLocationRec[ro][IndexCarLocRec[ro]].y, CarLocationRec[ro][IndexCarLocRec[ro]].z);
  846.                 recalcModelViewVehicleCentric();
  847.                 glTranslatef (sensors_W[closer_sensor].x, sensors_W[closer_sensor].y, sensors_W[closer_sensor].z);
  848.                 renderBlueBox();
  849.                 PlaySound ("booom.wav",NULL,SND_ASYNC); //WinUnin
  850.            }
  851.        }
  852.    }
  853.    // Draws the warning flashing lines on the gods eye display.
  854.    // When we back up in the blue Stone.
  855.    if (         (eyec.x - 358.5) * 
  856.                 (eyec.x - 358.5) +
  857.                 (eyec.y - 0.0) * 
  858.                 (eyec.y - 0.0) +
  859.                 (eyec.z + 483.0) * 
  860.                 (eyec.z + 483.0) 
  861.                 < 25 * 25 ) {// if cars are distante more then 30 units then
  862.             closer_sensor = calculate_closer_sensor(358.5f, 0.0f, -483.0f);
  863.             recalcModelViewVehicleCentric();
  864.             glTranslatef (sensors_W[closer_sensor].x, sensors_W[closer_sensor].y, sensors_W[closer_sensor].z);
  865.             renderRedBox();
  866.             PlaySound ("boom.wav",NULL,SND_ASYNC); //WinUnin
  867.  
  868.            }
  869.    else
  870.            if ( (eyec.x - 358.5) * 
  871.                 (eyec.x - 358.5) +
  872.                 (eyec.y - 0.0) * 
  873.                 (eyec.y - 0.0) +
  874.                 (eyec.z + 483.0) * 
  875.                 (eyec.z + 483.0) 
  876.                 < 40 * 40 ) {// if cars are distante more then 30 units then
  877.                 closer_sensor = calculate_closer_sensor(358.5f, 0.0f, -483.0f);
  878.                 recalcModelViewVehicleCentric();
  879.                 glTranslatef (sensors_W[closer_sensor].x, sensors_W[closer_sensor].y, sensors_W[closer_sensor].z);
  880.                 renderBlueBox();
  881.                 PlaySound ("booom.wav",NULL,SND_ASYNC); //WinUnin
  882.            }
  883.  
  884.    // Draws the warning flashing lines on the gods eye display.
  885.    // When we back up in the 2 stationary cars.
  886.    if (         (eyec.x - 274.61) * 
  887.                 (eyec.x - 274.61) +
  888.                 (eyec.y - 0.0) * 
  889.                 (eyec.y - 0.0) +
  890.                 (eyec.z + 722.49) * 
  891.                 (eyec.z + 722.49) 
  892.                 < 25 * 25 ) {// if cars are distante more then 30 units then
  893.             closer_sensor = calculate_closer_sensor(274.61f, 0.0f, -722.49f);
  894.             recalcModelViewVehicleCentric();
  895.             glTranslatef (sensors_W[closer_sensor].x, sensors_W[closer_sensor].y, sensors_W[closer_sensor].z);
  896.             renderRedBox();
  897.             PlaySound ("boom.wav",NULL,SND_ASYNC); //WinUnin
  898.  
  899.            }
  900.    else
  901.            if ( (eyec.x - 274.61) * 
  902.                 (eyec.x - 274.61) +
  903.                 (eyec.y - 0.0) * 
  904.                 (eyec.y - 0.0) +
  905.                 (eyec.z + 722.49) * 
  906.                 (eyec.z + 722.49) 
  907.                 < 40 * 40 ) {// if cars are distante more then 30 units then
  908.                 closer_sensor = calculate_closer_sensor(274.61f, 0.0f, -722.49f);
  909.                 recalcModelViewVehicleCentric();
  910.                 glTranslatef (sensors_W[closer_sensor].x, sensors_W[closer_sensor].y, sensors_W[closer_sensor].z);
  911.                 renderBlueBox();
  912.                 PlaySound ("booom.wav",NULL,SND_ASYNC); //WinUnin
  913.            }
  914.    // Draws the warning flashing lines on the gods eye display.
  915.    // When we back up in the 2 stationary cars.
  916.    if (         (eyec.x - 267.46) * 
  917.                 (eyec.x - 267.46) +
  918.                 (eyec.y - 0.0) * 
  919.                 (eyec.y - 0.0) +
  920.                 (eyec.z + 701.968) * 
  921.                 (eyec.z + 701.968) 
  922.                 < 25 * 25 ) {// if cars are distante more then 30 units then
  923.             closer_sensor = calculate_closer_sensor(267.46f, 0.0f, -701.968f);
  924.             recalcModelViewVehicleCentric();
  925.             glTranslatef (sensors_W[closer_sensor].x, sensors_W[closer_sensor].y, sensors_W[closer_sensor].z);
  926.             renderRedBox();
  927.             PlaySound ("boom.wav",NULL,SND_ASYNC); //WinUnin
  928.  
  929.            }
  930.    else
  931.            if ( (eyec.x - 267.46) * 
  932.                 (eyec.x - 267.46) +
  933.                 (eyec.y - 0.0) * 
  934.                 (eyec.y - 0.0) +
  935.                 (eyec.z + 701.968) * 
  936.                 (eyec.z + 701.968)
  937.                 < 40 * 40 ) {// if cars are distante more then 30 units then
  938.                 closer_sensor = calculate_closer_sensor(267.46f, 0.0f, -701.968f);
  939.                 recalcModelViewVehicleCentric();
  940.                 glTranslatef (sensors_W[closer_sensor].x, sensors_W[closer_sensor].y, sensors_W[closer_sensor].z);
  941.                 renderBlueBox();
  942.                 PlaySound ("booom.wav",NULL,SND_ASYNC); //WinUnin
  943.            }
  944.  
  945.  
  946.    // glCallList(9); // City.
  947.    recalcModelViewVehicleCentric();
  948.    glTranslatef (eyec.x,eyec.y,eyec.z); 
  949.    glRotatef (2*acos(curquatc[0])*180.0/3.15169,curquatc[1], curquatc[2],curquatc[3]);
  950.    glScalef( car_scale_factor , -car_scale_factor , car_scale_factor);
  951.    glCallList(27); // render sensors.
  952.   for (iti=0; iti<10; iti++) { // For each car
  953.       if (RouteNum[iti]) {
  954.         recalcModelViewVehicleCentric();
  955.         glTranslatef (    CarLocationRec[iti][IndexCarLocRec[iti]].x,                     CarLocationRec[iti][IndexCarLocRec[iti]].y,       CarLocationRec[iti][IndexCarLocRec[iti]].z);
  956.         glRotatef (2*acos(CarLocationRec[iti][IndexCarLocRec[iti]].quat[0])*180.0/3.15169,CarLocationRec[iti][IndexCarLocRec[iti]].quat[1], CarLocationRec[iti][IndexCarLocRec[iti]].quat[2],CarLocationRec[iti][IndexCarLocRec[iti]].quat[3]);
  957.         glScalef(car_scale_factor, -car_scale_factor, car_scale_factor);
  958.         glCallList(19); // render other cars.
  959.       }
  960.   }
  961.    glFlush();
  962.  
  963.    // reads the GL_Back buffer into the texture.
  964.    glReadBuffer(GL_BACK);
  965.     
  966.    /* glCopyTexImage2D (GL_TEXTURE_2D, 0,  
  967.             GL_RGB, 0, 0, 128, 128, 0);  */ // very slow
  968.    glReadPixels (0,0, TEX_WIDTH, TEX_HEIGHT, GL_RGB, GL_UNSIGNED_BYTE,TEX_BUF[i][0][0]); // image[0][0]); //
  969.  
  970.    glBindTexture(GL_TEXTURE_2D, texName[i]);
  971.    glTexImage2D(  GL_TEXTURE_2D,    // target
  972.                      0,                // level
  973.                      //0, 0,                              // xoffset, yoffset
  974.                      GL_RGB, // format
  975.                      TEX_WIDTH, TEX_HEIGHT,             // Width, Height
  976.                      //im_width[0], im_height[0],
  977.                      0, // border
  978.                      GL_RGB,           // format
  979.                      GL_UNSIGNED_BYTE, // type
  980.                      //image);
  981.                      TEX_BUF[i][0][0]);        // GLvoid *pixels */ 
  982.    glViewport(0,0,W, H);
  983. }
  984. void
  985. inline
  986. texture_map_symbolic_godseye(int i)
  987. {
  988.  
  989.     Calculate_Geye_in_Vehicle_coord();
  990.     Calculate_Geye_in_Worlds_coord();
  991.    // Render what the mirror is seeing and create the texture map
  992.    // But do not display it yet, it only creates it in TEX_BUF buffer.
  993.    glViewport(0,0, TEX_WIDTH, TEX_HEIGHT);
  994.    recalcboundingboxVehicleCentric();
  995.    recalcModelViewVehicleCentric();
  996.    // Draws the warning flashing lines on the gods eye display.
  997.    for (int ro=0; ro<10; ro++){
  998.      if (RouteNum[ro]){
  999.         if ( (CarLocationRec[ro][IndexCarLocRec[ro]].x - eyec.x) * 
  1000.                 (CarLocationRec[ro][IndexCarLocRec[ro]].x - eyec.x) +
  1001.                 (CarLocationRec[ro][IndexCarLocRec[ro]].y - eyec.y) * 
  1002.                 (CarLocationRec[ro][IndexCarLocRec[ro]].y - eyec.y) +
  1003.                 (CarLocationRec[ro][IndexCarLocRec[ro]].z - eyec.z) * 
  1004.                 (CarLocationRec[ro][IndexCarLocRec[ro]].z - eyec.z) 
  1005.                 < 25 * 25 ) {// if cars are distante more then 30 units then
  1006.             glBegin(GL_LINES); // draw the line...
  1007.             glColor3f (1.0f,1.0f,0.8f);
  1008.             glVertex3f (CarLocationRec[ro][IndexCarLocRec[ro]].x,
  1009.                         CarLocationRec[ro][IndexCarLocRec[ro]].y,
  1010.                         CarLocationRec[ro][IndexCarLocRec[ro]].z );
  1011.             glVertex3f (eyec.x, eyec.y, eyec.z);
  1012.             PlaySound ("boom.wav",NULL,SND_ASYNC); //WinUnin
  1013.             glEnd();
  1014.            }
  1015.         else
  1016.            if ( (CarLocationRec[ro][IndexCarLocRec[ro]].x - eyec.x) * 
  1017.                 (CarLocationRec[ro][IndexCarLocRec[ro]].x - eyec.x) +
  1018.                 (CarLocationRec[ro][IndexCarLocRec[ro]].y - eyec.y) * 
  1019.                 (CarLocationRec[ro][IndexCarLocRec[ro]].y - eyec.y) +
  1020.                 (CarLocationRec[ro][IndexCarLocRec[ro]].z - eyec.z) * 
  1021.                 (CarLocationRec[ro][IndexCarLocRec[ro]].z - eyec.z) 
  1022.                 < 40 * 40 ) {// if cars are distante more then 30 units then
  1023.             glBegin(GL_LINES); // draw the line...
  1024.             glColor3f (0.2f,0.2f,1.0f);
  1025.             glVertex3f (CarLocationRec[ro][IndexCarLocRec[ro]].x,
  1026.                         CarLocationRec[ro][IndexCarLocRec[ro]].y,
  1027.                         CarLocationRec[ro][IndexCarLocRec[ro]].z );
  1028.             PlaySound ("booom.wav",NULL,SND_ASYNC); //WinUnin
  1029.             glVertex3f (eyec.x, eyec.y, eyec.z);
  1030.             glEnd();
  1031.            }
  1032.        }
  1033.    }
  1034.    // Draws the warning lazer lines on the gods eye display.
  1035.    // When we back up in the blue Stone.
  1036.    if (         (eyec.x - 358.5) * 
  1037.                 (eyec.x - 358.5) +
  1038.                 (eyec.y - 0.0) * 
  1039.                 (eyec.y - 0.0) +
  1040.                 (eyec.z + 483.0) * 
  1041.                 (eyec.z + 483.0) 
  1042.                 < 25 * 25 ) {// if cars are distante more then 30 units then
  1043.             glBegin(GL_LINES); // draw the line...
  1044.             glColor3f (1.0f,1.0f,0.8f);
  1045.             glVertex3f (358.5f, 0.0f, -483.0f );
  1046.             glVertex3f (eyec.x, eyec.y, eyec.z);
  1047.             PlaySound ("boom.wav",NULL,SND_ASYNC); //WinUnin
  1048.             glEnd();
  1049.            }
  1050.    else
  1051.            if ( (eyec.x - 358.5) * 
  1052.                 (eyec.x - 358.5) +
  1053.                 (eyec.y - 0.0) * 
  1054.                 (eyec.y - 0.0) +
  1055.                 (eyec.z + 483.0) * 
  1056.                 (eyec.z + 483.0) 
  1057.                 < 40 * 40 ) {// if cars are distante more then 30 units then
  1058.             glBegin(GL_LINES); // draw the line...
  1059.             glColor3f (0.2f,0.2f,1.0f);
  1060.             glVertex3f (358.5f, 0.0f, -483.0f );
  1061.             glVertex3f (eyec.x, eyec.y, eyec.z);
  1062.             PlaySound ("booom.wav",NULL,SND_ASYNC); //WinUnin
  1063.             glEnd();
  1064.            }
  1065.   // Draws the warning lazer lines on the gods eye display.
  1066.    // When we back up in the 2 stationary cars.
  1067.    if (         (eyec.x - 274.61) * 
  1068.                 (eyec.x - 274.61) +
  1069.                 (eyec.y - 0.0) * 
  1070.                 (eyec.y - 0.0) +
  1071.                 (eyec.z + 722.49) * 
  1072.                 (eyec.z + 722.49) 
  1073.                 < 25 * 25 ) {// if cars are distante more then 30 units then
  1074.             glBegin(GL_LINES); // draw the line...
  1075.             glColor3f (0.2f,0.2f,1.0f);
  1076.             glVertex3f (274.61f, 0.0f, -722.49f );
  1077.             glVertex3f (eyec.x, eyec.y, eyec.z);
  1078.             PlaySound ("boom.wav",NULL,SND_ASYNC); //WinUnin
  1079.             glEnd();
  1080.  
  1081.            }
  1082.    else
  1083.            if ( (eyec.x - 274.61) * 
  1084.                 (eyec.x - 274.61) +
  1085.                 (eyec.y - 0.0) * 
  1086.                 (eyec.y - 0.0) +
  1087.                 (eyec.z + 722.49) * 
  1088.                 (eyec.z + 722.49) 
  1089.                 < 40 * 40 ) {// if cars are distante more then 30 units then
  1090.              glBegin(GL_LINES); // draw the line...
  1091.             glColor3f (0.2f,0.2f,1.0f);
  1092.             glVertex3f (274.61f, 0.0f, -722.49f );
  1093.             glVertex3f (eyec.x, eyec.y, eyec.z);
  1094.             PlaySound ("booom.wav",NULL,SND_ASYNC); //WinUnin
  1095.             glEnd();
  1096.            }
  1097.    // Draws the warning lazer lines on the gods eye display.
  1098.    // When we back up in the 2 stationary cars.
  1099.    if (         (eyec.x - 267.46) * 
  1100.                 (eyec.x - 267.46) +
  1101.                 (eyec.y - 0.0) * 
  1102.                 (eyec.y - 0.0) +
  1103.                 (eyec.z + 701.968) * 
  1104.                 (eyec.z + 701.968) 
  1105.                 < 25 * 25 ) {// if cars are distante more then 30 units then
  1106.              glBegin(GL_LINES); // draw the line...
  1107.             glColor3f (0.2f,0.2f,1.0f);
  1108.             glVertex3f (267.46f, 0.0f, -701.968f );
  1109.             glVertex3f (eyec.x, eyec.y, eyec.z);
  1110.             PlaySound ("booom.wav",NULL,SND_ASYNC); //WinUnin
  1111.             glEnd();
  1112.            }
  1113.    else
  1114.            if ( (eyec.x - 267.46) * 
  1115.                 (eyec.x - 267.46) +
  1116.                 (eyec.y - 0.0) * 
  1117.                 (eyec.y - 0.0) +
  1118.                 (eyec.z + 701.968) * 
  1119.                 (eyec.z + 701.968)
  1120.                 < 40 * 40 ) {// if cars are distante more then 30 units then
  1121.              glBegin(GL_LINES); // draw the line...
  1122.             glColor3f (0.2f,0.2f,1.0f);
  1123.             glVertex3f (267.46f, 0.0f, -701.968f );
  1124.             glVertex3f (eyec.x, eyec.y, eyec.z);
  1125.             PlaySound ("booom.wav",NULL,SND_ASYNC); //WinUnin
  1126.             glEnd();
  1127.            }
  1128.  
  1129.    // glCallList(9); // City.
  1130.    glTranslatef (eyec.x,eyec.y,eyec.z); 
  1131.    glRotatef (2*acos(curquatc[0])*180.0/3.15169,curquatc[1], curquatc[2],curquatc[3]);
  1132.    glScalef( car_scale_factor , -car_scale_factor , car_scale_factor);
  1133.    glCallList(19);//Vehicle
  1134.   for (iti=0; iti<10; iti++) { // For each car
  1135.       if (RouteNum[iti]){
  1136.         recalcModelViewVehicleCentric();
  1137.         glTranslatef (    CarLocationRec[iti][IndexCarLocRec[iti]].x,                     CarLocationRec[iti][IndexCarLocRec[iti]].y,       CarLocationRec[iti][IndexCarLocRec[iti]].z);
  1138.         glRotatef (2*acos(CarLocationRec[iti][IndexCarLocRec[iti]].quat[0])*180.0/3.15169,CarLocationRec[iti][IndexCarLocRec[iti]].quat[1], CarLocationRec[iti][IndexCarLocRec[iti]].quat[2],CarLocationRec[iti][IndexCarLocRec[iti]].quat[3]);
  1139.         glScalef(car_scale_factor, -car_scale_factor, car_scale_factor);
  1140.         glCallList(19); // render car.
  1141.       }
  1142.   }
  1143.    glFlush();
  1144.  
  1145.    // reads the GL_Back buffer into the texture.
  1146.    glReadBuffer(GL_BACK);
  1147.     
  1148.    /* glCopyTexImage2D (GL_TEXTURE_2D, 0,  
  1149.             GL_RGB, 0, 0, 128, 128, 0);  */ // very slow
  1150.    glReadPixels (0,0, TEX_WIDTH, TEX_HEIGHT, GL_RGB, GL_UNSIGNED_BYTE,TEX_BUF[i][0][0]); // image[0][0]); //
  1151.  
  1152.    glBindTexture(GL_TEXTURE_2D, texName[i]);
  1153.    glTexImage2D(  GL_TEXTURE_2D,    // target
  1154.                      0,                // level
  1155.                      //0, 0,                              // xoffset, yoffset
  1156.                      GL_RGB, // format
  1157.                      TEX_WIDTH, TEX_HEIGHT,             // Width, Height
  1158.                      //im_width[0], im_height[0],
  1159.                      0, // border
  1160.                      GL_RGB,           // format
  1161.                      GL_UNSIGNED_BYTE, // type
  1162.                      //image);
  1163.                      TEX_BUF[i][0][0]);        // GLvoid *pixels */ 
  1164.    glViewport(0,0,W, H);
  1165. }
  1166. void
  1167. inline
  1168. texture_map_vehicle_centric_display(int i)
  1169. {
  1170.     Geye.x = eyec.x;
  1171.     Geye.y = eyec.x+GeyeHIGHT;
  1172.     Geye.z = eyec.z;
  1173.  
  1174.     Gup.x  = -lkc_rt.x;
  1175.     Gup.y  = -lkc_rt.y;
  1176.     Gup.z  = -lkc_rt.z;
  1177.  
  1178.     Glk.x  = Glk.z = 0;
  1179.     Glk.y = -1.0;
  1180.    // Render what the mirror is seeing and create the texture map
  1181.    // But do not display it yet, it only creates it in TEX_BUF buffer.
  1182.    glViewport(0,0, TEX_WIDTH, TEX_HEIGHT);
  1183.    recalcboundingboxVehicleCentric();
  1184.    recalcModelViewVehicleCentric();
  1185.    glCallList(9); // City.
  1186.    glTranslatef (eyec.x,eyec.y,eyec.z);
  1187.    glRotatef (2*acos(curquatc[0])*180.0/3.15169,curquatc[1], curquatc[2],curquatc[3]);
  1188.    glScalef( car_scale_factor , -car_scale_factor , car_scale_factor);
  1189.    glCallList(19);//Vehicle
  1190.   for (iti=0; iti<10; iti++) { // For each car
  1191.       if (RouteNum[iti]){
  1192.         recalcModelViewVehicleCentric();
  1193.         glTranslatef (    CarLocationRec[iti][IndexCarLocRec[iti]].x,                     CarLocationRec[iti][IndexCarLocRec[iti]].y,       CarLocationRec[iti][IndexCarLocRec[iti]].z);
  1194.         glRotatef (2*acos(CarLocationRec[iti][IndexCarLocRec[iti]].quat[0])*180.0/3.15169,CarLocationRec[iti][IndexCarLocRec[iti]].quat[1], CarLocationRec[iti][IndexCarLocRec[iti]].quat[2],CarLocationRec[iti][IndexCarLocRec[iti]].quat[3]);
  1195.         glScalef(car_scale_factor, -car_scale_factor, car_scale_factor);
  1196.         glCallList(19); // render car.
  1197.       }
  1198.   }
  1199.    glFlush();
  1200.  
  1201.    // reads the GL_Back buffer into the texture.
  1202.    glReadBuffer(GL_BACK);
  1203.     
  1204.    /* glCopyTexImage2D (GL_TEXTURE_2D, 0,  
  1205.             GL_RGB, 0, 0, 128, 128, 0);  */ // very slow
  1206.    glReadPixels (0,0, TEX_WIDTH, TEX_HEIGHT, GL_RGB, GL_UNSIGNED_BYTE,TEX_BUF[i][0][0]); // image[0][0]); //
  1207.  
  1208.    glBindTexture(GL_TEXTURE_2D, texName[i]);
  1209.    glTexImage2D(  GL_TEXTURE_2D,    // target
  1210.                      0,                // level
  1211.                      //0, 0,                              // xoffset, yoffset
  1212.                      GL_RGB, // format
  1213.                      TEX_WIDTH, TEX_HEIGHT,             // Width, Height
  1214.                      //im_width[0], im_height[0],
  1215.                      0, // border
  1216.                      GL_RGB,           // format
  1217.                      GL_UNSIGNED_BYTE, // type
  1218.                      //image);
  1219.                      TEX_BUF[i][0][0]);        // GLvoid *pixels */ 
  1220.    glViewport(0,0,W, H);
  1221. }
  1222. //____________________________________texture_map___________________________________________
  1223. //ftexture_map
  1224. void
  1225. inline
  1226. texture_map(int i) //ftexture_map
  1227. {
  1228.    extern void Draw_Vrml(Type_Transform *, int numlist);
  1229.  
  1230.    // Render what the mirror is seeing and create the texture map
  1231.    // But do not display it yet, it only creates it in TEX_BUF buffer.
  1232.    
  1233.    // calc the new postion of the virtual eye of the mirror.
  1234.    eye_mirror = calc_the_symetric_of_a_pt_rel_to_a_plane(m1[i].nl,m1[i].cr,eye);
  1235.    eye_mirror = add_vect_to_pt (eye_mirror,
  1236.                   mul_vect_par_nbr_reel(
  1237.                                 sous_vect_to_pt (eye_mirror , m1[i].cr) ,
  1238.                                      (mz[i]/200.0)));
  1239.    // put the virtual camera behind the mirror symetrically to the eye.
  1240.    // Recalc Model View.
  1241.    glViewport(0,0, TEX_WIDTH, TEX_HEIGHT);
  1242.    recalcboundingbox_mirror(i);
  1243.    recalcModelView_mirror(i);
  1244.    glCallList(9); // City.
  1245.   //Render other cars.
  1246.   for (iti=0; iti<10; iti++) { // For each other car
  1247.       if (RouteNum[iti]) {
  1248.         recalcModelView_mirror(i);
  1249.         glTranslatef (    CarLocationRec[iti][IndexCarLocRec[iti]].x,                     CarLocationRec[iti][IndexCarLocRec[iti]].y,       CarLocationRec[iti][IndexCarLocRec[iti]].z);
  1250.         glRotatef (2*acos(CarLocationRec[iti][IndexCarLocRec[iti]].quat[0])*180.0/3.15169,CarLocationRec[iti][IndexCarLocRec[iti]].quat[1], CarLocationRec[iti][IndexCarLocRec[iti]].quat[2],CarLocationRec[iti][IndexCarLocRec[iti]].quat[3]);
  1251.         glScalef(car_scale_factor, -car_scale_factor, car_scale_factor);
  1252.         glCallList(19); // render car.
  1253.       }
  1254.   }
  1255.    glTranslatef (eyec.x,eyec.y,eyec.z);
  1256.    glRotatef (2*acos(curquatc[0])*180.0/3.15169,curquatc[1], curquatc[2],curquatc[3]);
  1257.    glScalef( car_scale_factor , -car_scale_factor , car_scale_factor);
  1258.    glCallList(19);//Vehicle
  1259.  
  1260.    glFlush();
  1261.  
  1262.    // reads the GL_Back buffer into the texture.
  1263.    glReadBuffer(GL_BACK);
  1264.     
  1265.    /* glCopyTexImage2D (GL_TEXTURE_2D, 0,  
  1266.             GL_RGB, 0, 0, 128, 128, 0);  */ // very slow
  1267.    glReadPixels (0,0, TEX_WIDTH,TEX_HEIGHT, GL_RGB, GL_UNSIGNED_BYTE,TEX_BUF[i][0][0]); // image[0][0]); //
  1268.  
  1269.    glBindTexture(GL_TEXTURE_2D, texName[i]);
  1270.    glTexImage2D(  GL_TEXTURE_2D,    // target
  1271.                      0,                // level
  1272.                      //0, 0,                              // xoffset, yoffset
  1273.                      GL_RGB, // format
  1274.                      TEX_WIDTH, TEX_HEIGHT,             // Width, Height
  1275.                      //im_width[0], im_height[0],
  1276.                      0, // border
  1277.                      GL_RGB,           // format
  1278.                      GL_UNSIGNED_BYTE, // type
  1279.                      //image);
  1280.                      TEX_BUF[i][0][0]);        // GLvoid *pixels */ 
  1281.    glViewport(0,0,W, H);
  1282. }
  1283. //_______________________________draw_mirror____________________________________________
  1284. //fdraw_mirror
  1285. inline
  1286. void draw_mirror(int i)
  1287. {
  1288.    glEnable(GL_TEXTURE_2D);
  1289.    glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
  1290. #ifdef GL_VERSION_1_1
  1291.    glBindTexture(GL_TEXTURE_2D, texName[i]);  
  1292. #endif
  1293.    glBegin(GL_QUADS);
  1294.    glTexCoord2f(1.0, 1.0); 
  1295.    glVertex3f(m1[i].c1.x, m1[i].c1.y, m1[i].c1.z); html //finitialize_some_var
  1296.    glTexCoord2f(1.0, 0.0); 
  1297.    glVertex3f(m1[i].c2.x, m1[i].c2.y, m1[i].c2.z); html //finitialize_some_var
  1298.    glTexCoord2f(0.0, 0.0); 
  1299.    glVertex3f(m1[i].c3.x, m1[i].c3.y, m1[i].c3.z); html //finitialize_some_var
  1300.    glTexCoord2f(0.0, 1.0); 
  1301.    glVertex3f(m1[i].c4.x, m1[i].c4.y, m1[i].c4.z); html //finitialize_some_var
  1302.  
  1303.    glEnd();
  1304.    glPointSize (4);
  1305.    glBegin(GL_LINES);
  1306.    glVertex3f(m1[i].c1.x, m1[i].c1.y, m1[i].c1.z); html //finitialize_some_var
  1307.    glVertex3f(m1[i].c2.x, m1[i].c2.y, m1[i].c2.z); html //finitialize_some_var
  1308.    glVertex3f(m1[i].c2.x, m1[i].c2.y, m1[i].c2.z); html //finitialize_some_var
  1309.    glVertex3f(m1[i].c3.x, m1[i].c3.y, m1[i].c3.z); html //finitialize_some_var
  1310.    glVertex3f(m1[i].c3.x, m1[i].c3.y, m1[i].c3.z); html //finitialize_some_var
  1311.    glVertex3f(m1[i].c4.x, m1[i].c4.y, m1[i].c4.z); html //finitialize_some_var
  1312.    glVertex3f(m1[i].c4.x, m1[i].c4.y, m1[i].c4.z); html //finitialize_some_var
  1313.    glVertex3f(m1[i].c1.x, m1[i].c1.y, m1[i].c1.z); html //finitialize_some_var
  1314.    glEnd();
  1315.    glFlush();
  1316.    glDisable(GL_TEXTURE_2D);
  1317. }
  1318. inline
  1319. void draw_mirror_top_view(int i)
  1320. {
  1321.    glPointSize (4);
  1322.    glBegin(GL_LINES);
  1323.    glVertex3f(m1[i].c1.x, m1[i].c1.y, m1[i].c1.z); html //finitialize_some_var
  1324.    glVertex3f(m1[i].c2.x, m1[i].c2.y, m1[i].c2.z); html //finitialize_some_var
  1325.    glVertex3f(m1[i].c2.x, m1[i].c2.y, m1[i].c2.z); html //finitialize_some_var
  1326.    glVertex3f(m1[i].c3.x, m1[i].c3.y, m1[i].c3.z); html //finitialize_some_var
  1327.    glVertex3f(m1[i].c3.x, m1[i].c3.y, m1[i].c3.z); html //finitialize_some_var
  1328.    glVertex3f(m1[i].c4.x, m1[i].c4.y, m1[i].c4.z); html //finitialize_some_var
  1329.    glVertex3f(m1[i].c4.x, m1[i].c4.y, m1[i].c4.z); html //finitialize_some_var
  1330.    glVertex3f(m1[i].c1.x, m1[i].c1.y, m1[i].c1.z); html //finitialize_some_var
  1331.    glEnd();
  1332.    glFlush();
  1333.    glDisable(GL_TEXTURE_2D);
  1334. }
  1335. void
  1336. inline draw_bg()
  1337. {
  1338.          // Set Projection Matrix
  1339.          glMatrixMode(GL_PROJECTION);/* set up projection transform */
  1340.          glLoadIdentity();
  1341.          glOrtho (0,1, 0,1, -1,1);
  1342.          
  1343.          // Set ModelView Matrix.
  1344.          glMatrixMode (GL_MODELVIEW);
  1345.          glLoadIdentity();
  1346.          
  1347.          //glDisable(GL_LIGHTING);
  1348.  
  1349.          // Draw bg
  1350.          glBegin (GL_POLYGON);
  1351.          glColor3f (0.5f, 0.0f,0.0f);
  1352.          glVertex3f (1  ,  0,-0.5f);
  1353.          glColor3f (0.4f,0.0f,0.0f);
  1354.          glVertex3f (1,  1,-0.5f);
  1355.          glColor3f (0.9f,1.0f,0.0f);
  1356.          glVertex3f (0,1,-0.5f);
  1357.          glColor3f (0.2f,0.0f,1.0f);
  1358.          glVertex3f (0  ,0,-0.5);
  1359.          glEnd(); 
  1360. }
  1361. void inline  draw_light_position()
  1362. {
  1363.     glPointSize (5);
  1364.     glBegin(GL_POINTS);
  1365.     glColor3f (1.0f,1.0f,1.0f);
  1366.     glVertex3f (lightZeroPosition[0], lightZeroPosition[1], lightZeroPosition[2]);
  1367.     glVertex3f (lightOnePosition [0], lightOnePosition [1], lightOnePosition [2]);
  1368.     glEnd();
  1369. }
  1370. void redraw4()
  1371. {
  1372.     extern struct Virtual_Espace espace[DimX][DimY][DimZ];
  1373.     void redraw();
  1374.    if (FLAG_TOGGLE_MENU1) {
  1375.        glEnable(GL_LIGHTING);
  1376.    }
  1377.    glDrawBuffer(GL_BACK_LEFT);
  1378.    glClearColor (.1f,0.2f,0.1f,1);
  1379.  
  1380.    glClearColor (.6f,0.4f,0.2f,0.4f);
  1381.    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  1382.  
  1383.    if (viewport&& !FLAG_TOP_VIEW){
  1384.       // draw command margin then set the viewport for the 3D
  1385.       draw_commande_de_bord(); // Sets the control band viewport and draws in it.
  1386.       glViewport (CDW,0,W,H);  // set the viewport 
  1387.     }                                          
  1388.     else 
  1389.        if (viewport && FLAG_TOP_VIEW) {
  1390.           draw_commande_de_bord(); // Sets the control band viewport and draws in it.
  1391.           glViewport (TOP_V_X,TOP_V_Y,TOP_W,TOP_H);
  1392.           draw_bg();
  1393.           if (FLAG_TOGGLE_MENU1)  glEnable(GL_LIGHTING);
  1394.           recalcboundingboxTOPVIEW();
  1395.           recalcModelViewTOPVIEW();
  1396.           if (Draw_relative_axe) draw_axes();
  1397.           if (SHOW_LOCATION_DIRECTION_OF_LIGHTS) draw_light_position();
  1398.     for (int i= 0; i<DimX; i=i+2)
  1399.         for (int j=0; j<DimY; j=j+2)
  1400.             for (int k=0; k<DimZ; k=k+2)
  1401.                 if (espace[i][j][k].FULL){
  1402.                     glBegin (GL_POINTS);
  1403.                     glVertex3d (i,j,k);
  1404.                     glEnd();
  1405.                 }
  1406.                 glViewport (CDW,0,W,H-TOP_H); // establish the viewport for the rendering of the scene.
  1407.        }
  1408.        else {
  1409.          // Set all the screen viewport for the 3D rendering the left eye..            
  1410.          glViewport (0,0,W    ,H);
  1411.        }
  1412.  
  1413.    // at this point we know what the glViewport is for the main scene.
  1414.    if (displayListInited) {
  1415.        if (FLAG_TOGGLE_MENU1) { glEnable(GL_LIGHTING); }
  1416.         // Recalc Model View.
  1417.         recalcboundingbox(); 
  1418.         recalcModelView();
  1419.  
  1420.     for (int i= 0; i<DimX; i=i+2)
  1421.         for (int j=0; j<DimY; j=j+2)
  1422.             for (int k=0; k<DimZ; k=k+2)
  1423.                 if (espace[i][j][k].FULL){
  1424.                     glBegin (GL_POINTS);
  1425.                     glVertex3d (i,j,k);
  1426.                     glEnd();
  1427.                 }
  1428.  
  1429.     }
  1430.     else {
  1431.         Draw_Vrml(CNC,9); // Draws the Vehicle CNC = Current Node City.
  1432.         Draw_Vrml(CNV,19); // Draws the Vehicle CNV = Current Node Vehicle
  1433.         displayListInited = 1;
  1434.         redraw();
  1435.         glFlush();
  1436.     }
  1437.     glutSwapBuffers();
  1438. }
  1439. inline void fix_light_car()
  1440. {
  1441.  if (LIGHTS_FIX_WITH_CAMERA) {
  1442.     glLightfv(GL_LIGHT0, GL_POSITION, lightZeroPosition);
  1443.     glLightfv(GL_LIGHT1, GL_POSITION, lightOnePosition);
  1444.     glLightfv(GL_LIGHT0, GL_DIFFUSE, lightZeroColor_Car);
  1445.     glLightfv(GL_LIGHT1, GL_DIFFUSE, lightOneColor_Car);// Because light is affected by the scale.
  1446.     }
  1447.    if (!LIGHTS_FIX_WITH_CAMERA) {
  1448.       glLightfv(GL_LIGHT0, GL_POSITION, lightZeroPosition);
  1449.     glLightfv(GL_LIGHT1, GL_POSITION, lightOnePosition);
  1450.     glLightfv(GL_LIGHT0, GL_DIFFUSE, lightZeroColor_Car);
  1451.     glLightfv(GL_LIGHT1, GL_DIFFUSE, lightOneColor_Car); // Because light is affected by the scale.
  1452.   }
  1453. }
  1454. void
  1455. redraw() //fredraw
  1456. {
  1457.  extern struct Virtual_Espace espace[DimX][DimY][DimZ];
  1458.  extern void Draw_Vrml(Type_Transform *, int numlist);
  1459.  extern void recalc_mirror_coord_in_fix_coord_based_on_camera_movements(int i);
  1460.  extern double XmaxVrmlCity, YmaxVrmlCity, ZmaxVrmlCity;
  1461.  extern double XminVrmlCity, YminVrmlCity, ZminVrmlCity;
  1462.  
  1463.  int i;
  1464.  if (FLAG_TOGGLE_MENU1) {
  1465.   glEnable(GL_LIGHTING);
  1466.  }
  1467.  else 
  1468.      glDisable (GL_LIGHTING);
  1469.  glDrawBuffer(GL_BACK_LEFT);
  1470.  glClearColor (0.05882f, 0.498f, 0.8353f,1.0f);
  1471.  
  1472.  // Texture map all mirrors
  1473.  for (i=0;i<number_of_mirrors; i++)
  1474.   if (FLAG_TOGGLE_MIRROR[i]) {
  1475.    if (FLAG_FIX_MIRROR) recalc_mirror_coord_in_fix_coord_based_on_camera_movements(i);
  1476.     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  1477.     if (FLAG_MOVE_GODS_EYE==1 && i==0)
  1478.         texture_map_gods_eye(i);
  1479.     else 
  1480.         if (FLAG_MOVE_GODS_EYE == 2 && i==0)
  1481.             texture_map_vehicle_centric_display(0);
  1482.         else
  1483.             if (FLAG_MOVE_GODS_EYE == 3 && i==0)
  1484.                 texture_map_symbolic_godseye(0);
  1485.             else if (FLAG_MOVE_GODS_EYE == 4 && i==0)
  1486.                 texture_map_sensors_godseye(0);
  1487.             else
  1488.              texture_map(i);  
  1489.    }
  1490.  
  1491.  glClearColor (0.05882f, 0.498f, 0.8353f, 1.0f);
  1492.  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  1493.  
  1494.  if (viewport&& !FLAG_TOP_VIEW){
  1495.   // draw command margin then set the viewport for the 3D
  1496.   draw_commande_de_bord(); // Sets the control band viewport and draws in it.
  1497.   glViewport (CDW,0,W,H);  // set the viewport 
  1498.  }                                          
  1499.  else 
  1500.   if (viewport && FLAG_TOP_VIEW) {
  1501.    draw_commande_de_bord(); // Sets the control band viewport and draws in it.
  1502.    glViewport (TOP_V_X,TOP_V_Y,TOP_W,TOP_H);
  1503.    draw_bg();
  1504.    if (FLAG_TOGGLE_MENU1)  glEnable(GL_LIGHTING);
  1505.    recalcboundingboxTOPVIEW();
  1506.    recalcModelViewTOPVIEW();
  1507.    if (Draw_relative_axe) draw_axes();
  1508.    if (SHOW_LOCATION_DIRECTION_OF_LIGHTS) draw_light_position();
  1509.    glCallList(9); // City.
  1510.    for (i=0; i<number_of_mirrors; i++) 
  1511.     if (FLAG_TOGGLE_MIRROR[i]) {
  1512.      draw_mirror_top_view(i);
  1513.     }
  1514.    // Rotate the car first
  1515.    glTranslatef (eyec.x,eyec.y,eyec.z);
  1516.    glRotatef (2*acos(curquatc[0])*180.0/3.15169,curquatc[1], curquatc[2],curquatc[3]);
  1517.    glScalef(car_scale_factor, -car_scale_factor, car_scale_factor);
  1518.    glCallList(19);//Vehicle 
  1519.    /*for (int i=0; i<DimX; i=i+6)
  1520.     for (int j=0; j<DimY; j=j+6)
  1521.      for (int k=0; k<DimZ; k=k+6)
  1522.       if (espace[i][j][k].FULL){
  1523.        glBegin (GL_POINTS);
  1524.        xx = i*(XmaxVrmlCity - XminVrmlCity)/DimX + XminVrmlCity;
  1525.        yy = j*(YmaxVrmlCity - YminVrmlCity)/DimY + YminVrmlCity;
  1526.        zz = k*(ZmaxVrmlCity - ZminVrmlCity)/DimZ + ZminVrmlCity;
  1527.        glVertex3f (xx,yy,zz);
  1528.        glEnd();
  1529.       }*/
  1530.      //recalcModelView_Car();
  1531.   for (iti=0; iti<10; iti++) { // For each car
  1532.       if (RouteNum[iti]){
  1533.         recalcModelViewOtherCars();
  1534.         glTranslatef (    CarLocationRec[iti][IndexCarLocRec[iti]].x,                     CarLocationRec[iti][IndexCarLocRec[iti]].y,       CarLocationRec[iti][IndexCarLocRec[iti]].z);
  1535.         glRotatef (2*acos(CarLocationRec[iti][IndexCarLocRec[iti]].quat[0])*180.0/3.15169,CarLocationRec[iti][IndexCarLocRec[iti]].quat[1], CarLocationRec[iti][IndexCarLocRec[iti]].quat[2],CarLocationRec[iti][IndexCarLocRec[iti]].quat[3]);
  1536.         glScalef(car_scale_factor, -car_scale_factor, car_scale_factor);
  1537.         glCallList(19); // render car.
  1538.       }
  1539.   }
  1540.     glViewport (CDW,0,W,H-TOP_H); // establish the viewport for the rendering of the scene.
  1541.   } //if (viewport && FLAG_TOP_VIEW
  1542.   else { // Set all the screen viewport for the 3D rendering the left eye..            
  1543.    glViewport (0,0,W    ,H);
  1544.   }
  1545.  
  1546.  // at this point we know what the glViewport is for the main scene.
  1547.  // at this point we know what the glViewport is for the main scene.
  1548.  if (displayListInited) {
  1549.   // Draw           
  1550.   // eye.x = -baseline;
  1551.   // Draw axes left eye
  1552.   if (FLAG_TOGGLE_MENU1) { glEnable(GL_LIGHTING); }
  1553.   // Recalc Model View.
  1554.   recalcboundingbox(); 
  1555.   recalcModelView();
  1556.   glCallList(9);
  1557.   for (i=0; i<number_of_mirrors; i++) 
  1558.    if (FLAG_TOGGLE_MIRROR[i]) {
  1559.     draw_mirror(i);
  1560.    }
  1561.   //recalcModelView_Car(); 
  1562.   glTranslatef (eyec.x,eyec.y,eyec.z);
  1563.   glRotatef (2*acos(curquatc[0])*180.0/3.15169,curquatc[1], curquatc[2],curquatc[3]);
  1564.   glScalef(car_scale_factor, -car_scale_factor, car_scale_factor);
  1565.   glCallList(19); // render car. 
  1566.   for (iti=0; iti<10; iti++) { // For each car
  1567.       if (RouteNum[iti]){
  1568.         recalcModelViewOtherCars();
  1569.         glTranslatef (    CarLocationRec[iti][IndexCarLocRec[iti]].x,                     CarLocationRec[iti][IndexCarLocRec[iti]].y,       CarLocationRec[iti][IndexCarLocRec[iti]].z);
  1570.         glRotatef (2*acos(CarLocationRec[iti][IndexCarLocRec[iti]].quat[0])*180.0/3.15169,CarLocationRec[iti][IndexCarLocRec[iti]].quat[1], CarLocationRec[iti][IndexCarLocRec[iti]].quat[2],CarLocationRec[iti][IndexCarLocRec[iti]].quat[3]);
  1571.         glScalef(car_scale_factor, -car_scale_factor, car_scale_factor);
  1572.         glCallList(19); // render car.
  1573.       }
  1574.   }
  1575.  }
  1576.  else {
  1577.   /* otherwise compile and execute to create the display list 
  1578.   glNewList(28, GL_COMPILE_AND_EXECUTE);
  1579.   /* front face 
  1580.   glPointSize (pt_size);
  1581.   glBegin(GL_POINTS);
  1582.   /*    glColor3f(0.0, 0.7, 0.1);    green 
  1583.   printf ("Drawing for the first time \n");
  1584.   for (i=0; i<dim[0]; i=i+fraction){
  1585.   if ((xc[i] != NaN) && (yc[i] != NaN) && (zc[i] != NaN)){
  1586.   glColor3f (cxx[i], cyy[i], czz[i]);
  1587.   glVertex3f(xc[i],yc[i],zc[i]);
  1588.   }
  1589.   }
  1590.   glEnd();
  1591.   glEndList(); */
  1592.         
  1593.   Draw_Vrml(CNC,9); // Draws the Vehicle CNV = Current Node City
  1594.   Draw_Vrml(CNV,19); // Draws the Vehicle CNV = Current Node Vehicle
  1595.   Draw_Vrml(CNSe,27);// Draws the display list 27 of the Censors.
  1596.   displayListInited = 1;
  1597.   redraw();
  1598.   glFlush();
  1599.  }
  1600.  glutSwapBuffers();
  1601. }
  1602.  
  1603. void
  1604. load_configuration(char num)
  1605. {
  1606.  FILE *file;
  1607.  char configurationNum [15];
  1608.  
  1609.  strcpy (configurationNum,"configuration");
  1610.  strncat (configurationNum, &num,1);
  1611.  
  1612.  if ((file = fopen (configurationNum,"r")) == NULL)
  1613.   printf ("\n pas de chance l'ami ton fichier est corrompu 95478567\n");
  1614.  
  1615.  fscanf (file, "number_of_mirrors %d \n",
  1616.      &number_of_mirrors);
  1617.  
  1618.  for (int v=0; v<6;v++){
  1619.   fscanf (file, "m1[v].cr %f %f %f \n",
  1620.      &m1[v].cr.x,  &m1[v].cr.y,  &m1[v].cr.z);
  1621.   fscanf (file, "m1[v].c1 %f %f %f \n",
  1622.      &m1[v].c1.x,  &m1[v].c1.y,  &m1[v].c1.z);
  1623.   fscanf (file, "m1[v].c2 %f %f %f \n",
  1624.      &m1[v].c2.x,  &m1[v].c2.y,  &m1[v].c2.z);
  1625.   fscanf (file, "m1[v].c3 %f %f %f \n",
  1626.      &m1[v].c3.x,  &m1[v].c3.y,  &m1[v].c3.z);
  1627.   fscanf (file, "m1[v].c4 %f %f %f \n",
  1628.      &m1[v].c4.x,  &m1[v].c4.y,  &m1[v].c4.z);
  1629.   fscanf (file, "m1[v].cc1 %f %f %f \n",
  1630.      &m1[v].cc1.x, &m1[v].cc1.y, &m1[v].cc1.z);
  1631.   fscanf (file, "m1[v].cc2 %f %f %f \n",
  1632.      &m1[v].cc2.x, &m1[v].cc2.y, &m1[v].cc2.z);
  1633.   fscanf (file, "m1[v].cc3 %f %f %f \n",
  1634.      &m1[v].cc3.x, &m1[v].cc3.y, &m1[v].cc3.z);
  1635.   fscanf (file, "m1[v].cc4 %f %f %f \n",
  1636.      &m1[v].cc4.x, &m1[v].cc4.y, &m1[v].cc4.z);
  1637.   fscanf (file, "m1[v].nl %f %f %f \n",
  1638.      &m1[v].nl.x , &m1[v].nl.y,  &m1[v].nl.z);
  1639.   fscanf (file, "m1[v].up %f %f %f \n",
  1640.      &m1[v].up.x , &m1[v].up.y,  &m1[v].up.z);
  1641.   fscanf (file, "m1[v].side %f %f %f \n",
  1642.      &m1[v].side.x , &m1[v].side.y,  &m1[v].side.z);
  1643.   fscanf (file, "m1[v].width %f, m1[v].height %f \n \n \n",
  1644.      &m1[v].width  ,  &m1[v].height);
  1645.  }
  1646.  
  1647.  fscanf (file, "angle %lf \n",
  1648.      &angle);
  1649.  fscanf (file, "curquat[.] %lf %lf %lf %lf \n",
  1650.      &curquat[0],          &curquat[1],          &curquat[2],          &curquat[3]);
  1651.  fscanf (file, "curquatc[.] %lf %lf %lf %lf \n",
  1652.      &curquatc[0],         &curquatc[1],         &curquatc[2],         &curquatc[3]);
  1653.  fscanf (file, "curquat_mirror[.] %lf %lf %lf %lf \n",
  1654.      &curquat_mirror[0],   &curquat_mirror[1],   &curquat_mirror[2],   &curquat_mirror[3]);
  1655.  fscanf (file, "curquat_top_view[.] %lf %lf %lf %lf \n",
  1656.      &curquat_top_view[0], &curquat_top_view[1], &curquat_top_view[2], &curquat_top_view[3]);
  1657.  fscanf (file, "curquat_light0[.] %lf %lf %lf %lf \n",
  1658.      &curquat_light0[0],   &curquat_light0[1],   &curquat_light0[2],   &curquat_light0[3]);
  1659.  fscanf (file, "curquat_light1[.] %lf %lf %lf %lf \n",
  1660.      &curquat_light1[0],   &curquat_light1[1],   &curquat_light1[2],   &curquat_light1[3]);
  1661.  fscanf (file, "lastquat_top_view[.] %lf %lf %lf %lf \n",
  1662.      &lastquat_top_view[0], &lastquat_top_view[1], &lastquat_top_view[2], &lastquat_top_view[3]);
  1663.  fscanf (file, "lastquat[.] %lf %lf %lf %lf \n",
  1664.      &lastquat[0],          &lastquat[1],          &lastquat[2],          &lastquat[3]);
  1665.  fscanf (file, "lastquat_mirror[.] %lf %lf %lf %lf \n",
  1666.      &lastquat_mirror[0],   &lastquat_mirror[1],   &lastquat_mirror[2],   &lastquat_mirror[3]);
  1667.  fscanf (file, "lastquat_light0[.] %lf %lf %lf %lf \n",
  1668.      &lastquat_light0[0],   &lastquat_light0[1],   &lastquat_light0[2],   &lastquat_light0[3]);
  1669.  fscanf (file, "lastquat_light1[.] %lf %lf %lf %lf \n",
  1670.      &lastquat_light1[0],   &lastquat_light1[1],   &lastquat_light1[2],   &lastquat_light1[3]);
  1671.  
  1672.  fscanf (file, "newModel %d scalefactor %lf \n",
  1673.      &newModel, &scalefactor);
  1674.  
  1675.  fscanf (file, "TOP %lf \n BOTTOM %lf \n LEFT %lf \n RIGTH %lf \n TRANSLATE_X %lf \n TRANSLATE_Y %lf \n TRANSLATE_Z %lf \n TRANSLATE_H %lf \n NEAR2 %lf FAR2 %lf \n \n ",
  1676.      &TOP, &BOTTOM, &LEFT, &RIGHT, &TRANSLATE_X, &TRANSLATE_Y, &TRANSLATE_Z, &TRANSLATE_H, &NEAR2, &FAR2);
  1677.  fscanf (file, "FLAG_MOVE_CAR %d  FLAG_MOVE_SCENE %d  WALK_SLOWLY %d",
  1678.      &FLAG_MOVE_CAR, &FLAG_MOVE_SCENE, &WALK_SLOWLY);
  1679.  fscanf (file ,"DriverPos %f %f %f \n",
  1680.      &DriverPos.x, &DriverPos.y, &DriverPos.z);
  1681.  
  1682.  fscanf (file, "eye %f %f %f \n",
  1683.      &eye.x, &eye.y, &eye.z);
  1684.  fscanf (file, "eye1 %f %f %f \n",
  1685.      &eye1.x, &eye1.y, &eye1.z);
  1686.  fscanf (file, "eye2 %f %f %f \n",
  1687.      &eye2.x, &eye2.y, &eye2.z);
  1688.  fscanf (file, "eye_mirror %f %f %f \n",
  1689.      &eye_mirror.x, &eye_mirror.y, &eye_mirror.z);
  1690.  fscanf (file ,"eyec %f %f %f \n",
  1691.      &eyec.x, &eyec.y, &eyec.z);
  1692.  fscanf (file, "eyeP %f %f %f \n",
  1693.      &eyeP.x, &eyeP.y, &eyeP.z);
  1694.  fscanf (file, "lk %f %f %f \n",
  1695.      &lk.x, &lk.y, &lk.z);
  1696.  fscanf (file, "up %f %f %f \n",
  1697.      &up.x, &up.y, &up.z);
  1698.  fscanf (file, "hor %f %f %f \n",
  1699.      &hor.x, &hor.y, &hor.z);
  1700.  fscanf (file, "lk_rt %f %f %f \n",
  1701.      &lk_rt.x, &lk_rt.y, &lk_rt.z);
  1702.  fscanf (file, "up_rt %f %f %f \n",
  1703.      &up_rt.x, &up_rt.y, &up_rt.z);
  1704.  fscanf (file, "hor_rt %f %f %f \n",
  1705.      &hor_rt.x, &hor_rt.y, &hor_rt.z);
  1706.  fscanf (file, "lkc_rt %f %f %f \n",
  1707.      &lkc_rt.x, &lkc_rt.y, &lkc_rt.z);
  1708.  fscanf (file, "upc_rt %f %f %f \n",
  1709.      &upc_rt.x, &upc_rt.y, &upc_rt.z);
  1710.  fscanf (file, "horc_rt %f %f %f \n",
  1711.      &horc_rt.x, &horc_rt.y, &horc_rt.z);
  1712.  fscanf (file, "lkP %f %f %f \n",
  1713.      &lkP.x , &lkP.y, &lkP.z);
  1714.  fscanf (file, "upP %f %f %f \n",
  1715.      &upP.x, &upP.y, &upP.z);
  1716.  fscanf (file, "horP %f %f %f \n",
  1717.      &horP.x, &horP.y, &horP.z);
  1718.  fscanf (file, "meye %f %f %f \n",
  1719.      &meye.x , &meye.y, &meye.z);
  1720.  fscanf (file, "MEM_POINT %f %f %f \n",
  1721.      &MEM_POINT.x, &MEM_POINT.y, &MEM_POINT.z);
  1722.  fscanf (file, "pos_light0 %f %f %f \n",
  1723.      &pos_light0.x, &pos_light0.y, &pos_light0.z);
  1724.  fscanf (file, "pos_light1 %f %f %f \n",
  1725.      &pos_light1.x, &pos_light1.y, &pos_light1.z);
  1726.  fscanf (file, "z %lf  teta %lf  phi %lf  teta2 %lf  cam_angle %lf",                            
  1727.      &z, &teta, &phi, &teta2, &cam_angle);
  1728.  
  1729.  fscanf (file, "viewport %d  FLAG_TOP_VIEW  %d  FLAG_SELECTED_MIRROR  %d  FLAG_TOGGLE_MIRROR[0] %d",
  1730.     &viewport               , &FLAG_TOP_VIEW        , &FLAG_SELECTED_MIRROR , &FLAG_TOGGLE_MIRROR[0]);
  1731.  fscanf (file, "FLAG_TOGGLE_MIRROR[1]  %d %d %d %d %d %d \n",
  1732.     &FLAG_TOGGLE_MIRROR[0]  , &FLAG_TOGGLE_MIRROR[1], &FLAG_TOGGLE_MIRROR[2], &FLAG_TOGGLE_MIRROR[3],
  1733.     &FLAG_TOGGLE_MIRROR[4]  , &FLAG_TOGGLE_MIRROR[5]);
  1734.  fscanf (file, "FLAG_FRONT_VIEW  %d   FLAG_TOGGLE_MENU1 %d     FLAG_TOGGLE_TEXTURE_MAP %d \n",
  1735.     &FLAG_FRONT_VIEW      , &FLAG_TOGGLE_MENU1    , &FLAG_TOGGLE_TEXTURE_MAP);
  1736.  fscanf (file, "FLAG_DROP_MENU  %d    TRANSLATE_TO_GRAVITY %d    TRANSLATE_TO_MIDDLE %d \n",
  1737.     &FLAG_DROP_MENU         , &TRANSLATE_TO_GRAVITY , &TRANSLATE_TO_MIDDLE);
  1738.  fscanf (file, "Draw_relative_axe %d     Draw_light_position %d   spinning %d   expand_carre1 %d\n", 
  1739.     &Draw_relative_axe      , &Draw_light_position  , &spinning             , &expand_carre1);
  1740.  fscanf (file, "expand_carre2 %d    expand_carre3 %d        APPLY_MOUSE_MOTION %d   FLAG_ORTHO_PERSP %d \n",
  1741.     &expand_carre2          , &expand_carre3        , &APPLY_MOUSE_MOTION   , &FLAG_ORTHO_PERSP);
  1742.  fscanf (file, "FLAG_FIX_MIRROR %d      FLAG_HORIZ %d         SHOW_LOCATION_DIRECTION_OF_LIGHTS %d \n",
  1743.     &FLAG_FIX_MIRROR        , &FLAG_HORIZ           , &SHOW_LOCATION_DIRECTION_OF_LIGHTS);
  1744.  fscanf (file, "LIGHTS_FIX_WITH_CAMERA %d",
  1745.     &LIGHTS_FIX_WITH_CAMERA);
  1746.  fscanf (file, "Center_Of_Rot_Of_Lights %f %f %f \n",
  1747.     &Center_Of_Rot_Of_Lights.x, &Center_Of_Rot_Of_Lights.y, &Center_Of_Rot_Of_Lights.z);
  1748.  
  1749.  fscanf (file, "lightZeroPosition[.] %f %f %f %f \n",
  1750.     &lightZeroPosition[0], &lightZeroPosition[1], &lightZeroPosition[2], &lightZeroPosition[3]);
  1751.  fscanf (file, "lightOnePosition[.] %f %f %f %f \n",
  1752.     &lightOnePosition[0] , &lightOnePosition[1],  &lightOnePosition[2] , &lightOnePosition[3]);
  1753.  fscanf (file, "lightZeroColor[.] %f %f %f %f \n",
  1754.     &lightZeroColor[0],    &lightZeroColor[1],    &lightZeroColor[2],    &lightZeroColor[3]);
  1755.  fscanf (file, "lightOneColor[.] %f %f %f %f \n",
  1756.     &lightOneColor[0],     &lightOneColor[1],     &lightOneColor[2],     &lightOneColor[3]);
  1757.  fscanf (file, "lightZeroColor_Car[.] %f %f %f %f \n",
  1758.     &lightZeroColor_Car[0],&lightZeroColor_Car[1],&lightZeroColor_Car[2],&lightZeroColor_Car[3]);
  1759.  fscanf (file, "lightOneColor_Car[.] %f %f %f %f \n",
  1760.     &lightOneColor_Car[0], &lightOneColor_Car[1], &lightOneColor_Car[2], &lightOneColor_Car[3] );
  1761.  fscanf (file, "aspect_ratio %lf \n", &aspect_ratio);
  1762.  fscanf (file, "FLAG_MOVE_GODS_EYE %d \n", &FLAG_MOVE_GODS_EYE);
  1763.  fscanf (file, "Geye %f %f %f \n", &Geye.x, &Geye.y, &Geye.z);
  1764.  fscanf (file, "Gup %f %f %f \n", &Gup.x, &Gup.y, &Gup.z);
  1765.  fscanf (file, "Ghor %f %f %f \n", &Ghor.x, &Ghor.y, &Ghor.z);
  1766.  fscanf (file, "Glk %f %f %f \n", &Glk.x, &Glk.y, &Glk.z);
  1767.  fscanf (file, "Gup_V %f %f %f \n", &Gup_V.x, &Gup_V.y, &Gup_V.z);
  1768.  fscanf (file, "Geye_V %f %f %f \n", &Geye_V.x, &Geye_V.y, &Geye_V.z);
  1769.  fscanf (file, "curquat_Geye[.] %lf %lf %lf %lf \n",
  1770.      &curquat_Geye[0], &curquat_Geye[1], &curquat_Geye[2], &curquat_Geye[3]);
  1771.  for (i=0;i<9;i++)
  1772.     fscanf (file, "mz[i] %d \n", &mz[i]);
  1773.  
  1774.     fclose (file);
  1775. }
  1776. void
  1777. save_configurations(char num){
  1778.  FILE *file;
  1779.  char configurationNum [15];
  1780.  strcpy (configurationNum,"configuration");
  1781.  strncat (configurationNum, &num, 1);
  1782.  
  1783.  if ((file = fopen (configurationNum,"w")) == NULL)
  1784.   printf ("\n pas de chance l'ami ton fichier est corrompu 95478567\n");
  1785.  
  1786.  fprintf (file, "number_of_mirrors %d \n",
  1787.      number_of_mirrors);
  1788.  
  1789.  for (int v=0; v<6;v++){
  1790.   fprintf (file, "m1[v].cr %f %f %f \n",
  1791.      m1[v].cr.x,  m1[v].cr.y,  m1[v].cr.z);
  1792.   fprintf (file, "m1[v].c1 %f %f %f \n",
  1793.      m1[v].c1.x,  m1[v].c1.y,  m1[v].c1.z);
  1794.   fprintf (file, "m1[v].c2 %f %f %f \n",
  1795.      m1[v].c2.x,  m1[v].c2.y,  m1[v].c2.z);
  1796.   fprintf (file, "m1[v].c3 %f %f %f \n",
  1797.      m1[v].c3.x,  m1[v].c3.y,  m1[v].c3.z);
  1798.   fprintf (file, "m1[v].c4 %f %f %f \n",
  1799.      m1[v].c4.x,  m1[v].c4.y,  m1[v].c4.z);
  1800.   fprintf (file, "m1[v].cc1 %f %f %f \n",
  1801.      m1[v].cc1.x, m1[v].cc1.y, m1[v].cc1.z);
  1802.   fprintf (file, "m1[v].cc2 %f %f %f \n",
  1803.      m1[v].cc2.x, m1[v].cc2.y, m1[v].cc2.z);
  1804.   fprintf (file, "m1[v].cc3 %f %f %f \n",
  1805.      m1[v].cc3.x, m1[v].cc3.y, m1[v].cc3.z);
  1806.   fprintf (file, "m1[v].cc4 %f %f %f \n",
  1807.      m1[v].cc4.x, m1[v].cc4.y, m1[v].cc4.z);
  1808.   fprintf (file, "m1[v].nl %f %f %f \n",
  1809.      m1[v].nl.x , m1[v].nl.y,  m1[v].nl.z);
  1810.   fprintf (file, "m1[v].up %f %f %f \n",
  1811.      m1[v].up.x , m1[v].up.y,  m1[v].up.z);
  1812.   fprintf (file, "m1[v].side %f %f %f \n",
  1813.      m1[v].side.x , m1[v].side.y,  m1[v].side.z);
  1814.   fprintf (file, "m1[v].width %f, m1[v].height %f \n \n \n",
  1815.      m1[v].width  ,  m1[v].height);
  1816.  }
  1817.  
  1818.  fprintf (file, "angle %lf \n",
  1819.      angle);
  1820.  fprintf (file, "curquat[.] %lf %lf %lf %lf \n",
  1821.      curquat[0],          curquat[1],          curquat[2],          curquat[3]);
  1822.  fprintf (file, "curquatc[.] %lf %lf %lf %lf \n",
  1823.      curquatc[0],         curquatc[1],         curquatc[2],         curquatc[3]);
  1824.  fprintf (file, "curquat_mirror[.] %lf %lf %lf %lf \n",
  1825.      curquat_mirror[0],   curquat_mirror[1],   curquat_mirror[2],   curquat_mirror[3]);
  1826.  fprintf (file, "curquat_top_view[.] %lf %lf %lf %lf \n",
  1827.      curquat_top_view[0], curquat_top_view[1], curquat_top_view[2], curquat_top_view[3]);
  1828.  fprintf (file, "curquat_light0[.] %lf %lf %lf %lf \n",
  1829.      curquat_light0[0],   curquat_light0[1],   curquat_light0[2],   curquat_light0[3]);
  1830.  fprintf (file, "curquat_light1[.] %lf %lf %lf %lf \n",
  1831.      curquat_light1[0],   curquat_light1[1],   curquat_light1[2],   curquat_light1[3]);
  1832.  fprintf (file, "lastquat_top_view[.] %lf %lf %lf %lf \n",
  1833.      lastquat_top_view[0], lastquat_top_view[1], lastquat_top_view[2], lastquat_top_view[3]);
  1834.  fprintf (file, "lastquat[.] %lf %lf %lf %lf \n",
  1835.      lastquat[0],          lastquat[1],          lastquat[2],          lastquat[3]);
  1836.  fprintf (file, "lastquat_mirror[.] %lf %lf %lf %lf \n",
  1837.      lastquat_mirror[0],   lastquat_mirror[1],   lastquat_mirror[2],   lastquat_mirror[3]);
  1838.  fprintf (file, "lastquat_light0[.] %lf %lf %lf %lf \n",
  1839.      lastquat_light0[0],   lastquat_light0[1],   lastquat_light0[2],   lastquat_light0[3]);
  1840.  fprintf (file, "lastquat_light1[.] %lf %lf %lf %lf \n",
  1841.      lastquat_light1[0],   lastquat_light1[1],   lastquat_light1[2],   lastquat_light1[3]);
  1842.  
  1843.  fprintf (file, "newModel %d scalefactor %lf \n",
  1844.      newModel, scalefactor);
  1845.  
  1846.  fprintf (file, "TOP %lf \n BOTTOM %lf \n LEFT %lf \n RIGTH %lf \n TRANSLATE_X %lf \n TRANSLATE_Y %lf \n TRANSLATE_Z %lf \n TRANSLATE_H %lf \n NEAR2 %lf FAR2 %lf \n \n ",
  1847.      TOP, BOTTOM, LEFT, RIGHT, TRANSLATE_X, TRANSLATE_Y, TRANSLATE_Z, TRANSLATE_H, NEAR2, FAR2);
  1848.  fprintf (file, "FLAG_MOVE_CAR %d  FLAG_MOVE_SCENE %d  WALK_SLOWLY %d",
  1849.      FLAG_MOVE_CAR, FLAG_MOVE_SCENE, WALK_SLOWLY);
  1850.  fprintf (file ,"DriverPos %f %f %f \n",
  1851.      DriverPos.x, DriverPos.y, DriverPos.z);
  1852.  
  1853.  fprintf (file, "eye %f %f %f \n",
  1854.      eye.x, eye.y, eye.z);
  1855.  fprintf (file, "eye1 %f %f %f \n",
  1856.      eye1.x, eye1.y, eye1.z);
  1857.  fprintf (file, "eye2 %f %f %f \n",
  1858.      eye2.x, eye2.y, eye2.z);
  1859.  fprintf (file, "eye_mirror %f %f %f \n",
  1860.      eye_mirror.x, eye_mirror.y, eye_mirror.z);
  1861.  fprintf (file ,"eyec %f %f %f \n",
  1862.      eyec.x, eyec.y, eyec.z);
  1863.  fprintf (file, "eyeP %f %f %f \n",
  1864.      eyeP.x, eyeP.y, eyeP.z);
  1865.  fprintf (file, "lk %f %f %f \n",
  1866.      lk.x, lk.y, lk.z);
  1867.  fprintf (file, "up %f %f %f \n",
  1868.      up.x, up.y, up.z);
  1869.  fprintf (file, "hor %f %f %f \n",
  1870.      hor.x, hor.y, hor.z);
  1871.  fprintf (file, "lk_rt %f %f %f \n",
  1872.      lk_rt.x, lk_rt.y, lk_rt.z);
  1873.  fprintf (file, "up_rt %f %f %f \n",
  1874.      up_rt.x, up_rt.y, up_rt.z);
  1875.  fprintf (file, "hor_rt %f %f %f \n",
  1876.      hor_rt.x, hor_rt.y, hor_rt.z);
  1877.  fprintf (file, "lkc_rt %f %f %f \n",
  1878.      lkc_rt.x, lkc_rt.y, lkc_rt.z);
  1879.  fprintf (file, "upc_rt %f %f %f \n",
  1880.      upc_rt.x, upc_rt.y, upc_rt.z);
  1881.  fprintf (file, "horc_rt %f %f %f \n",
  1882.      horc_rt.x, horc_rt.y, horc_rt.z);
  1883.  fprintf (file, "lkP %f %f %f \n",
  1884.      lkP.x , lkP.y, lkP.z);
  1885.  fprintf (file, "upP %f %f %f \n",
  1886.      upP.x, upP.y, upP.z);
  1887.  fprintf (file, "horP %f %f %f \n",
  1888.      horP.x, horP.y, horP.z);
  1889.  fprintf (file, "meye %f %f %f \n",
  1890.      meye.x , meye.y, meye.z);
  1891.  fprintf (file, "MEM_POINT %f %f %f \n",
  1892.      MEM_POINT.x, MEM_POINT.y, MEM_POINT.z);
  1893.  fprintf (file, "pos_light0 %f %f %f \n",
  1894.      pos_light0.x, pos_light0.y, pos_light0.z);
  1895.  fprintf (file, "pos_light1 %f %f %f \n",
  1896.      pos_light1.x, pos_light1.y, pos_light1.z);
  1897.  fprintf (file, "z %lf  teta %lf  phi %lf  teta2 %lf  cam_angle %lf",                            
  1898.      z, teta, phi, teta2, cam_angle);
  1899.  
  1900.  fprintf (file, "viewport %d  FLAG_TOP_VIEW  %d  FLAG_SELECTED_MIRROR  %d  FLAG_TOGGLE_MIRROR[0] %d",
  1901.     viewport               , FLAG_TOP_VIEW        , FLAG_SELECTED_MIRROR , FLAG_TOGGLE_MIRROR[0]);
  1902.  fprintf (file, "FLAG_TOGGLE_MIRROR[1]  %d %d %d %d %d %d \n",
  1903.     FLAG_TOGGLE_MIRROR[0]  , FLAG_TOGGLE_MIRROR[1], FLAG_TOGGLE_MIRROR[2], FLAG_TOGGLE_MIRROR[3],
  1904.     FLAG_TOGGLE_MIRROR[4]  , FLAG_TOGGLE_MIRROR[5]);
  1905.  fprintf (file, "FLAG_FRONT_VIEW  %d   FLAG_TOGGLE_MENU1 %d     FLAG_TOGGLE_TEXTURE_MAP %d \n",
  1906.     FLAG_FRONT_VIEW      , FLAG_TOGGLE_MENU1    , FLAG_TOGGLE_TEXTURE_MAP);
  1907.  fprintf (file, "FLAG_DROP_MENU  %d    TRANSLATE_TO_GRAVITY %d    TRANSLATE_TO_MIDDLE %d \n",
  1908.     FLAG_DROP_MENU         , TRANSLATE_TO_GRAVITY , TRANSLATE_TO_MIDDLE);
  1909.  fprintf (file, "Draw_relative_axe %d     Draw_light_position %d   spinning %d   expand_carre1 %d\n", 
  1910.     Draw_relative_axe      , Draw_light_position  , spinning             , expand_carre1);
  1911.  fprintf (file, "expand_carre2 %d    expand_carre3 %d        APPLY_MOUSE_MOTION %d   FLAG_ORTHO_PERSP %d \n",
  1912.     expand_carre2          , expand_carre3        , APPLY_MOUSE_MOTION   , FLAG_ORTHO_PERSP);
  1913.  fprintf (file, "FLAG_FIX_MIRROR %d      FLAG_HORIZ %d         SHOW_LOCATION_DIRECTION_OF_LIGHTS %d \n",
  1914.     FLAG_FIX_MIRROR        , FLAG_HORIZ           , SHOW_LOCATION_DIRECTION_OF_LIGHTS);
  1915.  fprintf (file, "LIGHTS_FIX_WITH_CAMERA %d",
  1916.     LIGHTS_FIX_WITH_CAMERA);
  1917.  fprintf (file, "Center_Of_Rot_Of_Lights %f %f %f \n",
  1918.     Center_Of_Rot_Of_Lights.x, Center_Of_Rot_Of_Lights.y, Center_Of_Rot_Of_Lights.z);
  1919.  
  1920.  fprintf (file, "lightZeroPosition[.] %f %f %f %f \n",
  1921.     lightZeroPosition[0], lightZeroPosition[1], lightZeroPosition[2], lightZeroPosition[3]);
  1922.  fprintf (file, "lightOnePosition[.] %f %f %f %f \n",
  1923.     lightOnePosition[0] , lightOnePosition[1],  lightOnePosition[2] , lightOnePosition[3]);
  1924.  fprintf (file, "lightZeroColor[.] %f %f %f %f \n",
  1925.     lightZeroColor[0],    lightZeroColor[1],    lightZeroColor[2],    lightZeroColor[3]);
  1926.  fprintf (file, "lightOneColor[.] %f %f %f %f \n",
  1927.     lightOneColor[0],     lightOneColor[1],     lightOneColor[2],     lightOneColor[3]);
  1928.  fprintf (file, "lightZeroColor_Car[.] %f %f %f %f \n",
  1929.     lightZeroColor_Car[0],lightZeroColor_Car[1],lightZeroColor_Car[2],lightZeroColor_Car[3]);
  1930.  fprintf (file, "lightOneColor_Car[.] %f %f %f %f \n",
  1931.     lightOneColor_Car[0], lightOneColor_Car[1], lightOneColor_Car[2], lightOneColor_Car[3] );
  1932.  fprintf (file, "aspect_ratio %lf \n", aspect_ratio);
  1933.  fprintf (file, "FLAG_MOVE_GODS_EYE %d \n", FLAG_MOVE_GODS_EYE);
  1934.  fprintf (file, "Geye %f %f %f \n", Geye.x, Geye.y, Geye.z);
  1935.  fprintf (file, "Gup %f %f %f \n", Gup.x, Gup.y, Gup.z);
  1936.  fprintf (file, "Ghor %f %f %f \n", Ghor.x, Ghor.y, Ghor.z);
  1937.  fprintf (file, "Glk %f %f %f \n", Glk.x, Glk.y, Glk.z);
  1938.  fprintf (file, "Gup_V %f %f %f \n", Gup_V.x, Gup_V.y, Gup_V.z);
  1939.  fprintf (file, "Geye_V %f %f %f \n", Geye_V.x, Geye_V.y, Geye_V.z);
  1940.  fprintf (file, "curquat_Geye[.] %lf %lf %lf %lf \n",
  1941.   curquat_Geye[0], curquat_Geye[1], curquat_Geye[2], curquat_Geye[3]);
  1942.  for (i=0;i<9;i++)
  1943.     fprintf (file, "mz[i] %d \n", mz[i]);
  1944.  
  1945.  fclose (file);
  1946. }
  1947.  
  1948. void
  1949. fog()
  1950. {
  1951.  glEnable(GL_DEPTH_TEST);
  1952.  GLfloat fogColor[4] = {0, 0,0 , 1.0};
  1953.  glEnable (GL_FOG);
  1954.  glFogi (GL_FOG_MODE, GL_EXP);
  1955.  glFogf (GL_FOG_DENSITY, fogDensity);
  1956.  glFogfv(GL_FOG_COLOR, fogColor);
  1957.  // glHint (GL_FOG_HINT, GL_NICEST);
  1958.  //glFogf (GL_FOG_START, 0);
  1959.  //glFogf (GL_FOG_END, abs(zmin) + abs(zmax));
  1960. }
  1961.  
  1962. void
  1963. extrudeSolidFromPolygon(GLdouble data[][2], unsigned int dataSize,
  1964.                                                 GLdouble thickness, GLuint side, GLuint edge, GLuint whole)
  1965. {
  1966.  static GLUtriangulatorObj *tobj = NULL;
  1967.  GLdouble vertex[3], dx, dy, len;
  1968.  int i;
  1969.  int count = dataSize / (2 * sizeof(GLfloat));
  1970.  
  1971.  if (tobj == NULL) {
  1972.    tobj = gluNewTess();  /* create and initialize a GLU
  1973.    polygon * * tesselation object */
  1974.    // gluTessCallback(tobj, GLU_BEGIN, glBegin);
  1975.    // gluTessCallback(tobj, GLU_VERTEX, glVertex2fv);  // semi-tricky                                                     
  1976.    gluTessCallback(tobj, GLU_END, glEnd);
  1977.  }
  1978.  glNewList(side, GL_COMPILE);
  1979.  glShadeModel(GL_SMOOTH);  /* smooth minimizes seeing
  1980.                                tessellation */
  1981.  gluBeginPolygon(tobj);
  1982.  for (i = 0; i < count; i++) {
  1983.   vertex[0] = data[i][0];
  1984.   vertex[1] = data[i][1];
  1985.   vertex[2] = 0;
  1986.   gluTessVertex(tobj, vertex, data[i]);
  1987.  }
  1988.  gluEndPolygon(tobj);
  1989.  glEndList();
  1990.  glNewList(edge, GL_COMPILE);
  1991.  glShadeModel(GL_FLAT);  /* flat shade keeps angular hands
  1992.                              from being * * "smoothed" */
  1993.  glBegin(GL_QUAD_STRIP);
  1994.  for (i = 0; i <= count; i++) {
  1995.   /* mod function handles closing the edge */
  1996.   glVertex3f(data[i % count][0], data[i % count][1], 0.0);
  1997.   glVertex3f(data[i % count][0], data[i % count][1], thickness);
  1998.   /* Calculate a unit normal by dividing by Euclidean
  1999.   distance. We * could be lazy and use
  2000.   glEnable(GL_NORMALIZE) so we could pass in * arbitrary
  2001.   normals for a very slight performance hit. */
  2002.   dx = data[(i + 1) % count][1] - data[i % count][1];
  2003.   dy = data[i % count][0] - data[(i + 1) % count][0];
  2004.   len = sqrt(dx * dx + dy * dy);
  2005.   glNormal3f(dx / len, dy / len, 0.0);
  2006.  }
  2007.  glEnd();
  2008.  glEndList();
  2009.  glNewList(whole, GL_COMPILE);
  2010.  glFrontFace(GL_CW);
  2011.  glCallList(edge);
  2012.  glNormal3f(0.0, 0.0, -1.0);  /* constant normal for side */
  2013.  glCallList(side);
  2014.  glPushMatrix();
  2015.  glTranslatef(0.0, 0.0, thickness);
  2016.  glFrontFace(GL_CCW);
  2017.  glNormal3f(0.0, 0.0, 1.0);  /* opposite normal for other side 
  2018.                                */
  2019.  glCallList(side);
  2020.  glPopMatrix();
  2021.  glEndList();
  2022. }
  2023. void
  2024. redraw2(void)
  2025. {
  2026.  if (newModel)
  2027.   recalcModelView();
  2028.  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  2029.  glCallList(DINOSAUR);
  2030.  // showMessage(2, 7.1, 4.1, "Habib.");
  2031.  glutSwapBuffers();
  2032. }
  2033.  
  2034. void
  2035. myReshape(int w, int h)
  2036. {
  2037.  glViewport(0, 0, w, h);
  2038.  W = w;
  2039.  H = h;
  2040.  TOP_V_Y= H- TOP_H; 
  2041. }
  2042. void
  2043. myReshape2(int w, int h)
  2044. {
  2045.  glViewport(0, 0, w, h);
  2046.  W2 = w;
  2047.  H2 = h;
  2048. }
  2049. void
  2050. animate(void)
  2051. {
  2052.  glutPostRedisplay();
  2053. }
  2054. void
  2055. vis(int visible)
  2056. {
  2057.  if (visible == GLUT_VISIBLE) {                
  2058.   if (spinning) 
  2059.    glutIdleFunc(animate);
  2060.  }
  2061.  else {
  2062.   if (spinning)
  2063.    glutIdleFunc(NULL);
  2064.  }
  2065. }
  2066. void initialize_a_mirror(int i)
  2067. {
  2068.  extern void calc_corners_of_mirror(int i);
  2069.  
  2070.  mz[0] = mz[1] = mz[2] = mz[3] = mz[4] = mz[5] = mz[6] = mz[7] = mz[8] = mz[9] = 0;
  2071.  // m1[i] is the mirror link---> struct mirror
  2072.  m1[i].cr.x= eye.x+2*lk_rt.x; //mirror.center.x (m1[i] is mirror) (cr is center)
  2073.  m1[i].cr.y= eye.y+2*lk_rt.y;
  2074.  m1[i].cr.z= eye.z+2*lk_rt.z;
  2075.  
  2076.  m1[i].nl.x =0; //mirror.normal.dx (m1[i] is mirror) (nl is normal)
  2077.  m1[i].nl.y =0;
  2078.  m1[i].nl.z =1;
  2079.  
  2080.  m1[i].up.x = 0; // mirror.up.x (m1[i] is mirror) (up is the vector up).
  2081.  m1[i].up.y = 1;
  2082.  m1[i].up.z = 0;
  2083.  
  2084.  m1[i].side = vectoriel (m1[i].up,m1[i].nl);
  2085.  
  2086.  m1[i].width =  1; // this is the width / 2
  2087.  m1[i].height = 1;// this is the height / 2.
  2088.  
  2089.  calc_corners_of_mirror(i);
  2090. }
  2091. //finitialize_some_var
  2092. void initialize_some_var()
  2093. {
  2094.  int i;
  2095.  
  2096.  sensors_V[0].x = -8.103f;
  2097.  sensors_V[0].y =  0.0f; 
  2098.  sensors_V[0].z =  3.642f;
  2099.  
  2100.  sensors_V[1].x =  -7.978f;
  2101.  sensors_V[1].y =  0.0f; 
  2102.  sensors_V[1].z =  -1.915f;
  2103.  
  2104.  sensors_V[2].x =  -5.595f;
  2105.  sensors_V[2].y =  0.0f; 
  2106.  sensors_V[2].z =  -7.096f;
  2107.  
  2108.  sensors_V[3].x =  -1.749f;
  2109.  sensors_V[3].y =  0.0f; 
  2110.  sensors_V[3].z =  -9.728f;
  2111.  
  2112.  sensors_V[4].x =  2.892f;
  2113.  sensors_V[4].y =  0.0f; 
  2114.  sensors_V[4].z =  -9.477f;
  2115.  
  2116.  sensors_V[5].x =  8.535f;
  2117.  sensors_V[5].y =  0.0f; 
  2118.  sensors_V[5].z = -1.037f;
  2119.  
  2120.  sensors_V[6].x =  7.365f;
  2121.  sensors_V[6].y =  0.0f; 
  2122.  sensors_V[6].z = -6.176f;
  2123.  
  2124.  sensors_V[7].x =  8.159f;
  2125.  sensors_V[7].y =  0.0f; 
  2126.  sensors_V[7].z =  4.227f;
  2127.  
  2128.  // For rotating the car...
  2129.  axisup[0] = 0;
  2130.  axisup[1] = 1;
  2131.  axisup[2] = 0;
  2132.  // When recording the path of some cars, we
  2133.  // need those variables.
  2134.  for (i=0;i<10;i++)
  2135.     RouteNum[i] = 0; // This says that none of the 10 cars is running nor loaded 
  2136.                      // in the environment.
  2137.     RecRouteNum =999; // The RecRouteNum is the Route Number that is being Recorde.
  2138.                       // If RecRouteNum == 999 => we are not recording any route...
  2139.        
  2140.  for (i=0;i<10;i++){
  2141.     IndexCarLocRec[i] = 0;
  2142.     RECORD_CAR_MVMT = 0; // Flag Oh Stupid, you don't need to have it inside here!!
  2143.     CarLocAllocated[i] = 100; // How many are allocated in *CarLocationRec[#]
  2144.     }
  2145.  for (i=0;i<10;i++)
  2146.  if ((CarLocationRec[i]  = (struct car_location*) malloc (CarLocAllocated[i]*sizeof(struct car_location))) == NULL)
  2147.      printf ("Error in malloc CarLocationRec \n");
  2148.  
  2149.  // render all mirror toggled on!
  2150.  for (i =0; i<100;i++)
  2151.   FLAG_TOGGLE_MIRROR[i] = 1;
  2152.  
  2153.  // initialize the quaternions.
  2154.  trackball(curquat, 0.0, 0.0, 0.0, 0.0);
  2155.  trackball(curquatc, 0.0, 0.0, 0.0, 0.0);
  2156.  trackball(curquat_mirror, 0.0, 0.0, 0.0, 0.0);
  2157.  trackball(curquat_top_view, 0.0, 0.0, 0.0, 0.0);
  2158.  trackball(curquat_light0, 0.0, 0.0, 0.0, 0.0);
  2159.  trackball(curquat_light1, 0.0, 0.0, 0.0, 0.0);
  2160.  trackball(curquat_Geye, 0.0, 0.0, 0.0, 0.0);
  2161.  //trackball(curquat_top_view, 0.20877532719535, 0.85882181074556, 0.3624872845568, -0.29570412353706);
  2162.  
  2163.  // fix vectors used for the mirror rotation.
  2164.  vz.x = 0;   
  2165.  vz.y = 0;   
  2166.  vz.z = 1;   
  2167.  
  2168.  // fix vectors used for the mirror rotation.
  2169.  vy.x = 0;   
  2170.  vy.y = 1;   
  2171.  vy.z = 0; 
  2172.  
  2173.  // fix vectors used for the mirror rotation.
  2174.  vx.x = 1;   
  2175.  vx.y = 0;   
  2176.  vx.z = 0; 
  2177.  
  2178.  // puts the center of rot of lights at (0,0,0).
  2179.  Center_Of_Rot_Of_Lights.x = 0;
  2180.  Center_Of_Rot_Of_Lights.y = 0;
  2181.  Center_Of_Rot_Of_Lights.z = 0;
  2182.    
  2183.  glClearColor (0.0, 0.0, 0.0, 0.0);
  2184.  glShadeModel(GL_FLAT);
  2185.  glEnable(GL_DEPTH_TEST);
  2186.  glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
  2187.  glGenTextures(4,texName);
  2188.  
  2189.  for (i=0;i<4;i++) {
  2190.   glBindTexture(GL_TEXTURE_2D, texName[i]);
  2191.   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); //GL_REPEAT);
  2192.   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); //GL_REPEAT);
  2193.   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
  2194.   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
  2195.  
  2196.   glTexImage2D(GL_TEXTURE_2D,           // target
  2197.                 0,                       // level
  2198.                 GL_RGB,                  // internal format
  2199.                 TEX_WIDTH, TEX_HEIGHT,   // 
  2200.                 //im_width[0], im_height[0],
  2201.                 0,                       // border
  2202.                 GL_RGB,                  // format
  2203.                 GL_UNSIGNED_BYTE,        // type
  2204.                 TEX_BUF[i][0][0]
  2205.                 //image
  2206.                 );                // GLvoid *pixels 
  2207.  }
  2208.  // glEnable(GL_TEXTURE_2D); 
  2209.  html // glteximage2d */ 
  2210.  add_to_the_menus_a_mirror(0);
  2211.  add_to_the_menus_a_mirror(1);
  2212.  add_to_the_menus_a_mirror(2);
  2213.  add_to_the_menus_a_mirror(3);
  2214. }
  2215. void init(void)
  2216. {
  2217.  // glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 1);
  2218.  // Light 0
  2219.  glEnable(GL_LIGHTING);
  2220.  
  2221.  glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE);
  2222.  glLightfv(GL_LIGHT0, GL_AMBIENT, ambi);
  2223.  glLightfv(GL_LIGHT0, GL_POSITION, lightZeroPosition);
  2224.  glLightfv(GL_LIGHT0, GL_DIFFUSE, lightZeroColor);
  2225.  //glLightfv (GL_LIGHT0, GL_AMBIENT, ambi); 
  2226.  //glLightf (GL_LIGHT0, GL_CONSTANT_ATTENUATION, 0.5);
  2227.  //glLightf (GL_LIGHT0, GL_LINEAR_ATTENUATION, 0.5);
  2228.  //glLighti (GL_LIGHT0, GL_SPOT_EXPONENT, 75);
  2229.  //glLighti (GL_LIGHT0, GL_SPOT_CUTOFF, 100.0);
  2230.  glEnable (GL_LIGHT0);
  2231.  // Light 1
  2232.  glLightfv(GL_LIGHT1, GL_POSITION, lightOnePosition);
  2233.  glLightfv(GL_LIGHT1, GL_DIFFUSE, lightOneColor);
  2234.  glLightfv (GL_LIGHT1, GL_AMBIENT, ambi); 
  2235.  glEnable (GL_LIGHT1); 
  2236.  // glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambi);
  2237.  
  2238.  glLightfv(GL_LIGHT2, GL_POSITION, light2Position);
  2239.  glLightfv(GL_LIGHT2, GL_DIFFUSE, lightOneColor);
  2240.  glLightfv (GL_LIGHT2, GL_AMBIENT, ambi); 
  2241.  glEnable (GL_LIGHT2);
  2242.  
  2243.  glLightfv(GL_LIGHT3, GL_POSITION, light3Position);
  2244.  glLightfv(GL_LIGHT3, GL_DIFFUSE, lightOneColor);
  2245.  glLightfv (GL_LIGHT3, GL_AMBIENT, ambi); 
  2246.  glEnable (GL_LIGHT3); 
  2247.  glLineWidth(2.0);
  2248. }
  2249. int
  2250. main(int argc, char **argv)
  2251. {
  2252.  vrml_city_filename = argv[1];
  2253.  vrml_vehicle_filename  = argv[2];
  2254.  int i,j,k; 
  2255.  //image = read_JPEG_file ("D:\\Arch98_Class\\Edtown15\\230409e.jpg", image, im_width, im_height);    
  2256.  //Allocating the TEX_BUF.
  2257.  /* for (k=0;k<4;k++) 
  2258.  TEX_BUF[k] = (unsigned char *) calloc (TEX_HEIGHT*TEX_WIDTH*3, sizeof (unsigned char)); */
  2259.  if (argc == 1)  {
  2260.   cout << "hello... " << endl;
  2261.   vrml_city_filename = new char[170];
  2262.   vrml_vehicle_filename  = new char[170];
  2263.   vrml_sensors_filename  = new char[170];
  2264.   //strcpy (vrml_city_filename,"D:\\VRML\\habibtest.wrl");
  2265.   //strcpy (vrml_city_filename,"D:\\VRML\\HabibTestEdmond2.wrl");
  2266.   //strcpy (vrml_city_filename,"D:\\VRML\\stuff\\jeep22.wrl");
  2267.   //strcpy (vrml_city_filename, "D:\\Arch98_Class\\EDTOWN14\\zobroad.wrl");
  2268.   //strcpy (vrml_city_filename, "D:\\Arch98_Class\\EDTOWN14\\Edtown14spaced.wrl");
  2269.   //strcpy (vrml_city_filename, "D:\\Arch98_Class\\EDTOWN14\\Edtown14spacedSmall.wrl"); // WinUnix
  2270.   
  2271.   //strcpy (vrml_city_filename, "D:\\C\\LilysCars\\RedCar04.wrl"); 
  2272.   //strcpy (vrml_city_filename, "D:\\C\\vrml2_viewer\\Debug\\Edtown14spaced.wrl");
  2273.   //strcpy (vrml_city_filename, "D:\\C\\vrml2_viewer\\roads.wrl");
  2274.   //strcpy (vrml_city_filename, "D:\\C\\vrml2_viewer\\toto.wrl");
  2275.   //strcpy (vrml_city_filename, "D:\\C\\Vrml2_Viewer\\Debug\\Jeep22.wrl");
  2276.   strcpy (vrml_city_filename, "D:\\VRML\\Cars\\pickupS.wrl");
  2277.  
  2278.   //strcpy (vrml_city_filename, "D:\\Arch98_Class\\VirtCity\\vc02.wrl");
  2279.   //strcpy (vrml_city_filename, "D:\\Arch98_Class\\VirtCity\\VirtCityNew.wrl");
  2280.   //strcpy (vrml_city_filename, "D:\\Arch98_Class\\VirtCity\\test01.wrl");
  2281.   //strcpy (vrml_city_filename, "D:\\C\\vrml2_viewer\\Debug\\VirtCity\\VirtCity.wrl"); // WinUnix  
  2282.   strcpy (vrml_vehicle_filename, "D:\\C\\vrml2_viewer\\Debug\\VirtCity\\RedCar03.wrl");    // WinUnix
  2283.   strcpy (vrml_sensors_filename, "D:\\C\\vrml2_viewer\\Debug\\VirtCity\\RedCar04.wrl");    // WinUnix
  2284.  
  2285.   //strcpy (vrml_city_filename, "D:\\C\\Vrml2_Viewer\\Debug\\Jeep22.wrl");
  2286.  }
  2287.  cout << "argv[0]=" << argv[0] << endl ;
  2288.  // cout << "argv[1]=" << argv[1] << endl ;
  2289.  cout << "vrml_city_filename = " << vrml_city_filename << endl;
  2290.  // Reads the Vrml File + Compiles the list 9.
  2291.  // glClearColor (.3f,0.7f,0.8f,0.5f);
  2292.  GLenum type;
  2293.  flag_motion = rotating;
  2294.  glutInit(&argc, argv);
  2295.  glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH | GLUT_MULTISAMPLE); // | GLUT_STEREO); 
  2296.  win = glutCreateWindow("Mirror Demo");
  2297.  glutDisplayFunc(redraw);
  2298.  glutReshapeFunc(myReshape);
  2299.  glutVisibilityFunc(vis);
  2300.  glutMouseFunc(mouse);
  2301.  glutMotionFunc(motion);
  2302.  glutPassiveMotionFunc(passive_motion);
  2303.  cout << "hihi... " << NaN << endl;
  2304.  CNV = Read_Vrml_File(vrml_vehicle_filename);
  2305.  CNSe = Read_Vrml_File(vrml_sensors_filename);
  2306.  CNC = Read_Vrml_File(vrml_city_filename);
  2307.  create_menus();
  2308.  initialize_some_var();
  2309.  glShadeModel(GL_SMOOTH);
  2310.  //glCullFace (GL_FRONT_AND_BACK);
  2311.  //glEnable(GL_CULL_FACE);
  2312.  glEnable(GL_DEPTH_TEST);
  2313.  glEnable(GL_POLYGON_SMOOTH);
  2314.  glEnable(GL_LINE_SMOOTH);
  2315.  glEnable(GL_POINT_SMOOTH);
  2316.  glHint(GL_LINE_SMOOTH_HINT, GL_DONT_CARE);
  2317.  glMatrixMode(GL_PROJECTION);
  2318.  NEAR2 =   -10000;
  2319.  FAR2 =     10000;
  2320.  glMatrixMode(GL_MODELVIEW);
  2321.  transX = 0;
  2322.  transY = 0;
  2323.  transZ = 0;
  2324.  eyec.x = eye.x = 25; //-baseline;
  2325.  eye.y = 70;
  2326.  eyec.z = eye.z = 10;
  2327.  eyec.y =  80;
  2328.  CRot.x = CRot.y = CRot.z = 0; // Center of rotation of an object.
  2329.  lkc_rt.x = lk_rt.x = lk.x = 0;
  2330.  lkc_rt.y = lk_rt.y = lk.y = 0;
  2331.  lkc_rt.z = lk_rt.z = lk.z = 1;
  2332.  upc_rt.x = up_rt.x = up.x = 0;
  2333.  upc_rt.y = up_rt.y = up.y = 1;
  2334.  upc_rt.z = up_rt.z = up.z = 0;
  2335.  horc_rt.x = hor_rt.x = hor.x=1;
  2336.  horc_rt.y = hor_rt.y = hor.y=0;
  2337.  horc_rt.z = hor_rt.z = hor.z=0;
  2338.  glPushMatrix();       /* dummy push so we can pop on model
  2339.                                                             recalc   */
  2340.  init();
  2341.  glutKeyboardFunc(Key);
  2342.  glutIdleFunc (SpaceOrb); //WinUnix     
  2343.  glutSpecialFunc(SpecialKey);
  2344.  glutMainLoop();
  2345.  return 0;             /* ANSI C requires main to return int. */
  2346. }
  2347.