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