Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members

quad.cpp

Go to the documentation of this file.
00001 /*
00002 ** ----------------------------------------------------------------
00003 ** quad.cpp  -  Quadrilateral primitive class.
00004 **
00005 ** ----------------------------------------------------------------
00006 */
00007 
00034 /*
00035 ** ---------------------------------------------------------------
00036 ** Global variables and symbols:
00037 */
00038 #ifdef _WIN32
00039 #include <windows.h>
00040 #endif
00041 #include <stdlib.h>
00042 #include <stdio.h>
00043 #include <math.h>
00044 #include <GL/gl.h>
00045 #include <GL/glu.h>
00046 
00047 #include "prm.h"
00048 #include "quad.h"
00049 #include "cd.h"
00050 #include "wd.h"
00051 #include "dsp.h"
00052 
00053 /*
00054 ** ---------------------------------------------------------------
00055 ** Public constructor and destructor functions:
00056 **
00057 */
00058 /*==========================  Quad::Quad  =========================*/
00059 
00060 Quad::Quad( )
00061 {
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076 }
00077 /*==========================  Quad::Quad  =========================*/
00078 
00079 Quad::Quad( int back ) : Prm( back )
00080 {
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095 }
00096 
00097 /*==========================  Quad::~Quad  =========================*/
00098 
00099 Quad::~Quad( )
00100 {
00101 }
00102 
00103 /*
00104 ** ---------------------------------------------------------------
00105 ** Protected class functions:
00106 **
00107 */
00108 /*=========================  Quad::PickCode  =======================*/
00109 
00110 void Quad::PickCode( double x, double y, double xmin, double xmax,
00111                      double ymin, double ymax, int cod[4] )
00112 {
00113
00114
00115
00116
00117 }
00118 
00119 /*=========================  Quad::PickLine  =======================*/
00120   
00121 int Quad::PickLine( double x, double y, double pick_tol,
00122                     double x0, double y0, double x1, double y1 )
00123 {
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174 }
00175 
00176 /*=======================  Quad::FaceNormal  =======================*/
00177 
00178 void Quad::FaceNormal( Pnt3d* p0, Pnt3d* p1, Pnt3d* p2, Pnt3d* p3,
00179                        Vec3d* normal )
00180 {
00181  double len;
00182  
00183  normal->x = 0.0;
00184  normal->y = 0.0;
00185  normal->z = 0.0;
00186  
00187  normal->x +=  (p1->y - p0->y) * (p2->z - p0->z) -
00188                (p1->z - p0->z) * (p2->y - p0->y);
00189  normal->y += -(p1->x - p0->x) * (p2->z - p0->z) +
00190                (p1->z - p0->z) * (p2->x - p0->x);
00191  normal->z +=  (p1->x - p0->x) * (p2->y - p0->y) -
00192                (p1->y - p0->y) * (p2->x - p0->x);
00193  
00194  normal->x +=  (p2->y - p0->y) * (p3->z - p0->z) -
00195                (p2->z - p0->z) * (p3->y - p0->y);
00196  normal->y += -(p2->x - p0->x) * (p3->z - p0->z) +
00197                (p2->z - p0->z) * (p3->x - p0->x);
00198  normal->z +=  (p2->x - p0->x) * (p3->y - p0->y) -
00199                (p2->y - p0->y) * (p3->x - p0->x);
00200  
00201  len = sqrt( normal->x*normal->x + normal->y*normal->y + normal->z*normal->z );
00202  
00203  if( len != 0.0 )
00204  {
00205   normal->x /= len;
00206   normal->y /= len;
00207   normal->z /= len;
00208  }
00209 }
00210 
00211 /*
00212 ** ---------------------------------------------------------------
00213 ** Protected instance (object) functions:
00214 **
00215 */
00216 /*======================  Quad::BuildSolidPrm  ======================*/
00217 
00218 void Quad::BuildSolidPrm( Pnt3d* solid_prm )
00219 {
00220  Pnt3d face[4];
00221  Vec3d prm_norm;
00222 
00223 /* Build a temporary face with the primitive points.
00224  */
00225  face[0].x = p[0].x;
00226  face[0].y = p[0].y;
00227  face[0].z = 0.0;
00228  face[1].x = p[1].x;
00229  face[1].y = p[1].y;
00230  face[1].z = 0.0;
00231  face[2].x = p[2].x;
00232  face[2].y = p[2].y;
00233  face[2].z = 0.0;
00234  face[3].x = p[3].x;
00235  face[3].y = p[3].y;
00236  face[3].z = 0.0;
00237 
00238 /* Compute the normal vector of the 2D primitive to find out whether
00239  * it has a clockwise or counter-clockwise orientation.
00240  * A negative z component of the normal vector indicates a 
00241  * clockwise orientation.
00242  */
00243  FaceNormal( &face[0], &face[1], &face[2], &face[3], &prm_norm );
00244 
00245 /* Build solid version of primitive with the base faces with normal
00246  * vectors pointing outward when traversing the vertices in 
00247  * counter-clockwise orientation. 
00248  */
00249  if( prm_norm.z < 0.0 )
00250  {
00251   solid_prm[0] = face[0];
00252   solid_prm[1] = face[1];
00253   solid_prm[2] = face[2];
00254   solid_prm[3] = face[3];
00255 
00256   solid_prm[4] = face[0];
00257   solid_prm[5] = face[3];
00258   solid_prm[6] = face[2];
00259   solid_prm[7] = face[1];
00260  }
00261  else
00262  {
00263   solid_prm[0] = face[0];
00264   solid_prm[1] = face[3];
00265   solid_prm[2] = face[2];
00266   solid_prm[3] = face[1];
00267 
00268   solid_prm[4] = face[0];
00269   solid_prm[5] = face[1];
00270   solid_prm[6] = face[2];
00271   solid_prm[7] = face[3];
00272  }
00273  solid_prm[4].z += height;
00274  solid_prm[5].z += height;
00275  solid_prm[6].z += height;
00276  solid_prm[7].z += height;
00277 }
00278 
00279 /*
00280 ** ---------------------------------------------------------------
00281 ** Public instance (object) functions
00282 ** (implemented in the derived class):
00283 **
00284 */
00285 /*==========================  Quad::Read  =========================*/
00286 
00287 void Quad::Read( FILE* fd )
00288 {
00289
00290
00291
00292
00293
00294
00295 }
00296 
00297 /*=========================  Quad::Write  =========================*/
00298 
00299 void Quad::Write( FILE* fd )
00300 {
00301
00302
00303
00304
00305
00306
00307 }
00308 
00309 /*========================  Quad::GetNPts  ========================*/
00310 
00311 int Quad::GetNPts( void )
00312 {
00313
00314 }
00315 
00316 /*=======================  Quad::SetCoords  =======================*/
00317 
00318 void Quad::SetCoords( int id, double x, double y )
00319 {
00320
00321
00322
00323
00324
00325 }
00326 
00327 /*=======================  Quad::GetCoords  =======================*/
00328 
00329 void Quad::GetCoords( int id, double* x, double* y )
00330 {
00331
00332
00333
00334
00335
00336 }
00337 
00338 /*=======================  Quad::Set1stPt  ========================*/
00339 
00340 void Quad::Set1stPt( double x, double y )
00341 {
00342
00343
00344 }
00345 
00346 /*=======================  Quad::Set2ndPt  ========================*/
00347 
00348 void Quad::Set2ndPt( double x, double y )
00349 {
00350
00351
00352 }
00353 
00354 /*=======================  Quad::PickArea  ========================*/
00355 
00356 int Quad::PickArea( double x, double y )
00357 {
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404 }
00405 
00406 /*======================  Quad::PickVertex  =======================*/
00407 
00408 int Quad::PickVertex( double x, double y, double tol, int* id )
00409 {
00410
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420
00421
00422
00423
00424
00425 }
00426 
00427 /*=======================  Quad::PickSide  ========================*/
00428 
00429 int Quad::PickSide( double x, double y, double tol, int* id )
00430 {
00431
00432
00433
00434
00435
00436
00437
00438
00439
00440
00441
00442
00443
00444
00445
00446
00447 }
00448 
00449 /*=======================  Quad::Translate  =======================*/
00450 
00451 void Quad::Translate( double dx, double dy )
00452 {
00453
00454
00455
00456
00457
00458
00459
00460 }
00461 
00462 /*====================  Quad::TranslateVertex  ====================*/
00463 
00464 void Quad::TranslateVertex( int id, double dx, double dy )
00465 {
00466
00467
00468
00469
00470
00471 }
00472 
00473 /*=====================  Quad::TranslateSide  =====================*/
00474 
00475 void Quad::TranslateSide( int id, double dx, double dy )
00476 {
00477
00478
00479
00480
00481
00482
00483
00484 }
00485 
00486 /*=========================  Quad::GetBox  ========================*/
00487 
00488 void Quad::GetBox( double* xmin, double* xmax, double* ymin, double* ymax )
00489 {
00490
00491
00492
00493
00494
00495
00496
00497
00498
00499
00500 }
00501 
00502 /*====================  Quad::DisplayBoundary  ====================*/
00503 
00504 void Quad::DisplayBoundary( void )
00505 {
00506
00507
00508
00509
00510
00511
00512
00513
00514
00515
00516
00517
00518 }
00519 
00520 /*====================  Quad::DisplayInterior  ====================*/
00521 
00522 void Quad::DisplayInterior( void )
00523 {
00524
00525
00526
00527
00528
00529
00530
00531
00532
00533
00534
00535 }
00536 
00537 /*=====================  Quad::DisplaySolid  ======================*/
00538 
00539 void Quad::DisplaySolid( )
00540 {
00541
00542
00543
00544
00545
00546
00547
00548
00549
00550
00551
00552
00553
00554
00555
00556
00557
00558
00559
00560
00561
00562
00563
00564
00565
00566
00567
00568
00569
00570
00571
00572
00573
00574
00575
00576
00577
00578
00579
00580
00581
00582
00583
00584
00585
00586
00587
00588
00589
00590
00591
00592
00593
00594
00595
00596
00597
00598
00599
00600
00601
00602
00603
00604
00605
00606
00607
00608
00609
00610
00611
00612
00613
00614 }
00615 
00616 /*======================  Quad::HighltSolid  ======================*/
00617 
00618 void Quad::HighltSolid( )
00619 {
00620
00621 
00622
00623
00624
00625
00626
00627
00628
00629
00630
00631
00632
00633
00634
00635
00636
00637
00638
00639
00640
00641
00642
00643
00644
00645
00646
00647
00648
00649
00650
00651
00652
00653
00654
00655
00656
00657
00658
00659
00660
00661
00662
00663
00664
00665
00666
00667
00668
00669
00670
00671
00672
00673
00674
00675
00676
00677
00678
00679
00680
00681
00682
00683 }
00684 
00685 /*====================  Quad::DisplayZbuffer  =====================*/
00686 
00687 void Quad::DisplayZbuffer( )
00688 {
00689
00690
00691
00692
00693
00694
00695
00696
00697
00698
00699
00700
00701
00702
00703
00704
00705
00706
00707
00708
00709
00710
00711
00712
00713
00714
00715
00716
00717
00718
00719
00720
00721
00722
00723
00724
00725
00726
00727
00728
00729
00730
00731
00732
00733
00734
00735
00736
00737
00738
00739
00740
00741
00742
00743
00744
00745
00746
00747
00748
00749
00750
00751
00752
00753
00754
00755
00756
00757
00758
00759
00760
00761
00762
00763
00764 }
00765 

Generated on Mon Jun 21 12:45:12 2010 for Trab4 by  doxygen 1.4.2-20050421