#ifndef __TRIANGLE3_H #define __TRIANGLE3_H #include "Vector3.h" namespace GtpVisibilityPreprocessor { class AxisAlignedBox3; class Ray; 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 GetCenter() const; float GetSpatialAngle(const Vector3 &point) const; float GetArea() const; /// returns bounding box around this triangle AxisAlignedBox3 GetBoundingBox() const; /// Casts ray into this triangle. Returns hit int CastRay(const Ray &ray, float &t, const float nearestT, Vector3 &normal) const; friend ostream& operator<< (ostream &s, const Triangle3 &A); friend istream& operator>> (istream &s, Triangle3 &A); /** Checks if this triangle is ill-defined. */ bool CheckValidity() 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; /////////////////// /// the triangle vertices Vector3 mVertices[3]; }; // Overload << operator for C++-style output inline ostream& operator<< (ostream &s, const Triangle3 &A) { return s << "(" << A.mVertices[0] << ", " << A.mVertices[1] << ", " << A.mVertices[2] << ")"; } // Overload >> operator for C++-style input inline istream& operator>> (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