1 | #ifndef __TRIANGLE3_H
|
---|
2 | #define __TRIANGLE3_H
|
---|
3 |
|
---|
4 | #include "Vector3.h"
|
---|
5 |
|
---|
6 |
|
---|
7 | namespace GtpVisibilityPreprocessor {
|
---|
8 |
|
---|
9 | class AxisAlignedBox3;
|
---|
10 | class Ray;
|
---|
11 |
|
---|
12 |
|
---|
13 | struct Triangle3
|
---|
14 | {
|
---|
15 | Triangle3() {};
|
---|
16 | Triangle3(const Vector3 &a, const Vector3 &b, const Vector3 &c);
|
---|
17 |
|
---|
18 | void Init(const Vector3 &a, const Vector3 &b, const Vector3 &c);
|
---|
19 |
|
---|
20 | Vector3 GetNormal() const;
|
---|
21 |
|
---|
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
|
---|
32 | int CastRay(const Ray &ray, float &t, const float nearestT, Vector3 &normal) const;
|
---|
33 |
|
---|
34 | friend ostream& operator<< (ostream &s, const Triangle3 &A);
|
---|
35 | friend istream& operator>> (istream &s, Triangle3 &A);
|
---|
36 |
|
---|
37 |
|
---|
38 | //////////////////////////////
|
---|
39 | /// the triangle vertices
|
---|
40 | Vector3 mVertices[3];
|
---|
41 | };
|
---|
42 |
|
---|
43 |
|
---|
44 | // Overload << operator for C++-style output
|
---|
45 | inline ostream&
|
---|
46 | operator<< (ostream &s, const Triangle3 &A)
|
---|
47 | {
|
---|
48 | return s << "(" << A.mVertices[0] << ", " << A.mVertices[1] << ", " << A.mVertices[2] << ")";
|
---|
49 | }
|
---|
50 |
|
---|
51 | // Overload >> operator for C++-style input
|
---|
52 | inline istream&
|
---|
53 | operator>> (istream &s, Triangle3 &A)
|
---|
54 | {
|
---|
55 | char a;
|
---|
56 | // read "(x, y, z)"
|
---|
57 | return s >> a >> A.mVertices[0] >> a >> A.mVertices[1] >> a >> A.mVertices[2] >> a;
|
---|
58 | }
|
---|
59 |
|
---|
60 |
|
---|
61 | }
|
---|
62 |
|
---|
63 | #endif
|
---|
64 |
|
---|