[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" |
---|
[270] | 10 | #include <iomanip> |
---|
[235] | 11 | |
---|
[236] | 12 | class Polygon3; |
---|
[235] | 13 | class Plane3; |
---|
| 14 | class Face; |
---|
[286] | 15 | class Intersectable; |
---|
[235] | 16 | |
---|
[289] | 17 | //typedef Vertex3 Vector3; |
---|
| 18 | |
---|
| 19 | /** Class representing a planar convex polygon in 3d. |
---|
[235] | 20 | */ |
---|
| 21 | class Polygon3 |
---|
| 22 | { |
---|
| 23 | public: |
---|
| 24 | Polygon3(); |
---|
[236] | 25 | Polygon3(const VertexContainer &vertices); |
---|
[286] | 26 | Polygon3(Intersectable *parent); |
---|
[235] | 27 | |
---|
| 28 | /** Copies all the vertices of the face. |
---|
| 29 | */ |
---|
[286] | 30 | Polygon3(Face *face, Mesh *parentMesh); |
---|
[235] | 31 | |
---|
| 32 | /** Returns supporting plane of this polygon. |
---|
| 33 | */ |
---|
[238] | 34 | Plane3 GetSupportingPlane() const; |
---|
[235] | 35 | |
---|
| 36 | /** Splits polygon. |
---|
| 37 | @param partition the split plane |
---|
| 38 | @param front the front polygon |
---|
| 39 | @param back the back polygon |
---|
| 40 | */ |
---|
[289] | 41 | void Split(Plane3 *partition, Polygon3 *front, Polygon3 *back); |
---|
[235] | 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 | |
---|
[256] | 55 | /** Scales the polygon about its center |
---|
| 56 | */ |
---|
| 57 | void Scale(const float scale); |
---|
| 58 | |
---|
| 59 | /** Computes the center of mass of the polygon |
---|
| 60 | */ |
---|
| 61 | Vector3 Center() const; |
---|
[289] | 62 | /** Checks if the polygon is valid, i.e., not degenerated. |
---|
| 63 | @returns true if polygon is valid. |
---|
| 64 | */ |
---|
| 65 | bool CheckValid() const; |
---|
[256] | 66 | |
---|
[235] | 67 | /// vertices are connected in counterclockwise order. |
---|
| 68 | VertexContainer mVertices; |
---|
[242] | 69 | |
---|
| 70 | /// we can also store materials with polygons |
---|
| 71 | Material *mMaterial; |
---|
[286] | 72 | |
---|
| 73 | /// pointer to the intersectable this polygon is derived from |
---|
| 74 | Intersectable *mParent; |
---|
[235] | 75 | }; |
---|
| 76 | |
---|
[237] | 77 | // Overload << operator for C++-style output |
---|
| 78 | inline ostream& |
---|
| 79 | operator<< (ostream &s, const Polygon3 &A) |
---|
| 80 | { |
---|
| 81 | VertexContainer::const_iterator it; |
---|
[235] | 82 | |
---|
[289] | 83 | //s << setprecision(6) << "Polygon:\n"; |
---|
[237] | 84 | for (it = A.mVertices.begin(); it != A.mVertices.end(); ++it) |
---|
| 85 | s << *it << endl; |
---|
| 86 | |
---|
| 87 | return s; |
---|
| 88 | } |
---|
[235] | 89 | |
---|
[237] | 90 | |
---|
[235] | 91 | #endif |
---|