#ifndef __TRIANGLE3_H #define __TRIANGLE3_H #include "Vector3.h" namespace CHCDemoEngine { class AxisAlignedBox3; class Plane3; struct Triangle3 { Triangle3() {}; Triangle3(const Vector3 &a, const Vector3 &b, const Vector3 &c); void Init(const Vector3 &a, const Vector3 &b, const Vector3 &c); Vector3 GetNormal() const; Vector3 GetWorldCenter() const; float GetSpatialAngle(const Vector3 &point) const; float GetArea() const; /** returns bounding box around this triangle */ AxisAlignedBox3 GetBoundingBox() const; /** Intersects triangle with plane, returns intersection points if intersection is happening. @returns true if triangle intersects plane */ bool GetPlaneIntersection(const Plane3 &plane, Vector3 &intersectA, Vector3 &intersectB) const; /** Returns false if this triangle is ill-defined, true otherwise */ bool Valid() const; friend std::ostream& operator<< (std::ostream &s, const Triangle3 &A); friend std::istream& operator>> (std::istream &s, Triangle3 &A); /////////////////// /// the triangle vertices Vector3 mVertices[3]; }; // Overload << operator for C++-style output inline std::ostream& operator<< (std::ostream &s, const Triangle3 &A) { return s << "(" << A.mVertices[0] << ", " << A.mVertices[1] << ", " << A.mVertices[2] << ")"; } // Overload >> operator for C++-style input inline std::istream& operator>> (std::istream &s, Triangle3 &A) { char a; // read "(x, y, z)" return s >> a >> A.mVertices[0] >> a >> A.mVertices[1] >> a >> A.mVertices[2] >> a; } } #endif