00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "controler-gmap-types.hh"
00026 #include "precompile-preview.hh"
00027 #include "parameter-preview.hh"
00028 #include "parameter-object-position.hh"
00029 #include "parameter-polyline-position.hh"
00030 #include "parameter-creation.hh"
00031 #include "transformation-matrix.hh"
00032 #include "vertex.hh"
00033 #include <cassert>
00034 using namespace GMap3d;
00035
00036 CPrecompilePreview::CPrecompilePreview(CParameterPreview * APreview,
00037 CParameterObjectPosition * APosition,
00038 CParameterCreation * AParams,
00039 CParameterPolylinePosition * APolylinePosition) :
00040 FParameterPreview (APreview),
00041 FParameterPosition (APosition),
00042 FParameterCreation (AParams),
00043 FParameterPolylinePosition(APolylinePosition)
00044 {
00045 assert(FParameterPreview != NULL);
00046 assert(FParameterPosition != NULL);
00047 assert(FParameterCreation != NULL);
00048 assert(FParameterPolylinePosition != NULL);
00049
00050 FParameterPreview->addPrecompileToUpdate(this);
00051 FParameterPosition->addPrecompileToUpdate(this);
00052 FParameterCreation->addPrecompileToUpdate(this);
00053 FParameterPolylinePosition->addPrecompileToUpdate(this);
00054 disable();
00055 }
00056
00057 CPrecompilePreview::CPrecompilePreview(const CPrecompilePreview & APrecompile) :
00058 CPrecompile (APrecompile),
00059 FParameterPreview (static_cast<CParameterPreview*>
00060 (APrecompile.FParameterPreview->copy())),
00061 FParameterPosition (APrecompile.FParameterPosition),
00062 FParameterCreation (APrecompile.FParameterCreation),
00063 FParameterPolylinePosition(APrecompile.FParameterPolylinePosition)
00064 {
00065 assert(FParameterPreview != NULL);
00066 assert(FParameterPosition != NULL);
00067 assert(FParameterCreation != NULL);
00068 assert(FParameterPolylinePosition != NULL);
00069
00070 FParameterPreview->addPrecompileToUpdate(this);
00071 FParameterPosition->addPrecompileToUpdate(this);
00072 FParameterCreation->addPrecompileToUpdate(this);
00073 FParameterPolylinePosition->addPrecompileToUpdate(this);
00074 disable();
00075 }
00076
00077 CPrecompilePreview::~CPrecompilePreview()
00078 {
00079 FParameterPreview->removePrecompileToUpdate(this);
00080 FParameterPosition->removePrecompileToUpdate(this);
00081 FParameterCreation->removePrecompileToUpdate(this);
00082 FParameterPolylinePosition->removePrecompileToUpdate(this);
00083 }
00084
00085 CPrecompile * CPrecompilePreview::copy() const
00086 { return new CPrecompilePreview(*this); }
00087
00088 void CPrecompilePreview::setParameter(CParameter * AParameter)
00089 {
00090 switch (AParameter->getType())
00091 {
00092 case PARAMETER_PREVIEW:
00093 setPreview(static_cast<CParameterPreview *>(AParameter));
00094 break;
00095 case PARAMETER_OBJECT_POSITION:
00096 setPosition(static_cast<CParameterObjectPosition *>(AParameter));
00097 break;
00098 case PARAMETER_CREATION:
00099 setCreation(static_cast<CParameterCreation *>(AParameter));
00100 break;
00101 case PARAMETER_POLYLINE_POSITION:
00102 setPolylinePosition(static_cast<CParameterPolylinePosition *>(AParameter));
00103 break;
00104 }
00105 }
00106
00107 CParameter* CPrecompilePreview::getParameter() const
00108 { return FParameterPreview; }
00109
00110 void CPrecompilePreview::setPreview(CParameterPreview * APreview)
00111 {
00112 assert(APreview != NULL);
00113 APreview->addPrecompileToUpdate(this);
00114 FParameterPreview->removePrecompileToUpdate(this);
00115 FParameterPreview = APreview;
00116 setToUpdate();
00117 }
00118
00119 void CPrecompilePreview::setPosition(CParameterObjectPosition * APosition)
00120 {
00121 assert(APosition != NULL);
00122 APosition->addPrecompileToUpdate(this);
00123 FParameterPosition->removePrecompileToUpdate(this);
00124 FParameterPosition = APosition;
00125 setToUpdate();
00126 }
00127
00128 void CPrecompilePreview::setCreation(CParameterCreation * ACreation)
00129 {
00130 assert(ACreation != NULL);
00131 ACreation->addPrecompileToUpdate(this);
00132 FParameterCreation->removePrecompileToUpdate(this);
00133 FParameterCreation = ACreation;
00134 setToUpdate();
00135 }
00136
00137 void CPrecompilePreview::setPolylinePosition(CParameterPolylinePosition *
00138 APolylinePosition)
00139 {
00140 assert(APolylinePosition != NULL);
00141 APolylinePosition->addPrecompileToUpdate(this);
00142 FParameterPolylinePosition->removePrecompileToUpdate(this);
00143 FParameterPolylinePosition = APolylinePosition;
00144 setToUpdate();
00145 }
00146
00147 TPrecompile CPrecompilePreview::getType() const
00148 { return PRECOMPILE_PREVIEW; }
00149
00150 void CPrecompilePreview::setCurrentMode(TMode AMode)
00151 {
00152 if ( AMode!=FCurrentMode )
00153 {
00154 FCurrentMode = AMode;
00155 setToUpdate();
00156 }
00157 }
00158
00159 void CPrecompilePreview::drawModel()
00160 {
00161 switch(FCurrentMode)
00162 {
00163 case MODE_CREATION_CYLINDER: drawCylinder(); break;
00164 case MODE_CREATION_MESH : drawMesh(); break;
00165 case MODE_CREATION_POLYGON : drawPolygon(); break;
00166 case MODE_CREATION_POLYLINE: drawPolyline(); break;
00167 case MODE_CREATION_PYRAMID : drawPyramid(); break;
00168 case MODE_CREATION_SPHERE : drawSphere(); break;
00169 case MODE_CREATION_TORUS : drawTorus(); break;
00170 }
00171 }
00172
00173 void CPrecompilePreview::drawCylinder()
00174 {
00175
00176 int M = FParameterCreation->getCylinderNbMeridians();
00177 int P = FParameterCreation->getCylinderNbParallels();
00178 int i,j;
00179
00180
00181 CTransformationMatrix globalMatrix =
00182 FParameterPosition->getTransformationMatrix();
00183
00184
00185 CVertex** V;
00186 V = new CVertex*[P+1];
00187 for (i=0; i<=P; ++i)
00188 V[i] = new CVertex[M];
00189
00190 CVertex vertex((OX-OZ) / 2);
00191 CTransformationMatrix rotationMatrix(CTransformationMatrix::IdentityMatrix);
00192 rotationMatrix.rotate(OZ, 360.0/M);
00193
00194 for (i=0; i<M; ++i)
00195 {
00196 for (j=0; j<=P; ++j)
00197 {
00198 V[j][i] = vertex;
00199 globalMatrix.applyOn(V[j][i]);
00200 if (j<P)
00201 vertex += OZ/P;
00202 }
00203
00204 vertex -= OZ;
00205 rotationMatrix.applyOn(vertex);
00206 }
00207
00208
00209 glLineWidth(FParameterPreview->getLWPreview());
00210 glColor3fv(FParameterPreview->getCLPreview());
00211
00212
00213 glBegin(GL_LINES);
00214
00215 for (i=0; i<M; ++i)
00216 LINE(&V[0][i],&V[P][i]);
00217
00218 glEnd();
00219
00220
00221 for (j=0; j<=P; ++j)
00222 {
00223 glBegin(GL_LINE_LOOP);
00224
00225 for (i=0; i<M; ++i)
00226 PLOT(&V[j][i]);
00227
00228 glEnd();
00229 }
00230
00231
00232 TCoordinate x[2],y[2];
00233
00234 for (i=0; i<2; ++i)
00235 {
00236 int k0 = (1+4*i)*M/8;
00237
00238 TCoordinate x1= dCos(360.0/M* k0 );
00239 TCoordinate y1= dSin(360.0/M* k0 );
00240 TCoordinate x2= dCos(360.0/M*(k0+1));
00241 TCoordinate y2= dSin(360.0/M*(k0+1));
00242
00243 TCoordinate t = (x1-y1) / (x1-x2+y2-y1);
00244
00245 x[i] = (x1 + t*(x2-x1)) / 2;
00246 y[i] = (y1 + t*(y2-y1)) / 2;
00247 }
00248
00249
00250 glColor3fv(FParameterPreview->getCLPreviewBad());
00251 glBegin(GL_LINES);
00252
00253 CVertex v0, v1;
00254
00255 if (! FParameterCreation->getCylinderClosedUp())
00256 {
00257 v0.setXYZ(x[0], y[0],-0.5); globalMatrix.applyOn(v0);
00258 v1.setXYZ(x[1], y[1],-0.5); globalMatrix.applyOn(v1); LINE(& v0, & v1);
00259 v0.setXYZ(x[0],-y[0],-0.5); globalMatrix.applyOn(v0);
00260 v1.setXYZ(x[1],-y[1],-0.5); globalMatrix.applyOn(v1); LINE(& v0, & v1);
00261 }
00262
00263 if (! FParameterCreation->getCylinderClosedDown())
00264 {
00265 v0.setXYZ(x[0], y[0], 0.5); globalMatrix.applyOn(v0);
00266 v1.setXYZ(x[1], y[1], 0.5); globalMatrix.applyOn(v1); LINE(& v0, & v1);
00267 v0.setXYZ(x[0],-y[0], 0.5); globalMatrix.applyOn(v0);
00268 v1.setXYZ(x[1],-y[1], 0.5); globalMatrix.applyOn(v1); LINE(& v0, & v1);
00269 }
00270
00271 glEnd();
00272
00273 for (i=0; i<=P; ++i)
00274 delete [] V[i];
00275
00276 delete [] V;
00277 }
00278
00279 void CPrecompilePreview::drawMesh()
00280 {
00281
00282 int mesh = FParameterCreation->getMeshSubdivisionDimension();
00283
00284 int sx = FParameterCreation->getMeshNbSubdivisionsX();
00285 int sy = FParameterCreation->getMeshNbSubdivisionsY();
00286 int sz = FParameterCreation->getMeshNbSubdivisionsZ();
00287 unsigned char F = FParameterCreation->getMeshCreatedFaces();
00288
00289
00290 CTransformationMatrix globalMatrix = FParameterPosition->getTransformationMatrix();
00291
00292
00293 glLineWidth(FParameterPreview->getLWPreview());
00294 glColor3fv(FParameterPreview->getCLPreview());
00295
00296 glBegin(GL_LINES);
00297
00298 switch (FParameterCreation->getMeshDimension())
00299 {
00300 case 1:
00301 {
00302
00303 drawMesh1(globalMatrix, -OX/2, OX, mesh<1 ? 1 : sx);
00304 break;
00305 }
00306 case 2:
00307 {
00308
00309 switch (mesh)
00310 {
00311 case 0:
00312 drawMesh1(globalMatrix, (-OX-OY)/2, OX, 1);
00313 drawMesh1(globalMatrix, (+OX-OY)/2, OY, 1);
00314 drawMesh1(globalMatrix, (-OX+OY)/2, OX, 1);
00315 drawMesh1(globalMatrix, (-OX-OY)/2, OY, 1);
00316 break;
00317
00318 case 1:
00319 drawMesh1(globalMatrix, (-OX-OY)/2, OX, sx);
00320 drawMesh1(globalMatrix, (+OX-OY)/2, OY, sy);
00321 drawMesh1(globalMatrix, (-OX+OY)/2, OX, sx);
00322 drawMesh1(globalMatrix, (-OX-OY)/2, OY, sy);
00323 break;
00324
00325 case 2:
00326 drawMesh2(globalMatrix, -(OX+OY)/2, OX, sx, OY, sy);
00327 break;
00328 }
00329 break;
00330 }
00331 case 3:
00332 {
00333
00334 switch (mesh)
00335 {
00336 case 0:
00337 sx = sy = sz = 1;
00338
00339 case 1:
00340 if ((F & CUBE_X1) || (F & CUBE_Y1))
00341 drawMesh1(globalMatrix, (-OX-OY-OZ)/2, OZ, sz);
00342 if ((F & CUBE_X1) || (F & CUBE_Y2))
00343 drawMesh1(globalMatrix, (-OX+OY-OZ)/2, OZ, sz);
00344 if ((F & CUBE_X2) || (F & CUBE_Y1))
00345 drawMesh1(globalMatrix, (+OX-OY-OZ)/2, OZ, sz);
00346 if ((F & CUBE_X2) || (F & CUBE_Y2))
00347 drawMesh1(globalMatrix, (+OX+OY-OZ)/2, OZ, sz);
00348
00349 if ((F & CUBE_X1) || (F & CUBE_Z1))
00350 drawMesh1(globalMatrix, (-OX-OY-OZ)/2, OY, sy);
00351 if ((F & CUBE_X1) || (F & CUBE_Z2))
00352 drawMesh1(globalMatrix, (-OX-OY+OZ)/2, OY, sy);
00353 if ((F & CUBE_X2) || (F & CUBE_Z1))
00354 drawMesh1(globalMatrix, (+OX-OY-OZ)/2, OY, sy);
00355 if ((F & CUBE_X2) || (F & CUBE_Z2))
00356 drawMesh1(globalMatrix, (+OX-OY+OZ)/2, OY, sy);
00357
00358 if ((F & CUBE_Y1) || (F & CUBE_Z1))
00359 drawMesh1(globalMatrix, (-OX-OY-OZ)/2, OX, sx);
00360 if ((F & CUBE_Y1) || (F & CUBE_Z2))
00361 drawMesh1(globalMatrix, (-OX-OY+OZ)/2, OX, sx);
00362 if ((F & CUBE_Y2) || (F & CUBE_Z1))
00363 drawMesh1(globalMatrix, (-OX+OY-OZ)/2, OX, sx);
00364 if ((F & CUBE_Y2) || (F & CUBE_Z2))
00365 drawMesh1(globalMatrix, (-OX+OY+OZ)/2, OX, sx);
00366 break;
00367
00368 case 2:
00369 if (F & CUBE_X1)
00370 drawMesh2(globalMatrix, (-OX-OY-OZ)/2, OY, sy, OZ, sz);
00371 if (F & CUBE_X2)
00372 drawMesh2(globalMatrix, (+OX-OY-OZ)/2, OY, sy, OZ, sz);
00373
00374 if (F & CUBE_Y1)
00375 drawMesh2(globalMatrix, (-OX-OY-OZ)/2, OX, sx, OZ, sz);
00376 if (F & CUBE_Y2)
00377 drawMesh2(globalMatrix, (-OX+OY-OZ)/2, OX, sx, OZ, sz);
00378
00379 if (F & CUBE_Z1)
00380 drawMesh2(globalMatrix, (-OX-OY-OZ)/2, OX, sx, OY, sy);
00381 if (F & CUBE_Z2)
00382 drawMesh2(globalMatrix, (-OX-OY+OZ)/2, OX, sx, OY, sy);
00383 break;
00384
00385 case 3:
00386 drawMesh3(globalMatrix, -(OX+OY+OZ)/2, OX, sx, OY, sy, OZ, sz);
00387 break;
00388 }
00389
00390 glEnd();
00391
00392
00393 if (mesh<3)
00394 {
00395 CVertex v[2][2][2];
00396
00397 v[0][0][0] = (-OX-OY-OZ)/2; v[1][0][0]= (+OX-OY-OZ)/2;
00398 v[0][0][1] = (-OX-OY+OZ)/2; v[1][0][1]= (+OX-OY+OZ)/2;
00399 v[0][1][0] = (-OX+OY-OZ)/2; v[1][1][0]= (+OX+OY-OZ)/2;
00400 v[0][1][1] = (-OX+OY+OZ)/2; v[1][1][1]= (+OX+OY+OZ)/2;
00401
00402 for (int i=0; i<8; ++i)
00403 globalMatrix.applyOn(v[i/4][(i/2)%2][i%2]);
00404
00405
00406 glColor3fv(FParameterPreview->getCLPreviewBad());
00407 glBegin(GL_LINES);
00408
00409 if (mesh == 1)
00410 sx = sy = sz = 1;
00411
00412 if (sy==1 && sz==1 &&
00413 (!(F & CUBE_X1)) && ((F & CUBE_RING_X)==CUBE_RING_X))
00414 {
00415 LINE(& v[0][0][0], & v[0][1][1]);
00416 LINE(& v[0][0][1], & v[0][1][0]);
00417 }
00418
00419 if (sy==1 && sz==1 &&
00420 (!(F & CUBE_X2)) && ((F & CUBE_RING_X)==CUBE_RING_X))
00421 {
00422 LINE(& v[1][0][0], & v[1][1][1]);
00423 LINE(& v[1][0][1], & v[1][1][0]);
00424 }
00425
00426 if (sx==1 && sz==1 &&
00427 (!(F & CUBE_Y1)) && ((F & CUBE_RING_Y)==CUBE_RING_Y))
00428 {
00429 LINE(& v[0][0][0], & v[1][0][1]);
00430 LINE(& v[0][0][1], & v[1][0][0]);
00431 }
00432
00433 if (sx==1 && sz==1 &&
00434 (!(F & CUBE_Y2)) && ((F & CUBE_RING_Y)==CUBE_RING_Y))
00435 {
00436 LINE(& v[0][1][0], & v[1][1][1]);
00437 LINE(& v[0][1][1], & v[1][1][0]);
00438 }
00439
00440 if (sx==1 && sy==1 &&
00441 (!(F & CUBE_Z1)) && ((F & CUBE_RING_Z)==CUBE_RING_Z))
00442 {
00443 LINE(& v[0][0][0], & v[1][1][0]);
00444 LINE(& v[0][1][0], & v[1][0][0]);
00445 }
00446
00447 if (sx==1 && sy==1 &&
00448 (!(F & CUBE_Z2)) && ((F & CUBE_RING_Z)==CUBE_RING_Z))
00449 {
00450 LINE(& v[0][0][1], & v[1][1][1]);
00451 LINE(& v[0][1][1], & v[1][0][1]);
00452 }
00453
00454 glEnd();
00455 }
00456 break;
00457 }
00458 }
00459 glEnd();
00460 }
00461
00462 void CPrecompilePreview::drawPolygon()
00463 {
00464
00465 int n = FParameterCreation->getPolygonNbEdges();
00466
00467
00468 CTransformationMatrix globalMatrix = FParameterPosition->getTransformationMatrix();
00469
00470
00471 glLineWidth(FParameterPreview->getLWPreview());
00472 glColor3fv(FParameterPreview->getCLPreview());
00473
00474 glBegin(GL_LINE_LOOP);
00475 {
00476 CTransformationMatrix matrix(CTransformationMatrix::IdentityMatrix);
00477 matrix.rotate(OZ, 360.0/n);
00478
00479 CVertex x(OX/2);
00480 for (int i=0; i<n; ++i)
00481 {
00482 CVertex V(x);
00483 globalMatrix.applyOn(V);
00484 PLOT(& V);
00485 matrix.applyOn(x);
00486 }
00487 }
00488 glEnd();
00489
00490
00491 glColor3fv(FParameterPreview->getCLPreviewBad());
00492
00493
00494 glBegin(GL_LINE_LOOP);
00495 {
00496 CTransformationMatrix matrix(CTransformationMatrix::IdentityMatrix);
00497 matrix.rotate(OZ, 90.0);
00498
00499 CVertex x((OX-OY)/2);
00500 for (int i=0; i<4; ++i)
00501 {
00502 CVertex V(x);
00503 globalMatrix.applyOn(V);
00504 PLOT(& V);
00505 matrix.applyOn(x);
00506 }
00507 }
00508 glEnd();
00509 }
00510
00511 void CPrecompilePreview::drawPolyline()
00512 {
00513 if ( FParameterPolylinePosition->getNbVertices()==0 )
00514 return;
00515
00516
00517 glColor3fv(FParameterPreview->getCLPreview());
00518
00519 glPointSize(FParameterPreview->getLWPreviewPoint());
00520 glBegin(GL_POINTS);
00521 PLOT(&FParameterPolylinePosition->getLastVertex());
00522 glEnd();
00523
00524 glLineWidth(FParameterPreview->getLWPreview());
00525 glBegin(GL_LINE_STRIP);
00526
00527 for (unsigned int i=0; i<FParameterPolylinePosition->getNbVertices(); ++i)
00528 PLOT(&FParameterPolylinePosition->getVertex(i));
00529
00530 glEnd();
00531 }
00532
00533 void CPrecompilePreview::drawPyramid()
00534 {
00535
00536 int M = FParameterCreation->getPyramidNbMeridians();
00537 int P = FParameterCreation->getPyramidNbParallels();
00538 int i,j;
00539
00540
00541 CTransformationMatrix globalMatrix = FParameterPosition->getTransformationMatrix();
00542
00543
00544 CVertex top(OZ/2); globalMatrix.applyOn(top);
00545 CVertex** V = new CVertex* [P];
00546 for (i=0; i<P; ++i)
00547 V[i] = new CVertex[M];
00548
00549 CTransformationMatrix rotationMatrix(CTransformationMatrix::IdentityMatrix);
00550 rotationMatrix.rotate(OZ, 360.0/M);
00551
00552 for (j=0; j<P; ++j)
00553 {
00554 CVertex vertex = (0.5*(P-j)/P)*OX + (((float) j)/P-0.5)*OZ;
00555
00556 for (i=0; i<M; ++i)
00557 {
00558 V[j][i] = vertex;
00559 globalMatrix.applyOn(V[j][i]);
00560 rotationMatrix.applyOn(vertex);
00561 }
00562
00563 vertex += OZ / (P+1);
00564 }
00565
00566
00567 glLineWidth(FParameterPreview->getLWPreview());
00568 glColor3fv(FParameterPreview->getCLPreview());
00569
00570
00571 glBegin(GL_LINES);
00572
00573 for (i=0; i<M; ++i)
00574 LINE(&top,&V[0][i]);
00575
00576
00577 for (j=0; j<P; j++)
00578 for (i=0; i<M; ++i)
00579 LINE(& V[j][i], & V[j][(i+1)%M]);
00580
00581 glEnd();
00582
00583
00584 TCoordinate x[2],y[2];
00585
00586 for (i=0; i<2; ++i)
00587 {
00588 int k0 = (1+4*i)*M/8;
00589
00590 TCoordinate x1 = dCos(360.0/M* k0 )/2;
00591 TCoordinate y1 = dSin(360.0/M* k0 )/2;
00592 TCoordinate x2 = dCos(360.0/M*(k0+1))/2;
00593 TCoordinate y2 = dSin(360.0/M*(k0+1))/2;
00594
00595 TCoordinate t = (x1-y1) / (x1-x2+y2-y1);
00596
00597 x[i] = x1 + t*(x2-x1);
00598 y[i] = y1 + t*(y2-y1);
00599 }
00600
00601
00602 glColor3fv(FParameterPreview->getCLPreviewBad());
00603 glBegin(GL_LINES);
00604
00605 if (! FParameterCreation->getPyramidClosed())
00606 {
00607 CVertex v0, v1;
00608
00609 v0.setXYZ(x[0], y[0],-0.5); globalMatrix.applyOn(v0);
00610 v1.setXYZ(x[1], y[1],-0.5); globalMatrix.applyOn(v1); LINE(& v0, & v1);
00611 v0.setXYZ(x[0],-y[0],-0.5); globalMatrix.applyOn(v0);
00612 v1.setXYZ(x[1],-y[1],-0.5); globalMatrix.applyOn(v1); LINE(& v0, & v1);
00613 }
00614
00615 glEnd();
00616
00617 for (i=0; i<P; ++i)
00618 delete [] V[i];
00619 delete [] V;
00620 }
00621
00622 void CPrecompilePreview::drawSphere()
00623 {
00624
00625 int M = FParameterCreation->getSphereNbMeridians();
00626 int P = FParameterCreation->getSphereNbParallels();
00627 int i,j;
00628
00629
00630 CTransformationMatrix globalMatrix = FParameterPosition->getTransformationMatrix();
00631
00632
00633 CVertex south= -OZ/2; globalMatrix.applyOn(south);
00634 CVertex north= +OZ/2; globalMatrix.applyOn(north);
00635 CVertex v0,v1;
00636
00637 CVertex** grid = new CVertex*[P];
00638 for (i=0; i<P; ++i)
00639 grid[i] = new CVertex[M];
00640
00641 CTransformationMatrix matrix(CTransformationMatrix::IdentityMatrix);
00642 matrix.rotate(OZ, 360.0 / M);
00643
00644 for (j=0; j<P; ++j)
00645 {
00646 TCoordinate alpha = 180.0*(j+1)/(P+1) - 90.0;
00647
00648 CVertex v = dCos(alpha) / 2 * OX + dSin(alpha) / 2 * OZ;
00649
00650 for (i=0; i<M; ++i)
00651 {
00652 grid[j][i]= v;
00653 globalMatrix.applyOn(grid[j][i]);
00654 matrix.applyOn(v);
00655 }
00656 }
00657
00658
00659 glLineWidth(FParameterPreview->getLWPreview());
00660 glColor3fv(FParameterPreview->getCLPreview());
00661
00662
00663 for (i=0; i<M; i++)
00664 {
00665 glBegin(GL_LINE_STRIP);
00666 PLOT(& south);
00667
00668 for (j=0; j<P; j++)
00669 PLOT(& grid[j][i]);
00670
00671 PLOT(& north);
00672 glEnd();
00673 }
00674
00675
00676 for (j=0; j<P; j++)
00677 {
00678 glBegin(GL_LINE_LOOP);
00679
00680 for (i=0; i<M; i++)
00681 PLOT(& grid[j][i]);
00682
00683 glEnd();
00684 }
00685
00686 for (i=0; i<P; ++i)
00687 delete [] grid[i];
00688 delete [] grid;
00689 }
00690
00691 void CPrecompilePreview::drawTorus()
00692 {
00693
00694 int M = FParameterCreation->getTorusNbMeridians();
00695 int P = FParameterCreation->getTorusNbParallels();
00696 float k = FParameterCreation->getTorusRadiusRapport();
00697 int i,j;
00698
00699
00700 CTransformationMatrix globalMatrix = FParameterPosition->getTransformationMatrix();
00701
00702
00703 float _R_ = 1/(1+k)/2;
00704 float R_ = k/(1+k)/2;
00705
00706
00707 CTransformationMatrix matrix1(CTransformationMatrix::IdentityMatrix);
00708 CTransformationMatrix matrix2(CTransformationMatrix::IdentityMatrix);
00709 CTransformationMatrix matrix3(CTransformationMatrix::IdentityMatrix);
00710
00711 matrix1.rotate(OY, 360.0 / P);
00712 matrix2.translate(_R_ * OX);
00713 matrix3.rotate(OZ, 360.0 / M);
00714
00715 CVertex vertex1(R_ * OX);
00716 CVertex** grid = new CVertex*[P];
00717 for (i=0; i<P; ++i)
00718 grid[i] = new CVertex[M];
00719
00720 for (j=0; j<P; ++j)
00721 {
00722 CVertex vertex2(vertex1);
00723 matrix2.applyOn(vertex2);
00724
00725 for (i=0; i<M; ++i)
00726 {
00727 grid[j][i] = vertex2;
00728 globalMatrix.applyOn(grid[j][i]);
00729 matrix3.applyOn(vertex2);
00730 }
00731
00732 matrix1.applyOn(vertex1);
00733 }
00734
00735
00736 glLineWidth(FParameterPreview->getLWPreview());
00737 glColor3fv(FParameterPreview->getCLPreview());
00738
00739
00740 for (i=0; i<M; i++)
00741 {
00742 glBegin(GL_LINE_LOOP);
00743
00744 for (j=0; j<P; j++)
00745 PLOT(& grid[j][i]);
00746
00747 glEnd();
00748 }
00749
00750
00751 for (j=0; j<P; j++)
00752 {
00753 glBegin(GL_LINE_LOOP);
00754
00755 for (i=0; i<M; i++)
00756 PLOT(& grid[j][i]);
00757
00758 glEnd();
00759 }
00760
00761 for (i=0; i<P; ++i)
00762 delete [] grid[i];
00763 delete [] grid;
00764 }
00765
00766 #define K (0.015)
00767
00768 void CPrecompilePreview::drawMesh1(const CTransformationMatrix & AMatrix,
00769 const CVertex & AOrigin,
00770 const CVertex & AVector, int ASx)
00771 {
00772 CVertex v1, v2;
00773
00774 if (ASx > 1)
00775 {
00776 CVertex current = AOrigin;
00777 CVertex dx = AVector / ASx;
00778
00779 for (int i=0; i<=ASx; ++i, current += dx)
00780 {
00781 v1 = current - K*OX; AMatrix.applyOn(v1);
00782 v2 = current + K*OX; AMatrix.applyOn(v2); LINE(&v1,&v2);
00783
00784 v1 = current - K*OY; AMatrix.applyOn(v1);
00785 v2 = current + K*OY; AMatrix.applyOn(v2); LINE(&v1,&v2);
00786
00787 v1 = current - K*OZ; AMatrix.applyOn(v1);
00788 v2 = current + K*OZ; AMatrix.applyOn(v2); LINE(&v1,&v2);
00789 }
00790 }
00791
00792 v1 = AOrigin ; AMatrix.applyOn(v1);
00793 v2 = AOrigin + AVector; AMatrix.applyOn(v2); LINE(&v1,&v2);
00794 }
00795
00796 #undef K
00797
00798 void CPrecompilePreview::drawMesh2(const CTransformationMatrix & AMatrix,
00799 const CVertex & AOrigin,
00800 const CVertex & AVectorX, int ASx,
00801 const CVertex & AVectorY, int ASy)
00802 {
00803 CVertex v1, v2;
00804
00805 CVertex dx = AVectorX / ASx;
00806 CVertex dy = AVectorY / ASy;
00807
00808 CVertex current;
00809
00810 current = AOrigin;
00811 for (int i=0; i<=ASx; ++i, current += dx)
00812 {
00813 v1 = current ; AMatrix.applyOn(v1);
00814 v2 = current + AVectorY; AMatrix.applyOn(v2); LINE(& v1, & v2);
00815 }
00816
00817 current = AOrigin;
00818 for (int j=0; j<=ASy; ++j, current += dy)
00819 {
00820 v1 = current ; AMatrix.applyOn(v1);
00821 v2 = current + AVectorX; AMatrix.applyOn(v2); LINE(& v1, & v2);
00822 }
00823 }
00824
00825 void CPrecompilePreview::drawMesh3(const CTransformationMatrix & AMatrix,
00826 const CVertex & AOrigin,
00827 const CVertex & AVectorX, int ASx,
00828 const CVertex & AVectorY, int ASy,
00829 const CVertex & AVectorZ, int ASz)
00830 {
00831 CVertex v1, v2;
00832
00833 CVertex dx = AVectorX / ASx;
00834 CVertex dy = AVectorY / ASy;
00835 CVertex dz = AVectorZ / ASz;
00836
00837 CVertex currentX, currentY, currentZ;
00838 int i,j,k;
00839
00840 currentX = AOrigin;
00841 for (i=0; i<=ASx; ++i, currentX += dx)
00842 {
00843 currentY = currentX;
00844
00845 for (j=0; j<=ASy; ++j, currentY += dy)
00846 {
00847 v1 = currentY ; AMatrix.applyOn(v1);
00848 v2 = currentY + AVectorZ; AMatrix.applyOn(v2); LINE(& v1, & v2);
00849 }
00850 }
00851
00852 currentX = AOrigin;
00853 for (i=0; i<=ASx; ++i, currentX += dx)
00854 {
00855 currentZ = currentX;
00856
00857 for (k=0; k<=ASz; ++k, currentZ += dz)
00858 {
00859 v1 = currentZ ; AMatrix.applyOn(v1);
00860 v2 = currentZ + AVectorY; AMatrix.applyOn(v2); LINE(& v1, & v2);
00861 }
00862 }
00863
00864 currentY = AOrigin;
00865 for (j=0; j<=ASy; ++j, currentY += dy)
00866 {
00867 currentZ = currentY;
00868
00869 for (k=0; k<=ASz; ++k, currentZ += dz)
00870 {
00871 v1 = currentZ ; AMatrix.applyOn(v1);
00872 v2 = currentZ + AVectorX; AMatrix.applyOn(v2); LINE(& v1, & v2);
00873 }
00874 }
00875 }
00876