[191] | 1 | #ifndef __TRIANGLE3_H
|
---|
| 2 | #define __TRIANGLE3_H
|
---|
| 3 |
|
---|
| 4 | #include "Vector3.h"
|
---|
| 5 |
|
---|
[1328] | 6 |
|
---|
[860] | 7 | namespace GtpVisibilityPreprocessor {
|
---|
| 8 |
|
---|
[1328] | 9 | class AxisAlignedBox3;
|
---|
| 10 | class Ray;
|
---|
[1932] | 11 | class Plane3;
|
---|
[191] | 12 |
|
---|
[1328] | 13 | struct Triangle3
|
---|
| 14 | {
|
---|
| 15 | Triangle3() {};
|
---|
| 16 | Triangle3(const Vector3 &a, const Vector3 &b, const Vector3 &c);
|
---|
[191] | 17 |
|
---|
[1328] | 18 | void Init(const Vector3 &a, const Vector3 &b, const Vector3 &c);
|
---|
[191] | 19 |
|
---|
[1328] | 20 | Vector3 GetNormal() const;
|
---|
[544] | 21 |
|
---|
[1328] | 22 | Vector3 GetCenter() const;
|
---|
| 23 |
|
---|
| 24 | float GetSpatialAngle(const Vector3 &point) const;
|
---|
| 25 |
|
---|
| 26 | float GetArea() const;
|
---|
| 27 |
|
---|
| 28 | /// returns bounding box around this triangle
|
---|
| 29 | AxisAlignedBox3 GetBoundingBox() const;
|
---|
| 30 |
|
---|
| 31 | /// Casts ray into this triangle. Returns hit
|
---|
[1344] | 32 | int CastRay(const Ray &ray, float &t, const float nearestT, Vector3 &normal) const;
|
---|
[1328] | 33 |
|
---|
[2176] | 34 | friend std::ostream& operator<< (std::ostream &s, const Triangle3 &A);
|
---|
| 35 | friend std::istream& operator>> (std::istream &s, Triangle3 &A);
|
---|
[1328] | 36 |
|
---|
[1932] | 37 | /** Checks if this triangle is ill-defined.
|
---|
| 38 | */
|
---|
| 39 | bool CheckValidity() const;
|
---|
[1344] | 40 |
|
---|
[1932] | 41 | /** Intersects triangle with plane, returns intersection points
|
---|
| 42 | if intersection is happening.
|
---|
| 43 |
|
---|
| 44 | @returns true if triangle intersects plane
|
---|
| 45 | */
|
---|
[1933] | 46 | bool GetPlaneIntersection(const Plane3 &plane,
|
---|
| 47 | Vector3 &intersectA,
|
---|
| 48 | Vector3 &intersectB) const;
|
---|
[1932] | 49 |
|
---|
| 50 | ///////////////////
|
---|
| 51 |
|
---|
| 52 | /// the triangle vertices
|
---|
| 53 | Vector3 mVertices[3];
|
---|
[191] | 54 | };
|
---|
| 55 |
|
---|
[1344] | 56 |
|
---|
| 57 | // Overload << operator for C++-style output
|
---|
[2176] | 58 | inline std::ostream&
|
---|
| 59 | operator<< (std::ostream &s, const Triangle3 &A)
|
---|
[1344] | 60 | {
|
---|
| 61 | return s << "(" << A.mVertices[0] << ", " << A.mVertices[1] << ", " << A.mVertices[2] << ")";
|
---|
[860] | 62 | }
|
---|
[191] | 63 |
|
---|
[1344] | 64 | // Overload >> operator for C++-style input
|
---|
[2176] | 65 | inline std::istream&
|
---|
| 66 | operator>> (std::istream &s, Triangle3 &A)
|
---|
[1344] | 67 | {
|
---|
| 68 | char a;
|
---|
| 69 | // read "(x, y, z)"
|
---|
| 70 | return s >> a >> A.mVertices[0] >> a >> A.mVertices[1] >> a >> A.mVertices[2] >> a;
|
---|
| 71 | }
|
---|
| 72 |
|
---|
| 73 |
|
---|
| 74 | }
|
---|
| 75 |
|
---|
[191] | 76 | #endif
|
---|
| 77 |
|
---|