source: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Triangle3.h @ 3070

Revision 3070, 1.6 KB checked in by mattausch, 16 years ago (diff)
Line 
1#ifndef __TRIANGLE3_H
2#define __TRIANGLE3_H
3
4#include "Vector3.h"
5
6
7namespace CHCDemoEngine
8{
9
10class AxisAlignedBox3;
11class Plane3;
12
13
14struct 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 GetWorldCenter() const;
24
25        float GetSpatialAngle(const Vector3 &point) const;
26
27        float GetArea() const;
28        /** returns bounding box around this triangle
29        */
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
40        /** Returns false if this triangle is ill-defined, true otherwise
41        */
42        bool Valid() const;
43         
44        friend std::ostream& operator<< (std::ostream &s, const Triangle3 &A);
45        friend std::istream& operator>> (std::istream &s, Triangle3 &A);
46
47
48        ///////////////////
49
50        /// the triangle vertices
51        Vector3 mVertices[3];
52};
53
54
55// Overload << operator for C++-style output
56inline std::ostream&
57operator<< (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
63inline std::istream&
64operator>> (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
Note: See TracBrowser for help on using the repository browser.