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