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  |  92KB  |  2,648 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, 
  911.                      sensors_W[closer_sensor].y, 
  912.                      sensors_W[closer_sensor].z);
  913.        renderBlueBox();
  914.        //PlaySound ("booom.wav",NULL,SND_ASYNC); //WinUnin
  915.      }
  916.    
  917.    
  918.    // glCallList(9); // City.
  919.    recalcModelViewVehicleCentric();
  920.    glTranslatef (eyec.x,eyec.y,eyec.z); 
  921.    glRotatef (2*acos(curquatc[0])*180.0/3.15169,curquatc[1], curquatc[2],curquatc[3]);
  922.    glScalef( car_scale_factor , -car_scale_factor , car_scale_factor);
  923.    glCallList(27); // render sensors.
  924.    for (iti=0; iti<10; iti++) { // For each car
  925.      if (RouteNum[iti]) {
  926.        recalcModelViewVehicleCentric();
  927.        glTranslatef (    CarLocationRec[iti][IndexCarLocRec[iti]].x,              
  928.                          CarLocationRec[iti][IndexCarLocRec[iti]].y,    
  929.                          CarLocationRec[iti][IndexCarLocRec[iti]].z);
  930.        glRotatef (2*acos(CarLocationRec[iti][IndexCarLocRec[iti]].quat[0])*180.0/3.15169,
  931.                   CarLocationRec[iti][IndexCarLocRec[iti]].quat[1], 
  932.                   CarLocationRec[iti][IndexCarLocRec[iti]].quat[2],
  933.                   CarLocationRec[iti][IndexCarLocRec[iti]].quat[3]);
  934.        glScalef(car_scale_factor, -car_scale_factor, car_scale_factor);
  935.        //glCallList(19); // render other cars.
  936.      }
  937.    }
  938.    glFlush();
  939.    
  940.    // reads the GL_Back buffer into the texture.
  941.    glReadBuffer(GL_BACK);
  942.    
  943.    /* glCopyTexImage2D (GL_TEXTURE_2D, 0,  
  944.             GL_RGB, 0, 0, 128, 128, 0);  */ // very slow
  945.    glReadPixels (0,0, 
  946.                  TEX_WIDTH, TEX_HEIGHT, 
  947.                  GL_RGB, GL_UNSIGNED_BYTE,TEX_BUF[i][0][0]); // image[0][0]); //
  948.    
  949.    glBindTexture(GL_TEXTURE_2D, texName[i]);
  950.    glTexImage2D(  GL_TEXTURE_2D,    // target
  951.                   0,                // level
  952.                   //0, 0,                              // xoffset, yoffset
  953.                   GL_RGB, // format
  954.                   TEX_WIDTH, TEX_HEIGHT,             // Width, Height
  955.                   //im_width[0], im_height[0],
  956.                   0, // border
  957.                   GL_RGB,           // format
  958.                   GL_UNSIGNED_BYTE, // type
  959.                   //image);
  960.                   TEX_BUF[i][0][0]);        // GLvoid *pixels */ 
  961.    glViewport(0,0,W, H);
  962. }
  963.  
  964. void
  965. inline
  966. texture_map_symbolic_godseye(int i)
  967. {
  968.  
  969.     Calculate_Geye_in_Vehicle_coord();
  970.     Calculate_Geye_in_Worlds_coord();
  971.   // Render what the mirror is seeing and create the texture map
  972.   // But do not display it yet, it only creates it in TEX_BUF buffer.
  973.   glViewport(0,0, TEX_WIDTH, TEX_HEIGHT);
  974.   recalcboundingboxVehicleCentric();
  975.   recalcModelViewVehicleCentric();
  976.   // Draws the warning flashing lines on the gods eye display.
  977.   for (int ro=0; ro<10; ro++){
  978.     if (RouteNum[ro]){
  979.       if ( (CarLocationRec[ro][IndexCarLocRec[ro]].x - eyec.x) * 
  980.            (CarLocationRec[ro][IndexCarLocRec[ro]].x - eyec.x) +
  981.            (CarLocationRec[ro][IndexCarLocRec[ro]].y - eyec.y) * 
  982.            (CarLocationRec[ro][IndexCarLocRec[ro]].y - eyec.y) +
  983.            (CarLocationRec[ro][IndexCarLocRec[ro]].z - eyec.z) * 
  984.            (CarLocationRec[ro][IndexCarLocRec[ro]].z - eyec.z) 
  985.            < 25 * 25 ) {// if cars are distante more then 30 units then
  986.         glBegin(GL_LINES); // draw the line...
  987.         glColor3f (1.0f,1.0f,0.8f);
  988.         glVertex3f (CarLocationRec[ro][IndexCarLocRec[ro]].x,
  989.                     CarLocationRec[ro][IndexCarLocRec[ro]].y,
  990.                     CarLocationRec[ro][IndexCarLocRec[ro]].z );
  991.         glVertex3f (eyec.x, eyec.y, eyec.z);
  992.         //PlaySound ("boom.wav",NULL,SND_ASYNC); //WinUnin
  993.         glEnd();
  994.       }
  995.       else
  996.         if ( (CarLocationRec[ro][IndexCarLocRec[ro]].x - eyec.x) * 
  997.              (CarLocationRec[ro][IndexCarLocRec[ro]].x - eyec.x) +
  998.              (CarLocationRec[ro][IndexCarLocRec[ro]].y - eyec.y) * 
  999.              (CarLocationRec[ro][IndexCarLocRec[ro]].y - eyec.y) +
  1000.              (CarLocationRec[ro][IndexCarLocRec[ro]].z - eyec.z) * 
  1001.              (CarLocationRec[ro][IndexCarLocRec[ro]].z - eyec.z) 
  1002.              < 40 * 40 ) {// if cars are distante more then 30 units then
  1003.           glBegin(GL_LINES); // draw the line...
  1004.           glColor3f (0.2f,0.2f,1.0f);
  1005.           glVertex3f (CarLocationRec[ro][IndexCarLocRec[ro]].x,
  1006.                       CarLocationRec[ro][IndexCarLocRec[ro]].y,
  1007.                       CarLocationRec[ro][IndexCarLocRec[ro]].z );
  1008.           //PlaySound ("booom.wav",NULL,SND_ASYNC); //WinUnin
  1009.           glVertex3f (eyec.x, eyec.y, eyec.z);
  1010.           glEnd();
  1011.         }
  1012.     }
  1013.   }
  1014.   // Draws the warning lazer lines on the gods eye display.
  1015.   // When we back up in the blue Stone.
  1016.   if (         (eyec.x - 358.5) * 
  1017.                (eyec.x - 358.5) +
  1018.                (eyec.y - 0.0) * 
  1019.                (eyec.y - 0.0) +
  1020.                (eyec.z + 483.0) * 
  1021.                (eyec.z + 483.0) 
  1022.                < 25 * 25 ) {// if cars are distante more then 30 units then
  1023.     glBegin(GL_LINES); // draw the line...
  1024.     glColor3f (1.0f,1.0f,0.8f);
  1025.     glVertex3f (358.5f, 0.0f, -483.0f );
  1026.     glVertex3f (eyec.x, eyec.y, eyec.z);
  1027.     //PlaySound ("boom.wav",NULL,SND_ASYNC); //WinUnin
  1028.     glEnd();
  1029.   }
  1030.   else
  1031.     if ( (eyec.x - 358.5) * 
  1032.          (eyec.x - 358.5) +
  1033.          (eyec.y - 0.0) * 
  1034.          (eyec.y - 0.0) +
  1035.          (eyec.z + 483.0) * 
  1036.          (eyec.z + 483.0) 
  1037.          < 40 * 40 ) {// if cars are distante more then 30 units then
  1038.             glBegin(GL_LINES); // draw the line...
  1039.             glColor3f (0.2f,0.2f,1.0f);
  1040.             glVertex3f (358.5f, 0.0f, -483.0f );
  1041.             glVertex3f (eyec.x, eyec.y, eyec.z);
  1042.             //PlaySound ("booom.wav",NULL,SND_ASYNC); //WinUnin
  1043.             glEnd();
  1044.     }
  1045.   // Draws the warning lazer lines on the gods eye display.
  1046.   // When we back up in the 2 stationary cars.
  1047.   if (         (eyec.x - 274.61) * 
  1048.                (eyec.x - 274.61) +
  1049.                (eyec.y - 0.0) * 
  1050.                (eyec.y - 0.0) +
  1051.                (eyec.z + 722.49) * 
  1052.                (eyec.z + 722.49) 
  1053.                < 25 * 25 ) {// if cars are distante more then 30 units then
  1054.     glBegin(GL_LINES); // draw the line...
  1055.     glColor3f (0.2f,0.2f,1.0f);
  1056.     glVertex3f (274.61f, 0.0f, -722.49f );
  1057.     glVertex3f (eyec.x, eyec.y, eyec.z);
  1058.     //PlaySound ("boom.wav",NULL,SND_ASYNC); //WinUnin
  1059.     glEnd();
  1060.     
  1061.   }
  1062.   else
  1063.     if ( (eyec.x - 274.61) * 
  1064.          (eyec.x - 274.61) +
  1065.          (eyec.y - 0.0) * 
  1066.          (eyec.y - 0.0) +
  1067.          (eyec.z + 722.49) * 
  1068.          (eyec.z + 722.49) 
  1069.          < 40 * 40 ) {// if cars are distante more then 30 units then
  1070.              glBegin(GL_LINES); // draw the line...
  1071.             glColor3f (0.2f,0.2f,1.0f);
  1072.             glVertex3f (274.61f, 0.0f, -722.49f );
  1073.             glVertex3f (eyec.x, eyec.y, eyec.z);
  1074.             //PlaySound ("booom.wav",NULL,SND_ASYNC); //WinUnin
  1075.             glEnd();
  1076.     }
  1077.   // Draws the warning lazer lines on the gods eye display.
  1078.   // When we back up in the 2 stationary cars.
  1079.   if (         (eyec.x - 267.46) * 
  1080.                (eyec.x - 267.46) +
  1081.                (eyec.y - 0.0) * 
  1082.                (eyec.y - 0.0) +
  1083.                (eyec.z + 701.968) * 
  1084.                (eyec.z + 701.968) 
  1085.                < 25 * 25 ) {// if cars are distante more then 30 units then
  1086.     glBegin(GL_LINES); // draw the line...
  1087.     glColor3f (0.2f,0.2f,1.0f);
  1088.     glVertex3f (267.46f, 0.0f, -701.968f );
  1089.     glVertex3f (eyec.x, eyec.y, eyec.z);
  1090.     //PlaySound ("booom.wav",NULL,SND_ASYNC); //WinUnin
  1091.     glEnd();
  1092.   }
  1093.   else
  1094.     if ( (eyec.x - 267.46) * 
  1095.          (eyec.x - 267.46) +
  1096.          (eyec.y - 0.0) * 
  1097.          (eyec.y - 0.0) +
  1098.          (eyec.z + 701.968) * 
  1099.          (eyec.z + 701.968)
  1100.          < 40 * 40 ) {// if cars are distante more then 30 units then
  1101.              glBegin(GL_LINES); // draw the line...
  1102.             glColor3f (0.2f,0.2f,1.0f);
  1103.             glVertex3f (267.46f, 0.0f, -701.968f );
  1104.             glVertex3f (eyec.x, eyec.y, eyec.z);
  1105.             //PlaySound ("booom.wav",NULL,SND_ASYNC); //WinUnin
  1106.             glEnd();
  1107.     }
  1108.   
  1109.   // glCallList(9); // City.
  1110.   glTranslatef (eyec.x,eyec.y,eyec.z); 
  1111.   glRotatef (2*acos(curquatc[0])*180.0/3.15169,curquatc[1], curquatc[2],curquatc[3]);
  1112.   glScalef( car_scale_factor , -car_scale_factor , car_scale_factor);
  1113.   //glCallList(19);//Vehicle
  1114.   for (iti=0; iti<10; iti++) { // For each car
  1115.       if (RouteNum[iti]){
  1116.       recalcModelViewVehicleCentric();
  1117.       glTranslatef (    CarLocationRec[iti][IndexCarLocRec[iti]].x,                     CarLocationRec[iti][IndexCarLocRec[iti]].y,       CarLocationRec[iti][IndexCarLocRec[iti]].z);
  1118.       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]);
  1119.       glScalef(car_scale_factor, -car_scale_factor, car_scale_factor);
  1120.       //glCallList(19); // render car.
  1121.       }
  1122.   }
  1123.   glFlush();
  1124.   
  1125.   // reads the GL_Back buffer into the texture.
  1126.   glReadBuffer(GL_BACK);
  1127.   
  1128.   /* glCopyTexImage2D (GL_TEXTURE_2D, 0,  
  1129.      GL_RGB, 0, 0, 128, 128, 0);  */ // very slow
  1130.   glReadPixels (0,0, TEX_WIDTH, TEX_HEIGHT, GL_RGB, GL_UNSIGNED_BYTE,TEX_BUF[i][0][0]); // image[0][0]); //
  1131.   
  1132.   glBindTexture(GL_TEXTURE_2D, texName[i]);
  1133.   glTexImage2D(  GL_TEXTURE_2D,    // target
  1134.                  0,                // level
  1135.                  //0, 0,                              // xoffset, yoffset
  1136.                  GL_RGB, // format
  1137.                  TEX_WIDTH, TEX_HEIGHT,             // Width, Height
  1138.                  //im_width[0], im_height[0],
  1139.                  0, // border
  1140.                  GL_RGB,           // format
  1141.                  GL_UNSIGNED_BYTE, // type
  1142.                  //image);
  1143.                  TEX_BUF[i][0][0]);        // GLvoid *pixels */ 
  1144.   glViewport(0,0,W, H);
  1145. }
  1146.  
  1147. void
  1148. inline
  1149. texture_map_vehicle_centric_display(int i)
  1150. {
  1151.     extern float (*Pos)[6]; // Window code.
  1152.     Geye.x = eyec.x;
  1153.     Geye.y = eyec.y +GeyeHIGHT;
  1154.     Geye.z = eyec.z;
  1155.   
  1156.     Gup.x  = -lkc_rt.x;
  1157.     Gup.y  = -lkc_rt.y;
  1158.     Gup.z  = -lkc_rt.z;
  1159.   
  1160.     Glk.x  = 0.0;
  1161.     Glk.z = 0.0;
  1162.     Glk.y = 1.0;
  1163.   // Render what the mirror is seeing and create the texture map
  1164.   // But do not display it yet, it only creates it in TEX_BUF buffer.
  1165.   glViewport(0,0, TEX_WIDTH, TEX_HEIGHT);
  1166.   recalcboundingboxVehicleCentric();
  1167.   recalcModelViewVehicleCentric();
  1168.   glCallList(9); // City.
  1169.   glCallList(11); // Car number 1 1
  1170.   glTranslatef (eyec.x,eyec.y,eyec.z);
  1171.   glRotatef (2*acos(curquatc[0])*180.0/3.15169,curquatc[1], curquatc[2],curquatc[3]);
  1172.   glScalef( car_scale_factor , -car_scale_factor , car_scale_factor);
  1173.   glCallList(19);//Vehicle
  1174.   
  1175.   glTranslatef (0,0,Pos[0][1]*GS);
  1176.   glCallList(100); // Car number 0 0
  1177.   //glCallList (111); // A big point.
  1178.   recalcModelViewVehicleCentric();
  1179.   glTranslatef (0,0,Pos[0][2]*GS);
  1180.   //glCallList(1); // Car number 0 1
  1181.   glCallList (1);
  1182.   recalcModelViewVehicleCentric();
  1183.   glTranslatef (0,0,Pos[0][3]*GS);
  1184.   glCallList(2); // Car number 0 2
  1185.   recalcModelViewVehicleCentric();
  1186.   glTranslatef (0,0,Pos[0][4]*GS);
  1187.   glCallList(3); // Car number 0 3
  1188.   recalcModelViewVehicleCentric();
  1189.   glTranslatef (0,0,Pos[0][5]*GS);
  1190.   glCallList(4); // Car number 0 4
  1191.  
  1192.   recalcModelViewVehicleCentric();
  1193.   glTranslatef (0,0,Pos[1][1]*GS);  
  1194.   glCallList(10); // Car number 1 0
  1195.   recalcModelViewVehicleCentric();
  1196.   glTranslatef (0,0,Pos[1][2]*GS);  
  1197.   glCallList(11); // Car number 1 1
  1198.   recalcModelViewVehicleCentric();
  1199.   glTranslatef (0,0,Pos[1][4]*GS);  
  1200.   glCallList(13); // Car number 1 3
  1201.   recalcModelViewVehicleCentric();
  1202.   glTranslatef (0,0,Pos[1][5]*GS);  
  1203.   glCallList(14); // Car number 1 4
  1204.  
  1205.  
  1206.   recalcModelViewVehicleCentric();
  1207.   glTranslatef (0,0,Pos[2][1]*GS);
  1208.   glCallList(20); // Car number 2,0
  1209.   recalcModelViewVehicleCentric();
  1210.   glTranslatef (0,0,Pos[2][2]*GS);
  1211.   glCallList(21); // Car number 2,1
  1212.   recalcModelViewVehicleCentric();
  1213.   glTranslatef (0,0,Pos[2][3]*GS);
  1214.   glCallList(22); // Car number 2,2
  1215.   recalcModelViewVehicleCentric();
  1216.   glTranslatef (0,0,Pos[2][4]*GS);
  1217.   glCallList(23); // Car number 2,3
  1218.   recalcModelViewVehicleCentric();
  1219.   glTranslatef (0,0,Pos[2][5]*GS);
  1220.   glCallList(24); // Car number 2,4
  1221.   
  1222.   /*   for (iti=0; iti<10; iti++) { // For each car
  1223.        if (RouteNum[iti]){
  1224.        recalcModelViewVehicleCentric();
  1225.        glTranslatef (CarLocationRec[iti][IndexCarLocRec[iti]].x,            
  1226.        CarLocationRec[iti][IndexCarLocRec[iti]].y,      
  1227.        CarLocationRec[iti][IndexCarLocRec[iti]].z);
  1228.        glRotatef (2*acos(CarLocationRec[iti][IndexCarLocRec[iti]].quat[0])*180.0/3.15169,
  1229.        CarLocationRec[iti][IndexCarLocRec[iti]].quat[1], 
  1230.        CarLocationRec[iti][IndexCarLocRec[iti]].quat[2],
  1231.        CarLocationRec[iti][IndexCarLocRec[iti]].quat[3]);
  1232.        glScalef(car_scale_factor, -car_scale_factor, car_scale_factor);
  1233.        glCallList(19); // render car.
  1234.        }
  1235.        } */
  1236.   glFlush();
  1237.   
  1238.   // reads the GL_Back buffer into the texture.
  1239.   glReadBuffer(GL_BACK);
  1240.   
  1241.   /* glCopyTexImage2D (GL_TEXTURE_2D, 0,  
  1242.      GL_RGB, 0, 0, 128, 128, 0);  */ // very slow
  1243.   glReadPixels (0,0, TEX_WIDTH, TEX_HEIGHT, 
  1244.                 GL_RGB, GL_UNSIGNED_BYTE,TEX_BUF[i][0][0]); 
  1245.   
  1246.   glBindTexture(GL_TEXTURE_2D, texName[i]);
  1247.   glTexImage2D(  GL_TEXTURE_2D,    // target
  1248.                  0,                // level
  1249.                  //0, 0,                              // xoffset, yoffset
  1250.                  GL_RGB, // format
  1251.                  TEX_WIDTH, TEX_HEIGHT,             // Width, Height
  1252.                  //im_width[0], im_height[0],
  1253.                  0, // border
  1254.                  GL_RGB,           // format
  1255.                  GL_UNSIGNED_BYTE, // type
  1256.                  //image);
  1257.                  TEX_BUF[i][0][0]);        // GLvoid *pixels */ 
  1258.   glViewport(0,0,W, H);
  1259. }
  1260.  
  1261. //ftexture_map
  1262. void
  1263. inline
  1264. texture_map(int i) //ftexture_map
  1265. {
  1266.   extern float (*Pos)[6]; // Window code.
  1267.   extern void Draw_Vrml(Type_Transform *, int numlist);
  1268.   
  1269.   // Render what the mirror is seeing and create the texture map
  1270.   // But do not display it yet, it only creates it in TEX_BUF buffer.
  1271.   
  1272.   // calc the new postion of the virtual eye of the mirror.
  1273.   eye_mirror = calc_the_symetric_of_a_pt_rel_to_a_plane(m1[i].nl,m1[i].cr,eye);
  1274.   eye_mirror = add_vect_to_pt (eye_mirror,
  1275.                                mul_vect_par_nbr_reel(
  1276.                                                      sous_vect_to_pt (eye_mirror , m1[i].cr) ,
  1277.                                                      (mz[i]/200.0)));
  1278.   // put the virtual camera behind the mirror symetrically to the eye.
  1279.   // Recalc Model View.
  1280.   glViewport(0,0, TEX_WIDTH, TEX_HEIGHT);
  1281.   recalcboundingbox_mirror(i);
  1282.   recalcModelView_mirror(i);
  1283.   glCallList(9); // City.
  1284.   // glCallList(11); // Car Number 1 1
  1285.   glTranslatef (0,0,Pos[0][1]*GS);
  1286.   glCallList(100); // Car number 0 1
  1287.   recalcModelView_mirror(i);
  1288.   glTranslatef (0,0,Pos[0][2]*GS);
  1289.   glCallList(1); // Car number 0 1
  1290.   recalcModelView_mirror(i);
  1291.   glTranslatef (0,0,Pos[0][3]*GS);
  1292.   glCallList(2); // Car number 0 2
  1293.   recalcModelView_mirror(i);
  1294.   glTranslatef (0,0,Pos[0][4]*GS);
  1295.   glCallList(3); // Car number 0 3
  1296.   recalcModelView_mirror(i);
  1297.   glTranslatef (0,0,Pos[0][5]*GS);
  1298.   glCallList(4); // Car number 0 4
  1299.   
  1300.   recalcModelView_mirror(i);
  1301.   glTranslatef (0,0,Pos[1][1]*GS);  
  1302.   glCallList(10); // Car number 1 0
  1303.   recalcModelView_mirror(i);
  1304.   glTranslatef (0,0,Pos[1][2]*GS);  
  1305.   glCallList(11); // Car number 1 1
  1306.   recalcModelView_mirror(i);
  1307.   glTranslatef (0,0,Pos[1][4]*GS);  
  1308.   glCallList(13); // Car number 1 3
  1309.   recalcModelView_mirror(i);
  1310.   glTranslatef (0,0,Pos[1][5]*GS);  
  1311.   glCallList(14); // Car number 1 4
  1312.  
  1313.   recalcModelView_mirror(i);
  1314.   glTranslatef (0,0,Pos[2][1]*GS);
  1315.   glCallList(20); // Car number 2,0
  1316.   recalcModelView_mirror(i);
  1317.   glTranslatef (0,0,Pos[2][2]*GS);
  1318.   glCallList(21); // Car number 2,1
  1319.   recalcModelView_mirror(i);
  1320.   glTranslatef (0,0,Pos[2][3]*GS);
  1321.   glCallList(22); // Car number 2,2
  1322.   recalcModelView_mirror(i);
  1323.   glTranslatef (0,0,Pos[2][4]*GS);
  1324.   glCallList(23); // Car number 2,3
  1325.   recalcModelView_mirror(i);
  1326.   glTranslatef (0,0,Pos[2][5]*GS);
  1327.   glCallList(24); // Car number 2,4
  1328.  
  1329.   //Render other cars. (the red cars that I designed in Autocad that are blind).
  1330.   for (iti=0; iti<10; iti++) { // For each other car
  1331.       if (RouteNum[iti]) {
  1332.         recalcModelView_mirror(i);
  1333.         glTranslatef (    CarLocationRec[iti][IndexCarLocRec[iti]].x,                     CarLocationRec[iti][IndexCarLocRec[iti]].y,       CarLocationRec[iti][IndexCarLocRec[iti]].z);
  1334.         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]);
  1335.         glScalef(car_scale_factor, -car_scale_factor, car_scale_factor);
  1336.         glCallList(19); // render car.
  1337.       }
  1338.   }
  1339.    glTranslatef (eyec.x,eyec.y,eyec.z);
  1340.    glRotatef (2*acos(curquatc[0])*180.0/3.15169,curquatc[1], curquatc[2],curquatc[3]);
  1341.    glScalef( car_scale_factor , -car_scale_factor , car_scale_factor);
  1342.    glCallList(19);//Vehicle
  1343.  
  1344.    glFlush();
  1345.  
  1346.    // reads the GL_Back buffer into the texture.
  1347.    glReadBuffer(GL_BACK);
  1348.     
  1349.    /* glCopyTexImage2D (GL_TEXTURE_2D, 0,  
  1350.             GL_RGB, 0, 0, 128, 128, 0);  */ // very slow
  1351.    glReadPixels (0,0, TEX_WIDTH,TEX_HEIGHT, GL_RGB, GL_UNSIGNED_BYTE,TEX_BUF[i][0][0]); // image[0][0]); //
  1352.  
  1353.    glBindTexture(GL_TEXTURE_2D, texName[i]);
  1354.    glTexImage2D(  GL_TEXTURE_2D,    // target
  1355.                      0,                // level
  1356.                      //0, 0,                              // xoffset, yoffset
  1357.                      GL_RGB, // format
  1358.                      TEX_WIDTH, TEX_HEIGHT,             // Width, Height
  1359.                      //im_width[0], im_height[0],
  1360.                      0, // border
  1361.                      GL_RGB,           // format
  1362.                      GL_UNSIGNED_BYTE, // type
  1363.                      //image);
  1364.                      TEX_BUF[i][0][0]);        // GLvoid *pixels */ 
  1365.    glViewport(0,0,W, H);
  1366. }
  1367. //_______________________________draw_mirror____________________________________________
  1368. //fdraw_mirror
  1369. inline
  1370. void draw_mirror(int i)
  1371. {
  1372.    glEnable(GL_TEXTURE_2D);
  1373.    glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
  1374. #ifdef GL_VERSION_1_1
  1375.    glBindTexture(GL_TEXTURE_2D, texName[i]);  
  1376. #endif
  1377.    glBegin(GL_QUADS);
  1378.    glTexCoord2f(1.0, 1.0); 
  1379.    glVertex3f(m1[i].c1.x, m1[i].c1.y, m1[i].c1.z); html //finitialize_some_var
  1380.    glTexCoord2f(1.0, 0.0); 
  1381.    glVertex3f(m1[i].c2.x, m1[i].c2.y, m1[i].c2.z); html //finitialize_some_var
  1382.    glTexCoord2f(0.0, 0.0); 
  1383.    glVertex3f(m1[i].c3.x, m1[i].c3.y, m1[i].c3.z); html //finitialize_some_var
  1384.    glTexCoord2f(0.0, 1.0); 
  1385.    glVertex3f(m1[i].c4.x, m1[i].c4.y, m1[i].c4.z); html //finitialize_some_var
  1386.  
  1387.    glEnd();
  1388.    glPointSize (4);
  1389.    glBegin(GL_LINES);
  1390.    glVertex3f(m1[i].c1.x, m1[i].c1.y, m1[i].c1.z); html //finitialize_some_var
  1391.    glVertex3f(m1[i].c2.x, m1[i].c2.y, m1[i].c2.z); html //finitialize_some_var
  1392.    glVertex3f(m1[i].c2.x, m1[i].c2.y, m1[i].c2.z); html //finitialize_some_var
  1393.    glVertex3f(m1[i].c3.x, m1[i].c3.y, m1[i].c3.z); html //finitialize_some_var
  1394.    glVertex3f(m1[i].c3.x, m1[i].c3.y, m1[i].c3.z); html //finitialize_some_var
  1395.    glVertex3f(m1[i].c4.x, m1[i].c4.y, m1[i].c4.z); html //finitialize_some_var
  1396.    glVertex3f(m1[i].c4.x, m1[i].c4.y, m1[i].c4.z); html //finitialize_some_var
  1397.    glVertex3f(m1[i].c1.x, m1[i].c1.y, m1[i].c1.z); html //finitialize_some_var
  1398.    glEnd();
  1399.    glFlush();
  1400.    glDisable(GL_TEXTURE_2D);
  1401. }
  1402.  
  1403.  
  1404. inline
  1405. void draw_mirror_top_view(int i)
  1406. {
  1407.    glPointSize (4);
  1408.    glBegin(GL_LINES);
  1409.    glVertex3f(m1[i].c1.x, m1[i].c1.y, m1[i].c1.z); html //finitialize_some_var
  1410.    glVertex3f(m1[i].c2.x, m1[i].c2.y, m1[i].c2.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].c3.x, m1[i].c3.y, m1[i].c3.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].c4.x, m1[i].c4.y, m1[i].c4.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].c1.x, m1[i].c1.y, m1[i].c1.z); html //finitialize_some_var
  1417.    glEnd();
  1418.    glFlush();
  1419.    glDisable(GL_TEXTURE_2D);
  1420. }
  1421. void
  1422. inline draw_bg()
  1423. {
  1424.          // Set Projection Matrix
  1425.          glMatrixMode(GL_PROJECTION);/* set up projection transform */
  1426.          glLoadIdentity();
  1427.          glOrtho (0,1, 0,1, -1,1);
  1428.          
  1429.          // Set ModelView Matrix.
  1430.          glMatrixMode (GL_MODELVIEW);
  1431.          glLoadIdentity();
  1432.          
  1433.          //glDisable(GL_LIGHTING);
  1434.  
  1435.          // Draw bg
  1436.          glBegin (GL_POLYGON);
  1437.          glColor3f (0.5f, 0.0f,0.0f);
  1438.          glVertex3f (1  ,  0,-0.5f);
  1439.          glColor3f (0.4f,0.0f,0.0f);
  1440.          glVertex3f (1,  1,-0.5f);
  1441.          glColor3f (0.9f,1.0f,0.0f);
  1442.          glVertex3f (0,1,-0.5f);
  1443.          glColor3f (0.2f,0.0f,1.0f);
  1444.          glVertex3f (0  ,0,-0.5);
  1445.          glEnd(); 
  1446. }
  1447. void inline  draw_light_position()
  1448. {
  1449.     glPointSize (5);
  1450.     glBegin(GL_POINTS);
  1451.     glColor3f (1.0f,1.0f,1.0f);
  1452.     glVertex3f (lightZeroPosition[0], lightZeroPosition[1], lightZeroPosition[2]);
  1453.     glVertex3f (lightOnePosition [0], lightOnePosition [1], lightOnePosition [2]);
  1454.     glEnd();
  1455. }
  1456. /* void redraw4()
  1457. {
  1458.     extern struct Virtual_Espace espace[DimX][DimY][DimZ];
  1459.     void redraw ();
  1460.    if (FLAG_TOGGLE_MENU1) {
  1461.        glEnable(GL_LIGHTING);
  1462.    }
  1463.    glDrawBuffer(GL_BACK);
  1464.    glClearColor (.1f,0.2f,0.1f,1);
  1465.  
  1466.    glClearColor (.6f,0.4f,0.2f,0.4f);
  1467.    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  1468.  
  1469.    if (viewport&& !FLAG_TOP_VIEW){
  1470.       // draw command margin then set the viewport for the 3D
  1471.       draw_commande_de_bord(); // Sets the control band viewport and draws in it.
  1472.       glViewport (CDW,0,W,H);  // set the viewport 
  1473.     }                                          
  1474.     else 
  1475.        if (viewport && FLAG_TOP_VIEW) {
  1476.           draw_commande_de_bord(); // Sets the control band viewport and draws in it.
  1477.           glViewport (TOP_V_X,TOP_V_Y,TOP_W,TOP_H);
  1478.           draw_bg();
  1479.           if (FLAG_TOGGLE_MENU1)  glEnable(GL_LIGHTING);
  1480.           recalcboundingboxTOPVIEW();
  1481.           recalcModelViewTOPVIEW();
  1482.           if (Draw_relative_axe) draw_axes();
  1483.           if (SHOW_LOCATION_DIRECTION_OF_LIGHTS) draw_light_position();
  1484.     for (int i= 0; i<DimX; i=i+2)
  1485.         for (int j=0; j<DimY; j=j+2)
  1486.             for (int k=0; k<DimZ; k=k+2)
  1487.                 if (espace[i][j][k].FULL){
  1488.                     glBegin (GL_POINTS);
  1489.                     glVertex3d (i,j,k);
  1490.                     glEnd();
  1491.                 }
  1492.                 glViewport (CDW,0,W,H-TOP_H); // establish the viewport for the rendering of the scene.
  1493.        }
  1494.        else {
  1495.          // Set all the screen viewport for the 3D rendering the left eye..            
  1496.          glViewport (0,0,W    ,H);
  1497.        }
  1498.  
  1499.    // at this point we know what the glViewport is for the main scene.
  1500.    if (displayListInited) {
  1501.        if (FLAG_TOGGLE_MENU1) { glEnable(GL_LIGHTING); }
  1502.         // Recalc Model View.
  1503.         recalcboundingbox(); 
  1504.         recalcModelView();
  1505.  
  1506.     for (int i= 0; i<DimX; i=i+2)
  1507.         for (int j=0; j<DimY; j=j+2)
  1508.             for (int k=0; k<DimZ; k=k+2)
  1509.                 if (espace[i][j][k].FULL){
  1510.                     glBegin (GL_POINTS);
  1511.                     glVertex3d (i,j,k);
  1512.                     glEnd();
  1513.                 }
  1514.  
  1515.     }
  1516.     else {
  1517.         Draw_Vrml(CNC,9); // Draws the City CNC = Current Node City.
  1518.         Draw_Vrml(CNV,19); // Draws the Vehicle CNV = Current Node Vehicle
  1519.         Draw_Vrml(CNVo[1][1], 11); // Draws the Vehicle 11.
  1520.         Draw_Vrml(CNSphere, 101);
  1521.         displayListInited = 1;
  1522.         redraw ();
  1523.         glFlush();
  1524.     }
  1525.     glutSwapBuffers();
  1526. } */
  1527. inline void fix_light_car()
  1528. {
  1529.  if (LIGHTS_FIX_WITH_CAMERA) {
  1530.     glLightfv(GL_LIGHT0, GL_POSITION, lightZeroPosition);
  1531.     glLightfv(GL_LIGHT1, GL_POSITION, lightOnePosition);
  1532.     glLightfv(GL_LIGHT0, GL_DIFFUSE, lightZeroColor_Car);
  1533.     glLightfv(GL_LIGHT1, GL_DIFFUSE, lightOneColor_Car);// Because light is affected by the scale.
  1534.     }
  1535.    if (!LIGHTS_FIX_WITH_CAMERA) {
  1536.       glLightfv(GL_LIGHT0, GL_POSITION, lightZeroPosition);
  1537.     glLightfv(GL_LIGHT1, GL_POSITION, lightOnePosition);
  1538.     glLightfv(GL_LIGHT0, GL_DIFFUSE, lightZeroColor_Car);
  1539.     glLightfv(GL_LIGHT1, GL_DIFFUSE, lightOneColor_Car); // Because light is affected by the scale.
  1540.   }
  1541. }
  1542.  
  1543.  
  1544. int NumOfSquaresInX = DefNumOfEdgesInX - 1; // The number of Squares is #Edges -1.
  1545. int NumOfSquaresInY = DefNumOfEdgesInY - 1; // The number of Squares is #Edges -1.;
  1546.  
  1547. struct DistTex 
  1548. {
  1549.     float x[DefNumOfEdgesInX][DefNumOfEdgesInY];
  1550.     float y[DefNumOfEdgesInX][DefNumOfEdgesInY];
  1551. } Tex;
  1552.  
  1553.  
  1554. void
  1555. Render() //frender
  1556. {
  1557.   if (FLAG_TOGGLE_MENU1) 
  1558.       glEnable(GL_LIGHTING); 
  1559.   extern correct_image(int , int);
  1560.   
  1561.   recalcboundingbox(); 
  1562.   recalcModelView();
  1563.   glCallList(9); // render city
  1564.   glFlush();
  1565.   
  1566.   // reads the GL_Back buffer into the texture.
  1567.   if (FLAG_DISTORTION_WITHOUT_TEXTURE) {
  1568.     // reads the GL_Back buffer into the texture.
  1569.     glReadBuffer(GL_BACK);    
  1570.     /* glCopyTexImage2D (GL_TEXTURE_2D, 0,  
  1571.        GL_RGB, 0, 0, 128, 128, 0);  */ // very slow
  1572.     
  1573.     glReadPixels (0,0, 
  1574.                   DistWidth , 
  1575.                   DistHeight ,
  1576.                   GL_RGB, 
  1577.                   GL_UNSIGNED_BYTE,Distortion_buffer[0][0]); 
  1578.     glBindTexture(GL_TEXTURE_2D, texName[4]);
  1579.     /*glTexImage2D(  GL_TEXTURE_2D,    // target
  1580.       0,                // level
  1581.       //0, 0,                              // xoffset, yoffset
  1582.       3, // How Many colors
  1583.       DistWidth, DistHeight,             // Width, Height
  1584.       0, // border
  1585.       GL_RGB,           // format
  1586.       GL_UNSIGNED_BYTE, // type
  1587.       Distortion_buffer[0][0]);        // GLvoid *pixels */
  1588.     correct_image (W,H);
  1589.     glTexSubImage2D (GL_TEXTURE_2D, // target
  1590.                      0, // level
  1591.                      0,0, // xoffset, yoffset.
  1592.                      DistWidth, DistHeight, 
  1593.                      GL_RGB, // format
  1594.                      GL_UNSIGNED_BYTE, // type.
  1595.                      Distortion_buffer_corrected[0][0]);
  1596.     
  1597.     glViewport(0,0,W, H);
  1598.  
  1599.     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  1600.     glDrawBuffer(GL_BACK);
  1601.     glViewport(0,0,W,H);
  1602.     
  1603.     glMatrixMode(GL_PROJECTION);/* set up projection transform */
  1604.     glPopMatrix();
  1605.     glLoadIdentity();
  1606.     glOrtho (0,100,0, 100,100,-100);
  1607.     glPushMatrix();
  1608.     
  1609.     glMatrixMode(GL_MODELVIEW);
  1610.     glPopMatrix();
  1611.     glPushMatrix();
  1612.     
  1613.     glEnable(GL_TEXTURE_2D);
  1614.     glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
  1615. #ifdef GL_VERSION_1_1
  1616.     glBindTexture(GL_TEXTURE_2D, texName[4]);  
  1617. #endif
  1618.     glBegin(GL_QUADS);
  1619.     glTexCoord2f (0,0);
  1620.     glVertex3f(0,0, 0); 
  1621.     glTexCoord2f (1,0);
  1622.     glVertex3f(100,0, 0); 
  1623.     glTexCoord2f (1,1);
  1624.     glVertex3f(100,100, 0); 
  1625.     glTexCoord2f (0,1);
  1626.     glVertex3f(0,100, 0);
  1627.     glEnd();
  1628.     glFlush();
  1629.     glDisable(GL_TEXTURE_2D);    
  1630.   } // End if distortion correction.
  1631.   
  1632.   
  1633.   
  1634.   // reads the GL_Back buffer into the texture.
  1635.   if (FLAG_DISTORTION_WITH_TEXTURE) { 
  1636.     // reads the GL_Back buffer into the texture.
  1637.     /* if (!FLAG_STEREO)
  1638.        glReadBuffer(GL_BACK);    */
  1639.     /* glCopyTexImage2D (GL_TEXTURE_2D, 0,  
  1640.        GL_RGB, 0, 0, 128, 128, 0);  */ // very slow
  1641.     
  1642.     glReadPixels (0,0, 
  1643.                   DistWidth , 
  1644.                   DistHeight ,
  1645.                   GL_RGB, GL_UNSIGNED_BYTE,Distortion_buffer[0][0]);
  1646.     glBindTexture(GL_TEXTURE_2D, texName[4]);
  1647.     /*glTexImage2D(  GL_TEXTURE_2D,    // target
  1648.       0,                // level
  1649.       //0, 0,                              // xoffset, yoffset
  1650.       3, // How Many colors
  1651.       DistWidth, DistHeight,             // Width, Height
  1652.       0, // border
  1653.       GL_RGB,           // format
  1654.       GL_UNSIGNED_BYTE, // type
  1655.       Distortion_buffer[0][0]);        // GLvoid *pixels */
  1656.     glTexSubImage2D (GL_TEXTURE_2D, // target
  1657.                      0, // level
  1658.                      0,0, // xoffset, yoffset.
  1659.                      DistWidth, DistHeight, 
  1660.                      GL_RGB, // format
  1661.                      GL_UNSIGNED_BYTE, // type.
  1662.                      Distortion_buffer[0][0]);
  1663.     
  1664.     glViewport(0,0,W, H);
  1665.     //correct_image (W,H);
  1666.     
  1667.     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  1668.     glDrawBuffer(GL_BACK);
  1669.     glReadBuffer(GL_BACK);
  1670.     glViewport(0,0,W,H);
  1671.     
  1672.     glMatrixMode(GL_PROJECTION);/* set up projection transform */
  1673.     glPopMatrix();
  1674.     glLoadIdentity();
  1675.     glOrtho (0,NumOfSquaresInX,0, NumOfSquaresInY,100,-100);
  1676.     glPushMatrix();
  1677.     
  1678.     glMatrixMode(GL_MODELVIEW);
  1679.     glPopMatrix();
  1680.     glPushMatrix();
  1681.     
  1682.     glEnable(GL_TEXTURE_2D);
  1683.     glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
  1684. #ifdef GL_VERSION_1_1
  1685.     glBindTexture(GL_TEXTURE_2D, texName[4]);  
  1686. #endif
  1687.     for (int r = 0; r<NumOfSquaresInX; r++)
  1688.       for (int c = 0; c<NumOfSquaresInY; c++) {
  1689.         glBegin(GL_QUADS);
  1690.         glTexCoord2f (Tex.x[c][r], Tex.y[c][r]); 
  1691.         glVertex3f(c, r, 0);  
  1692.         glTexCoord2f (Tex.x[c][r+1] , Tex.y[c][r+1]); 
  1693.         glVertex3f(c, r+1, 0);
  1694.         glTexCoord2f (Tex.x[c+1][r+1], Tex.y[c+1][r+1]); 
  1695.         glVertex3f(c+1, r+1, 0); 
  1696.         glTexCoord2f (Tex.x[c+1][r] , Tex.y[c+1][r]); 
  1697.         glVertex3f(c+1, r, 0); 
  1698.         glEnd();
  1699.       }
  1700.     glFlush();
  1701.     glDisable(GL_TEXTURE_2D);    
  1702.   } // End if distortion correction.
  1703.   
  1704. }
  1705.  
  1706.  
  1707.  
  1708. struct point Meye;
  1709.  
  1710. void
  1711. Render_Stereo_CrystalEyes() //frender
  1712. {
  1713.   if (FLAG_TOGGLE_MENU1) 
  1714.       glEnable(GL_LIGHTING); 
  1715.   extern correct_image(int , int);
  1716.   
  1717.   glDrawBuffer(GL_BACK_LEFT);
  1718.   glReadBuffer(GL_BACK_LEFT); // for distortion correction later.
  1719.   glClearColor (0.05882f, 0.498f, 0.8353f,1.0f);
  1720.   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  1721.  
  1722.   Render ();
  1723.  
  1724.   glDrawBuffer(GL_BACK_RIGHT);
  1725.   glReadBuffer(GL_BACK_RIGHT); // for distortion correction later.
  1726.   glClearColor (0.05882f, 0.498f, 0.8353f,1.0f);
  1727.   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  1728.  
  1729.   Meye.x = eye.x;
  1730.   Meye.y = eye.y;
  1731.   Meye.z = eye.z;
  1732.   eye = add_vect_to_pt( eye, mul_vect_par_nbr (hor_rt, EYE_DISP));
  1733.   Render ();
  1734.   eye.x = Meye.x;
  1735.   eye.y = Meye.y;
  1736.   eye.z = Meye.z;
  1737. }
  1738.  
  1739.  
  1740.  
  1741. int FramesPerSec = 30;
  1742. int StereoCounterHab = 0;
  1743. int Flag_Switch_Eye = 0;
  1744.  
  1745. void
  1746. Render_Stereo_Natt() //frender_stereo
  1747. {
  1748.   if (FLAG_TOGGLE_MENU1) 
  1749.       glEnable(GL_LIGHTING); 
  1750.  
  1751.   // Flip eye each 1/5th of a second.
  1752.   if (StereoCounterHab >= (FramesPerSec / 10.0)){
  1753.     Flag_Switch_Eye = !Flag_Switch_Eye;
  1754.     StereoCounterHab = 0;
  1755.     }
  1756.   StereoCounterHab++;
  1757.  
  1758.  
  1759.   recalcboundingbox(); 
  1760.   if (Flag_Switch_Eye){
  1761.     // render left  eye
  1762.     recalcModelView();
  1763.   }
  1764.   else {
  1765.     // render right eye
  1766.     Meye.x = eye.x;
  1767.     Meye.y = eye.y;
  1768.     Meye.z = eye.z;
  1769.     eye = add_vect_to_pt( eye, mul_vect_par_nbr_reel (hor_rt, EYE_DISP));
  1770.     recalcModelView();
  1771.     eye.x = Meye.x;
  1772.     eye.y = Meye.y;
  1773.     eye.z = Meye.z;
  1774.   }
  1775.   glCallList(9); // render city
  1776.  
  1777. }
  1778.  
  1779. void
  1780. redraw() //fredraw
  1781. {
  1782.   FramesPerSec = FrameRate.PrintAverageFR(100);
  1783.   DTime = FrameRate.GetElapsedTime(100, DTime);
  1784.   //cout << "Dtime = " << DTime ;
  1785.   extern struct Virtual_Espace espace[DimX][DimY][DimZ];
  1786.   extern void Draw_Vrml(Type_Transform *, int numlist);
  1787.   extern void recalc_mirror_coord_in_fix_coord_based_on_camera_movements(int i);
  1788.   extern double XmaxVrmlCity, YmaxVrmlCity, ZmaxVrmlCity;
  1789.   extern double XminVrmlCity, YminVrmlCity, ZminVrmlCity;
  1790.   int i;
  1791.  
  1792.   glDrawBuffer(GL_BACK);
  1793.   glClearColor (0.05882f, 0.498f, 0.8353f,1.0f);
  1794.   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  1795.   
  1796.   if (FLAG_TOGGLE_MENU1) {
  1797.     glEnable(GL_LIGHTING);
  1798.   }
  1799.   else 
  1800.     glDisable (GL_LIGHTING);
  1801.   
  1802.   if (viewport&& !FLAG_TOP_VIEW){
  1803.     draw_commande_de_bord(); // Sets the control band viewport and draws in it.
  1804.     glViewport (CDW,0,W,H);  // set the viewport 
  1805.   }                                          
  1806.   else 
  1807.     if (viewport && FLAG_TOP_VIEW) {
  1808.       draw_commande_de_bord(); // Sets the control band viewport and draws in it.
  1809.       glViewport (TOP_V_X,TOP_V_Y,TOP_W,TOP_H);
  1810.       draw_bg();
  1811.       if (FLAG_TOGGLE_MENU1)  glEnable(GL_LIGHTING);
  1812.       recalcboundingboxTOPVIEW();
  1813.       recalcModelViewTOPVIEW();
  1814.       if (Draw_relative_axe) draw_axes();
  1815.       if (SHOW_LOCATION_DIRECTION_OF_LIGHTS) draw_light_position();
  1816.       glCallList(9); // City.
  1817.       /*for (int i=0; i<DimX; i=i+6)
  1818.         for (int j=0; j<DimY; j=j+6)
  1819.         for (int k=0; k<DimZ; k=k+6)
  1820.         if (espace[i][j][k].FULL){
  1821.         glBegin (GL_POINTS);
  1822.         xx = i*(XmaxVrmlCity - XminVrmlCity)/DimX + XminVrmlCity;
  1823.         yy = j*(YmaxVrmlCity - YminVrmlCity)/DimY + YminVrmlCity;
  1824.         zz = k*(ZmaxVrmlCity - ZminVrmlCity)/DimZ + ZminVrmlCity;
  1825.         glVertex3f (xx,yy,zz);
  1826.         glEnd();
  1827.         }*/
  1828.       //recalcModelView_Car();
  1829.       glViewport (CDW,0,W,H-TOP_H); // establish the viewport for the rendering of the scene.
  1830.     } //if (viewport && FLAG_TOP_VIEW
  1831.     else { // Set all the screen viewport for the 3D rendering the left eye..            
  1832.       glViewport (0,0,W    ,H);
  1833.     }
  1834.   //  -------------------------------------------
  1835.   //  |                                         |
  1836.   //  |                                         |
  1837.   //  |                                         |
  1838.   //  |                                         |
  1839.   //  |                                         |
  1840.   //  |                                         |
  1841.   //  |                                         |
  1842.   //  -------------------------------------------
  1843.   // at this point we know what the glViewport is for the main scene.
  1844.   // at this point we know what the glViewport is for the main scene.
  1845.   // Drawing
  1846.  
  1847.   if (displayListInited) {
  1848.     if (FLAG_STEREO_NATT)
  1849.       Render_Stereo_Natt ();
  1850.     else 
  1851.       if (FLAG_STEREO)
  1852.         Render_Stereo_CrystalEyes ();
  1853.       else 
  1854.         Render ();
  1855.   }
  1856.   else {
  1857.     cout << "Drawing the city for the first time" << endl;        
  1858.     Draw_Vrml(CNC,9); // Draws the City CNV = Current Node City
  1859.     displayListInited = 1;
  1860.     redraw ();
  1861.     glFlush();
  1862.   }
  1863.   glutSwapBuffers();
  1864. }
  1865.  
  1866.  
  1867. void
  1868. load_configuration(char num)
  1869. {
  1870.  FILE *file;
  1871.  char configurationNum [15];
  1872.  
  1873.  strcpy (configurationNum,"configuration");
  1874.  strncat (configurationNum, &num,1);
  1875.  
  1876.  if ((file = fopen (configurationNum,"r")) == NULL)
  1877.   printf ("\n pas de chance l'ami ton fichier est corrompu 95478567\n");
  1878.  
  1879.  fscanf (file, "number_of_mirrors %d \n",
  1880.      &number_of_mirrors);
  1881.  
  1882.  for (int v=0; v<6;v++){
  1883.   fscanf (file, "m1[v].cr %f %f %f \n",
  1884.      &m1[v].cr.x,  &m1[v].cr.y,  &m1[v].cr.z);
  1885.   fscanf (file, "m1[v].c1 %f %f %f \n",
  1886.      &m1[v].c1.x,  &m1[v].c1.y,  &m1[v].c1.z);
  1887.   fscanf (file, "m1[v].c2 %f %f %f \n",
  1888.      &m1[v].c2.x,  &m1[v].c2.y,  &m1[v].c2.z);
  1889.   fscanf (file, "m1[v].c3 %f %f %f \n",
  1890.      &m1[v].c3.x,  &m1[v].c3.y,  &m1[v].c3.z);
  1891.   fscanf (file, "m1[v].c4 %f %f %f \n",
  1892.      &m1[v].c4.x,  &m1[v].c4.y,  &m1[v].c4.z);
  1893.   fscanf (file, "m1[v].cc1 %f %f %f \n",
  1894.      &m1[v].cc1.x, &m1[v].cc1.y, &m1[v].cc1.z);
  1895.   fscanf (file, "m1[v].cc2 %f %f %f \n",
  1896.      &m1[v].cc2.x, &m1[v].cc2.y, &m1[v].cc2.z);
  1897.   fscanf (file, "m1[v].cc3 %f %f %f \n",
  1898.      &m1[v].cc3.x, &m1[v].cc3.y, &m1[v].cc3.z);
  1899.   fscanf (file, "m1[v].cc4 %f %f %f \n",
  1900.      &m1[v].cc4.x, &m1[v].cc4.y, &m1[v].cc4.z);
  1901.   fscanf (file, "m1[v].nl %f %f %f \n",
  1902.      &m1[v].nl.x , &m1[v].nl.y,  &m1[v].nl.z);
  1903.   fscanf (file, "m1[v].up %f %f %f \n",
  1904.      &m1[v].up.x , &m1[v].up.y,  &m1[v].up.z);
  1905.   fscanf (file, "m1[v].side %f %f %f \n",
  1906.      &m1[v].side.x , &m1[v].side.y,  &m1[v].side.z);
  1907.   fscanf (file, "m1[v].width %f, m1[v].height %f \n \n \n",
  1908.      &m1[v].width  ,  &m1[v].height);
  1909.  }
  1910.  
  1911.  fscanf (file, "angle %lf \n",
  1912.      &angle);
  1913.  fscanf (file, "curquat[.] %lf %lf %lf %lf \n",
  1914.      &curquat[0],          &curquat[1],          &curquat[2],          &curquat[3]);
  1915.  fscanf (file, "curquatc[.] %lf %lf %lf %lf \n",
  1916.      &curquatc[0],         &curquatc[1],         &curquatc[2],         &curquatc[3]);
  1917.  fscanf (file, "curquat_mirror[.] %lf %lf %lf %lf \n",
  1918.      &curquat_mirror[0],   &curquat_mirror[1],   &curquat_mirror[2],   &curquat_mirror[3]);
  1919.  fscanf (file, "curquat_top_view[.] %lf %lf %lf %lf \n",
  1920.      &curquat_top_view[0], &curquat_top_view[1], &curquat_top_view[2], &curquat_top_view[3]);
  1921.  fscanf (file, "curquat_light0[.] %lf %lf %lf %lf \n",
  1922.      &curquat_light0[0],   &curquat_light0[1],   &curquat_light0[2],   &curquat_light0[3]);
  1923.  fscanf (file, "curquat_light1[.] %lf %lf %lf %lf \n",
  1924.      &curquat_light1[0],   &curquat_light1[1],   &curquat_light1[2],   &curquat_light1[3]);
  1925.  fscanf (file, "lastquat_top_view[.] %lf %lf %lf %lf \n",
  1926.      &lastquat_top_view[0], &lastquat_top_view[1], &lastquat_top_view[2], &lastquat_top_view[3]);
  1927.  fscanf (file, "lastquat[.] %lf %lf %lf %lf \n",
  1928.      &lastquat[0],          &lastquat[1],          &lastquat[2],          &lastquat[3]);
  1929.  fscanf (file, "lastquat_mirror[.] %lf %lf %lf %lf \n",
  1930.      &lastquat_mirror[0],   &lastquat_mirror[1],   &lastquat_mirror[2],   &lastquat_mirror[3]);
  1931.  fscanf (file, "lastquat_light0[.] %lf %lf %lf %lf \n",
  1932.      &lastquat_light0[0],   &lastquat_light0[1],   &lastquat_light0[2],   &lastquat_light0[3]);
  1933.  fscanf (file, "lastquat_light1[.] %lf %lf %lf %lf \n",
  1934.      &lastquat_light1[0],   &lastquat_light1[1],   &lastquat_light1[2],   &lastquat_light1[3]);
  1935.  
  1936.  fscanf (file, "newModel %d scalefactor %lf \n",
  1937.      &newModel, &scalefactor);
  1938.  
  1939.  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 ",
  1940.      &TOP, &BOTTOM, &LEFT, &RIGHT, &TRANSLATE_X, &TRANSLATE_Y, &TRANSLATE_Z, &TRANSLATE_H, &NEAR2, &FAR2);
  1941.  fscanf (file, "FLAG_MOVE_CAR %d  FLAG_MOVE_SCENE %d  WALK_SLOWLY %d",
  1942.      &FLAG_MOVE_CAR, &FLAG_MOVE_SCENE, &WALK_SLOWLY);
  1943.  fscanf (file ,"DriverPos %f %f %f \n",
  1944.      &DriverPos.x, &DriverPos.y, &DriverPos.z);
  1945.  
  1946.  fscanf (file, "eye %f %f %f \n",
  1947.      &eye.x, &eye.y, &eye.z);
  1948.  fscanf (file, "eye1 %f %f %f \n",
  1949.      &eye1.x, &eye1.y, &eye1.z);
  1950.  fscanf (file, "eye2 %f %f %f \n",
  1951.      &eye2.x, &eye2.y, &eye2.z);
  1952.  fscanf (file, "eye_mirror %f %f %f \n",
  1953.      &eye_mirror.x, &eye_mirror.y, &eye_mirror.z);
  1954.  fscanf (file ,"eyec %f %f %f \n",
  1955.      &eyec.x, &eyec.y, &eyec.z);
  1956.  fscanf (file, "eyeP %f %f %f \n",
  1957.      &eyeP.x, &eyeP.y, &eyeP.z);
  1958.  fscanf (file, "lk %f %f %f \n",
  1959.      &lk.x, &lk.y, &lk.z);
  1960.  fscanf (file, "up %f %f %f \n",
  1961.      &up.x, &up.y, &up.z);
  1962.  fscanf (file, "hor %f %f %f \n",
  1963.      &hor.x, &hor.y, &hor.z);
  1964.  fscanf (file, "lk_rt %f %f %f \n",
  1965.      &lk_rt.x, &lk_rt.y, &lk_rt.z);
  1966.  fscanf (file, "up_rt %f %f %f \n",
  1967.      &up_rt.x, &up_rt.y, &up_rt.z);
  1968.  fscanf (file, "hor_rt %f %f %f \n",
  1969.      &hor_rt.x, &hor_rt.y, &hor_rt.z);
  1970.  fscanf (file, "lkc_rt %f %f %f \n",
  1971.      &lkc_rt.x, &lkc_rt.y, &lkc_rt.z);
  1972.  fscanf (file, "upc_rt %f %f %f \n",
  1973.      &upc_rt.x, &upc_rt.y, &upc_rt.z);
  1974.  fscanf (file, "horc_rt %f %f %f \n",
  1975.      &horc_rt.x, &horc_rt.y, &horc_rt.z);
  1976.  fscanf (file, "lkP %f %f %f \n",
  1977.      &lkP.x , &lkP.y, &lkP.z);
  1978.  fscanf (file, "upP %f %f %f \n",
  1979.      &upP.x, &upP.y, &upP.z);
  1980.  fscanf (file, "horP %f %f %f \n",
  1981.      &horP.x, &horP.y, &horP.z);
  1982.  fscanf (file, "meye %f %f %f \n",
  1983.      &meye.x , &meye.y, &meye.z);
  1984.  fscanf (file, "MEM_POINT %f %f %f \n",
  1985.      &MEM_POINT.x, &MEM_POINT.y, &MEM_POINT.z);
  1986.  fscanf (file, "pos_light0 %f %f %f \n",
  1987.      &pos_light0.x, &pos_light0.y, &pos_light0.z);
  1988.  fscanf (file, "pos_light1 %f %f %f \n",
  1989.      &pos_light1.x, &pos_light1.y, &pos_light1.z);
  1990.  fscanf (file, "z %lf  teta %lf  phi %lf  teta2 %lf  cam_angle %lf",                            
  1991.      &z, &teta, &phi, &teta2, &cam_angle);
  1992.  
  1993.  fscanf (file, "viewport %d  FLAG_TOP_VIEW  %d  FLAG_SELECTED_MIRROR  %d  FLAG_TOGGLE_MIRROR[0] %d",
  1994.     &viewport               , &FLAG_TOP_VIEW        , &FLAG_SELECTED_MIRROR , &FLAG_TOGGLE_MIRROR[0]);
  1995.  fscanf (file, "FLAG_TOGGLE_MIRROR[1]  %d %d %d %d %d %d \n",
  1996.     &FLAG_TOGGLE_MIRROR[0]  , &FLAG_TOGGLE_MIRROR[1], &FLAG_TOGGLE_MIRROR[2], &FLAG_TOGGLE_MIRROR[3],
  1997.     &FLAG_TOGGLE_MIRROR[4]  , &FLAG_TOGGLE_MIRROR[5]);
  1998.  fscanf (file, "FLAG_FRONT_VIEW  %d   FLAG_TOGGLE_MENU1 %d     FLAG_TOGGLE_TEXTURE_MAP %d \n",
  1999.     &FLAG_FRONT_VIEW      , &FLAG_TOGGLE_MENU1    , &FLAG_TOGGLE_TEXTURE_MAP);
  2000.  fscanf (file, "FLAG_DROP_MENU  %d    TRANSLATE_TO_GRAVITY %d    TRANSLATE_TO_MIDDLE %d \n",
  2001.     &FLAG_DROP_MENU         , &TRANSLATE_TO_GRAVITY , &TRANSLATE_TO_MIDDLE);
  2002.  fscanf (file, "Draw_relative_axe %d     Draw_light_position %d   spinning %d   expand_carre1 %d\n", 
  2003.     &Draw_relative_axe      , &Draw_light_position  , &spinning             , &expand_carre1);
  2004.  fscanf (file, "expand_carre2 %d    expand_carre3 %d        APPLY_MOUSE_MOTION %d   FLAG_ORTHO_PERSP %d \n",
  2005.     &expand_carre2          , &expand_carre3        , &APPLY_MOUSE_MOTION   , &FLAG_ORTHO_PERSP);
  2006.  fscanf (file, "FLAG_FIX_MIRROR %d      FLAG_HORIZ %d         SHOW_LOCATION_DIRECTION_OF_LIGHTS %d \n",
  2007.     &FLAG_FIX_MIRROR        , &FLAG_HORIZ           , &SHOW_LOCATION_DIRECTION_OF_LIGHTS);
  2008.  fscanf (file, "LIGHTS_FIX_WITH_CAMERA %d",
  2009.     &LIGHTS_FIX_WITH_CAMERA);
  2010.  fscanf (file, "Center_Of_Rot_Of_Lights %f %f %f \n",
  2011.     &Center_Of_Rot_Of_Lights.x, &Center_Of_Rot_Of_Lights.y, &Center_Of_Rot_Of_Lights.z);
  2012.  
  2013.  fscanf (file, "lightZeroPosition[.] %f %f %f %f \n",
  2014.     &lightZeroPosition[0], &lightZeroPosition[1], &lightZeroPosition[2], &lightZeroPosition[3]);
  2015.  fscanf (file, "lightOnePosition[.] %f %f %f %f \n",
  2016.     &lightOnePosition[0] , &lightOnePosition[1],  &lightOnePosition[2] , &lightOnePosition[3]);
  2017.  fscanf (file, "lightZeroColor[.] %f %f %f %f \n",
  2018.     &lightZeroColor[0],    &lightZeroColor[1],    &lightZeroColor[2],    &lightZeroColor[3]);
  2019.  fscanf (file, "lightOneColor[.] %f %f %f %f \n",
  2020.     &lightOneColor[0],     &lightOneColor[1],     &lightOneColor[2],     &lightOneColor[3]);
  2021.  fscanf (file, "lightZeroColor_Car[.] %f %f %f %f \n",
  2022.     &lightZeroColor_Car[0],&lightZeroColor_Car[1],&lightZeroColor_Car[2],&lightZeroColor_Car[3]);
  2023.  fscanf (file, "lightOneColor_Car[.] %f %f %f %f \n",
  2024.     &lightOneColor_Car[0], &lightOneColor_Car[1], &lightOneColor_Car[2], &lightOneColor_Car[3] );
  2025.  fscanf (file, "aspect_ratio %lf \n", &aspect_ratio);
  2026.  fscanf (file, "FLAG_MOVE_GODS_EYE %d \n", &FLAG_MOVE_GODS_EYE);
  2027.  fscanf (file, "Geye %f %f %f \n", &Geye.x, &Geye.y, &Geye.z);
  2028.  fscanf (file, "Gup %f %f %f \n", &Gup.x, &Gup.y, &Gup.z);
  2029.  fscanf (file, "Ghor %f %f %f \n", &Ghor.x, &Ghor.y, &Ghor.z);
  2030.  fscanf (file, "Glk %f %f %f \n", &Glk.x, &Glk.y, &Glk.z);
  2031.  fscanf (file, "Gup_V %f %f %f \n", &Gup_V.x, &Gup_V.y, &Gup_V.z);
  2032.  fscanf (file, "Geye_V %f %f %f \n", &Geye_V.x, &Geye_V.y, &Geye_V.z);
  2033.  fscanf (file, "curquat_Geye[.] %lf %lf %lf %lf \n",
  2034.      &curquat_Geye[0], &curquat_Geye[1], &curquat_Geye[2], &curquat_Geye[3]);
  2035.  for (i=0;i<9;i++)
  2036.     fscanf (file, "mz[i] %d \n", &mz[i]);
  2037.  
  2038.     fclose (file);
  2039. }
  2040. void
  2041. save_configurations(char num){
  2042.  FILE *file;
  2043.  char configurationNum [15];
  2044.  strcpy (configurationNum,"configuration");
  2045.  strncat (configurationNum, &num, 1);
  2046.  
  2047.  if ((file = fopen (configurationNum,"w")) == NULL)
  2048.   printf ("\n pas de chance l'ami ton fichier est corrompu 95478567\n");
  2049.  
  2050.  fprintf (file, "number_of_mirrors %d \n",
  2051.      number_of_mirrors);
  2052.  
  2053.  for (int v=0; v<6;v++){
  2054.   fprintf (file, "m1[v].cr %f %f %f \n",
  2055.      m1[v].cr.x,  m1[v].cr.y,  m1[v].cr.z);
  2056.   fprintf (file, "m1[v].c1 %f %f %f \n",
  2057.      m1[v].c1.x,  m1[v].c1.y,  m1[v].c1.z);
  2058.   fprintf (file, "m1[v].c2 %f %f %f \n",
  2059.      m1[v].c2.x,  m1[v].c2.y,  m1[v].c2.z);
  2060.   fprintf (file, "m1[v].c3 %f %f %f \n",
  2061.      m1[v].c3.x,  m1[v].c3.y,  m1[v].c3.z);
  2062.   fprintf (file, "m1[v].c4 %f %f %f \n",
  2063.      m1[v].c4.x,  m1[v].c4.y,  m1[v].c4.z);
  2064.   fprintf (file, "m1[v].cc1 %f %f %f \n",
  2065.      m1[v].cc1.x, m1[v].cc1.y, m1[v].cc1.z);
  2066.   fprintf (file, "m1[v].cc2 %f %f %f \n",
  2067.      m1[v].cc2.x, m1[v].cc2.y, m1[v].cc2.z);
  2068.   fprintf (file, "m1[v].cc3 %f %f %f \n",
  2069.      m1[v].cc3.x, m1[v].cc3.y, m1[v].cc3.z);
  2070.   fprintf (file, "m1[v].cc4 %f %f %f \n",
  2071.      m1[v].cc4.x, m1[v].cc4.y, m1[v].cc4.z);
  2072.   fprintf (file, "m1[v].nl %f %f %f \n",
  2073.      m1[v].nl.x , m1[v].nl.y,  m1[v].nl.z);
  2074.   fprintf (file, "m1[v].up %f %f %f \n",
  2075.      m1[v].up.x , m1[v].up.y,  m1[v].up.z);
  2076.   fprintf (file, "m1[v].side %f %f %f \n",
  2077.      m1[v].side.x , m1[v].side.y,  m1[v].side.z);
  2078.   fprintf (file, "m1[v].width %f, m1[v].height %f \n \n \n",
  2079.      m1[v].width  ,  m1[v].height);
  2080.  }
  2081.  
  2082.  fprintf (file, "angle %lf \n",
  2083.      angle);
  2084.  fprintf (file, "curquat[.] %lf %lf %lf %lf \n",
  2085.      curquat[0],          curquat[1],          curquat[2],          curquat[3]);
  2086.  fprintf (file, "curquatc[.] %lf %lf %lf %lf \n",
  2087.      curquatc[0],         curquatc[1],         curquatc[2],         curquatc[3]);
  2088.  fprintf (file, "curquat_mirror[.] %lf %lf %lf %lf \n",
  2089.      curquat_mirror[0],   curquat_mirror[1],   curquat_mirror[2],   curquat_mirror[3]);
  2090.  fprintf (file, "curquat_top_view[.] %lf %lf %lf %lf \n",
  2091.      curquat_top_view[0], curquat_top_view[1], curquat_top_view[2], curquat_top_view[3]);
  2092.  fprintf (file, "curquat_light0[.] %lf %lf %lf %lf \n",
  2093.      curquat_light0[0],   curquat_light0[1],   curquat_light0[2],   curquat_light0[3]);
  2094.  fprintf (file, "curquat_light1[.] %lf %lf %lf %lf \n",
  2095.      curquat_light1[0],   curquat_light1[1],   curquat_light1[2],   curquat_light1[3]);
  2096.  fprintf (file, "lastquat_top_view[.] %lf %lf %lf %lf \n",
  2097.      lastquat_top_view[0], lastquat_top_view[1], lastquat_top_view[2], lastquat_top_view[3]);
  2098.  fprintf (file, "lastquat[.] %lf %lf %lf %lf \n",
  2099.      lastquat[0],          lastquat[1],          lastquat[2],          lastquat[3]);
  2100.  fprintf (file, "lastquat_mirror[.] %lf %lf %lf %lf \n",
  2101.      lastquat_mirror[0],   lastquat_mirror[1],   lastquat_mirror[2],   lastquat_mirror[3]);
  2102.  fprintf (file, "lastquat_light0[.] %lf %lf %lf %lf \n",
  2103.      lastquat_light0[0],   lastquat_light0[1],   lastquat_light0[2],   lastquat_light0[3]);
  2104.  fprintf (file, "lastquat_light1[.] %lf %lf %lf %lf \n",
  2105.      lastquat_light1[0],   lastquat_light1[1],   lastquat_light1[2],   lastquat_light1[3]);
  2106.  
  2107.  fprintf (file, "newModel %d scalefactor %lf \n",
  2108.      newModel, scalefactor);
  2109.  
  2110.  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 ",
  2111.      TOP, BOTTOM, LEFT, RIGHT, TRANSLATE_X, TRANSLATE_Y, TRANSLATE_Z, TRANSLATE_H, NEAR2, FAR2);
  2112.  fprintf (file, "FLAG_MOVE_CAR %d  FLAG_MOVE_SCENE %d  WALK_SLOWLY %d",
  2113.      FLAG_MOVE_CAR, FLAG_MOVE_SCENE, WALK_SLOWLY);
  2114.  fprintf (file ,"DriverPos %f %f %f \n",
  2115.      DriverPos.x, DriverPos.y, DriverPos.z);
  2116.  
  2117.  fprintf (file, "eye %f %f %f \n",
  2118.      eye.x, eye.y, eye.z);
  2119.  fprintf (file, "eye1 %f %f %f \n",
  2120.      eye1.x, eye1.y, eye1.z);
  2121.  fprintf (file, "eye2 %f %f %f \n",
  2122.      eye2.x, eye2.y, eye2.z);
  2123.  fprintf (file, "eye_mirror %f %f %f \n",
  2124.      eye_mirror.x, eye_mirror.y, eye_mirror.z);
  2125.  fprintf (file ,"eyec %f %f %f \n",
  2126.      eyec.x, eyec.y, eyec.z);
  2127.  fprintf (file, "eyeP %f %f %f \n",
  2128.      eyeP.x, eyeP.y, eyeP.z);
  2129.  fprintf (file, "lk %f %f %f \n",
  2130.      lk.x, lk.y, lk.z);
  2131.  fprintf (file, "up %f %f %f \n",
  2132.      up.x, up.y, up.z);
  2133.  fprintf (file, "hor %f %f %f \n",
  2134.      hor.x, hor.y, hor.z);
  2135.  fprintf (file, "lk_rt %f %f %f \n",
  2136.      lk_rt.x, lk_rt.y, lk_rt.z);
  2137.  fprintf (file, "up_rt %f %f %f \n",
  2138.      up_rt.x, up_rt.y, up_rt.z);
  2139.  fprintf (file, "hor_rt %f %f %f \n",
  2140.      hor_rt.x, hor_rt.y, hor_rt.z);
  2141.  fprintf (file, "lkc_rt %f %f %f \n",
  2142.      lkc_rt.x, lkc_rt.y, lkc_rt.z);
  2143.  fprintf (file, "upc_rt %f %f %f \n",
  2144.      upc_rt.x, upc_rt.y, upc_rt.z);
  2145.  fprintf (file, "horc_rt %f %f %f \n",
  2146.      horc_rt.x, horc_rt.y, horc_rt.z);
  2147.  fprintf (file, "lkP %f %f %f \n",
  2148.      lkP.x , lkP.y, lkP.z);
  2149.  fprintf (file, "upP %f %f %f \n",
  2150.      upP.x, upP.y, upP.z);
  2151.  fprintf (file, "horP %f %f %f \n",
  2152.      horP.x, horP.y, horP.z);
  2153.  fprintf (file, "meye %f %f %f \n",
  2154.      meye.x , meye.y, meye.z);
  2155.  fprintf (file, "MEM_POINT %f %f %f \n",
  2156.      MEM_POINT.x, MEM_POINT.y, MEM_POINT.z);
  2157.  fprintf (file, "pos_light0 %f %f %f \n",
  2158.      pos_light0.x, pos_light0.y, pos_light0.z);
  2159.  fprintf (file, "pos_light1 %f %f %f \n",
  2160.      pos_light1.x, pos_light1.y, pos_light1.z);
  2161.  fprintf (file, "z %lf  teta %lf  phi %lf  teta2 %lf  cam_angle %lf",                            
  2162.      z, teta, phi, teta2, cam_angle);
  2163.  
  2164.  fprintf (file, "viewport %d  FLAG_TOP_VIEW  %d  FLAG_SELECTED_MIRROR  %d  FLAG_TOGGLE_MIRROR[0] %d",
  2165.     viewport               , FLAG_TOP_VIEW        , FLAG_SELECTED_MIRROR , FLAG_TOGGLE_MIRROR[0]);
  2166.  fprintf (file, "FLAG_TOGGLE_MIRROR[1]  %d %d %d %d %d %d \n",
  2167.     FLAG_TOGGLE_MIRROR[0]  , FLAG_TOGGLE_MIRROR[1], FLAG_TOGGLE_MIRROR[2], FLAG_TOGGLE_MIRROR[3],
  2168.     FLAG_TOGGLE_MIRROR[4]  , FLAG_TOGGLE_MIRROR[5]);
  2169.  fprintf (file, "FLAG_FRONT_VIEW  %d   FLAG_TOGGLE_MENU1 %d     FLAG_TOGGLE_TEXTURE_MAP %d \n",
  2170.     FLAG_FRONT_VIEW      , FLAG_TOGGLE_MENU1    , FLAG_TOGGLE_TEXTURE_MAP);
  2171.  fprintf (file, "FLAG_DROP_MENU  %d    TRANSLATE_TO_GRAVITY %d    TRANSLATE_TO_MIDDLE %d \n",
  2172.     FLAG_DROP_MENU         , TRANSLATE_TO_GRAVITY , TRANSLATE_TO_MIDDLE);
  2173.  fprintf (file, "Draw_relative_axe %d     Draw_light_position %d   spinning %d   expand_carre1 %d\n", 
  2174.     Draw_relative_axe      , Draw_light_position  , spinning             , expand_carre1);
  2175.  fprintf (file, "expand_carre2 %d    expand_carre3 %d        APPLY_MOUSE_MOTION %d   FLAG_ORTHO_PERSP %d \n",
  2176.     expand_carre2          , expand_carre3        , APPLY_MOUSE_MOTION   , FLAG_ORTHO_PERSP);
  2177.  fprintf (file, "FLAG_FIX_MIRROR %d      FLAG_HORIZ %d         SHOW_LOCATION_DIRECTION_OF_LIGHTS %d \n",
  2178.     FLAG_FIX_MIRROR        , FLAG_HORIZ           , SHOW_LOCATION_DIRECTION_OF_LIGHTS);
  2179.  fprintf (file, "LIGHTS_FIX_WITH_CAMERA %d",
  2180.     LIGHTS_FIX_WITH_CAMERA);
  2181.  fprintf (file, "Center_Of_Rot_Of_Lights %f %f %f \n",
  2182.     Center_Of_Rot_Of_Lights.x, Center_Of_Rot_Of_Lights.y, Center_Of_Rot_Of_Lights.z);
  2183.  
  2184.  fprintf (file, "lightZeroPosition[.] %f %f %f %f \n",
  2185.     lightZeroPosition[0], lightZeroPosition[1], lightZeroPosition[2], lightZeroPosition[3]);
  2186.  fprintf (file, "lightOnePosition[.] %f %f %f %f \n",
  2187.     lightOnePosition[0] , lightOnePosition[1],  lightOnePosition[2] , lightOnePosition[3]);
  2188.  fprintf (file, "lightZeroColor[.] %f %f %f %f \n",
  2189.     lightZeroColor[0],    lightZeroColor[1],    lightZeroColor[2],    lightZeroColor[3]);
  2190.  fprintf (file, "lightOneColor[.] %f %f %f %f \n",
  2191.     lightOneColor[0],     lightOneColor[1],     lightOneColor[2],     lightOneColor[3]);
  2192.  fprintf (file, "lightZeroColor_Car[.] %f %f %f %f \n",
  2193.     lightZeroColor_Car[0],lightZeroColor_Car[1],lightZeroColor_Car[2],lightZeroColor_Car[3]);
  2194.  fprintf (file, "lightOneColor_Car[.] %f %f %f %f \n",
  2195.     lightOneColor_Car[0], lightOneColor_Car[1], lightOneColor_Car[2], lightOneColor_Car[3] );
  2196.  fprintf (file, "aspect_ratio %lf \n", aspect_ratio);
  2197.  fprintf (file, "FLAG_MOVE_GODS_EYE %d \n", FLAG_MOVE_GODS_EYE);
  2198.  fprintf (file, "Geye %f %f %f \n", Geye.x, Geye.y, Geye.z);
  2199.  fprintf (file, "Gup %f %f %f \n", Gup.x, Gup.y, Gup.z);
  2200.  fprintf (file, "Ghor %f %f %f \n", Ghor.x, Ghor.y, Ghor.z);
  2201.  fprintf (file, "Glk %f %f %f \n", Glk.x, Glk.y, Glk.z);
  2202.  fprintf (file, "Gup_V %f %f %f \n", Gup_V.x, Gup_V.y, Gup_V.z);
  2203.  fprintf (file, "Geye_V %f %f %f \n", Geye_V.x, Geye_V.y, Geye_V.z);
  2204.  fprintf (file, "curquat_Geye[.] %lf %lf %lf %lf \n",
  2205.   curquat_Geye[0], curquat_Geye[1], curquat_Geye[2], curquat_Geye[3]);
  2206.  for (i=0;i<9;i++)
  2207.     fprintf (file, "mz[i] %d \n", mz[i]);
  2208.  
  2209.  fclose (file);
  2210. }
  2211.  
  2212. void
  2213. fog()
  2214. {
  2215.  glEnable(GL_DEPTH_TEST);
  2216.  GLfloat fogColor[4] = {0, 0,0 , 1.0};
  2217.  glEnable (GL_FOG);
  2218.  glFogi (GL_FOG_MODE, GL_EXP);
  2219.  glFogf (GL_FOG_DENSITY, fogDensity);
  2220.  glFogfv(GL_FOG_COLOR, fogColor);
  2221.  // glHint (GL_FOG_HINT, GL_NICEST);
  2222.  //glFogf (GL_FOG_START, 0);
  2223.  //glFogf (GL_FOG_END, abs(zmin) + abs(zmax));
  2224. }
  2225.  
  2226. void
  2227. extrudeSolidFromPolygon(GLdouble data[][2], unsigned int dataSize,
  2228.                                                 GLdouble thickness, GLuint side, GLuint edge, GLuint whole)
  2229. {
  2230.  static GLUtriangulatorObj *tobj = NULL;
  2231.  GLdouble vertex[3], dx, dy, len;
  2232.  int i;
  2233.  int count = dataSize / (2 * sizeof(GLfloat));
  2234.  
  2235.  if (tobj == NULL) {
  2236.    tobj = gluNewTess();  /* create and initialize a GLU
  2237.    polygon * * tesselation object */
  2238.    // gluTessCallback(tobj, GLU_BEGIN, glBegin);
  2239.    // gluTessCallback(tobj, GLU_VERTEX, glVertex2fv);  // semi-tricky                                                     
  2240.    gluTessCallback(tobj, GLU_END, glEnd);
  2241.  }
  2242.  glNewList(side, GL_COMPILE);
  2243.  glShadeModel(GL_SMOOTH);  /* smooth minimizes seeing
  2244.                                tessellation */
  2245.  gluBeginPolygon(tobj);
  2246.  for (i = 0; i < count; i++) {
  2247.   vertex[0] = data[i][0];
  2248.   vertex[1] = data[i][1];
  2249.   vertex[2] = 0;
  2250.   gluTessVertex(tobj, vertex, data[i]);
  2251.  }
  2252.  gluEndPolygon(tobj);
  2253.  glEndList();
  2254.  glNewList(edge, GL_COMPILE);
  2255.  glShadeModel(GL_FLAT);  /* flat shade keeps angular hands
  2256.                              from being * * "smoothed" */
  2257.  glBegin(GL_QUAD_STRIP);
  2258.  for (i = 0; i <= count; i++) {
  2259.   /* mod function handles closing the edge */
  2260.   glVertex3f(data[i % count][0], data[i % count][1], 0.0);
  2261.   glVertex3f(data[i % count][0], data[i % count][1], thickness);
  2262.   /* Calculate a unit normal by dividing by Euclidean
  2263.   distance. We * could be lazy and use
  2264.   glEnable(GL_NORMALIZE) so we could pass in * arbitrary
  2265.   normals for a very slight performance hit. */
  2266.   dx = data[(i + 1) % count][1] - data[i % count][1];
  2267.   dy = data[i % count][0] - data[(i + 1) % count][0];
  2268.   len = sqrt(dx * dx + dy * dy);
  2269.   glNormal3f(dx / len, dy / len, 0.0);
  2270.  }
  2271.  glEnd();
  2272.  glEndList();
  2273.  glNewList(whole, GL_COMPILE);
  2274.  glFrontFace(GL_CW);
  2275.  glCallList(edge);
  2276.  glNormal3f(0.0, 0.0, -1.0);  /* constant normal for side */
  2277.  glCallList(side);
  2278.  glPushMatrix();
  2279.  glTranslatef(0.0, 0.0, thickness);
  2280.  glFrontFace(GL_CCW);
  2281.  glNormal3f(0.0, 0.0, 1.0);  /* opposite normal for other side 
  2282.                                */
  2283.  glCallList(side);
  2284.  glPopMatrix();
  2285.  glEndList();
  2286. }
  2287. void
  2288. redraw2(void)
  2289. {
  2290.  if (newModel)
  2291.   recalcModelView();
  2292.  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  2293.  glCallList(DINOSAUR);
  2294.  // showMessage(2, 7.1, 4.1, "Habib.");
  2295.  glutSwapBuffers();
  2296. }
  2297.  
  2298. void
  2299. myReshape(int w, int h)
  2300. {
  2301.  extern correct_Textured_image (int, int);
  2302.  glViewport(0, 0, w, h);
  2303.  W = w;
  2304.  H = h;
  2305.  TOP_V_Y= H- TOP_H; 
  2306.  cout << "before corrected_texture SC = " << StereoCounterHab << endl; 
  2307.  correct_Textured_image (W,H);
  2308.  cout << "After corrected_texture SC = " << StereoCounterHab << endl; 
  2309.  
  2310.  
  2311. }
  2312. void
  2313. myReshape2(int w, int h)
  2314. {
  2315.  glViewport(0, 0, w, h);
  2316.  W2 = w;
  2317.  H2 = h;
  2318. }
  2319. void
  2320. animate(void)
  2321. {
  2322.  glutPostRedisplay();
  2323. }
  2324. void
  2325. vis(int visible)
  2326. {
  2327.  if (visible == GLUT_VISIBLE) {                
  2328.   if (spinning) 
  2329.    glutIdleFunc(animate);
  2330.  }
  2331.  else {
  2332.   if (spinning)
  2333.    glutIdleFunc(NULL);
  2334.  }
  2335. }
  2336. void initialize_a_mirror(int i)
  2337. {
  2338.  extern void calc_corners_of_mirror(int i);
  2339.  
  2340.  mz[0] = mz[1] = mz[2] = mz[3] = mz[4] = mz[5] = mz[6] = mz[7] = mz[8] = mz[9] = 0;
  2341.  // m1[i] is the mirror link---> struct mirror
  2342.  m1[i].cr.x= eye.x+2*lk_rt.x; //mirror.center.x (m1[i] is mirror) (cr is center)
  2343.  m1[i].cr.y= eye.y+2*lk_rt.y;
  2344.  m1[i].cr.z= eye.z+2*lk_rt.z;
  2345.  
  2346.  m1[i].nl.x =0; //mirror.normal.dx (m1[i] is mirror) (nl is normal)
  2347.  m1[i].nl.y =0;
  2348.  m1[i].nl.z =1;
  2349.  
  2350.  m1[i].up.x = 0; // mirror.up.x (m1[i] is mirror) (up is the vector up).
  2351.  m1[i].up.y = 1;
  2352.  m1[i].up.z = 0;
  2353.  
  2354.  m1[i].side = vectoriel (m1[i].up,m1[i].nl);
  2355.  
  2356.  m1[i].width =  1; // this is the width / 2
  2357.  m1[i].height = 1;// this is the height / 2.
  2358.  
  2359.  calc_corners_of_mirror(i);
  2360. }
  2361. //finitialize_some_var
  2362. void initialize_some_var()
  2363. {
  2364.  
  2365. /* DirectSoundCreate (NULL,ppDS,  NULL);
  2366.  VTBL * lpVtbl;
  2367.  HRESULT hr = ppDS->lpVtbl->SetCooperativeLevel(ppDS, NULL, DSSCL_NORMAL); */
  2368.  
  2369.  int i;
  2370.  
  2371.  sensors_V[0].x = -8.103f;
  2372.  sensors_V[0].y =  0.0f; 
  2373.  sensors_V[0].z =  3.642f;
  2374.  
  2375.  sensors_V[1].x =  -7.978f;
  2376.  sensors_V[1].y =  0.0f; 
  2377.  sensors_V[1].z =  -1.915f;
  2378.  
  2379.  sensors_V[2].x =  -5.595f;
  2380.  sensors_V[2].y =  0.0f; 
  2381.  sensors_V[2].z =  -7.096f;
  2382.  
  2383.  sensors_V[3].x =  -1.749f;
  2384.  sensors_V[3].y =  0.0f; 
  2385.  sensors_V[3].z =  -9.728f;
  2386.  
  2387.  sensors_V[4].x =  2.892f;
  2388.  sensors_V[4].y =  0.0f; 
  2389.  sensors_V[4].z =  -9.477f;
  2390.  
  2391.  sensors_V[5].x =  8.535f;
  2392.  sensors_V[5].y =  0.0f; 
  2393.  sensors_V[5].z = -1.037f;
  2394.  
  2395.  sensors_V[6].x =  7.365f;
  2396.  sensors_V[6].y =  0.0f; 
  2397.  sensors_V[6].z = -6.176f;
  2398.  
  2399.  sensors_V[7].x =  8.159f;
  2400.  sensors_V[7].y =  0.0f; 
  2401.  sensors_V[7].z =  4.227f;
  2402.  
  2403.  NEAR2 =   0;
  2404.  FAR2 =    10;
  2405.  transX = 0;
  2406.  transY = 0;
  2407.  transZ = 0;
  2408.  eyec.x = eye.x = 2.26; //-baseline;
  2409.  eye.y = 3;
  2410.  eyec.z = eye.z = 0 ; //60.95440;
  2411.  eyec.y =  1.7;
  2412.  CRot.x = CRot.y = CRot.z = 0; // Center of rotation of an object.
  2413.  lk_rt.x = lk.x = 0;
  2414.  lk_rt.y = lk.y = 0;
  2415.  lk_rt.z = lk.z = 1;
  2416.  up_rt.x = up.x = 0;
  2417.  up_rt.y = up.y = 1;
  2418.  up_rt.z = up.z = 0;
  2419.  hor_rt.x = hor.x=1;
  2420.  hor_rt.y = hor.y=0;
  2421.  hor_rt.z = hor.z=0;
  2422.  
  2423.  // For rotating the car...
  2424.  axisup[0] = 0;
  2425.  axisup[1] = 1;
  2426.  axisup[2] = 0;
  2427.  // When recording the path of some cars, we
  2428.  // need those variables.
  2429.  for (i=0;i<10;i++)
  2430.     RouteNum[i] = 0; // This says that none of the 10 cars is running nor loaded 
  2431.                      // in the environment.
  2432.     RecRouteNum =999; // The RecRouteNum is the Route Number that is being Recorde.
  2433.                       // If RecRouteNum == 999 => we are not recording any route...
  2434.        
  2435.  for (i=0;i<10;i++){
  2436.     IndexCarLocRec[i] = 0;
  2437.     RECORD_CAR_MVMT = 0; // Flag Oh Stupid, you don't need to have it inside here!!
  2438.     CarLocAllocated[i] = 100; // How many are allocated in *CarLocationRec[#]
  2439.     }
  2440.  for (i=0;i<10;i++)
  2441.  if ((CarLocationRec[i]  = (struct car_location*) malloc (CarLocAllocated[i]*sizeof(struct car_location))) == NULL)
  2442.      printf ("Error in malloc CarLocationRec \n");
  2443.  
  2444.  // render all mirror toggled on!
  2445.  for (i =0; i<100;i++)
  2446.   FLAG_TOGGLE_MIRROR[i] = 1;
  2447.  
  2448.  // Sets the car to face the tunnel (z positive coming out of the screen and out of the tunnel).
  2449.  trackball(curquatc, 0.0, 0.0, 0.0, 0.0);  // initialize its quaternion
  2450.  axis_to_quat (axisup ,3.14159 ,lastquat); // rotates the car to face the tunnel.
  2451.  add_quats(lastquat, curquatc, curquatc);  
  2452.  build_rotmatrix(mc, curquatc);            // builds mc so that to rotate lkc_rt, upc_rt, horc_rt according to curquatc.
  2453.  //rotate the 3D up,lk,hor system.
  2454.  lkc_rt  = mult_matrix_vector(mc,lk);  // lk is (0,0,1)      lk_rt  is the lk  after the quaternion rotation
  2455.  upc_rt  = mult_matrix_vector(mc,up ); // up  is (0,1,0)     up_rt  is up      after the quaternion rotation.
  2456.  horc_rt = mult_matrix_vector(mc,hor); // hor is (1,0,0)     hor_rt is hor     after the quaternion rotation.
  2457.  
  2458.  // initialize the quaternions.
  2459.  trackball(curquat, 0.0, 0.0, teta, 0.0);
  2460.  trackball(curquat_mirror, 0.0, 0.0, 0.0, 0.0);
  2461.  trackball(curquat_top_view, 0.0, 0.0, 0.0, 0.0);
  2462.  trackball(curquat_light0, 0.0, 0.0, 0.0, 0.0);
  2463.  trackball(curquat_light1, 0.0, 0.0, 0.0, 0.0);
  2464.  trackball(curquat_Geye, 0.0, 0.0, 0.0, 0.0);
  2465.  //trackball(curquat_top_view, 0.20877532719535, 0.85882181074556, 0.3624872845568, -0.29570412353706);
  2466.  
  2467.  // fix vectors used for the mirror rotation.
  2468.  vz.x = 0;   
  2469.  vz.y = 0;   
  2470.  vz.z = 1;   
  2471.  
  2472.  // fix vectors used for the mirror rotation.
  2473.  vy.x = 0;   
  2474.  vy.y = 1;   
  2475.  vy.z = 0; 
  2476.  
  2477.  // fix vectors used for the mirror rotation.
  2478.  vx.x = 1;   
  2479.  vx.y = 0;   
  2480.  vx.z = 0; 
  2481.  
  2482.  // puts the center of rot of lights at (0,0,0).
  2483.  Center_Of_Rot_Of_Lights.x = 0;
  2484.  Center_Of_Rot_Of_Lights.y = 0;
  2485.  Center_Of_Rot_Of_Lights.z = 0;
  2486.    
  2487.  glClearColor (0.0, 0.0, 0.0, 0.0);
  2488.  glShadeModel(GL_FLAT);
  2489.  glEnable(GL_DEPTH_TEST);
  2490.  glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
  2491.  glGenTextures(9,texName);
  2492.  
  2493.  for (i=0;i<4;i++) {
  2494.   glBindTexture(GL_TEXTURE_2D, texName[i]);
  2495.   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); //GL_REPEAT);
  2496.   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); //GL_REPEAT);
  2497.   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
  2498.   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
  2499.  
  2500.   glTexImage2D(GL_TEXTURE_2D,           // target
  2501.                 0,                       // level
  2502.                 GL_RGB,                  // internal format
  2503.                 TEX_WIDTH, TEX_HEIGHT,   // 
  2504.                 //im_width[0], im_height[0],
  2505.                 0,                       // border
  2506.                 GL_RGB,                  // format
  2507.                 GL_UNSIGNED_BYTE,        // type
  2508.                 TEX_BUF[i][0][0]
  2509.                 //image
  2510.                 );                // GLvoid *pixels 
  2511.  }
  2512.  
  2513.  // texName[4] is for the distortion correction of the dome and has DisWidth, DistHeight not TEX_WIDTH.
  2514.  glBindTexture(GL_TEXTURE_2D, texName[4]);
  2515.  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); //GL_REPEAT);
  2516.  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); //GL_REPEAT);
  2517.  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
  2518.  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
  2519.  glTexImage2D(  GL_TEXTURE_2D,    // target
  2520.                      0,                // level
  2521.                      //0, 0,                              // xoffset, yoffset
  2522.                      GL_RGB, // format
  2523.                      DistWidth, DistHeight,             // Width, Height
  2524.                      //im_width[0], im_height[0],
  2525.                      0, // border
  2526.                      GL_RGB,           // format
  2527.                      GL_UNSIGNED_BYTE, // type
  2528.                      //image);
  2529.                      Distortion_buffer_corrected[0][0]);        // GLvoid *pixels */ 
  2530.  
  2531.  // glEnable(GL_TEXTURE_2D); 
  2532.  html // glteximage2d */ 
  2533.  add_to_the_menus_a_mirror(0);
  2534.  add_to_the_menus_a_mirror(1);
  2535.  add_to_the_menus_a_mirror(2);
  2536.  add_to_the_menus_a_mirror(3);
  2537.  
  2538. }
  2539. void init(void)
  2540. {
  2541.  // glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 1);
  2542.  // Light 0
  2543.  glEnable(GL_LIGHTING);
  2544.  
  2545.  glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE);
  2546.  glLightfv(GL_LIGHT0, GL_AMBIENT, ambi);
  2547.  glLightfv(GL_LIGHT0, GL_POSITION, lightZeroPosition);
  2548.  glLightfv(GL_LIGHT0, GL_DIFFUSE, lightZeroColor);
  2549.  //glLightfv (GL_LIGHT0, GL_AMBIENT, ambi); 
  2550.  //glLightf (GL_LIGHT0, GL_CONSTANT_ATTENUATION, 0.5);
  2551.  //glLightf (GL_LIGHT0, GL_LINEAR_ATTENUATION, 0.5);
  2552.  //glLighti (GL_LIGHT0, GL_SPOT_EXPONENT, 75);
  2553.  //glLighti (GL_LIGHT0, GL_SPOT_CUTOFF, 100.0);
  2554.  glEnable (GL_LIGHT0);
  2555.  // Light 1
  2556.  glLightfv(GL_LIGHT1, GL_POSITION, lightOnePosition);
  2557.  glLightfv(GL_LIGHT1, GL_DIFFUSE, lightOneColor);
  2558.  glLightfv (GL_LIGHT1, GL_AMBIENT, ambi); 
  2559.  glEnable (GL_LIGHT1); 
  2560.  // glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambi);
  2561.  
  2562.  glLightfv(GL_LIGHT2, GL_POSITION, light2Position);
  2563.  glLightfv(GL_LIGHT2, GL_DIFFUSE, lightOneColor);
  2564.  glLightfv (GL_LIGHT2, GL_AMBIENT, ambi); 
  2565.  glEnable (GL_LIGHT2);
  2566.  
  2567.  glLightfv(GL_LIGHT3, GL_POSITION, light3Position);
  2568.  glLightfv(GL_LIGHT3, GL_DIFFUSE, lightOneColor);
  2569.  glLightfv (GL_LIGHT3, GL_AMBIENT, ambi); 
  2570.  glEnable (GL_LIGHT3); 
  2571.  glLineWidth(2.0);
  2572. }
  2573. int
  2574. main(int argc, char **argv)
  2575. {
  2576.   vrml_city_filename = argv[1];
  2577.   texture_directory  = argv[1];
  2578.   int i,j,k; 
  2579.   
  2580.   // if I Do not give an argument to the Vrml_viewer command
  2581.   if (argc == 1)  {
  2582.     cout << "hello... " << endl;
  2583.     vrml_city_filename = new char[128];
  2584.     vrml_vehicle_filename  = new char[128];
  2585.     for (i = 0; i<5;i++)
  2586.       for (j=0;j<5;j++)
  2587.         vrml_vehicle_filenames[i][j]  = new char[128];
  2588.     vrml_sphere_filename = new char[128];
  2589.     vrml_sensors_filename  = new char[128];
  2590.     texture_directory      = new char[128];
  2591.     /* strcpy (texture_directory,  "/home/habib/vrml/CpyvirtcityDNEH/");
  2592.        strcpy (vrml_city_filename, "../../vrml/CpyvirtcityDNEH/virtcity.wrl"); */
  2593.     strcpy (texture_directory,  "./ed22/");
  2594.     strcpy (vrml_city_filename, "./ed22/edtown22nts.wrl"); 
  2595.     
  2596.   } 
  2597.   
  2598.   extern void initialise();
  2599.   
  2600.   flag_motion = rotating;
  2601.   glutInit(&argc, argv);
  2602.   glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH | GLUT_MULTISAMPLE | GLUT_STEREO); 
  2603.   glutInitWindowSize(512, 512);
  2604.   win = glutCreateWindow("Kodak Demo");
  2605.   
  2606.   glutDisplayFunc(redraw);
  2607.   glutReshapeFunc(myReshape);
  2608.   glutVisibilityFunc(vis);
  2609.   glutMouseFunc(mouse);
  2610.   glutMotionFunc(motion);
  2611.   glutPassiveMotionFunc(passive_motion);
  2612.   
  2613.   cout << "Loading " << vrml_city_filename << endl;
  2614.   CNC = Read_Vrml_File(vrml_city_filename);
  2615.   cout << "Flag Children : " << CNC->FlagChildren << endl;
  2616.   create_menus();
  2617.   
  2618.   
  2619.   initialize_some_var();
  2620.   glShadeModel(GL_SMOOTH);
  2621.   //glCullFace (GL_FRONT_AND_BACK);
  2622.   //glEnable(GL_CULL_FACE);
  2623.   glEnable(GL_DEPTH_TEST);
  2624.   glEnable(GL_POLYGON_SMOOTH);
  2625.   glEnable(GL_LINE_SMOOTH);
  2626.   glEnable(GL_POINT_SMOOTH);
  2627.   // glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
  2628.   // glHint(GL_POLYGON_SMOOTH_HINT, GL_NICEST);
  2629.   //glBlendFunc 
  2630.   glEnable (GL_BLEND);
  2631.   
  2632.   glMatrixMode(GL_PROJECTION);
  2633.   glMatrixMode(GL_MODELVIEW);
  2634.   glPushMatrix();       /* dummy push so we can pop on model
  2635.                            recalc   */
  2636.   init();
  2637.   glutKeyboardFunc(Key);
  2638.   MyOrbHandle = orb_open ("/dev/ttyd4");
  2639.   glutIdleFunc (SpaceOrb); //WinUnix     
  2640.   glutSpecialFunc(SpecialKey);
  2641.   initialise();
  2642.     // load_configuration('6');
  2643.   glutMainLoop();
  2644.   return 0;             /* ANSI C requires main to return int. */
  2645. }
  2646.