[235] | 1 | #ifndef _Polygon3_h__ |
---|
| 2 | #define _Polygon3_h__ |
---|
| 3 | |
---|
| 4 | |
---|
| 5 | //#include <iostream> |
---|
| 6 | //#include <math.h> |
---|
| 7 | //#include "common.h" |
---|
| 8 | #include "Containers.h" |
---|
[236] | 9 | #include "Mesh.h" |
---|
[235] | 10 | |
---|
[236] | 11 | class Polygon3; |
---|
[235] | 12 | class Plane3; |
---|
| 13 | class Face; |
---|
| 14 | |
---|
[238] | 15 | /** Container storing polygons used during BSP tree construction |
---|
[236] | 16 | */ |
---|
[238] | 17 | typedef vector<Polygon3 *> PolygonContainer; |
---|
[236] | 18 | |
---|
[235] | 19 | /** Class representing a general planar polygon in 3d. |
---|
| 20 | */ |
---|
| 21 | class Polygon3 |
---|
| 22 | { |
---|
| 23 | public: |
---|
| 24 | Polygon3(); |
---|
[236] | 25 | Polygon3(const VertexContainer &vertices); |
---|
[235] | 26 | |
---|
| 27 | /** Copies all the vertices of the face. |
---|
| 28 | */ |
---|
| 29 | Polygon3(Face *face, Mesh *parent); |
---|
| 30 | |
---|
| 31 | /** Returns supporting plane of this polygon. |
---|
| 32 | */ |
---|
[238] | 33 | Plane3 GetSupportingPlane() const; |
---|
[235] | 34 | |
---|
| 35 | /** Splits polygon. |
---|
| 36 | @param partition the split plane |
---|
| 37 | @param front the front polygon |
---|
| 38 | @param back the back polygon |
---|
| 39 | @param splits number of splits |
---|
| 40 | */ |
---|
| 41 | void Split(Plane3 *partition, Polygon3 *front, Polygon3 *back, int &splits); |
---|
| 42 | |
---|
| 43 | enum {BACK_SIDE, FRONT_SIDE, SPLIT, COINCIDENT}; |
---|
| 44 | |
---|
[238] | 45 | /** Classify polygon with respect to the plane. |
---|
[235] | 46 | @returns one of BACK_SIDE, FRONT_SIDE, SPLIT, COINCIDENT |
---|
| 47 | */ |
---|
[238] | 48 | int ClassifyPlane(const Plane3 &plane) const; |
---|
[235] | 49 | |
---|
[238] | 50 | /** Side of the polygon with respect to the plane. |
---|
| 51 | @returns 1 if on front side, -1 if on back side, 0 else. |
---|
| 52 | */ |
---|
| 53 | int Side(const Plane3 &plane) const; |
---|
| 54 | |
---|
[235] | 55 | /** Deletes all polygons om the queue. |
---|
| 56 | */ |
---|
[238] | 57 | static void DeletePolygons(PolygonContainer *polys); |
---|
[235] | 58 | |
---|
| 59 | /// vertices are connected in counterclockwise order. |
---|
| 60 | VertexContainer mVertices; |
---|
| 61 | }; |
---|
| 62 | |
---|
[237] | 63 | // Overload << operator for C++-style output |
---|
| 64 | inline ostream& |
---|
| 65 | operator<< (ostream &s, const Polygon3 &A) |
---|
| 66 | { |
---|
| 67 | VertexContainer::const_iterator it; |
---|
[235] | 68 | |
---|
[237] | 69 | s << "Polygon:\n"; |
---|
| 70 | |
---|
| 71 | for (it = A.mVertices.begin(); it != A.mVertices.end(); ++it) |
---|
| 72 | s << *it << endl; |
---|
| 73 | |
---|
| 74 | return s; |
---|
| 75 | } |
---|
[235] | 76 | |
---|
[237] | 77 | |
---|
[235] | 78 | #endif |
---|