Moka controlers
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros
precompile-preview.cc
Go to the documentation of this file.
1 /*
2  * lib-controler-gmap : Le contrôleur de 3-G-cartes, surcouche de lib-controler.
3  * Copyright (C) 2004, Moka Team, Université de Poitiers, Laboratoire SIC
4  * http://www.sic.sp2mi.univ-poitiers.fr/
5  * Copyright (C) 2009, Guillaume Damiand, CNRS, LIRIS,
6  * guillaume.damiand@liris.cnrs.fr, http://liris.cnrs.fr/
7  *
8  * This file is part of lib-controler-gmap
9  *
10  * This program is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU Lesser General Public License as published by
12  * the Free Software Foundation, either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public License
21  * along with this program. If not, see <http://www.gnu.org/licenses/>.
22  */
23 
24 //******************************************************************************
25 #include "controler-gmap-types.hh"
26 #include "precompile-preview.hh"
27 #include "parameter-preview.hh"
30 #include "parameter-creation.hh"
31 #include "transformation-matrix.hh"
32 #include "vertex.hh"
33 #include <cassert>
34 using namespace GMap3d;
35 //******************************************************************************
37  CParameterObjectPosition * APosition,
38  CParameterCreation * AParams,
39  CParameterPolylinePosition * APolylinePosition) :
40  FParameterPreview (APreview),
41  FParameterPosition (APosition),
42  FParameterCreation (AParams),
43  FParameterPolylinePosition(APolylinePosition)
44 {
45  assert(FParameterPreview != NULL);
46  assert(FParameterPosition != NULL);
47  assert(FParameterCreation != NULL);
48  assert(FParameterPolylinePosition != NULL);
49 
50  FParameterPreview->addPrecompileToUpdate(this);
51  FParameterPosition->addPrecompileToUpdate(this);
52  FParameterCreation->addPrecompileToUpdate(this);
53  FParameterPolylinePosition->addPrecompileToUpdate(this);
54  disable();
55 }
56 //******************************************************************************
58  CPrecompile (APrecompile),
59  FParameterPreview (static_cast<CParameterPreview*>
60  (APrecompile.FParameterPreview->copy())),
61  FParameterPosition (APrecompile.FParameterPosition),
62  FParameterCreation (APrecompile.FParameterCreation),
63  FParameterPolylinePosition(APrecompile.FParameterPolylinePosition)
64 {
65  assert(FParameterPreview != NULL);
66  assert(FParameterPosition != NULL);
67  assert(FParameterCreation != NULL);
68  assert(FParameterPolylinePosition != NULL);
69 
70  FParameterPreview->addPrecompileToUpdate(this);
71  FParameterPosition->addPrecompileToUpdate(this);
72  FParameterCreation->addPrecompileToUpdate(this);
73  FParameterPolylinePosition->addPrecompileToUpdate(this);
74  disable();
75 }
76 //******************************************************************************
78 {
79  FParameterPreview->removePrecompileToUpdate(this);
80  FParameterPosition->removePrecompileToUpdate(this);
81  FParameterCreation->removePrecompileToUpdate(this);
82  FParameterPolylinePosition->removePrecompileToUpdate(this);
83 }
84 //******************************************************************************
86 { return new CPrecompilePreview(*this); }
87 //******************************************************************************
89 {
90  switch (AParameter->getType())
91  {
92  case PARAMETER_PREVIEW:
93  setPreview(static_cast<CParameterPreview *>(AParameter));
94  break;
96  setPosition(static_cast<CParameterObjectPosition *>(AParameter));
97  break;
98  case PARAMETER_CREATION:
99  setCreation(static_cast<CParameterCreation *>(AParameter));
100  break;
102  setPolylinePosition(static_cast<CParameterPolylinePosition *>(AParameter));
103  break;
104  }
105 }
106 //******************************************************************************
108 { return FParameterPreview; }
109 //******************************************************************************
111 {
112  assert(APreview != NULL);
113  APreview->addPrecompileToUpdate(this);
114  FParameterPreview->removePrecompileToUpdate(this);
115  FParameterPreview = APreview;
116  setToUpdate();
117 }
118 //******************************************************************************
120 {
121  assert(APosition != NULL);
122  APosition->addPrecompileToUpdate(this);
123  FParameterPosition->removePrecompileToUpdate(this);
124  FParameterPosition = APosition;
125  setToUpdate();
126 }
127 //******************************************************************************
129 {
130  assert(ACreation != NULL);
131  ACreation->addPrecompileToUpdate(this);
132  FParameterCreation->removePrecompileToUpdate(this);
133  FParameterCreation = ACreation;
134  setToUpdate();
135 }
136 //******************************************************************************
138  APolylinePosition)
139 {
140  assert(APolylinePosition != NULL);
141  APolylinePosition->addPrecompileToUpdate(this);
142  FParameterPolylinePosition->removePrecompileToUpdate(this);
143  FParameterPolylinePosition = APolylinePosition;
144  setToUpdate();
145 }
146 //******************************************************************************
148 { return PRECOMPILE_PREVIEW; }
149 //******************************************************************************
151 {
152  if ( AMode!=FCurrentMode )
153  {
154  FCurrentMode = AMode;
155  setToUpdate();
156  }
157 }
158 //******************************************************************************
160 {
161  switch(FCurrentMode)
162  {
163  case MODE_CREATION_CYLINDER: drawCylinder(); break;
164  case MODE_CREATION_MESH : drawMesh(); break;
165  case MODE_CREATION_POLYGON : drawPolygon(); break;
166  case MODE_CREATION_POLYLINE: drawPolyline(); break;
167  case MODE_CREATION_PYRAMID : drawPyramid(); break;
168  case MODE_CREATION_SPHERE : drawSphere(); break;
169  case MODE_CREATION_TORUS : drawTorus(); break;
170  }
171 }
172 //******************************************************************************
174 {
175  // Paramètres :
176  int M = FParameterCreation->getCylinderNbMeridians();
177  int P = FParameterCreation->getCylinderNbParallels();
178  int i,j;
179 
180  // Matrice de transformation :
181  CTransformationMatrix globalMatrix =
182  FParameterPosition->getTransformationMatrix();
183 
184  // Calcul des coordonnées des sommets :
185  CVertex** V;
186  V = new CVertex*[P+1];
187  for (i=0; i<=P; ++i)
188  V[i] = new CVertex[M];
189 
190  CVertex vertex((OX-OZ) / 2);
191  CTransformationMatrix rotationMatrix(CTransformationMatrix::IdentityMatrix);
192  rotationMatrix.rotate(OZ, 360.0/M);
193 
194  for (i=0; i<M; ++i)
195  {
196  for (j=0; j<=P; ++j)
197  {
198  V[j][i] = vertex;
199  globalMatrix.applyOn(V[j][i]);
200  if (j<P)
201  vertex += OZ/P;
202  }
203 
204  vertex -= OZ;
205  rotationMatrix.applyOn(vertex);
206  }
207 
208  // Initialisations OpenGL :
209  glLineWidth(FParameterPreview->getLWPreview());
210  glColor3fv(FParameterPreview->getCLPreview());
211 
212  // Méridiens :
213  glBegin(GL_LINES);
214 
215  for (i=0; i<M; ++i)
216  LINE(&V[0][i],&V[P][i]);
217 
218  glEnd();
219 
220  // Parallèles :
221  for (j=0; j<=P; ++j)
222  {
223  glBegin(GL_LINE_LOOP);
224 
225  for (i=0; i<M; ++i)
226  PLOT(&V[j][i]);
227 
228  glEnd();
229  }
230 
231  // Faces absentes :
232  TCoordinate x[2],y[2];
233 
234  for (i=0; i<2; ++i)
235  {
236  int k0 = (1+4*i)*M/8;
237 
238  TCoordinate x1= dCos(360.0/M* k0 );
239  TCoordinate y1= dSin(360.0/M* k0 );
240  TCoordinate x2= dCos(360.0/M*(k0+1));
241  TCoordinate y2= dSin(360.0/M*(k0+1));
242 
243  TCoordinate t = (x1-y1) / (x1-x2+y2-y1);
244 
245  x[i] = (x1 + t*(x2-x1)) / 2;
246  y[i] = (y1 + t*(y2-y1)) / 2;
247  }
248 
249  // Initialisations OpenGL :
250  glColor3fv(FParameterPreview->getCLPreviewBad());
251  glBegin(GL_LINES);
252 
253  CVertex v0, v1;
254 
255  if (! FParameterCreation->getCylinderClosedUp())
256  {
257  v0.setXYZ(x[0], y[0],-0.5); globalMatrix.applyOn(v0);
258  v1.setXYZ(x[1], y[1],-0.5); globalMatrix.applyOn(v1); LINE(& v0, & v1);
259  v0.setXYZ(x[0],-y[0],-0.5); globalMatrix.applyOn(v0);
260  v1.setXYZ(x[1],-y[1],-0.5); globalMatrix.applyOn(v1); LINE(& v0, & v1);
261  }
262 
263  if (! FParameterCreation->getCylinderClosedDown())
264  {
265  v0.setXYZ(x[0], y[0], 0.5); globalMatrix.applyOn(v0);
266  v1.setXYZ(x[1], y[1], 0.5); globalMatrix.applyOn(v1); LINE(& v0, & v1);
267  v0.setXYZ(x[0],-y[0], 0.5); globalMatrix.applyOn(v0);
268  v1.setXYZ(x[1],-y[1], 0.5); globalMatrix.applyOn(v1); LINE(& v0, & v1);
269  }
270 
271  glEnd();
272 
273  for (i=0; i<=P; ++i)
274  delete [] V[i];
275 
276  delete [] V;
277 }
278 //******************************************************************************
280 {
281  // Paramètres :
282  int mesh = FParameterCreation->getMeshSubdivisionDimension();
283 
284  int sx = FParameterCreation->getMeshNbSubdivisionsX();
285  int sy = FParameterCreation->getMeshNbSubdivisionsY();
286  int sz = FParameterCreation->getMeshNbSubdivisionsZ();
287  unsigned char F = FParameterCreation->getMeshCreatedFaces();
288 
289  // Matrice de transformation :
290  CTransformationMatrix globalMatrix = FParameterPosition->getTransformationMatrix();
291 
292  // Initialisations OpenGL :
293  glLineWidth(FParameterPreview->getLWPreview());
294  glColor3fv(FParameterPreview->getCLPreview());
295 
296  glBegin(GL_LINES);
297 
298  switch (FParameterCreation->getMeshDimension())
299  {
300  case 1:
301  {
302  /* ARETE */
303  drawMesh1(globalMatrix, -OX/2, OX, mesh<1 ? 1 : sx);
304  break;
305  }
306  case 2:
307  {
308  /* RECTANGLE */
309  switch (mesh)
310  {
311  case 0:
312  drawMesh1(globalMatrix, (-OX-OY)/2, OX, 1);
313  drawMesh1(globalMatrix, (+OX-OY)/2, OY, 1);
314  drawMesh1(globalMatrix, (-OX+OY)/2, OX, 1);
315  drawMesh1(globalMatrix, (-OX-OY)/2, OY, 1);
316  break;
317 
318  case 1:
319  drawMesh1(globalMatrix, (-OX-OY)/2, OX, sx);
320  drawMesh1(globalMatrix, (+OX-OY)/2, OY, sy);
321  drawMesh1(globalMatrix, (-OX+OY)/2, OX, sx);
322  drawMesh1(globalMatrix, (-OX-OY)/2, OY, sy);
323  break;
324 
325  case 2:
326  drawMesh2(globalMatrix, -(OX+OY)/2, OX, sx, OY, sy);
327  break;
328  }
329  break;
330  }
331  case 3:
332  {
333  /* CUBE */
334  switch (mesh)
335  {
336  case 0:
337  sx = sy = sz = 1;
338 
339  case 1:
340  if ((F & CUBE_X1) || (F & CUBE_Y1))
341  drawMesh1(globalMatrix, (-OX-OY-OZ)/2, OZ, sz);
342  if ((F & CUBE_X1) || (F & CUBE_Y2))
343  drawMesh1(globalMatrix, (-OX+OY-OZ)/2, OZ, sz);
344  if ((F & CUBE_X2) || (F & CUBE_Y1))
345  drawMesh1(globalMatrix, (+OX-OY-OZ)/2, OZ, sz);
346  if ((F & CUBE_X2) || (F & CUBE_Y2))
347  drawMesh1(globalMatrix, (+OX+OY-OZ)/2, OZ, sz);
348 
349  if ((F & CUBE_X1) || (F & CUBE_Z1))
350  drawMesh1(globalMatrix, (-OX-OY-OZ)/2, OY, sy);
351  if ((F & CUBE_X1) || (F & CUBE_Z2))
352  drawMesh1(globalMatrix, (-OX-OY+OZ)/2, OY, sy);
353  if ((F & CUBE_X2) || (F & CUBE_Z1))
354  drawMesh1(globalMatrix, (+OX-OY-OZ)/2, OY, sy);
355  if ((F & CUBE_X2) || (F & CUBE_Z2))
356  drawMesh1(globalMatrix, (+OX-OY+OZ)/2, OY, sy);
357 
358  if ((F & CUBE_Y1) || (F & CUBE_Z1))
359  drawMesh1(globalMatrix, (-OX-OY-OZ)/2, OX, sx);
360  if ((F & CUBE_Y1) || (F & CUBE_Z2))
361  drawMesh1(globalMatrix, (-OX-OY+OZ)/2, OX, sx);
362  if ((F & CUBE_Y2) || (F & CUBE_Z1))
363  drawMesh1(globalMatrix, (-OX+OY-OZ)/2, OX, sx);
364  if ((F & CUBE_Y2) || (F & CUBE_Z2))
365  drawMesh1(globalMatrix, (-OX+OY+OZ)/2, OX, sx);
366  break;
367 
368  case 2:
369  if (F & CUBE_X1)
370  drawMesh2(globalMatrix, (-OX-OY-OZ)/2, OY, sy, OZ, sz);
371  if (F & CUBE_X2)
372  drawMesh2(globalMatrix, (+OX-OY-OZ)/2, OY, sy, OZ, sz);
373 
374  if (F & CUBE_Y1)
375  drawMesh2(globalMatrix, (-OX-OY-OZ)/2, OX, sx, OZ, sz);
376  if (F & CUBE_Y2)
377  drawMesh2(globalMatrix, (-OX+OY-OZ)/2, OX, sx, OZ, sz);
378 
379  if (F & CUBE_Z1)
380  drawMesh2(globalMatrix, (-OX-OY-OZ)/2, OX, sx, OY, sy);
381  if (F & CUBE_Z2)
382  drawMesh2(globalMatrix, (-OX-OY+OZ)/2, OX, sx, OY, sy);
383  break;
384 
385  case 3:
386  drawMesh3(globalMatrix, -(OX+OY+OZ)/2, OX, sx, OY, sy, OZ, sz);
387  break;
388  }
389 
390  glEnd();
391 
392  // Faces ignorées :
393  if (mesh<3)
394  {
395  CVertex v[2][2][2];
396 
397  v[0][0][0] = (-OX-OY-OZ)/2; v[1][0][0]= (+OX-OY-OZ)/2;
398  v[0][0][1] = (-OX-OY+OZ)/2; v[1][0][1]= (+OX-OY+OZ)/2;
399  v[0][1][0] = (-OX+OY-OZ)/2; v[1][1][0]= (+OX+OY-OZ)/2;
400  v[0][1][1] = (-OX+OY+OZ)/2; v[1][1][1]= (+OX+OY+OZ)/2;
401 
402  for (int i=0; i<8; ++i)
403  globalMatrix.applyOn(v[i/4][(i/2)%2][i%2]);
404 
405  // Initialisations OpenGL :
406  glColor3fv(FParameterPreview->getCLPreviewBad());
407  glBegin(GL_LINES);
408 
409  if (mesh == 1)
410  sx = sy = sz = 1;
411 
412  if (sy==1 && sz==1 &&
413  (!(F & CUBE_X1)) && ((F & CUBE_RING_X)==CUBE_RING_X))
414  {
415  LINE(& v[0][0][0], & v[0][1][1]);
416  LINE(& v[0][0][1], & v[0][1][0]);
417  }
418 
419  if (sy==1 && sz==1 &&
420  (!(F & CUBE_X2)) && ((F & CUBE_RING_X)==CUBE_RING_X))
421  {
422  LINE(& v[1][0][0], & v[1][1][1]);
423  LINE(& v[1][0][1], & v[1][1][0]);
424  }
425 
426  if (sx==1 && sz==1 &&
427  (!(F & CUBE_Y1)) && ((F & CUBE_RING_Y)==CUBE_RING_Y))
428  {
429  LINE(& v[0][0][0], & v[1][0][1]);
430  LINE(& v[0][0][1], & v[1][0][0]);
431  }
432 
433  if (sx==1 && sz==1 &&
434  (!(F & CUBE_Y2)) && ((F & CUBE_RING_Y)==CUBE_RING_Y))
435  {
436  LINE(& v[0][1][0], & v[1][1][1]);
437  LINE(& v[0][1][1], & v[1][1][0]);
438  }
439 
440  if (sx==1 && sy==1 &&
441  (!(F & CUBE_Z1)) && ((F & CUBE_RING_Z)==CUBE_RING_Z))
442  {
443  LINE(& v[0][0][0], & v[1][1][0]);
444  LINE(& v[0][1][0], & v[1][0][0]);
445  }
446 
447  if (sx==1 && sy==1 &&
448  (!(F & CUBE_Z2)) && ((F & CUBE_RING_Z)==CUBE_RING_Z))
449  {
450  LINE(& v[0][0][1], & v[1][1][1]);
451  LINE(& v[0][1][1], & v[1][0][1]);
452  }
453 
454  glEnd();
455  }
456  break;
457  }
458  }
459  glEnd();
460 }
461 //******************************************************************************
463 {
464  // Paramètres :
465  int n = FParameterCreation->getPolygonNbEdges();
466 
467  // Matrice de transformation :
468  CTransformationMatrix globalMatrix = FParameterPosition->getTransformationMatrix();
469 
470  // Initialisations OpenGL :
471  glLineWidth(FParameterPreview->getLWPreview());
472  glColor3fv(FParameterPreview->getCLPreview());
473 
474  glBegin(GL_LINE_LOOP);
475  {
476  CTransformationMatrix matrix(CTransformationMatrix::IdentityMatrix);
477  matrix.rotate(OZ, 360.0/n);
478 
479  CVertex x(OX/2);
480  for (int i=0; i<n; ++i)
481  {
482  CVertex V(x);
483  globalMatrix.applyOn(V);
484  PLOT(& V);
485  matrix.applyOn(x);
486  }
487  }
488  glEnd();
489 
490  // Initialisations OpenGL :
491  glColor3fv(FParameterPreview->getCLPreviewBad());
492 
493  // Boîte englobante :
494  glBegin(GL_LINE_LOOP);
495  {
496  CTransformationMatrix matrix(CTransformationMatrix::IdentityMatrix);
497  matrix.rotate(OZ, 90.0);
498 
499  CVertex x((OX-OY)/2);
500  for (int i=0; i<4; ++i)
501  {
502  CVertex V(x);
503  globalMatrix.applyOn(V);
504  PLOT(& V);
505  matrix.applyOn(x);
506  }
507  }
508  glEnd();
509 }
510 //******************************************************************************
512 {
513  if ( FParameterPolylinePosition->getNbVertices()==0 )
514  return;
515 
516  // Initialisations OpenGL :
517  glColor3fv(FParameterPreview->getCLPreview());
518 
519  glPointSize(FParameterPreview->getLWPreviewPoint());
520  glBegin(GL_POINTS);
521  PLOT(&FParameterPolylinePosition->getLastVertex());
522  glEnd();
523 
524  glLineWidth(FParameterPreview->getLWPreview());
525  glBegin(GL_LINE_STRIP);
526 
527  for (unsigned int i=0; i<FParameterPolylinePosition->getNbVertices(); ++i)
528  PLOT(&FParameterPolylinePosition->getVertex(i));
529 
530  glEnd();
531 }
532 //******************************************************************************
534 {
535  // Paramètres :
536  int M = FParameterCreation->getPyramidNbMeridians();
537  int P = FParameterCreation->getPyramidNbParallels();
538  int i,j;
539 
540  // Matrice de transformation :
541  CTransformationMatrix globalMatrix = FParameterPosition->getTransformationMatrix();
542 
543  // Calcul des coordonnées des sommets :
544  CVertex top(OZ/2); globalMatrix.applyOn(top);
545  CVertex** V = new CVertex* [P];
546  for (i=0; i<P; ++i)
547  V[i] = new CVertex[M];
548 
549  CTransformationMatrix rotationMatrix(CTransformationMatrix::IdentityMatrix);
550  rotationMatrix.rotate(OZ, 360.0/M);
551 
552  for (j=0; j<P; ++j)
553  {
554  CVertex vertex = (0.5*(P-j)/P)*OX + (((float) j)/P-0.5)*OZ;
555 
556  for (i=0; i<M; ++i)
557  {
558  V[j][i] = vertex;
559  globalMatrix.applyOn(V[j][i]);
560  rotationMatrix.applyOn(vertex);
561  }
562 
563  vertex += OZ / (P+1);
564  }
565 
566  // Initialisations OpenGL :
567  glLineWidth(FParameterPreview->getLWPreview());
568  glColor3fv(FParameterPreview->getCLPreview());
569 
570  // Meridiens :
571  glBegin(GL_LINES);
572 
573  for (i=0; i<M; ++i)
574  LINE(&top,&V[0][i]);
575 
576  // Parallèles :
577  for (j=0; j<P; j++)
578  for (i=0; i<M; ++i)
579  LINE(& V[j][i], & V[j][(i+1)%M]);
580 
581  glEnd();
582 
583  // Base ignorée :
584  TCoordinate x[2],y[2];
585 
586  for (i=0; i<2; ++i)
587  {
588  int k0 = (1+4*i)*M/8;
589 
590  TCoordinate x1 = dCos(360.0/M* k0 )/2;
591  TCoordinate y1 = dSin(360.0/M* k0 )/2;
592  TCoordinate x2 = dCos(360.0/M*(k0+1))/2;
593  TCoordinate y2 = dSin(360.0/M*(k0+1))/2;
594 
595  TCoordinate t = (x1-y1) / (x1-x2+y2-y1);
596 
597  x[i] = x1 + t*(x2-x1);
598  y[i] = y1 + t*(y2-y1);
599  }
600 
601  // Initialisations OpenGL :
602  glColor3fv(FParameterPreview->getCLPreviewBad());
603  glBegin(GL_LINES);
604 
605  if (! FParameterCreation->getPyramidClosed())
606  {
607  CVertex v0, v1;
608 
609  v0.setXYZ(x[0], y[0],-0.5); globalMatrix.applyOn(v0);
610  v1.setXYZ(x[1], y[1],-0.5); globalMatrix.applyOn(v1); LINE(& v0, & v1);
611  v0.setXYZ(x[0],-y[0],-0.5); globalMatrix.applyOn(v0);
612  v1.setXYZ(x[1],-y[1],-0.5); globalMatrix.applyOn(v1); LINE(& v0, & v1);
613  }
614 
615  glEnd();
616 
617  for (i=0; i<P; ++i)
618  delete [] V[i];
619  delete [] V;
620 }
621 //******************************************************************************
623 {
624  // Paramètres :
625  int M = FParameterCreation->getSphereNbMeridians();
626  int P = FParameterCreation->getSphereNbParallels();
627  int i,j;
628 
629  // Matrice de transformation :
630  CTransformationMatrix globalMatrix = FParameterPosition->getTransformationMatrix();
631 
632  // Calcul des coordonnées :
633  CVertex south= -OZ/2; globalMatrix.applyOn(south);
634  CVertex north= +OZ/2; globalMatrix.applyOn(north);
635  CVertex v0,v1;
636 
637  CVertex** grid = new CVertex*[P];
638  for (i=0; i<P; ++i)
639  grid[i] = new CVertex[M];
640 
641  CTransformationMatrix matrix(CTransformationMatrix::IdentityMatrix);
642  matrix.rotate(OZ, 360.0 / M);
643 
644  for (j=0; j<P; ++j)
645  {
646  TCoordinate alpha = 180.0*(j+1)/(P+1) - 90.0;
647 
648  CVertex v = dCos(alpha) / 2 * OX + dSin(alpha) / 2 * OZ;
649 
650  for (i=0; i<M; ++i)
651  {
652  grid[j][i]= v;
653  globalMatrix.applyOn(grid[j][i]);
654  matrix.applyOn(v);
655  }
656  }
657 
658  // Initialisations OpenGL :
659  glLineWidth(FParameterPreview->getLWPreview());
660  glColor3fv(FParameterPreview->getCLPreview());
661 
662  // Méridiens:
663  for (i=0; i<M; i++)
664  {
665  glBegin(GL_LINE_STRIP);
666  PLOT(& south);
667 
668  for (j=0; j<P; j++)
669  PLOT(& grid[j][i]);
670 
671  PLOT(& north);
672  glEnd();
673  }
674 
675  // Parallèles:
676  for (j=0; j<P; j++)
677  {
678  glBegin(GL_LINE_LOOP);
679 
680  for (i=0; i<M; i++)
681  PLOT(& grid[j][i]);
682 
683  glEnd();
684  }
685 
686  for (i=0; i<P; ++i)
687  delete [] grid[i];
688  delete [] grid;
689 }
690 //******************************************************************************
692 {
693  // Paramètres :
694  int M = FParameterCreation->getTorusNbMeridians();
695  int P = FParameterCreation->getTorusNbParallels();
696  float k = FParameterCreation->getTorusRadiusRapport();
697  int i,j;
698 
699  // Matrice de transformation :
700  CTransformationMatrix globalMatrix = FParameterPosition->getTransformationMatrix();
701 
702  // Calcul des coordonnées :
703  float _R_ = 1/(1+k)/2;
704  float R_ = k/(1+k)/2;
705 
706  // Coordonnées des sommets :
707  CTransformationMatrix matrix1(CTransformationMatrix::IdentityMatrix);
708  CTransformationMatrix matrix2(CTransformationMatrix::IdentityMatrix);
709  CTransformationMatrix matrix3(CTransformationMatrix::IdentityMatrix);
710 
711  matrix1.rotate(OY, 360.0 / P);
712  matrix2.translate(_R_ * OX);
713  matrix3.rotate(OZ, 360.0 / M);
714 
715  CVertex vertex1(R_ * OX);
716  CVertex** grid = new CVertex*[P];
717  for (i=0; i<P; ++i)
718  grid[i] = new CVertex[M];
719 
720  for (j=0; j<P; ++j)
721  {
722  CVertex vertex2(vertex1);
723  matrix2.applyOn(vertex2);
724 
725  for (i=0; i<M; ++i)
726  {
727  grid[j][i] = vertex2;
728  globalMatrix.applyOn(grid[j][i]);
729  matrix3.applyOn(vertex2);
730  }
731 
732  matrix1.applyOn(vertex1);
733  }
734 
735  // Initialisations OpenGL :
736  glLineWidth(FParameterPreview->getLWPreview());
737  glColor3fv(FParameterPreview->getCLPreview());
738 
739  // Méridiens :
740  for (i=0; i<M; i++)
741  {
742  glBegin(GL_LINE_LOOP);
743 
744  for (j=0; j<P; j++)
745  PLOT(& grid[j][i]);
746 
747  glEnd();
748  }
749 
750  // Parallèles :
751  for (j=0; j<P; j++)
752  {
753  glBegin(GL_LINE_LOOP);
754 
755  for (i=0; i<M; i++)
756  PLOT(& grid[j][i]);
757 
758  glEnd();
759  }
760 
761  for (i=0; i<P; ++i)
762  delete [] grid[i];
763  delete [] grid;
764 }
765 //******************************************************************************
766 #define K (0.015)
767 
768 void CPrecompilePreview::drawMesh1(const CTransformationMatrix & AMatrix,
769  const CVertex & AOrigin,
770  const CVertex & AVector, int ASx)
771 {
772  CVertex v1, v2;
773 
774  if (ASx > 1)
775  {
776  CVertex current = AOrigin;
777  CVertex dx = AVector / ASx;
778 
779  for (int i=0; i<=ASx; ++i, current += dx)
780  {
781  v1 = current - K*OX; AMatrix.applyOn(v1);
782  v2 = current + K*OX; AMatrix.applyOn(v2); LINE(&v1,&v2);
783 
784  v1 = current - K*OY; AMatrix.applyOn(v1);
785  v2 = current + K*OY; AMatrix.applyOn(v2); LINE(&v1,&v2);
786 
787  v1 = current - K*OZ; AMatrix.applyOn(v1);
788  v2 = current + K*OZ; AMatrix.applyOn(v2); LINE(&v1,&v2);
789  }
790  }
791 
792  v1 = AOrigin ; AMatrix.applyOn(v1);
793  v2 = AOrigin + AVector; AMatrix.applyOn(v2); LINE(&v1,&v2);
794 }
795 
796 #undef K
797 //******************************************************************************
798 void CPrecompilePreview::drawMesh2(const CTransformationMatrix & AMatrix,
799  const CVertex & AOrigin,
800  const CVertex & AVectorX, int ASx,
801  const CVertex & AVectorY, int ASy)
802 {
803  CVertex v1, v2;
804 
805  CVertex dx = AVectorX / ASx;
806  CVertex dy = AVectorY / ASy;
807 
808  CVertex current;
809 
810  current = AOrigin;
811  for (int i=0; i<=ASx; ++i, current += dx)
812  {
813  v1 = current ; AMatrix.applyOn(v1);
814  v2 = current + AVectorY; AMatrix.applyOn(v2); LINE(& v1, & v2);
815  }
816 
817  current = AOrigin;
818  for (int j=0; j<=ASy; ++j, current += dy)
819  {
820  v1 = current ; AMatrix.applyOn(v1);
821  v2 = current + AVectorX; AMatrix.applyOn(v2); LINE(& v1, & v2);
822  }
823 }
824 //******************************************************************************
825 void CPrecompilePreview::drawMesh3(const CTransformationMatrix & AMatrix,
826  const CVertex & AOrigin,
827  const CVertex & AVectorX, int ASx,
828  const CVertex & AVectorY, int ASy,
829  const CVertex & AVectorZ, int ASz)
830 {
831  CVertex v1, v2;
832 
833  CVertex dx = AVectorX / ASx;
834  CVertex dy = AVectorY / ASy;
835  CVertex dz = AVectorZ / ASz;
836 
837  CVertex currentX, currentY, currentZ;
838  int i,j,k;
839 
840  currentX = AOrigin;
841  for (i=0; i<=ASx; ++i, currentX += dx)
842  {
843  currentY = currentX;
844 
845  for (j=0; j<=ASy; ++j, currentY += dy)
846  {
847  v1 = currentY ; AMatrix.applyOn(v1);
848  v2 = currentY + AVectorZ; AMatrix.applyOn(v2); LINE(& v1, & v2);
849  }
850  }
851 
852  currentX = AOrigin;
853  for (i=0; i<=ASx; ++i, currentX += dx)
854  {
855  currentZ = currentX;
856 
857  for (k=0; k<=ASz; ++k, currentZ += dz)
858  {
859  v1 = currentZ ; AMatrix.applyOn(v1);
860  v2 = currentZ + AVectorY; AMatrix.applyOn(v2); LINE(& v1, & v2);
861  }
862  }
863 
864  currentY = AOrigin;
865  for (j=0; j<=ASy; ++j, currentY += dy)
866  {
867  currentZ = currentY;
868 
869  for (k=0; k<=ASz; ++k, currentZ += dz)
870  {
871  v1 = currentZ ; AMatrix.applyOn(v1);
872  v2 = currentZ + AVectorX; AMatrix.applyOn(v2); LINE(& v1, & v2);
873  }
874  }
875 }
876 //******************************************************************************