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