#ifndef _Polygon3_h__ #define _Polygon3_h__ #include "common.h" #include "Vector3.h" #include #include namespace CHCDemoEngine { class Polygon3; class Plane3; class AxisAlignedBox3; struct Triangle3; /** Class representing a planar convex polygon in 3d. */ class Polygon3 { public: enum {BACK_SIDE, FRONT_SIDE, SPLIT, COINCIDENT}; /** Default constructor creating an empty polygon. */ Polygon3(); /** Constructor creating a polygon from the vertices. */ Polygon3(const VertexArray &vertices); ~Polygon3(); /** Returns supporting plane of this polygon. */ Plane3 GetSupportingPlane() const; /** Splits polygon. @param partition the split plane @param front returns the front polygon @param back returns the back polygon @param epsilon epsilon where two points are considered equal */ void Split(const Plane3 &partition, Polygon3 &front, Polygon3 &back, float eps); /** Returns the area of this polygon. */ float GetArea() const; /** Classify polygon with respect to the plane. @param epsilon tolerance value @returns one of BACK_SIDE, FRONT_SIDE, SPLIT, COINCIDENT */ int ClassifyPlane(const Plane3 &plane, const float eps) const; /** Side of the polygon with respect to the plane. @returns 1 if on front side, -1 if on back side, 0 else. */ int Side(const Plane3 &plane, float eps) const; /** Computes the center of mass of the polygon */ Vector3 Center() const; /** Checks if the polygon is valid, i.e., not degenerated. @returns true if polygon is valid. */ bool Valid(float epsilon) const; /** Returns the surface normal. */ Vector3 GetNormal() const; /** Returns new polygon with reverse orientation. */ Polygon3 *CreateReversePolygon() const; AxisAlignedBox3 GetBoundingBox() const; ////////////////////////////////////////// /// vertices are connected in counterclockwise order. VertexArray mVertices; }; // Overload << operator for C++-style output inline std::ostream& operator<< (std::ostream &s, const Polygon3 &A) { VertexArray::const_iterator it; //s << setprecision(6) << "Polygon:\n"; for (it = A.mVertices.begin(); it != A.mVertices.end(); ++ it) { s << *it << " "; } return s; } } #endif