home *** CD-ROM | disk | FTP | other *** search
/ RISC DISC 3 / RISC_DISC_3.iso / resources / etexts / gems / gemsv / ch7_4 / main.cc < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-22  |  1.5 KB  |  50 lines

  1. // -*- C++ -*-
  2. // Gems V: Spatial Partitioning of a Polygon by a Plane
  3. // by George Vanecek Jr, Sept. 1994
  4.  
  5. #include "polygon.h"
  6.  
  7. static void printPolys( const char* const label, const List<Polygon>& pL )
  8. {
  9.   if( pL.size() ) {
  10.     cout << "----------" << endl
  11.      << pL.size() << " polygon(s) " << label << endl;
  12.     forEachItemOnList( pL ) {
  13.       cout << "  Polygon:" << endl;
  14.       const Polygon* const g = getItem(Polygon);
  15.       forEachDEdgeOfPoly(d1,g) {
  16.     const Point& p = d1->srcPoint();
  17.     cout << "  " << p.x() << ' ' << p.y() << ' ' << p.z() << endl;
  18.       }
  19.     }
  20.   }
  21. }
  22.  
  23. int main( )
  24. {
  25.   // Sample polygon shown in Figure 1(a) of the Gems V article.
  26.   const Point pts[] = {
  27.     Point( 0,0,0), Point( 2,0,0), Point( 3,3,0),
  28.     Point( 4,0,0), Point( 9,0,0), Point( 9,3,0),
  29.     Point(10,3,0), Point(10,0,0), Point(13,0,0),
  30.     Point(13,3,0), Point(14,3,0), Point(14,6,0),
  31.     Point( 6,6,0), Point( 6,2,0), Point( 7,2,0),
  32.     Point( 7,5,0), Point(12,5,0), Point(12,1,0),
  33.     Point(11,1,0), Point(11,4,0), Point( 8,4,0),
  34.     Point( 8,1,0), Point( 5,1,0), Point( 5,3,0),
  35.     Point( 4,3,0), Point( 4,6,0), Point( 3,6,0),
  36.     Point( 2,3,0), Point( 1,6,0), Point( 0,6,0)
  37.   };
  38.   Polygon* g = new Polygon( 30, pts );
  39.   cout << "Before:" << endl;
  40.   forEachDEdgeOfPoly(d1,g)
  41.     cout << d1->srcPoint() << endl;
  42.   List<Polygon> above;
  43.   List<Polygon> on;
  44.   List<Polygon> below;
  45.   split( g, Plane(Vector(0.0,1.0,0.0),-3.0), above, on, below);
  46.   printPolys( "Above", above);
  47.   printPolys( "On",    on);
  48.   printPolys( "Below", below);
  49. }
  50.