home *** CD-ROM | disk | FTP | other *** search
/ ftp.hitl.washington.edu / ftp.hitl.washington.edu.tar / ftp.hitl.washington.edu / pub / people / habib / VirtCity / glut_viewer.cc < prev    next >
C/C++ Source or Header  |  2000-04-24  |  66KB  |  2,393 lines

  1. // By Habib Abi-Rached
  2. // Summer 1997.
  3. // Intern in Ford Motor.
  4. // Parts of code taken from Mark J. Kilgard, 1994.
  5. // Using Glut / OpenGl
  6. // Implementation of Data Desk using Stereo-Vision.
  7.  
  8. #include <stdio.h>
  9. #include <iostream.h>  
  10. #include <stdlib.h>
  11. #include <string.h>
  12. #include <math.h>       /* for cos(), sin(), and sqrt() */
  13. #include <GL/glut.h>
  14. #include "trackball.h"
  15.  
  16. #define FLAG int
  17.  
  18. float zero1 = 0.0;
  19. float zero2 = 0.0;
  20. float NaN = 999999999; 
  21.  
  22. extern void add_quats (float, float, float);
  23. extern void add_quats (float *, float *, float *);
  24.  
  25.  
  26. typedef enum  {
  27.   RESERVED, BODY_SIDE, BODY_EDGE, BODY_WHOLE, ARM_SIDE, ARM_EDGE, ARM_WHOLE,
  28.   LEG_SIDE, LEG_EDGE, LEG_WHOLE, EYE_SIDE, EYE_EDGE, EYE_WHOLE, DINOSAUR
  29. } displayLists;
  30.  
  31. GLfloat angle = -150;   /* in degrees */
  32. GLboolean doubleBuffer = GL_TRUE, iconic = GL_FALSE, keepAspect = GL_FALSE;
  33. int beginx, beginy;
  34. float curquat[4];
  35. float lastquat[4];
  36. GLdouble bodyWidth = 2.0;
  37. int dinosor =0;
  38. int newModel = 1;
  39. float scalefactor = 1.0;
  40.  
  41. GLdouble TOP = 1;      /* it is the limits of the bounding box */
  42. GLdouble BOTTOM = -1;  /* it is the limits of the bounding box */
  43.  
  44. GLdouble LEFT = -13.8/10.5;    /* it is the limits of the bounding box */
  45. GLdouble RIGHT = 13.8/10.5;    /* it is the limits of the bounding box */
  46.  
  47. GLdouble NEAR2 =  0;
  48. GLdouble FAR2 =   3;
  49.  
  50. /* *INDENT-OFF* */
  51. GLfloat body[][2] = { {0, 3}, {1, 1}, {5, 1}, {8, 4}, {10, 4}, {11, 5},
  52.   {11, 11.5}, {13, 12}, {13, 13}, {10, 13.5}, {13, 14}, {13, 15}, {11, 16},
  53.   {8, 16}, {7, 15}, {7, 13}, {8, 12}, {7, 11}, {6, 6}, {4, 3}, {3, 2},
  54.   {1, 2} };
  55. GLfloat arm[][2] = { {8, 10}, {9, 9}, {10, 9}, {13, 8}, {14, 9}, {16, 9},
  56.   {15, 9.5}, {16, 10}, {15, 10}, {15.5, 11}, {14.5, 10}, {14, 11}, {14, 10},
  57.   {13, 9}, {11, 11}, {9, 11} };
  58. GLfloat leg[][2] = { {8, 6}, {8, 4}, {9, 3}, {9, 2}, {8, 1}, {8, 0.5}, {9, 0},
  59.   {12, 0}, {10, 1}, {10, 2}, {12, 4}, {11, 6}, {10, 7}, {9, 7} };
  60. GLfloat eye[][2] = { {8.75, 15}, {9, 14.7}, {9.6, 14.7}, {10.1, 15},
  61.   {9.6, 15.25}, {9, 15.25} };
  62.  
  63. GLfloat skinColor[] = {0.1, 1.0, 0.1, 1.0}, eyeColor[] = {1.0, 0.2, 0.2, 1.0};
  64.  
  65. // Structures --------------------------------------------------------------------------- Structures
  66. // Structures -------------------------------------------------------------------------- Structures
  67. // Structures -------------------------------------------------------------------------- Structures
  68.  
  69. struct bmm  {
  70.          double bar;     /*pr calc xmin xbar xmax ymin... */
  71.          double min;     /*sans parcourir a chaque fois   */
  72.          double max;     /*trois fois l'array xc, yc, zc. */
  73. } ;
  74.  
  75. struct color {
  76.         char r;
  77.         char g;
  78.         char b;
  79. };
  80.  
  81. struct scr_bar
  82.      // corner of the green square
  83.          int x_g_min, x_g_max, y_g_min, y_g_max;
  84.  
  85.      // corner of the red square
  86.          int x_r_min, x_r_max, y_r_min, y_r_max;
  87.  
  88.          // corners of the middle square.
  89.          int x_m_min, x_m_max, y_m_min, y_m_max;
  90.  
  91.          // corners of the higher triangle
  92.          int x_ht_min, x_ht_max, y_ht_min, y_ht_max;
  93.  
  94.          // corners of the lower triangle
  95.          int x_lt_min, x_lt_max, y_lt_min, y_lt_max;
  96. };
  97.  
  98. struct rect
  99. {
  100.          int xmin, xmax, ymin, ymax;
  101. };
  102.  
  103.  
  104.  
  105. // Variables of my data (The Cloud of points) ------------------------- Variables of my data (The Cloud of points)
  106. // Variables of my data (The Cloud of points) ------------------------- Variables of my data (The Cloud of points)
  107. // Variables of my data (The Cloud of points) ------------------------- Variables of my data (The Cloud of points)
  108.  
  109. float *var[100]; // Contains all the variables at hand.
  110.  
  111. float *var_animation;
  112. float var_animation_min;
  113. float var_animation_max;
  114. char var_name[100][40];
  115. int nbr_of_col = 0;
  116. float *zc; // Contain the z value 4th column (cloud of pts)
  117. float *yc; // Contain the y value 3rd column (cloud of pts)
  118. float *xc; // Contain the x value 2nd column (cloud of pts)
  119.  
  120. int *col1; // I have 5 column in my data this is the first one
  121. int *col4; // I have 5 column in my data this is the 5th   one
  122.  
  123. float *czz;  /* arrays containg the color information of the 3D pts */
  124. float *cyy;  /* arrays containg the color information of the 3D pts */
  125. float *cxx;  /* arrays containg the color information of the 3D pts */
  126.  
  127. double xmin,xmin_e ; 
  128. double xmax,xmax_e ; 
  129. double ymin,ymin_e ; 
  130. double ymax,ymax_e ; 
  131. double zmin,zmin_e ; 
  132. double zmax,zmax_e ; 
  133.  
  134. double delta_min;
  135. double sig_min;
  136. double deltax ; // abs (xmax-xmin)
  137. double deltay ; // abs (ymax-ymin)
  138. double deltaz ; // abs (zmax-zmin)
  139.  
  140. double deltax_n ; // abs (xmax-xmin) after normalization to have normalized scaling
  141. double deltay_n ; // abs (ymax-ymin) after normalization to have normalized scaling
  142. double deltaz_n ; // abs (zmax-zmin) after normalization to have normalized scaling
  143.  
  144. double xbar = 1;  /* Ce sont les coordonnes du */
  145. double ybar = 2;  /* centre du gravite de la   */
  146. double zbar = 3;  /* carte de profondeur       */
  147.  
  148. double sigx; // sigmax
  149. double sigy; // sigmay
  150. double sigz; // sigmaz
  151.  
  152. double sig_x_n; // sigmax after normalization to have normalized scaling
  153. double sig_y_n; // sigmay after normalization to have normalized scaling
  154. double sig_z_n; // sigmaz after normalization to have normalized scaling
  155.  
  156. int dim[1]; // Number of 3D points => dim[0]-1 is the last indice. [of the point with the Nans].
  157.  
  158. // Variables for my camera  -------------------------------------------- Variables for my camera
  159. // Variables for my camera  -------------------------------------------- Variables for my camera
  160. // Variables for my camera  -------------------------------------------- Variables for my camera
  161. double transX, transY, transZ;
  162. double baseline = -1.14; // 0.2;
  163. double eyex,eyey,eyez,upx,upy,upz,sidex,sidey,sidez,teta=0,phi=0,teta2;
  164.  
  165. // Flags ------------------------------------------------------------------------------------------------ Flags
  166. // Flags ------------------------------------------------------------------------------------------------ Flags
  167. // Flags ------------------------------------------------------------------------------------------------ Flags
  168. FLAG DRAW_CARRE1 = 0;
  169. FLAG DRAW_CARRE2 = 0;
  170. FLAG DRAW_CARRE3 = 0;
  171. FLAG FLAG_X_SMALLER_THAN_100 = 0;
  172. FLAG TOGGLE_BOX = 0;
  173. FLAG TRANSLATE_TO_GRAVITY=0;
  174. FLAG TRANSLATE_TO_MIDDLE =1;
  175. FLAG  displayListInited = 0;
  176. FLAG Draw_relative_axe = 1;
  177. FLAG spinning = 0;
  178. FLAG expand_carre1 = 0;
  179. FLAG expand_carre2 = 0;
  180. FLAG expand_carre3 = 0;
  181. FLAG APPLY_MOUSE_MOTION = 0;
  182. enum  {baseline_zoom, rotating, translating, scaling, motion_carre1, motion_carre2, motion_carre3, vertical_adj} 
  183. flag_motion, flag_motion_command;
  184. FLAG VIRGULE = 0;
  185. FLAG VIRGULE_AT_END_OF_LINE = 0;
  186. enum {up, down, bandflag}
  187. flag_elevator;
  188.  
  189. // int SCALE_DEFAULT = 1 ; not necessary since by default it's 1!!!
  190. int SCALE_SIGMA   = 0 ;
  191. int SCALE_MIDDLE  = 1 ;
  192.  
  193. // OpenGl Variables. --------------------------------------------------------------------- OpenGl Variables.
  194. // OpenGl Variables. --------------------------------------------------------------------- OpenGl Variables.
  195. // OpenGl Variables. --------------------------------------------------------------------- OpenGl Variables.
  196. double pt_size = 1.0;
  197. int fraction =1 ; // the fraction of the points displayed.
  198. float fogDensity = 0.02;
  199.  
  200. // strings strings -----------------------------------------------------------------strings
  201. // strings strings -----------------------------------------------------------------strings
  202. // strings strings -----------------------------------------------------------------strings
  203. char string1[40]; // Z Blue.
  204. char string2[40]; // Y Green.
  205. char string3[40]; // X RED.
  206. char string4[]="Stereo_zoom";
  207. char string5[]="Zoom";
  208. char string6[]="Animation";
  209. char string7[]="Vert_adj.";
  210. char string8[]="Color.";
  211. char string9[]="Pt_Size";
  212.  
  213. // Variables for the viewport -------------------------------------- Variables for the viewport
  214. // Variables for the viewport--------------------------------------- Variables for the viewport 
  215. // Variables for the viewport -------------------------------------- Variables for the viewport
  216. FLAG viewport = 1; // initially no command bar.
  217. struct scr_bar
  218. sb_c1[1], sb_c2[1], sb_c3[1];
  219.  
  220. struct rect
  221. stereo_zoom_rect[1],scaling_rect[1],animation_rect[1],vertical_adj_rect[1], color_rect[1], pt_size_rect[1];
  222.  
  223. // Variables for the elevator------------------------------------- Variables for the elevator
  224. // Variables for the elevator------------------------------------- Variables for the elevator
  225. // Variables for the elevator------------------------------------- Variables for the elevator
  226. struct rect
  227. up_rect[1], down_rect[1],band_rect[1];
  228. float band; //determins the band width of highlight points.
  229.  
  230. float thresh; // threshhold for window2 (the elevator) (The line).
  231.  
  232. // GLUT Variables -------------------------------------------------------------------- GLUT Variables
  233. // GLUT Variables -------------------------------------------------------------------- GLUT Variables
  234. // GLUT Variables -------------------------------------------------------------------- GLUT Variables
  235. int Menu1_id,Menu2_id;
  236. int X,Y;
  237. int W = 930, H = 350;
  238. int W2 = 400, H2 = 100;
  239. int vav = 33; // vav  = vertical adjustment value.
  240. int win; // identifier of the big big windoooooow...
  241.  
  242. // Variables -------------------------------------------------------------------- Variables
  243. // Variables -------------------------------------------------------------------- Variables
  244. // Variables -------------------------------------------------------------------- Variables
  245. double carre1 = 0;
  246. double carre2 = 0;
  247. double carre3 = 0;
  248. double carre1_trans=0.5;
  249. double carre2_trans=0.5;
  250. double carre3_trans=0.5;
  251. float         lUPt[16][3] = {  1 , 0 , 0 ,
  252.                               0 , 1 , 0 ,
  253.                               0 , 0 , 1 ,
  254.  
  255.                               1  , 0.8, 0.3,
  256.                               0.8,  1 , 0.3,
  257.                               0.8, 0.3, 1,
  258.  
  259.                               1 , 1 , 0 ,
  260.                               1 , 0 , 1 ,
  261.                               0 , 1 , 1 , 
  262.  
  263.                               1  , 0.3, 0.8,
  264.                               0.3,  1 , 0.8,
  265.                               0.3, 0.8, 1,
  266.  
  267.                               0.5 , 0.5 , 1,
  268.                               0.5 ,  1  , 0.5,
  269.                                 1 ,  0.5, 0.5,
  270.  
  271.                                 1 , 1 , 1} ;
  272.  
  273.                               
  274.  
  275.  
  276.  
  277. int i;
  278.  
  279. void 
  280. inputdollar (char phrase[70]) 
  281. {  
  282.    char mot[20] ;
  283.    char blanc [2];
  284.    blanc[0] = ' ';
  285.    strcpy (phrase,""); /* pour vider input car on va lui faire un strcat. */
  286.    printf ("---> ");
  287.    while (blanc[0] == ' ')
  288.    {
  289.     scanf ("%s",mot);
  290.     scanf ("%1c",blanc);
  291.     strcat (phrase,mot);
  292.     strncat (phrase,blanc,1);
  293.     
  294.    }
  295.    
  296. }
  297.  
  298. void
  299. showMessage(GLfloat x, GLfloat y, GLfloat z, char *message)
  300. {
  301.          glPushMatrix();
  302.          glDisable(GL_LIGHTING);
  303.          glRasterPos3f(x,y,z);
  304.          //glScalef(.02, .02, .02); 
  305.          
  306.          while (*message) {
  307.                     //glutStrokeCharacter(GLUT_STROKE_ROMAN, *message);
  308.                     glutBitmapCharacter(GLUT_BITMAP_8_BY_13, *message);
  309.                     message++;
  310.          }
  311.          glPopMatrix();
  312.          if (dinosor) glEnable(GL_LIGHTING);
  313. }
  314. /*________________________trouver____________________________________*/
  315. /* c'est une fct qui calcul la moyenne */
  316. /* d'un tableau TABC et le min et le   */
  317. /* et le max du meme TABC et renvoie   */
  318. /* ces 3 valeurs en renvoyant une struc*/
  319. struct bmm trouver (float *tabc,int dim[1])
  320. { int i;
  321.   int local_dim = dim[0];
  322.   struct bmm bmm2;
  323.   bmm2.bar=0;
  324.   bmm2.min=tabc[0];
  325.   bmm2.max=tabc[0];
  326.   for (i=0; i<dim[0]; i++)
  327.   {
  328.       if (tabc[i] != NaN) {
  329.             bmm2.bar = bmm2.bar + tabc [i];
  330.             if (tabc[i]<bmm2.min) bmm2.min = tabc[i];
  331.             if (tabc[i]>bmm2.max) bmm2.max = tabc[i];
  332.       }
  333.       else local_dim = local_dim -1;
  334.   }
  335.   bmm2.bar = bmm2.bar/local_dim;
  336.   return bmm2;
  337. }
  338. /*_____________________trouver_bar_min_max_________________________*/
  339. /* c'est une fct qui calcul le bar, max et min */
  340. /* de 3 tableaux: xc, yc, zc.                  */
  341. trouver_bar_min_max_sig(float *xc,float *yc, float* zc,int dim[1])
  342. { struct bmm bmm1;
  343.   
  344.   bmm1=trouver (xc,dim);
  345.   xmax = bmm1.max;
  346.   xbar = bmm1.bar;
  347.   xmin = bmm1.min;
  348.   bmm1=trouver (yc,dim);
  349.   ymax = bmm1.max;
  350.   ybar = bmm1.bar;
  351.   ymin = bmm1.min;
  352.   bmm1=trouver (zc,dim);
  353.   zmax = bmm1.max;
  354.   zbar = bmm1.bar;
  355.   zmin = bmm1.min;
  356.  
  357.     // Calculating sigma and taking care of NaN.
  358.     sigx = sigy = sigz = 0;
  359.     int dimx, dimy, dimz; // to take care of NaN.
  360.     dimx = dimy = dimz = dim[0];
  361.     for (int i=0; i< dim[0]; i++){
  362.             if (xc[i] != NaN)
  363.                 sigx = sigx + (xbar - xc[i]) * (xbar - xc[i]);
  364.             else dimx = dimx -1;
  365.  
  366.             if (yc[i] != NaN)
  367.                 sigy = sigy + (ybar - yc[i]) * (ybar - yc[i]);
  368.             else (dimy = dimy -1);
  369.  
  370.             if (zc[i] != NaN)
  371.                 sigz = sigz + (zbar - zc[i]) * (zbar - zc[i]);
  372.             else (dimz = dimz -1);
  373.     }
  374.     sigx = sigx/dimx;
  375.     sigy = sigy/dimy;
  376.     sigz = sigz/dimz;
  377.  
  378.     sigx = sqrt (sigx);    
  379.     sigy = sqrt (sigy);    
  380.     sigz = sqrt (sigz);    
  381.  
  382.     // Normalizing sigma so that when we scale it keeps the smallest axes fix.
  383.     if ((sigx<sigy) && (sigx<sigz)) sig_min = sigx;
  384.     else     
  385.              if ((sigy<sigx) && (sigy<sigz)) sig_min = sigy;
  386.              else sig_min = sigz;
  387.     
  388.     sig_x_n = sigx/sig_min;
  389.     sig_y_n = sigy/sig_min;
  390.     sig_z_n = sigz/sig_min;
  391.  
  392.     // Calculating delta.
  393.     deltax = fabs(xmax - xmin);
  394.     deltay = fabs(ymax - ymin);
  395.     deltaz = fabs(zmax - zmin);
  396.  
  397. // Normalizing sigma so that when we scale it keeps the smallest axes fix.
  398.     if ((deltax<deltay) && (deltax<deltaz)) delta_min = deltax;
  399.     else     
  400.              if ((deltay<deltax) && (deltay<deltaz)) delta_min = deltay;
  401.              else delta_min = deltaz;
  402.  
  403.     deltax_n = deltax/delta_min;
  404.     deltay_n = deltay/delta_min;
  405.     deltaz_n = deltaz/delta_min;
  406.  
  407.     // Calculating xmin_e ... for some extraneous uses...
  408.     xmin_e = xmin - 0.3*deltax;
  409.     ymin_e = ymin - 0.3*deltay;
  410.     zmin_e = zmin - 0.3*deltaz;
  411.     xmax_e = xmax + 0.3*deltax;
  412.     ymax_e = ymax + 0.3*deltay;
  413.     zmax_e = zmax + 0.3*deltaz;
  414.  
  415.     cout << "xmax=" << xmax << "  ymax=" << ymax << "  zmax=" << zmax << endl;
  416.     cout << "xmin=" << xmin << "  ymin=" << ymin << "  zmin=" << zmin << endl;
  417.     cout << "xbar=" << xbar << "  ybar=" << ybar << "  zbar=" << zbar << endl;
  418.     cout << "sigx="<< sigx << "  sigy=" << sigy << "  sigz=" << sigz << endl;
  419.     cout << "sig_x_n="<< sig_x_n << "  sig_y_n=" << sig_y_n << "  sig_z_n=" << sig_z_n << endl;
  420.     cout << "xmax-xmin=" << xmax - xmin << "  ymax-ymin=" << ymax - ymin << " zmax-zmin=" << zmax - zmin << endl;
  421.     cout << "deltax=" << deltax << "  deltay="<<  deltay << "  deltaz=" << deltaz << endl;
  422.     cout << "deltax_n=" << deltax_n << "  deltay_n="<<  deltay_n << "  deltaz_n=" << deltaz_n << endl;
  423.   
  424. }
  425. void
  426. load_data_NZP ()
  427. {
  428.     // initializing the look up table.
  429.  
  430.      int fin,i,choice;
  431.          int pts = 1000;
  432.          char joumlat[10000];
  433.      FILE *file;
  434.          char filename[70];
  435.          char fileroot[70];
  436.      i=0;
  437.          strcpy (fileroot,"./");
  438.          cout << "Please give the name of the file : " ;
  439.          cin >> filename;
  440.          strcat (fileroot,filename);
  441.      printf ("loading ...\n");
  442.      if ((file = fopen (fileroot,"r")) == NULL)
  443.                     //     if ((file = fopen ("/ford/sl1426/u/habirach/c/data/data.hab","r")) == NULL)
  444.       printf ("mako1 it's not opening the NZP file \n");
  445.  
  446.          // Reading the first line of the file + prompting the user
  447.          // to get rid of the junk. Junk will point AT the last char read.
  448.          int junk = 0;  // contains the junk
  449.          int junkl = 0; // contains the junk + the last line read
  450.          choice = 3;
  451.          while (choice == 3){
  452.                     junk = junkl;
  453.                     joumlat[junkl] = '-';  // initializing joumlat[junk]
  454.                     cout << endl << endl;
  455.                     cout << "*********************************************************"<< endl; 
  456.                     while (joumlat[junkl] !='\n'){
  457.                              junkl++;
  458.                              fscanf (file, "%1c",&joumlat[junkl]);
  459.                              cout << joumlat[junkl] ;
  460.                     }
  461.                     cout << "*********************************************************"<< endl; 
  462.                     cout << endl << endl;
  463.                     cout << "*     1) Use as a header         *"<< endl; 
  464.                     cout << "*     2) Start loading           *"<< endl; 
  465.                     cout << "*     3) Skip  row               *"<< endl; 
  466.                     cout << "       Press 1,2 or 3 --->  ";
  467.                     cin >> choice;
  468.          }
  469.          cout <<  "How Many points do you want to load ? " ;
  470.          cin >> pts;
  471.          // Setting the VIRGULE FLAG.
  472.          char harf [2];
  473.          harf[0] = 't';
  474.          while (harf[0]!='\n'){
  475.                     fscanf (file, "%1c",&harf[0]);
  476.                     if (harf[0] == ',') VIRGULE = VIRGULE + 1;
  477.          }
  478.  
  479.          // counting the number of columns and placing the file pointer on the first number.
  480.          nbr_of_col = 0;
  481.          float f;
  482.          harf[0] = 't';
  483.          while (harf[0] != '\n'){
  484.                     while ( (harf[0]!=32) && (harf[0]!=9) && (harf[0]!=',') && (harf[0]!='\n')) // scan the first number
  485.                              fscanf (file, "%1c",&harf[0]);
  486.                   nbr_of_col++;
  487.                     while ( (harf[0]==32) || (harf[0]==9) || (harf[0]==',') ) // scan the following del.
  488.                              fscanf (file, "%1c",&harf[0]);
  489.          }
  490.          fflush(file);
  491.          fclose(file);
  492.          if ((file = fopen (fileroot,"r")) == NULL)  // Reopening the file
  493.                     printf ("mako2 it's not opening the NZP file \n");
  494.          for (i = 0; i<junk-1; i++){  // Passing all the junk again.
  495.                     fscanf (file, "%1c",&joumlat[i]);
  496.          }
  497.          fscanf (file, "%1c",&joumlat[i]);
  498.  
  499.          // set VIRGULE_AT_END_OF_LINE
  500.          if (VIRGULE == nbr_of_col) VIRGULE_AT_END_OF_LINE = 1;
  501.          
  502.          // Load the damn data!!
  503.          int dim_list_points = 0;
  504.          if (choice == 1){
  505.                     if (!VIRGULE){
  506.                              for (i=0; i<nbr_of_col; i++){
  507.                                         fscanf (file, "%s",var_name[i]);
  508.                                         cout << var_name[i] << endl;
  509.                              }
  510.                     }
  511.                     if (VIRGULE){
  512.                              for (i=0; i<nbr_of_col; i++){
  513.                                         int j = 0;
  514.                                         fscanf (file, "%1c",&harf[0]);
  515.                                         while ((harf[0]!=',')&&(harf[0]!='\n')) {
  516.                                                  var_name[i][j] = harf[0];
  517.                                                  fscanf (file, "%1c",&harf[0]);
  518.                                                  j++;
  519.                                         }
  520.                              }
  521.                     }
  522.                     for (i=0; i<nbr_of_col; i++)
  523.                              cout << var_name[i] << endl;
  524.          }
  525.          
  526.          // setting var_name
  527.          char cca[1],ccb[1];
  528.          i=0;
  529.          if (choice ==2)
  530.                     for (cca[0]=48;cca[0]<58;cca[0]++)
  531.                              for (ccb[0]=48;ccb[0]<58;ccb[0]++){
  532.                                         strcat (var_name[i],"var_");
  533.                                         strcat (var_name[i],ccb);
  534.                                         strcat (var_name[i],cca);
  535.                                         i++;
  536.                              }
  537.          i = 0;
  538.          fin = 1;
  539.          char string[40];
  540.          // Reading the numerical value of the data points
  541.          while ((fin!=-1)&&(dim_list_points < pts)){
  542.                     if ((dim_list_points%1000) == 0) printf (".");
  543.                     glFlush();
  544.                     dim_list_points = dim_list_points +1;
  545.                     for (i=0; i<nbr_of_col; i++){
  546.                              var[i] = (float *) realloc (var[i],(dim_list_points) * sizeof(float)); 
  547.                              fin = fscanf (file, "%s", &string);
  548.                              if ((string[0] == 'N') && (string[1]=='a')) var[i][dim_list_points-1] = NaN;
  549.                              else var[i][dim_list_points-1] = atof(string);
  550.                              if (dim_list_points <= 2) printf(" - %f - ",var[i][dim_list_points-1]);
  551.                              if (VIRGULE){
  552.                                         fscanf (file, "%1c",&harf[0]);
  553.                                         while ( (harf[0]==32) || (harf[0]==9) ) // scan until ',' read
  554.                                                  fscanf (file, "%1c",&harf[0]);
  555.                              }
  556.                     }    
  557.                     if (VIRGULE_AT_END_OF_LINE){
  558.                              fscanf (file, "%1c",&harf[0]);
  559.                              while ( (harf[0]==32) || (harf[0]==9) ) // scan the following del.
  560.                                         fscanf (file, "%1c",&harf[0]);
  561.                     }
  562.          }
  563.  
  564.          fclose (file);
  565.  
  566.          if (fin ==-1)
  567.                     dim_list_points = dim_list_points -1;
  568.          // dim_list_points is now = to the number of points. dim_list_points-1 --> to the last point.
  569.          
  570.          cxx = (float *) realloc (cxx,(dim_list_points) * sizeof(float));
  571.          cyy = (float *) realloc (cyy,(dim_list_points) * sizeof(float));
  572.          czz = (float *) realloc (czz,(dim_list_points) * sizeof(float));
  573.          for (i=0;i<dim_list_points;i++){
  574.                     cxx[i] = 1.0;
  575.                     cyy[i] = 1.0;
  576.                     czz[i] = 1.0;
  577.          }                    
  578.          
  579.          cout << endl << "There is " << dim_list_points << " loaded" << endl;
  580.          dim[0] = dim_list_points;
  581.          printf ("finishing the Load data from disk process...\n" );
  582.  
  583.          // set string1,2,3
  584.          strcat (string1,"Z: ");
  585.          strcat (string1,var_name[0]);
  586.          strcat (string2,"Y: ");
  587.          strcat (string2,var_name[1]);
  588.          strcat (string3,"X: ");
  589.          strcat (string3,var_name[2]);
  590.  
  591.         xc = var[0];
  592.         yc = var[1];
  593.         zc = var[2];
  594.  
  595.          trouver_bar_min_max_sig (xc,yc,zc,dim);
  596.  
  597.          /* if (Flag_eternal) {
  598.             // Set TOP RIGHT
  599.             if (fabs(xmax) > fabs (xmin)) RIGHT = 2*fabs(xmax);
  600.             else RIGHT = 2*fabs (xmin);
  601.          
  602.             if (fabs(ymax) > fabs (ymin)) TOP = 2*fabs(ymax);
  603.             else TOP = 2*fabs (ymin);
  604.          
  605.             // Scaling so that it is in the same ratio as the pixel ratio : 5/4 
  606.             if (TOP > RIGHT) RIGHT = 5*TOP/4;
  607.             else  TOP = 4*RIGHT/5;
  608.  
  609.             BOTTOM = - TOP;
  610.             LEFT   = - RIGHT;
  611.          }
  612.          Flag_eternal = 0; */
  613.  
  614. }
  615.  
  616. void 
  617. rectangle(int x1,int y1,int x2,int y2, float r, float g, float b, rect *re) //frectangle
  618. // x1 , y1 are the upper left  corner
  619. // x2 , y2 are the low   right corner
  620. {
  621.          glBegin(GL_POLYGON);
  622.          glColor3f (r,g,b);
  623.          glVertex2f(x1 , y1 );
  624.          glVertex2f(x1 , y2 );
  625.          glVertex2f(x2 , y2 );
  626.          glVertex2f(x2 , y1 );
  627.          glEnd();
  628.          re->xmin = x1;
  629.          re->xmax = x2;
  630.          re->ymin = y1;
  631.          re->ymax = y2;
  632. }
  633. void
  634. scrollbar(int x,int y,int w,scr_bar *s) //fscrollbar
  635. // (x,y) is the upper left corner
  636. // w is the width of the scroll bar.
  637. // The scrollbar is 88 pixel long
  638.  
  639. {
  640.          // Create a srall bar.
  641.  
  642.          // Drawing the green squar up
  643.          glBegin(GL_POLYGON);
  644.          glColor3f (0,1,0);
  645.          glVertex2f(x  ,y   );
  646.          glVertex2f(x  ,y+10);
  647.          glVertex2f(x+w,y+10);
  648.          glVertex2f(x+w,y   );
  649.          glEnd();
  650.          s->x_g_min = x;
  651.          s->x_g_max = x+w;
  652.          s->y_g_min = y;
  653.          s->y_g_max = y+10;
  654.  
  655.          // Drawing the red squar down
  656.          glBegin(GL_POLYGON);
  657.          glColor3f (1,0,0);
  658.          glVertex2f(x  ,y+78);
  659.          glVertex2f(x  ,y+88);
  660.          glVertex2f(x+w,y+88);
  661.          glVertex2f(x+w,y+78);
  662.          glEnd();
  663.          s->x_r_min = x;
  664.          s->x_r_max = x+w;
  665.          s->y_r_min = y+78;
  666.          s->y_r_max = y+88;
  667.  
  668.          // Drawing upper triangle
  669.          glBegin (GL_TRIANGLES);
  670.           glColor3f (0.7,0.6,0.5);
  671.          glVertex2f(x+w/2, y+12);
  672.          glVertex2f(x    , y+22);
  673.          glVertex2f(x+w  , y+22);
  674.          glEnd();
  675.          s->x_ht_min = x;
  676.          s->x_ht_max = x+w;
  677.          s->y_ht_min = y+12;
  678.          s->y_ht_max = y+22;
  679.  
  680.          // Drawing lower triangle
  681.          glBegin (GL_TRIANGLES);
  682.           glColor3f (0.7,0.6,0.5);
  683.          glVertex2f(x    ,y+66);
  684.          glVertex2f(x+w/2,y+76);
  685.          glVertex2f(x+w  ,y+66);
  686.          glEnd();
  687.          s->x_lt_min = x;
  688.          s->x_lt_max = x+w;
  689.          s->y_lt_min = y+66;
  690.          s->y_lt_max = y+76;
  691.  
  692.          // Drawing the middle rectangle.
  693.          glBegin (GL_POLYGON);
  694.          glColor3f (0.7,0.9,0.6);
  695.          glVertex2f(x   ,y+24   );
  696.          glVertex2f(x   ,y+24+40);
  697.          glVertex2f(x+w ,y+24+40);
  698.          glVertex2f(x+w ,y+24   );
  699.          glEnd();
  700.          s->x_m_min = x;
  701.          s->x_m_max = x+w;
  702.          s->y_m_min = y+24;
  703.          s->y_m_max = y+64;
  704.  
  705. }
  706.  
  707.  
  708. void
  709. draw_carre1() //fdraw_carre1
  710. {
  711.          glEnable (GL_BLEND);
  712.          glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  713.          // glDepthMask(GL_FALSE);
  714.          // glMateriali (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE,1);
  715.          double z = zmin+carre1;
  716.          if (expand_carre1){
  717.                     glBegin (GL_POLYGON);
  718.                     glColor4f (0, 0, 0.9,carre1_trans);
  719.                     // glShadeModel (GL_FLAT);
  720.                     glVertex3f (xmin_e,ymin_e,z);
  721.                     glVertex3f (xmax_e,ymin_e,z);
  722.                     glVertex3f (xmax_e,ymax_e,z);
  723.                     glVertex3f (xmin_e,ymax_e,z);
  724.                     glEnd();
  725.  
  726.                     glBegin (GL_POLYGON);
  727.                     glColor4f (0, 0, 0.9,carre1_trans);
  728.                     glVertex3f (xmin_e,ymax_e,z);
  729.                     glVertex3f (xmax_e,ymax_e,z);
  730.                     glVertex3f (xmax_e,ymin_e,z);
  731.                     glVertex3f (xmin_e,ymin_e,z);
  732.                     glEnd();
  733.          }
  734.          else{
  735.                     glBegin (GL_POLYGON);
  736.                     glColor4f (0, 0, 0.9,carre1_trans);
  737.                     glVertex3f (xmin,ymin,z);
  738.                     glVertex3f (xmax,ymin,z);
  739.                     glVertex3f (xmax,ymax,z);
  740.                     glVertex3f (xmin,ymax,z);
  741.                     glEnd();
  742.  
  743.                     glBegin (GL_POLYGON);
  744.                     glColor4f (0, 0, 0.9,carre1_trans);
  745.                     glVertex3f (xmin,ymax,z);
  746.                     glVertex3f (xmax,ymax,z);
  747.                     glVertex3f (xmax,ymin,z);
  748.                     glVertex3f (xmin,ymin,z);
  749.                     glEnd();
  750.          }
  751.          glDisable(GL_BLEND);
  752.          // glDepthMask(GL_TRUE);
  753. }
  754.  
  755. void
  756. draw_carre2() //fdraw_carre2
  757. {
  758.          glEnable (GL_BLEND);
  759.          glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  760.          // glDepthMask(GL_FALSE);
  761.          double y = ymin+carre2;
  762.          if (expand_carre2){
  763.                     glBegin (GL_POLYGON);
  764.                     glColor4f (0, 0.9, 0.0,carre2_trans);
  765.                     glVertex3f (xmin_e,y,zmin_e);
  766.                     glVertex3f (xmax_e,y,zmin_e);
  767.                     glVertex3f (xmax_e,y,zmax_e);
  768.                     glVertex3f (xmin_e,y,zmax_e);
  769.                     glEnd();
  770.  
  771.                     glBegin (GL_POLYGON);
  772.                     glColor4f (0, 0.9, 0.0,carre1_trans);
  773.                     glVertex3f (xmin_e,y,zmax_e);
  774.                     glVertex3f (xmax_e,y,zmax_e);
  775.                     glVertex3f (xmax_e,y,zmin_e);
  776.                     glVertex3f (xmin_e,y,zmin_e);
  777.                     glEnd();
  778.          }
  779.          else{
  780.                     glBegin (GL_POLYGON);
  781.                     glColor4f (0, 0.9, 0.0,carre1_trans);
  782.                     glVertex3f (xmin ,y,zmin );
  783.                     glVertex3f (xmax ,y,zmin );
  784.                     glVertex3f (xmax ,y,zmax );
  785.                     glVertex3f (xmin ,y,zmax );
  786.                     glEnd();
  787.  
  788.                     glBegin (GL_POLYGON);
  789.                     glColor4f (0, 0.9, 0.0,carre1_trans);
  790.                     glVertex3f (xmin ,y,zmax );
  791.                     glVertex3f (xmax ,y,zmax );
  792.                     glVertex3f (xmax ,y,zmin );
  793.                     glVertex3f (xmin ,y,zmin );
  794.                     glEnd();
  795.          }
  796.          glDisable(GL_BLEND);
  797.          // glDepthMask(GL_TRUE);
  798. }
  799.  
  800. void
  801. draw_carre3() //fdraw_carre3
  802. {
  803.          glEnable (GL_BLEND);
  804.          glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  805.          // glDepthMask(GL_FALSE);
  806.          double x = xmin+carre3;
  807.          if (expand_carre3){
  808.                     glBegin (GL_POLYGON);
  809.                     glColor4f (0.9, 0.0, 0.0,carre3_trans);
  810.                     glVertex3f (x,ymin_e,zmax_e);
  811.                     glVertex3f (x,ymin_e,zmin_e);
  812.                     glVertex3f (x,ymax_e,zmin_e);
  813.                     glVertex3f (x,ymax_e,zmax_e);
  814.                     glEnd();
  815.  
  816.                     glBegin (GL_POLYGON);
  817.                     glColor4f (0.9, 0, 0.0,carre3_trans);
  818.                     glVertex3f (x,ymax_e,zmax_e);
  819.                     glVertex3f (x,ymax_e,zmin_e);
  820.                     glVertex3f (x,ymin_e,zmin_e);
  821.                     glVertex3f (x,ymin_e,zmax_e);
  822.                     glEnd();
  823.          }
  824.          else{
  825.                     glBegin (GL_POLYGON);
  826.                     glColor4f (0.9, 0.0, 0.0,carre3_trans);
  827.                     glVertex3f (x,ymin,zmax);
  828.                     glVertex3f (x,ymin,zmin);
  829.                     glVertex3f (x,ymax,zmin);
  830.                     glVertex3f (x,ymax,zmax);
  831.                     glEnd();
  832.  
  833.                     glBegin (GL_POLYGON);
  834.                     glColor4f (0.9, 0, 0.0,carre3_trans);
  835.                     glVertex3f (x,ymax,zmax);
  836.                     glVertex3f (x,ymax,zmin);
  837.                     glVertex3f (x,ymin,zmin);
  838.                     glVertex3f (x,ymin,zmax);
  839.                     glEnd();
  840.          }
  841.          glDisable(GL_BLEND);
  842.          // glDepthMask(GL_TRUE);
  843. }
  844.  
  845. void
  846. draw_axes()
  847. {
  848.          void dvertical_adjx();
  849.          glBegin(GL_LINES);
  850.          glColor3f (0.2,0.2,1.0);
  851.          glVertex3f (0.0, 0.0, 0.0);
  852.          glVertex3f (deltax, 0.0, 0.0);
  853.          glEnd();
  854.          showMessage(deltax,0,0, string3);
  855.          glBegin(GL_LINES);
  856.          glColor3f (0.15,0.7,0.15);
  857.          glVertex3f (0.0, 0.0, 0.0);
  858.          glVertex3f (0.0, deltay, 0.0);    
  859.          glEnd();
  860.          showMessage(0,deltay,0, string2);
  861.          glBegin(GL_LINES);
  862.          glColor3f (1,0.2,0.2);
  863.          glVertex3f (0, 0, 0);
  864.          glVertex3f (0.0, 0.0, deltaz);
  865.          glEnd();      
  866.          showMessage(0,0,deltaz, string1);
  867. }
  868.  
  869. void
  870. draw_box()
  871. {
  872.          glBegin(GL_LINES);
  873.          glColor3f (0.45,0.45,0.45);
  874.          glVertex3f (xmin,ymax,zmax);
  875.          glVertex3f (xmax,ymax,zmax);
  876.          glEnd();
  877.  
  878.          glBegin(GL_LINES);
  879.          glColor3f (0.45,0.45,0.45);
  880.          glVertex3f (xmax,ymax,zmax);
  881.          glVertex3f (xmax,ymin,zmax);
  882.          glEnd();
  883.  
  884.          glBegin(GL_LINES);
  885.          glColor3f (0.45,0.45,0.45);
  886.          // glColor3f (0.5,0,0);
  887.          glVertex3f (xmax,ymin,zmax);
  888.          glVertex3f (xmin,ymin,zmax);
  889.          glEnd();
  890.  
  891.          glBegin(GL_LINES);
  892.          glColor3f (0.45,0.45,0.45);
  893.          // glColor3f (0.0,0.5,0.0);
  894.          glVertex3f (xmin,ymin,zmax);
  895.          glVertex3f (xmin,ymax,zmax);
  896.          glEnd();
  897.  
  898.          glBegin(GL_LINES);
  899.          glColor3f (0.45,0.45,0.45);
  900.          // glColor3f (0,0,0.8);
  901.          glVertex3f (xmin,ymax,zmax);
  902.          glVertex3f (xmin,ymax,zmin);
  903.          glEnd();
  904.  
  905.          glBegin(GL_LINES);
  906.          glColor3f (0.45,0.45,0.45);
  907.          //glColor3f (0,0,0.8);
  908.          glVertex3f (xmax,ymax,zmax);
  909.          glVertex3f (xmax,ymax,zmin);
  910.          glEnd();
  911.  
  912.          glBegin(GL_LINES);
  913.          glColor3f (0.45,0.45,0.45);
  914.          //glColor3f (0,0,0.8);
  915.          glVertex3f (xmax,ymin,zmax);
  916.          glVertex3f (xmax,ymin,zmin);
  917.          glEnd();
  918.  
  919.          glBegin(GL_LINES);
  920.          glColor3f (0.45,0.45,0.45);
  921.          //glColor3f (0,0,0.8);
  922.          glVertex3f (xmin,ymin,zmax);
  923.          glVertex3f (xmin,ymin,zmin);
  924.          glEnd();
  925.  
  926.          glBegin(GL_LINES);
  927.          glColor3f (0.45,0.45,0.45);
  928.          //glColor3f (0.0,0.5,0.0);
  929.          glVertex3f (xmin,ymax,zmin);
  930.          glVertex3f (xmin,ymin,zmin);
  931.          glEnd();
  932.  
  933.          glBegin(GL_LINES);
  934.          glColor3f (0.45,0.45,0.45);
  935.          //glColor3f (0.5,0,0);
  936.          glVertex3f (xmin,ymin,zmin);
  937.          glVertex3f (xmax,ymin,zmin);
  938.          glEnd();
  939.  
  940.          glBegin(GL_LINES);
  941.          glColor3f (0.45,0.45,0.45);
  942.          //glColor3f (0.0,0.5,0.0);
  943.          glVertex3f (xmax,ymin,zmin);
  944.          glVertex3f (xmax,ymax,zmin);
  945.          glEnd();
  946.  
  947.          glBegin(GL_LINES);
  948.          glColor3f (0.45,0.45,0.45);
  949.          //glColor3f (0.5,0,0);
  950.          glVertex3f (xmax,ymax,zmin);
  951.          glVertex3f (xmin,ymax,zmin);
  952.          glEnd();
  953.  
  954.  
  955. }
  956.  
  957. void
  958. recalcModelView(void) //frecalcmodelview
  959. {
  960.   GLfloat m[4][4];
  961.     glMatrixMode(GL_MODELVIEW);
  962.   glPopMatrix();
  963.   glPushMatrix();
  964.  
  965.     double scalex, scaley, scalez;
  966.  
  967.   build_rotmatrix(m, curquat);
  968.     gluLookAt(eyex,eyey,eyez,   /* eye is at (... */
  969.                         0,0,0,      /* looking to */
  970.                         upx,upy,upz);      /* up is in positive Y direction */
  971.     
  972.     // rotate
  973.   glMultMatrixf(&m[0][0]);
  974.  
  975.     // We should normalize scaling in order to maintain the same lenth for the smaller axes.
  976.     if (SCALE_SIGMA)  {
  977.              scalex = 1/sigx;
  978.              scaley = 1/sigy;
  979.              scalez = 1/sigz;
  980.     }
  981.  
  982.     // We should normalize scaling in order to maintain the same lenth for the smaller axes.
  983.     if (SCALE_MIDDLE)  {
  984.              scalex = 1/deltax;
  985.              scaley = 1/deltay;
  986.              scalez = 1/deltaz;
  987.     }
  988.     else {
  989.              scalex = 1;  
  990.              scaley = 1;
  991.              scalez = 1;
  992.     }
  993.  
  994.     // Translate the origin ONLY IF INDICATED OTHERWHISE PUT IT IN 0,0,0
  995.              // 
  996.     if (TRANSLATE_TO_GRAVITY) glTranslatef (-xbar*scalex,-ybar*scaley,-zbar*scalez); 
  997.     if (TRANSLATE_TO_MIDDLE ) glTranslatef (-(xmin+xmax)*scalex/2,-(ymin+ymax)*scaley/2,-(zmin+zmax)*scalez/2); 
  998.  
  999.  
  1000.     // SCALE ONLY IF REQUESTED OTHERWISE DO NOT SCALE (1,1,1).
  1001.   glScalef (scalex, scaley, scalez);
  1002.   newModel = 0;
  1003. }
  1004.  
  1005. void
  1006. ViewPort() //fViewPort()
  1007. {
  1008.          // Draw The Vertical Control Menu.
  1009.  
  1010.          // Set View Port.
  1011.          glViewport (0,0,100,H);
  1012.  
  1013.          // Set Projection Matrix
  1014.          glMatrixMode(GL_PROJECTION);/* set up projection transform */
  1015.          glLoadIdentity();
  1016.          glOrtho (0,100, H,0, -1,1);
  1017.          
  1018.          // Set ModelView Matrix.
  1019.          glMatrixMode (GL_MODELVIEW);
  1020.          glLoadIdentity();
  1021.          
  1022.          // Draw Menu.
  1023.          glBegin (GL_POLYGON);
  1024.          glColor3f (0.25,0.2,0.1);
  1025.          glVertex3f (0  ,H,-0.5);
  1026.          glColor3f (0.25,0.2,0.1);
  1027.          glVertex3f (100,H,-0.5);
  1028.          glColor3f (0.3,0.1,0.15);
  1029.          glVertex3f (100,  0,-0.5);
  1030.          glColor3f (0.3, 0.1,0.15);
  1031.          glVertex3f (0  ,  0,-0.5);
  1032.          glEnd(); 
  1033.  
  1034.          // writing on the window characters Blue -->X...
  1035.          int i;
  1036.          glColor3f (0.75,0.75,1.0);
  1037.          glRasterPos3f(0,10,0.5);
  1038.          int len;
  1039.          len = (int) strlen(string3);
  1040.          for (i = 0; i < len; i++) 
  1041.                     glutBitmapCharacter(GLUT_BITMAP_8_BY_13, string3[i]);
  1042.          
  1043.          glColor3f (0.75,1.0,0.75);
  1044.          glRasterPos3f(0,20,0.5);
  1045.          len = (int) strlen(string2);
  1046.          for (i = 0; i < len; i++) 
  1047.                     glutBitmapCharacter(GLUT_BITMAP_8_BY_13, string2[i]);
  1048.          
  1049.          glColor3f (1.0,0.75,0.75);
  1050.          glRasterPos3f(0,30,0.5);
  1051.          len = (int) strlen(string1);
  1052.          for (i = 0; i < len; i++) 
  1053.                     glutBitmapCharacter(GLUT_BITMAP_8_BY_13, string1[i]);
  1054.          
  1055.  
  1056.          // Drawing the scrollbar for carre1.
  1057.          scrollbar (10,40,20,sb_c1);
  1058.          scrollbar (40,40,20,sb_c2);
  1059.          scrollbar (70,40,20,sb_c3);
  1060.  
  1061.          // Drawing rectanle Stereo_Zoom
  1062.          rectangle (10,130,90,143,0.9,0.3,0.7,stereo_zoom_rect);
  1063.          glColor3f (0,0,0);
  1064.          glRasterPos3f(10,142,0.5);
  1065.          len = (int) strlen(string4);
  1066.          for (i = 0; i < len; i++) 
  1067.                     glutBitmapCharacter(GLUT_BITMAP_8_BY_13, string4[i]);
  1068.  
  1069.          // Drawing rectanle Scaling
  1070.          rectangle (10,145,90,158,0.7,0.9,0.4,scaling_rect);
  1071.          glColor3f (0,0,0);
  1072.          glRasterPos3f(10,157,0.5);
  1073.          len = (int) strlen(string5);
  1074.          for (i = 0; i < len; i++) 
  1075.                     glutBitmapCharacter(GLUT_BITMAP_8_BY_13, string5[i]);
  1076.          
  1077.          // Drawing rectanle Animation.
  1078.          rectangle (10,160,90,173,0.7,0.9,0.4,animation_rect);
  1079.          glColor3f (0,0,0);
  1080.          glRasterPos3f(10,172,0.5);
  1081.          len = (int) strlen(string6);
  1082.          for (i = 0; i < len; i++) 
  1083.                     glutBitmapCharacter(GLUT_BITMAP_8_BY_13, string6[i]);
  1084.  
  1085.          // Drawing rectanle Vertical Adjustment..
  1086.          rectangle (10,175,90,188,0.9,0.9,0.4,vertical_adj_rect);
  1087.          glColor3f (0,0,0);
  1088.          glRasterPos3f(10,187,0.5);
  1089.          len = (int) strlen(string7);
  1090.          for (i = 0; i < len; i++) 
  1091.                     glutBitmapCharacter(GLUT_BITMAP_8_BY_13, string7[i]);
  1092.  
  1093.     
  1094.          // Drawing rectanle Color mapping...
  1095.          rectangle (10,191,90,204,0.9,0.3,0.4,color_rect);
  1096.          glColor3f (0,0,0);
  1097.          glRasterPos3f(10,203,0.5);
  1098.          len = (int) strlen(string8);
  1099.          for (i = 0; i < len; i++) 
  1100.                     glutBitmapCharacter(GLUT_BITMAP_8_BY_13, string8[i]);
  1101.  
  1102.          // Drawing rectanle change pt_size...
  1103.          rectangle (10,207,90,220,0.5,0.3,0.8,pt_size_rect);
  1104.          glColor3f (0,0,0);
  1105.          glRasterPos3f(10,219,0.5);
  1106.          len = (int) strlen(string8);
  1107.          for (i = 0; i < len; i++) 
  1108.                     glutBitmapCharacter(GLUT_BITMAP_8_BY_13, string9[i]);
  1109. }
  1110.  
  1111. void
  1112. recalcModelView_axes(void)
  1113. {
  1114.   GLfloat m[4][4];
  1115.     glMatrixMode(GL_MODELVIEW);
  1116.   glPopMatrix();
  1117.   glPushMatrix();
  1118.   build_rotmatrix(m, curquat);
  1119.     gluLookAt(eyex,eyey,eyez,   /* eye is at (... */
  1120.                         0,0,0,      /* looking to */
  1121.                         upx,upy,upz);      /* up is in positive Y direction */
  1122.     
  1123.     // rotate
  1124.   glMultMatrixf(&m[0][0]);
  1125.  
  1126.     // SCALE ONLY IF REQUESTED OTHERWISE DO NOT SCALE (1,1,1).
  1127.     if (SCALE_SIGMA)   glScalef (1/sigx,1/sigy,1/sigz); // normalized scaling.
  1128.     else  
  1129.         if (SCALE_MIDDLE)  glScalef (1/deltax,1/deltay,1/deltaz);
  1130.         else
  1131.             glScalef (1,1,1);
  1132.  
  1133.   newModel = 0;
  1134. }
  1135.  
  1136.  
  1137. recalcboundingbox() //frecalcboundingbox
  1138. {
  1139.      glMatrixMode(GL_PROJECTION);/* set up projection transform */
  1140.      glPopMatrix();
  1141.      glLoadIdentity();
  1142.      glOrtho (LEFT,RIGHT, BOTTOM,TOP, NEAR2,FAR2);
  1143.      glPushMatrix();
  1144. }
  1145.  
  1146. void
  1147. redraw() //fredraw
  1148. {
  1149.      int i;
  1150.         glDrawBuffer(GL_BACK_LEFT);
  1151.          if (viewport){
  1152.                     // draw command margin then set the viewport for the 3D
  1153.                   
  1154.                     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  1155.                     ViewPort(); // Sets the control band viewport and draws in it.
  1156.                     glViewport (100,0,W-100,H); // set the viewport for the 3D left eye
  1157.          }                                          // vav = vertical adj value.
  1158.          else {
  1159.                     // Set all the screen viewport for the 3D rendering the left eye..
  1160.                     
  1161.                     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  1162.                     glViewport (0,0,W    ,H);
  1163.                              }
  1164.  
  1165.      if (displayListInited) {
  1166.  
  1167.                     // Draw left eye
  1168.                   
  1169.                     eyex = -baseline;
  1170.  
  1171.                     // Draw axes left eye
  1172.                     if (Draw_relative_axe) {
  1173.                              recalcboundingbox(); 
  1174.                              recalcModelView_axes();
  1175.                              draw_axes();
  1176.                     }
  1177.  
  1178.                     // Recalc Model View.
  1179.                     recalcboundingbox(); 
  1180.                     recalcModelView();
  1181.  
  1182.                     // Draw either Dinosaur or pts in left eye
  1183.                     if (dinosor)
  1184.                              glCallList(DINOSAUR);
  1185.                     else
  1186.                              glCallList(28);
  1187.                     
  1188.                     // Draw box left eye
  1189.                     if (TOGGLE_BOX) draw_box();
  1190.  
  1191.                     // Draw carre1
  1192.                     if (DRAW_CARRE1) draw_carre1();
  1193.  
  1194.                     // Draw carre2
  1195.                     if (DRAW_CARRE2) draw_carre2();
  1196.  
  1197.                     // Draw carre3
  1198.                     if (DRAW_CARRE3) draw_carre3();
  1199.                              
  1200.                     // Draw right eye
  1201.                     glDrawBuffer(GL_BACK_RIGHT);
  1202.                     eyex = baseline;
  1203.  
  1204.                     // Draw axes right eye
  1205.                     if (viewport){
  1206.                         glViewport (100,0,W-100,H); // set the viewport for the 3D
  1207.                     }
  1208.                     else {
  1209.                         // Set all the screen viewport for the 3D rendering.
  1210.                         glViewport (0,0,W,H);
  1211.                     }
  1212.  
  1213.                     if (Draw_relative_axe) {
  1214.                             recalcboundingbox(); 
  1215.                             recalcModelView_axes();
  1216.                             draw_axes();
  1217.                     }
  1218.  
  1219.                     // Recalc Model View.
  1220.                     recalcboundingbox();
  1221.                     recalcModelView();
  1222.                     
  1223.                     // Draw Object right eye
  1224.                     if (dinosor)
  1225.                              glCallList(DINOSAUR);
  1226.                     else
  1227.                              glCallList(28);
  1228.                     
  1229.                     // Draw box right eye
  1230.                     if (TOGGLE_BOX) draw_box();
  1231.                     
  1232.                     // Draw carre1
  1233.                     if (DRAW_CARRE1) draw_carre1();
  1234.                     
  1235.                     // Draw carre2
  1236.                     if (DRAW_CARRE2) draw_carre2();
  1237.                     
  1238.                     // Draw carre3
  1239.                     if (DRAW_CARRE3) draw_carre3(); 
  1240.                     glutSwapBuffers();
  1241.          }
  1242.          else {
  1243.                     /* otherwise compile and execute to create the display list */
  1244.                     glNewList(28, GL_COMPILE_AND_EXECUTE);
  1245.                     /* front face */
  1246.                     glPointSize (pt_size);
  1247.                     glBegin(GL_POINTS);
  1248.                     /*    glColor3f(0.0, 0.7, 0.1);    green */
  1249.                     printf ("Drawing for the first time \n");
  1250.                     for (i=0; i<dim[0]; i=i+fraction){
  1251.                         if ((xc[i] != NaN) && (yc[i] != NaN) && (zc[i] != NaN)){
  1252.                              glColor3f (cxx[i], cyy[i], czz[i]);
  1253.                              glVertex3f(xc[i],yc[i],zc[i]);
  1254.                         }
  1255.                     }
  1256.                     
  1257.                     glEnd();
  1258.                     glEndList();
  1259.                     displayListInited = 1;
  1260.                     redraw();
  1261.                     glFlush();
  1262.      }
  1263. }
  1264.  
  1265. void
  1266. fog()
  1267. {
  1268.          glEnable(GL_DEPTH_TEST);
  1269.          GLfloat fogColor[4] = {0, 0,0 , 1.0};
  1270.          glEnable (GL_FOG);
  1271.          glFogi (GL_FOG_MODE, GL_EXP);
  1272.          glFogf (GL_FOG_DENSITY, fogDensity);
  1273.          glFogfv(GL_FOG_COLOR, fogColor);
  1274.          // glHint (GL_FOG_HINT, GL_NICEST);
  1275.           //glFogf (GL_FOG_START, 0);
  1276.          //glFogf (GL_FOG_END, abs(zmin) + abs(zmax));
  1277. }
  1278.  
  1279. void
  1280. extrudeSolidFromPolygon(GLfloat data[][2], unsigned int dataSize,
  1281.                                                 GLdouble thickness, GLuint side, GLuint edge, GLuint whole)
  1282. {
  1283.   static GLUtriangulatorObj *tobj = NULL;
  1284.   GLdouble vertex[3], dx, dy, len;
  1285.   int i;
  1286.   int count = dataSize / (2 * sizeof(GLfloat));
  1287.  
  1288.   if (tobj == NULL) {
  1289.     tobj = gluNewTess();  /* create and initialize a GLU
  1290.                              polygon * * tesselation object */
  1291.     // gluTessCallback(tobj, GLU_BEGIN, glBegin);
  1292.     // gluTessCallback(tobj, GLU_VERTEX, glVertex2fv);  // semi-tricky 
  1293.                                                       
  1294.     gluTessCallback(tobj, GLU_END, glEnd);
  1295.   }
  1296.   glNewList(side, GL_COMPILE);
  1297.   glShadeModel(GL_SMOOTH);  /* smooth minimizes seeing
  1298.                                tessellation */
  1299.   gluBeginPolygon(tobj);
  1300.   for (i = 0; i < count; i++) {
  1301.     vertex[0] = data[i][0];
  1302.     vertex[1] = data[i][1];
  1303.     vertex[2] = 0;
  1304.     gluTessVertex(tobj, vertex, data[i]);
  1305.   }
  1306.   gluEndPolygon(tobj);
  1307.   glEndList();
  1308.   glNewList(edge, GL_COMPILE);
  1309.   glShadeModel(GL_FLAT);  /* flat shade keeps angular hands
  1310.                              from being * * "smoothed" */
  1311.   glBegin(GL_QUAD_STRIP);
  1312.   for (i = 0; i <= count; i++) {
  1313.     /* mod function handles closing the edge */
  1314.     glVertex3f(data[i % count][0], data[i % count][1], 0.0);
  1315.     glVertex3f(data[i % count][0], data[i % count][1], thickness);
  1316.     /* Calculate a unit normal by dividing by Euclidean
  1317.        distance. We * could be lazy and use
  1318.        glEnable(GL_NORMALIZE) so we could pass in * arbitrary
  1319.        normals for a very slight performance hit. */
  1320.     dx = data[(i + 1) % count][1] - data[i % count][1];
  1321.     dy = data[i % count][0] - data[(i + 1) % count][0];
  1322.     len = sqrt(dx * dx + dy * dy);
  1323.     glNormal3f(dx / len, dy / len, 0.0);
  1324.   }
  1325.   glEnd();
  1326.   glEndList();
  1327.   glNewList(whole, GL_COMPILE);
  1328.   glFrontFace(GL_CW);
  1329.   glCallList(edge);
  1330.   glNormal3f(0.0, 0.0, -1.0);  /* constant normal for side */
  1331.   glCallList(side);
  1332.   glPushMatrix();
  1333.   glTranslatef(0.0, 0.0, thickness);
  1334.   glFrontFace(GL_CCW);
  1335.   glNormal3f(0.0, 0.0, 1.0);  /* opposite normal for other side 
  1336.                                */
  1337.   glCallList(side);
  1338.   glPopMatrix();
  1339.   glEndList();
  1340. }
  1341.  
  1342. void
  1343. makeDinosaur(void)
  1344. {
  1345.   GLfloat bodyWidth = 3.0;
  1346.  
  1347.   extrudeSolidFromPolygon(body, sizeof(body), bodyWidth,
  1348.     BODY_SIDE, BODY_EDGE, BODY_WHOLE);
  1349.   extrudeSolidFromPolygon(arm, sizeof(arm), bodyWidth / 4,
  1350.     ARM_SIDE, ARM_EDGE, ARM_WHOLE);
  1351.   extrudeSolidFromPolygon(leg, sizeof(leg), bodyWidth / 2,
  1352.     LEG_SIDE, LEG_EDGE, LEG_WHOLE);
  1353.   extrudeSolidFromPolygon(eye, sizeof(eye), bodyWidth + 0.2,
  1354.                                                     EYE_SIDE, EYE_EDGE, EYE_WHOLE);
  1355.   glNewList(DINOSAUR, GL_COMPILE);
  1356.   glMaterialfv(GL_FRONT, GL_DIFFUSE, skinColor);
  1357.   glCallList(BODY_WHOLE);
  1358.   glPushMatrix();
  1359.   glTranslatef(0.0, 0.0, bodyWidth);
  1360.   glCallList(ARM_WHOLE);
  1361.   glCallList(LEG_WHOLE);
  1362.   glTranslatef(0.0, 0.0, -bodyWidth - bodyWidth / 4);
  1363.   glCallList(ARM_WHOLE);
  1364.   glTranslatef(0.0, 0.0, -bodyWidth / 4);
  1365.   glCallList(LEG_WHOLE);
  1366.   glTranslatef(0.0, 0.0, bodyWidth / 2 - 0.1);
  1367.   glMaterialfv(GL_FRONT, GL_DIFFUSE, eyeColor);
  1368.   glCallList(EYE_WHOLE);
  1369.   glPopMatrix();
  1370.     glMatrixMode(GL_MODELVIEW);
  1371.     glTranslatef(8, 8, bodyWidth/2 );
  1372.   glEndList();
  1373. }
  1374.  
  1375. void
  1376. redraw1(void)
  1377. {
  1378.          if (newModel)
  1379.                     recalcModelView();
  1380.          glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  1381.          glCallList(DINOSAUR);
  1382.          // showMessage(2, 7.1, 4.1, "Habib.");
  1383.          glutSwapBuffers();
  1384. }
  1385.  
  1386. void
  1387. myReshape(int w, int h)
  1388. {
  1389.   glViewport(0, 0, w, h);
  1390.   W = w;
  1391.   H = h;
  1392. }
  1393.  
  1394. void
  1395. myReshape2(int w, int h)
  1396. {
  1397.   glViewport(0, 0, w, h);
  1398.   W2 = w;
  1399.   H2 = h;
  1400. }
  1401.  
  1402. void 
  1403. commande_de_bord(int x, int y) //fcommand_de_bord
  1404. {
  1405.          void animation_window2();
  1406.  
  1407.          // if... draw the transparent carre1.
  1408.          if (x>sb_c1->x_g_min  && x<sb_c1->x_g_max 
  1409.                  && y>sb_c1->y_g_min && y<sb_c1->y_g_max){
  1410.                     DRAW_CARRE1 = 1;
  1411.                     if (expand_carre1)
  1412.                              expand_carre1 = 0;
  1413.                     else
  1414.                              expand_carre1 = 1;
  1415.                     flag_motion_command = motion_carre1;
  1416.          }
  1417.  
  1418.          // if... DO NOT draw the transparent carre1.
  1419.          if (x>sb_c1->x_r_min && x<sb_c1->x_r_max 
  1420.                  && y>sb_c1->y_r_min && y<sb_c1->y_r_max) 
  1421.                     DRAW_CARRE1 = 0;
  1422.  
  1423.          // if... draw the transparent carre2.
  1424.          if (x>sb_c2->x_g_min  && x<sb_c2->x_g_max 
  1425.                  && y>sb_c2->y_g_min && y<sb_c2->y_g_max){
  1426.                     DRAW_CARRE2 = 1;
  1427.                     if (expand_carre2)
  1428.                              expand_carre2 = 0;
  1429.                     else
  1430.                              expand_carre2 = 1;
  1431.                     flag_motion_command = motion_carre2;
  1432.          }
  1433.          
  1434.          // if... DO NOT draw the transparent carre2.  
  1435.          if (x>sb_c2->x_r_min && x<sb_c2->x_r_max && 
  1436.                  y>sb_c2->y_r_min && y<sb_c2->y_r_max) 
  1437.                     DRAW_CARRE2     = 0;
  1438.  
  1439.          // if... draw the transparent carre3.
  1440.          if (x>sb_c3->x_g_min  && x<sb_c3->x_g_max 
  1441.                  && y>sb_c3->y_g_min && y<sb_c3->y_g_max){
  1442.                     DRAW_CARRE3 = 1;
  1443.                     if (expand_carre3)
  1444.                              expand_carre3 = 0;
  1445.                     else
  1446.                              expand_carre3 = 1;
  1447.                     flag_motion_command = motion_carre3;
  1448.          }
  1449.  
  1450.          // if... DO NOT draw the transparent carre3.
  1451.          if (x>sb_c3->x_r_min && x<sb_c3->x_r_max 
  1452.                  && y>sb_c3->y_r_min && y<sb_c3->y_r_max) 
  1453.                     DRAW_CARRE3 = 0;
  1454.  
  1455.          // if... Baseline_zoom = stereo_zoom
  1456.          if (x > stereo_zoom_rect->xmin && x < stereo_zoom_rect->xmax && 
  1457.                  y > stereo_zoom_rect->ymin && y < stereo_zoom_rect->ymax )
  1458.                     flag_motion_command = baseline_zoom;
  1459.  
  1460.  
  1461.          // if... scaling = 3D Zoom
  1462.          if (x > scaling_rect->xmin && x < scaling_rect->xmax && 
  1463.                  y > scaling_rect->ymin && y < scaling_rect->ymax )
  1464.                     flag_motion_command = scaling;
  1465.  
  1466.          // if... Animation
  1467.          if (x > animation_rect->xmin && x < animation_rect->xmax && 
  1468.                  y > animation_rect->ymin && y < animation_rect->ymax )
  1469.                     animation_window2();
  1470.          
  1471.          // if... vertical_adj
  1472.          if (x > vertical_adj_rect->xmin && x < vertical_adj_rect->xmax && 
  1473.                  y > vertical_adj_rect->ymin && y < vertical_adj_rect->ymax )
  1474.                     flag_motion_command = vertical_adj;
  1475.  
  1476.          redraw();
  1477. }
  1478.  
  1479. void  
  1480.  
  1481. mouse(int button, int state, int x, int y) //fmouse
  1482. {
  1483.          // if button down
  1484.          if (button == GLUT_MIDDLE_BUTTON && state == GLUT_DOWN ) {
  1485.                     // if commande board exist and mouse in it
  1486.                     if (viewport && x<100) {
  1487.                              commande_de_bord(x,y);
  1488.                     }
  1489.                     // if y>100 or viewport do not exist
  1490.                     else{
  1491.                              beginx = x;
  1492.                              beginy = y;
  1493.                              APPLY_MOUSE_MOTION = 1;
  1494.                              flag_motion = flag_motion_command;
  1495.                     }
  1496.          }
  1497.          else {
  1498.             // Translation / Rotation
  1499.             if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN) {
  1500.                 APPLY_MOUSE_MOTION = 1;
  1501.                 flag_motion = rotating;
  1502.                 beginx = x;
  1503.                 beginy = y;        
  1504.                 if(glutGetModifiers() & GLUT_ACTIVE_SHIFT) {
  1505.                          flag_motion = translating;
  1506.                 }
  1507.             }     
  1508.          }
  1509.          // if button up
  1510.          if (state == GLUT_UP) {
  1511.                     APPLY_MOUSE_MOTION =0;
  1512.          }
  1513.          
  1514.          /*                     translating = rotating =scaling = baseline_zoom = 0;
  1515.                                     DRAW_CARRE1 = DRAW_CARRE2 = DRAW_CARRE3 = 0; */         
  1516.          
  1517. }
  1518.  
  1519. void
  1520. mouse2(int button, int state, int x, int y) //fmouse
  1521. {
  1522.          float thresh2;
  1523.          void draw_elevator();
  1524.  
  1525.          // if left button down highlight some points
  1526.          if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN) {
  1527.                     thresh= (var_animation_min - var_animation_max) * (H2-y) / H2 + var_animation_max;
  1528.                     Y = y;
  1529.                     draw_elevator();
  1530.  
  1531.                     glutSetWindow(win);
  1532.                     // highlightint points in the band
  1533.                     if (flag_elevator == bandflag){
  1534.                              // Recompiling the list.
  1535.                              glNewList(28, GL_COMPILE_AND_EXECUTE);
  1536.                              thresh2 = thresh + band;
  1537.                              glPointSize(pt_size);
  1538.                              glBegin(GL_POINTS);
  1539.                              for (i=0; i<dim[0]; i=i+fraction){
  1540.                                         if (var_animation[i] < thresh && var_animation[i] > thresh2 ) {
  1541.                                                  glColor3f (cxx[i], cyy[i], czz[i]);
  1542.                                                  glVertex3f(xc[i],yc[i],zc[i]);
  1543.                                         }
  1544.                              }
  1545.                              glEnd();
  1546.                              glPointSize(pt_size+2);
  1547.                              glBegin(GL_POINTS);
  1548.                              for (i=0; i<dim[0]; i=i+fraction){
  1549.                                         if (var_animation[i] >= thresh && var_animation[i] <= thresh2 ) {
  1550.                                                  glColor3f (cxx[i], cyy[i], czz[i]);
  1551.                                                  glVertex3f(xc[i],yc[i],zc[i]);
  1552.                                         }
  1553.                              }
  1554.                              glEnd();
  1555.                     }
  1556.                     else {
  1557.                              // Highlighting point in the upper or lower part of the elevator.
  1558.                              glNewList(28, GL_COMPILE_AND_EXECUTE);
  1559.                              if (flag_elevator == up)
  1560.                                         glPointSize (pt_size);
  1561.                              else if (flag_elevator == down)
  1562.                                         glPointSize (pt_size+2);
  1563.                              glBegin(GL_POINTS);
  1564.                              for (i=0; i<dim[0]; i=i+fraction){
  1565.                                         if (var_animation[i] <= thresh ) {
  1566.                                                  glColor3f (cxx[i], cyy[i], czz[i]);
  1567.                                                  glVertex3f(xc[i],yc[i],zc[i]);
  1568.                                         }
  1569.                              }
  1570.                              glEnd();
  1571.                     
  1572.                              if (flag_elevator == up)
  1573.                                         glPointSize (pt_size+2);
  1574.                              else if (flag_elevator == down)
  1575.                                         glPointSize (pt_size);
  1576.                              glBegin(GL_POINTS);
  1577.                              for (i=0; i<dim[0]; i=i+fraction){
  1578.                                         if (var_animation[i] > thresh ) {
  1579.                                                  glColor3f (cxx[i], cyy[i], czz[i]);
  1580.                                                  glVertex3f(xc[i],yc[i],zc[i]);
  1581.                                         }
  1582.                              }
  1583.                              glEnd();
  1584.                              
  1585.                              glEndList();
  1586.                              displayListInited = 1;
  1587.                     }
  1588.                     redraw();
  1589.          }
  1590.          
  1591.          // if middle button down
  1592.          if (button == GLUT_MIDDLE_BUTTON && state == GLUT_DOWN) {
  1593.                     if (x > up_rect->xmin && x < up_rect->xmax && 
  1594.                             y > up_rect->ymin && y < up_rect->ymax )
  1595.                              flag_elevator = up;
  1596.  
  1597.                     if (x > down_rect->xmin && x < down_rect->xmax && 
  1598.                             y > down_rect->ymin && y < down_rect->ymax )
  1599.                              flag_elevator = down;
  1600.  
  1601.                     if (x > band_rect->xmin && x < band_rect->xmax && 
  1602.                             y > band_rect->ymin && y < band_rect->ymax )
  1603.                              flag_elevator = bandflag;
  1604.          }
  1605.  
  1606.  
  1607. }
  1608.  
  1609. void
  1610. animate(void)
  1611. {
  1612.          glutPostRedisplay();
  1613. }
  1614.  
  1615. void
  1616. passive_motion(int x, int y) //fpassive_motion
  1617. {
  1618.          X = x;
  1619.          Y = y;
  1620.          if ((x>200) && FLAG_X_SMALLER_THAN_100) {
  1621.                     FLAG_X_SMALLER_THAN_100 = 0;
  1622.                     glutSetMenu(Menu1_id);
  1623.                     glutAttachMenu(GLUT_RIGHT_BUTTON);
  1624.          }
  1625.          else {
  1626.                     if ((x<100) && !FLAG_X_SMALLER_THAN_100) {
  1627.                              FLAG_X_SMALLER_THAN_100 =1;
  1628.                              glutSetMenu(Menu2_id);
  1629.                              glutAttachMenu(GLUT_RIGHT_BUTTON);
  1630.                     }
  1631.          }
  1632. }
  1633.  
  1634. void
  1635. motion2(int x, int y) //f02
  1636. {
  1637.          float thresh; // threshhold
  1638.          float thresh2;
  1639.          void draw_elevator();
  1640.  
  1641.          Y = y;
  1642.          draw_elevator();
  1643.          // highlight some pts.
  1644.          if (1){
  1645.                     thresh= (var_animation_min - var_animation_max) * (H2-y) / H2 + var_animation_max;
  1646.                     glutSetWindow(win);
  1647.                     
  1648.                     // highlightint points in the band
  1649.                     if (flag_elevator == bandflag){
  1650.                              // Recompiling the list.
  1651.                              glNewList(28, GL_COMPILE_AND_EXECUTE);
  1652.                              thresh2 = thresh + band;
  1653.                              glPointSize(pt_size);
  1654.                              glBegin(GL_POINTS);
  1655.                              for (i=0; i<dim[0]; i=i+fraction){
  1656.                                         if (var_animation[i] < thresh && var_animation[i] > thresh2 ) {
  1657.                                                  glColor3f (cxx[i], cyy[i], czz[i]);
  1658.                                                  glVertex3f(xc[i],yc[i],zc[i]);
  1659.                                         }
  1660.                              }
  1661.                              glEnd();
  1662.                              glPointSize(pt_size+2);
  1663.                              glBegin(GL_POINTS);
  1664.                              for (i=0; i<dim[0]; i=i+fraction){
  1665.                                         if (var_animation[i] >= thresh && var_animation[i] <= thresh2 ) {
  1666.                                                  glColor3f (cxx[i], cyy[i], czz[i]);
  1667.                                                  glVertex3f(xc[i],yc[i],zc[i]);
  1668.                                         }
  1669.                              }
  1670.                              glEnd();
  1671.                     }
  1672.                     else {
  1673.                              // Highlighting point in the upper or lower part of the elevator.
  1674.                              glNewList(28, GL_COMPILE_AND_EXECUTE);
  1675.                              if (flag_elevator == up)
  1676.                                         glPointSize (pt_size);
  1677.                              else if (flag_elevator == down)
  1678.                                         glPointSize  (pt_size+2);
  1679.                              glBegin(GL_POINTS);
  1680.                              for (i=0; i<dim[0]; i=i+fraction){
  1681.                                         if (var_animation[i] <= thresh ) {
  1682.                                                  glColor3f (cxx[i], cyy[i], czz[i]);
  1683.                                                  glVertex3f(xc[i],yc[i],zc[i]);
  1684.                                         }
  1685.                              }
  1686.                              glEnd();
  1687.                     
  1688.                              if (flag_elevator == up)
  1689.                                         glPointSize (pt_size+2);
  1690.                              else if (flag_elevator == down)
  1691.                                         glPointSize  (pt_size);
  1692.                              glBegin(GL_POINTS);
  1693.                              for (i=0; i<dim[0]; i=i+fraction){
  1694.                                         if (var_animation[i] > thresh ) {
  1695.                                                  glColor3f (cxx[i], cyy[i], czz[i]);
  1696.                                                  glVertex3f(xc[i],yc[i],zc[i]);
  1697.                                         }
  1698.                              }
  1699.                              glEnd();
  1700.                              
  1701.                              glEndList();
  1702.                              displayListInited = 1;
  1703.                     }
  1704.                     redraw();
  1705.          }
  1706.          
  1707. }
  1708.  
  1709. void
  1710. motion(int x, int y) //fmotion
  1711. // Handles the motion of the mouse in the big black window.
  1712. {
  1713.          if (APPLY_MOUSE_MOTION) {
  1714.                     double step1, step2;
  1715.                     int stepo,steppss,stepppi;
  1716.                     switch (flag_motion) {
  1717.                              
  1718.                     case motion_carre1:
  1719.                              stepo = (y-beginy);
  1720.                              carre1 = carre1 + stepo*(deltaz/1000); 
  1721.                              beginy = y;
  1722.                              break;
  1723.  
  1724.                     case motion_carre2:
  1725.                              steppss = (y-beginy);
  1726.                              carre2 = carre2 + steppss*(deltay/1000); 
  1727.                              beginy = y;
  1728.                              break;
  1729.  
  1730.                     case motion_carre3:
  1731.                              stepppi = (y-beginy);
  1732.                              carre3 = carre3 + stepppi*(deltax/1000); 
  1733.                              beginy = y;
  1734.                              break;
  1735.  
  1736.                     case scaling:
  1737.                              if (beginy!=y) {
  1738.                                         // scalefactor = scalefactor * (1.0 + (((float) (beginy - y)) / H));
  1739.                                         int sgnn = (y-beginy); 
  1740.                                         step1 = (LEFT-RIGHT)/200.0;
  1741.                                         step2 = (BOTTOM-TOP)/200.0;
  1742.                                         LEFT   = LEFT  + sgnn*step1;
  1743.                                         RIGHT  = RIGHT - sgnn*step1;
  1744.                                         BOTTOM = BOTTOM+ sgnn*step2;
  1745.                                         TOP    = TOP   - sgnn*step2;
  1746.                                         beginy = y;
  1747.                                         newModel = 1;
  1748.                                         //glutPostRedisplay();
  1749.                              }
  1750.                              break;
  1751.                              
  1752.                     case baseline_zoom:
  1753.                              if (beginy!=y) {
  1754.                                         int sgnn = (beginy-y); //abs((beginx-x));
  1755.                                         baseline = baseline + sgnn*0.001;
  1756.                                         beginy = y;
  1757.                                         //glutPostRedisplay();
  1758.                              }
  1759.                              break;
  1760.                     case vertical_adj:
  1761.                             vav = vav + (beginy - y); // vav = vertical adjustment value.
  1762.                             beginy=y;
  1763.                             break;
  1764.                              
  1765.                     case translating:
  1766.                              int sgnx,sgny;
  1767.                              sgnx = sgny =0;
  1768.                              if (beginx != x) sgnx = (beginx-x); //abs(beginx-x);
  1769.                              if (beginy != y) sgny = (beginy-y); //abs(beginy-y);
  1770.                              step1 = (LEFT-RIGHT)/800.0;
  1771.                              step2 = (BOTTOM-TOP)/700.0;
  1772.                              LEFT   = LEFT  - sgnx*step1;
  1773.                              RIGHT  = RIGHT - sgnx*step1;
  1774.                              BOTTOM = BOTTOM+ sgny*step2;
  1775.                              TOP    = TOP   + sgny*step2;
  1776.                              beginx = x;
  1777.                              beginy = y;
  1778.                              newModel = 1;
  1779.                              //glutPostRedisplay();
  1780.                              break;
  1781.                              
  1782.                     case rotating:
  1783.                              double deux = 2.0;
  1784.                              trackball(lastquat,
  1785.                                                  (deux*beginx - W) / W,
  1786.                                                  (H - deux*beginy) / H,
  1787.                                                  (deux*x - W) / W,
  1788.                                                  (H - deux*y) / H
  1789.                                                  );
  1790.                              beginx = x;
  1791.                              beginy = y;
  1792.                              spinning = 0;
  1793.                              add_quats(lastquat, curquat, curquat);
  1794.                              newModel = 1;
  1795.                              //glutPostRedisplay();
  1796.                              break;
  1797.                     }
  1798.                     redraw();
  1799.          }
  1800.  
  1801. }
  1802. GLboolean lightZeroSwitch = GL_TRUE, lightOneSwitch = GL_TRUE;
  1803. void
  1804. DropMenu2(int value)
  1805. {
  1806.          int i;
  1807.          FLAG FLAG_DRAW = 0;
  1808.          // Choosing the appropriate axe to load our data too.
  1809.          if (Y>0 && Y<=10) {
  1810.                     xc = var[value-2];
  1811.                     strcpy (string3,"");
  1812.                     strcat (string3,"X: ");
  1813.                     strcat (string3,var_name[value-2]);
  1814.                     FLAG_DRAW =1;
  1815.          }
  1816.          
  1817.          if (Y>10 && Y<20) {
  1818.                     yc = var[value-2];
  1819.                     strcpy (string2,"");
  1820.                     strcat (string2,"Y: ");
  1821.                     strcat (string2,var_name[value-2]);
  1822.                     FLAG_DRAW =1;
  1823.          }
  1824.          
  1825.          if (Y>20 && Y<30) {
  1826.                     zc = var[value-2];
  1827.                     strcpy (string1,"");
  1828.                     strcat (string1,"Z: ");
  1829.                     strcat (string1,var_name[value-2]);
  1830.                     FLAG_DRAW =1;
  1831.          }
  1832.  
  1833.          // Animation Variable.... Maximizing a part of the points...
  1834.          if (Y>160 && Y<173){
  1835.              if (value >= 2) {
  1836.                     // setting the var_animation value
  1837.                     var_animation = var[value-2];
  1838.                     // Setting the max & min
  1839.                     var_animation_min= var_animation[0];
  1840.                     var_animation_max= var_animation[0];
  1841.                     for (i=0; i<dim[0]; i++)
  1842.                     {
  1843.                              if (var_animation[i]<var_animation_min )  var_animation_min = var_animation[i];
  1844.                              if (var_animation[i]>var_animation_max )  var_animation_max = var_animation[i];
  1845.                     }
  1846.              }
  1847.              else {
  1848.                  pt_size = 1;
  1849.                  displayListInited = 0;
  1850.                  redraw();
  1851.              }
  1852.  
  1853.          }
  1854.  
  1855.          // if you are in the color zone... you want to choose a color linked to a variable.
  1856.          if (Y>190 && Y<205) {
  1857.              if (value >=2) {
  1858.                 float *tmp,delta;
  1859.                 float min;
  1860.                 float max;
  1861.                 tmp = var [value - 2];
  1862.                 // setting max & min.
  1863.                 min = max = tmp[0]; // initializing.
  1864.                 for (i=0; i<dim[0]; i++){
  1865.                      if (tmp[i]<min )  min = tmp[i];
  1866.                      if (tmp[i]>max )  max = tmp[i];
  1867.                 }
  1868.                 delta = (max - min)/14.0;
  1869.                 // coloring the points
  1870.                 int index;
  1871.                 for (i=0; i<dim[0]; i++) {
  1872.                      index = (tmp[i] - min) / delta ; // possible value for index 0...14
  1873.                      cxx[i] = lUPt[index][0];
  1874.                      cyy[i] = lUPt[index][1];
  1875.                      czz[i] = lUPt[index][2];
  1876.                  }
  1877.               displayListInited = 0;
  1878.               redraw();
  1879.              }
  1880.              else {
  1881.                  for (i = 0; i<dim[0]; i++) {
  1882.                      cxx[i] = 1;
  1883.                      cyy[i] = 1;
  1884.                      czz[i] = 1;
  1885.                  }
  1886.                  displayListInited = 0;
  1887.                  redraw();
  1888.              }
  1889.          }
  1890.  
  1891.  
  1892.          // Determin the pt_size...
  1893.          if (Y> 206 && Y<221) {
  1894.              pt_size = value;
  1895.              displayListInited = 0;
  1896.              redraw();
  1897.          }
  1898.  
  1899.  
  1900.          if (FLAG_DRAW){
  1901.                     trouver_bar_min_max_sig (xc,yc,zc,dim);
  1902.                     // Set TOP RIGHT
  1903.                     /* if (fabs(xmax) > fabs (xmin)) RIGHT = 2*fabs(xmax);
  1904.                     else RIGHT = 2*fabs (xmin);
  1905.                     
  1906.                     if (fabs(ymax) > fabs (ymin)) TOP = 2*fabs(ymax);
  1907.                     else TOP = 2*fabs (ymin);
  1908.                     
  1909.                     // Scaling so that it is in the same ratio as the pixel ratio : 5/4
  1910.                     if (TOP > RIGHT) RIGHT = 5*TOP/4;
  1911.                     else  TOP = 4*RIGHT/5;
  1912.  
  1913.                     BOTTOM = - TOP;
  1914.                     LEFT   = - RIGHT; */
  1915.                     
  1916.                     displayListInited = 0;
  1917.                     redraw();
  1918.          }
  1919. }
  1920. void
  1921. DropMenu1(int value)
  1922. {
  1923.          switch (value) {
  1924.          case 1:
  1925.                     glEnable(GL_LIGHTING); 
  1926.                     dinosor = 1;
  1927.                     break;
  1928.          case 2:
  1929.                     glDisable(GL_LIGHTING); 
  1930.                     dinosor = 0;
  1931.                     break;
  1932.          case 3:
  1933. /* workaround hack */
  1934. #if 0
  1935.                     if(glIsEnabled(GL_MULTISAMPLE_SGIS)) {
  1936.                              glDisable(GL_MULTISAMPLE_SGIS);
  1937.                     } else {
  1938.                              glEnable(GL_MULTISAMPLE_SGIS);
  1939.                     }
  1940. #endif
  1941.                     break;
  1942.          case 4:
  1943.                     glutFullScreen();
  1944.                     break;
  1945.          case 5:
  1946.                     cout << "Baseline = " << baseline << endl  ;
  1947.                     cout << "Give new Baseline : " ;
  1948.                     cin >> baseline;
  1949.                     break;
  1950.          case 6:
  1951.                     displayListInited=0;
  1952.                     for (i=0; i<dim[0]; i++){
  1953.                              cxx[i]=1.0;
  1954.                              cyy[i]=1.0;
  1955.                              czz[i]=1.0;
  1956.                     }
  1957.                     break;
  1958.          case 7:
  1959.                     displayListInited=0;
  1960.                     for (i=0; i<dim[0]; i++){
  1961.                              switch (col1[i]){
  1962.                              case 1:
  1963.                                         cxx[i]=0.0; cyy[i]=1.0; czz[i]=1.0;
  1964.                                         break;
  1965.                              case 2:
  1966.                                         cxx[i]=1.0; cyy[i]=0.0; czz[i]=1.0;
  1967.                                         break;
  1968.                              case 3:
  1969.                                         cxx[i]=1.0; cyy[i]=1.0; czz[i]=0.0;
  1970.                                         break;
  1971.                              case 4:
  1972.                                         cxx[i]=1.0; cyy[i]=0.0; czz[i]=0.0;
  1973.                                         break;
  1974.                              case 5:
  1975.                                         cxx[i]=0.0; cyy[i]=1.0; czz[i]=0.0;
  1976.                                         break;
  1977.                              case 6:
  1978.                                         cxx[i]=0.0; cyy[i]=0.0; czz[i]=1.0;
  1979.                                         break;
  1980.                              case 7:
  1981.                                         cxx[i]=1.0; cyy[i]=0.5; czz[i]=0.25;
  1982.                                         break;
  1983.                              case 8:
  1984.                                         cxx[i]=1.0; cyy[i]=1.0; czz[i]=1.0;
  1985.                                         break;
  1986.                              }
  1987.                     }
  1988.                     break;
  1989.          case 8:
  1990.                     displayListInited=0;
  1991.                     for (i=0; i<dim[0]; i++){
  1992.                              switch (col4[i]){ 
  1993.                              case 1:
  1994.                                         cxx[i]=1.0; cyy[i]=0.5; czz[i]=0.25;
  1995.                                         break;
  1996.                              case -1:
  1997.                                         cxx[i]=0.25; cyy[i]=0.9; czz[i]=0.75;
  1998.                                         break;
  1999.                              }
  2000.                     }
  2001.                     break;
  2002.          case 9:
  2003.                     TRANSLATE_TO_GRAVITY = 0; 
  2004.                     TRANSLATE_TO_MIDDLE  = 0;
  2005.                     break;
  2006.          case 10:
  2007.                     TRANSLATE_TO_GRAVITY = 1; 
  2008.                     TRANSLATE_TO_MIDDLE  = 0;
  2009.                     break;
  2010.          case 11:
  2011.                     TRANSLATE_TO_GRAVITY = 0; 
  2012.                     TRANSLATE_TO_MIDDLE  = 1;
  2013.                     break;
  2014.          case 12: // normal scaling (1,1,1)
  2015.                     SCALE_SIGMA   = 0 ;
  2016.                     SCALE_MIDDLE  = 0 ;
  2017.                     break;
  2018.          case 13: // sigma scaling
  2019.                     SCALE_SIGMA   = 1 ;
  2020.                     SCALE_MIDDLE  = 0 ;
  2021.                     break;
  2022.          case 14: // middle scaling 
  2023.                     SCALE_SIGMA   = 0 ;
  2024.                     SCALE_MIDDLE  = 1 ;
  2025.                     break;
  2026.          case 15:
  2027.                     cout << "Give the pixel size : " << endl;
  2028.                     cin >> pt_size;
  2029.                     displayListInited = 0;
  2030.                     break;
  2031.          case 16:
  2032.                     cout << "What fraction of the points would you like to display ?" ;
  2033.                     cin >> fraction;
  2034.                     displayListInited = 0;
  2035.                     break;
  2036.          case 17:
  2037.                     if (TOGGLE_BOX == 1 ) TOGGLE_BOX = 0;
  2038.                     else TOGGLE_BOX = 1;
  2039.                     redraw();
  2040.                     break;
  2041.          case 18:
  2042.                     baseline = -baseline;
  2043.                     redraw();
  2044.                     break;
  2045.          case 19:
  2046.                     fog();
  2047.                     redraw();
  2048.                     break;
  2049.          case 20:
  2050.                     glDisable(GL_FOG);
  2051.                     redraw();
  2052.                     break;
  2053.          case 21:
  2054.                     if (viewport == 0)
  2055.                              viewport = 1; 
  2056.                     else{
  2057.                              viewport = 0;
  2058.                     }
  2059.                     redraw();
  2060.                     break;
  2061.          case 22:
  2062.                     if (Draw_relative_axe == 0)
  2063.                              Draw_relative_axe = 1; 
  2064.                     else{
  2065.                              Draw_relative_axe = 0;
  2066.                     }
  2067.                     redraw();
  2068.                     break;
  2069.          case 99:
  2070.                     exit(0);
  2071.                     break;
  2072.          }
  2073.          glutPostRedisplay();
  2074. }
  2075.  
  2076. void
  2077. vis(int visible)
  2078. {
  2079.          
  2080.          if (visible == GLUT_VISIBLE) {
  2081.                     
  2082.                     if (spinning) 
  2083.                              glutIdleFunc(animate);
  2084.          } 
  2085.          else {
  2086.                     if (spinning)
  2087.                              glutIdleFunc(NULL);
  2088.          }
  2089. }
  2090. static void 
  2091. Key(unsigned char key, int x, int y)
  2092. {
  2093.          switch (key) {
  2094.          case 'd':
  2095.                     fogDensity *= 1.10;
  2096.                     glFogf(GL_FOG_DENSITY, fogDensity);
  2097.                     glutPostRedisplay();
  2098.                     break;
  2099.          case 'D':
  2100.                     fogDensity /= 1.10;
  2101.                     glFogf(GL_FOG_DENSITY, fogDensity);
  2102.                     glutPostRedisplay();
  2103.                     break;
  2104.          case 'b':
  2105.                     if (flag_motion == motion_carre1); 
  2106.                              carre1_trans = carre1_trans +0.05;
  2107.                     if (flag_motion == motion_carre2); 
  2108.                              carre2_trans = carre2_trans +0.05;
  2109.                     if (flag_motion == motion_carre3); 
  2110.                              carre3_trans = carre3_trans +0.05;
  2111.                     glutPostRedisplay();
  2112.                     break;
  2113.          case 'c':
  2114.                     if (flag_motion == motion_carre1); 
  2115.                              carre1_trans = carre1_trans -0.05;
  2116.                     if (flag_motion == motion_carre2); 
  2117.                              carre2_trans = carre2_trans -0.05;
  2118.                     if (flag_motion == motion_carre3); 
  2119.                              carre3_trans = carre3_trans -0.05;
  2120.                     glutPostRedisplay();
  2121.                     break;
  2122.  
  2123.                     
  2124.          case 27:
  2125.                     exit(0);
  2126.          }
  2127. }
  2128.  
  2129. static void 
  2130. SpecialKey(int key, int x, int y)
  2131. {
  2132.          switch (key) {
  2133.          case GLUT_KEY_UP:
  2134.                     DRAW_CARRE1 = 1;
  2135.                     carre1 = carre1 + (deltaz/100);
  2136.                     glutPostRedisplay();
  2137.                     break;
  2138.          case GLUT_KEY_DOWN:
  2139.                     DRAW_CARRE1 = 1;
  2140.                     carre1 = carre1 - (deltaz/100);
  2141.                     glutPostRedisplay();
  2142.                     break;
  2143.          case GLUT_KEY_LEFT:
  2144.                     carre1_trans = carre1_trans-0.03;
  2145.                     glutPostRedisplay();
  2146.                     break;
  2147.          case GLUT_KEY_RIGHT:
  2148.                     carre1_trans = carre1_trans+0.03;
  2149.                     glutPostRedisplay();
  2150.                     break;
  2151.          case GLUT_KEY_INSERT: // Expand carre.
  2152.                     if (expand_carre1) 
  2153.                              expand_carre1 = 0;
  2154.                     else
  2155.                              expand_carre1 = 1;
  2156.                     glutPostRedisplay();
  2157.                     break;
  2158.          }
  2159. }
  2160. void
  2161. create_menus()
  2162. {
  2163.  
  2164.          glutCreateMenu(DropMenu1);
  2165.          Menu1_id = glutGetMenu();
  2166.          glutAddMenuEntry("Show Dinosor"                       , 1);
  2167.          glutAddMenuEntry("Show Pts",                            2);
  2168.          glutAddMenuEntry("Full screen"                        , 4);
  2169.          glutAddMenuEntry("Set baseline"                       , 5);
  2170.          glutAddMenuEntry("Remove color "                      , 6);
  2171.          glutAddMenuEntry("Put color col1"                     , 7);
  2172.          glutAddMenuEntry("Put color col4"                     , 8);
  2173.          glutAddMenuEntry("Origine at 0"                       , 9);
  2174.          glutAddMenuEntry("Origine at mean"                    , 10);
  2175.          glutAddMenuEntry("Origine at mid-range"               , 11);
  2176.          glutAddMenuEntry("Scaling unity"                     , 12);
  2177.          glutAddMenuEntry("Scaling sigma"                     , 13);
  2178.          glutAddMenuEntry("Scaling range"                     , 14);
  2179.          glutAddMenuEntry("Size_pt = "                        , 15);
  2180.          glutAddMenuEntry("Number_points = "                  , 16);
  2181.          glutAddMenuEntry("Toggle box"                        , 17);
  2182.          glutAddMenuEntry("Toggle cameras left-right"         , 18);
  2183.          glutAddMenuEntry("Add some Fog..."                   , 19);
  2184.          glutAddMenuEntry("Remove the Fog..."                 , 20);
  2185.          glutAddMenuEntry("Toggle viewport"                   , 21);
  2186.          glutAddMenuEntry("Toggle axes "                      , 22);
  2187.          if(glutGet(GLUT_WINDOW_NUM_SAMPLES) > 0) {
  2188.                     glutAddMenuEntry("Toggle multisampling", 3);
  2189.                     glutSetWindowTitle("dinospin (multisample capable)");
  2190.          }
  2191.          glutAddMenuEntry("Quit", 99);
  2192.  
  2193.          glutCreateMenu(DropMenu2);
  2194.          Menu2_id = glutGetMenu();
  2195.          int i;
  2196.          glutAddMenuEntry ("None",1);
  2197.          for (i=0;i<nbr_of_col; i++){
  2198.                     glutAddMenuEntry(var_name[i],i+2);
  2199.          }
  2200. }
  2201.  
  2202. void
  2203. draw_elevator() //fdraw_elevator
  2204. /* draws the background of the window2 the elevator window. */
  2205. {
  2206.          int len;
  2207.          char string1[] = "Up";
  2208.          char string2[] = "Do";
  2209.          char string3[] = "Ba";
  2210.          char string4[] = "9.11";
  2211.  
  2212.  
  2213.          glDrawBuffer(GL_BACK);
  2214.          glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  2215.  
  2216.          // Set Projection Matrix
  2217.          glMatrixMode(GL_PROJECTION);/* set up projection transform */
  2218.      glLoadIdentity();
  2219.      glOrtho (0,W2, H2,0 ,-1 ,1);
  2220.  
  2221.          // Set ModelView Matrix.
  2222.          glMatrixMode (GL_MODELVIEW);
  2223.          glLoadIdentity();
  2224.  
  2225.          // Drawing the up box.
  2226.          up_rect->xmin = 0 ;
  2227.          up_rect->xmax = 20;
  2228.          up_rect->ymin = 0 ;
  2229.          up_rect->ymax = 10 ;
  2230.          glBegin (GL_POLYGON);
  2231.          glColor3f (0.9,0.8,0.7);
  2232.          glVertex2i (up_rect->xmin,up_rect->ymin);
  2233.          glVertex2i (up_rect->xmin,up_rect->ymax);
  2234.          glVertex2i (up_rect->xmax,up_rect->ymax);
  2235.          glVertex2i (up_rect->xmax,up_rect->ymin);
  2236.          glEnd();
  2237.          glColor3f (0.15,0.15,1.0);
  2238.          glRasterPos2i(up_rect->xmin, up_rect->ymax);
  2239.          len = (int) strlen(string1);
  2240.          for (i = 0; i < len; i++) 
  2241.                     glutBitmapCharacter(GLUT_BITMAP_8_BY_13, string1[i]);
  2242.  
  2243.          // Drawing the down box.
  2244.          down_rect->xmin = 30 ;
  2245.          down_rect->xmax = 50;
  2246.          down_rect->ymin = 0 ;
  2247.          down_rect->ymax = 10 ;
  2248.          glBegin (GL_POLYGON);
  2249.          glColor3f (0.7,0.9,0.8);
  2250.          glVertex2i (down_rect->xmin,down_rect->ymin);
  2251.          glVertex2i (down_rect->xmin,down_rect->ymax);
  2252.          glVertex2i (down_rect->xmax,down_rect->ymax);
  2253.          glVertex2i (down_rect->xmax,down_rect->ymin);
  2254.          glEnd();
  2255.          glColor3f (0.2,0.15,0.1);
  2256.          glRasterPos2i(down_rect->xmin, down_rect->ymax);
  2257.          len = (int) strlen(string2);
  2258.          for (i = 0; i < len; i++) 
  2259.                     glutBitmapCharacter(GLUT_BITMAP_8_BY_13, string2[i]);
  2260.  
  2261.          // Drawing the Band box.
  2262.          band_rect->xmin = 60 ;
  2263.          band_rect->xmax = 80;
  2264.          band_rect->ymin = 0 ;
  2265.          band_rect->ymax = 10 ;
  2266.          glBegin (GL_POLYGON);
  2267.          glColor3f (0.76,0.9,0.6);
  2268.          glVertex2i (band_rect->xmin,band_rect->ymin);
  2269.          glVertex2i (band_rect->xmin,band_rect->ymax);
  2270.          glVertex2i (band_rect->xmax,band_rect->ymax);
  2271.          glVertex2i (band_rect->xmax,band_rect->ymin);
  2272.          glEnd();
  2273.          glColor3f (0.15,0.15,0.3);
  2274.          glRasterPos2i(band_rect->xmin, band_rect->ymax);
  2275.          len = (int) strlen(string3);
  2276.          for (i = 0; i < len; i++) 
  2277.                     glutBitmapCharacter(GLUT_BITMAP_8_BY_13, string3[i]);
  2278.  
  2279.          // Draw the line indicating where you are in the window.
  2280.          glBegin (GL_LINES);
  2281.          glColor3f (0.15,1.0,0.3);
  2282.          glVertex2i (0,Y);
  2283.          glVertex2i (90,Y);
  2284.          glEnd();
  2285.          glColor3f (1,1,1);
  2286.          glRasterPos2i(3,Y);
  2287.          len = (int) strlen(string4);
  2288.          for (i = 0; i < len; i++) 
  2289.                     glutBitmapCharacter(GLUT_BITMAP_8_BY_13, string4[i]);        
  2290.          
  2291.  
  2292.          glutSwapBuffers();
  2293.  
  2294. }
  2295.  
  2296. void
  2297. animation_window2() //fanimation_window
  2298. {
  2299.          cout << "Animation window activated" << endl;
  2300.          // glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH | GLUT_MULTISAMPLE | GLUT_STEREO); 
  2301.          // glutCreateSubWindow (win, 0,0,100,H);
  2302.          glutCreateWindow("a second window");
  2303.          glutPositionWindow(0,175);
  2304.          glutReshapeWindow (90,350);
  2305.          glutDisplayFunc(draw_elevator);
  2306.          //gfxinit();
  2307.          glutReshapeFunc(myReshape2);
  2308.          glutMouseFunc(mouse2);
  2309.          glutMotionFunc(motion2);
  2310.          glutPassiveMotionFunc(passive_motion);
  2311.          // create_menus();
  2312.  
  2313. }
  2314.  
  2315.  
  2316.  
  2317. int
  2318. main(int argc, char **argv)
  2319. {
  2320.          GLenum type;
  2321.          load_data_NZP ();
  2322.          flag_motion = rotating;
  2323.          glutInit(&argc, argv);
  2324.          glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH | GLUT_MULTISAMPLE | GLUT_STEREO); 
  2325.          // glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH | GLUT_MULTISAMPLE ); 
  2326.          trackball(curquat, 0.0, 0.0, 0.0, 0.0);
  2327.          win = glutCreateWindow("Ford's Demo");
  2328.          glutDisplayFunc(redraw);
  2329.          glutReshapeFunc(myReshape);
  2330.          glutVisibilityFunc(vis);
  2331.          glutMouseFunc(mouse);
  2332.          glutMotionFunc(motion);
  2333.          glutPassiveMotionFunc(passive_motion);           
  2334.          cout << "hihi... " << NaN << endl;
  2335.  
  2336.          create_menus();
  2337.          makeDinosaur();
  2338.          glEnable(GL_CULL_FACE);
  2339.          glEnable(GL_DEPTH_TEST);
  2340.          // glEnable(GL_LIGHTING);
  2341.          glMatrixMode(GL_PROJECTION);
  2342.          //gluPerspective( /* field of view in degree */ 40.0,  /* aspect blen
  2343.          //                                ratio 
  2344.          //                                */ 1.0,
  2345.          //    /* Z near */ 1.0, /* Z far */ 40.0);
  2346.  
  2347.          NEAR2 =   -10000;
  2348.          FAR2 =     10000;
  2349.          glMatrixMode(GL_MODELVIEW);
  2350.          transX = 0;
  2351.          transY = 0;
  2352.          transZ = 0;
  2353.          eyex = -baseline;
  2354.          eyey = 0;
  2355.          eyez =  30;
  2356.          upy = 1;
  2357.          upz = 0;
  2358.  
  2359.          glPushMatrix();       /* dummy push so we can pop on model
  2360.                                                             recalc */
  2361.          GLfloat lightZeroPosition[] = {10.0, 4.0, 10.0, 1.0};
  2362.          GLfloat lightZeroColor[] = {0.8, 1.0, 0.8, 1.0}; /* green-tinted */
  2363.          GLfloat lightOnePosition[] = {-1.0, -2.0, 1.0, 0.0};
  2364.          GLfloat lightOneColor[] = {0.6, 0.3, 0.2, 1.0}; /* red-tinted */
  2365.          glMatrixMode(GL_PROJECTION);/* set up projection transform */
  2366.          glOrtho (LEFT,RIGHT, BOTTOM,TOP, NEAR2,FAR2);
  2367.          
  2368.          glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 1);
  2369.          glLightfv(GL_LIGHT0, GL_POSITION, lightZeroPosition);
  2370.          glLightfv(GL_LIGHT0, GL_DIFFUSE, lightZeroColor);
  2371.          glLightf(GL_LIGHT0, GL_CONSTANT_ATTENUATION, 0.1);
  2372.          glLightf(GL_LIGHT0, GL_LINEAR_ATTENUATION, 0.05);
  2373.          glLightfv(GL_LIGHT1, GL_POSITION, lightOnePosition);
  2374.          glLightfv(GL_LIGHT1, GL_DIFFUSE, lightOneColor);
  2375.          glEnable(GL_LIGHT0);
  2376.          glEnable(GL_LIGHT1); 
  2377.          GLfloat ambi[] = {1.0, 1.0, 1.0, 1.0};
  2378.          glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambi);
  2379.  
  2380.          if (dinosor)
  2381.                     glEnable(GL_LIGHTING); 
  2382.          glLineWidth(2.0);
  2383.  
  2384.          glutKeyboardFunc(Key);
  2385.          glutSpecialFunc(SpecialKey);
  2386.          glutMainLoop();
  2387.          return 0;             /* ANSI C requires main to return int. */
  2388. }
  2389.  
  2390.  
  2391.  
  2392.