source: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Plane3.h @ 2911

Revision 2911, 1.9 KB checked in by mattausch, 16 years ago (diff)
Line 
1#ifndef __Plane3_H__
2#define __Plane3_H__
3
4#include "Vector3.h"
5
6
7namespace CHCDemoEngine
8{
9
10/** Class describing a 3D Plane.
11*/
12class Plane3
13{
14public:
15
16        Plane3() {}
17
18        Plane3(const Vector3 &a, const Vector3 &b, const Vector3 &c);
19
20        Plane3(const Vector3 &normal, const Vector3 &point);
21
22        inline void ReverseOrientation()
23        {
24                mNormal *= -1;
25                mD *= -1;
26        }
27        /** Get distance to a point.
28        */
29        inline float Distance(const Vector3 &v) const
30        {
31                return DotProd(v, mNormal) + mD;
32        }
33
34        enum {BACK_SIDE = -1, INTERSECTS = 0, FRONT_SIDE = 1};
35        /** Returns 1 if v is on front side, -1 if on back side, 0 if on plane.
36        */
37        int Side(const Vector3 &v, float threshold = 1e-6) const;
38        /** Finds intersection of line segment between points a and b with plane.
39            @param a start point
40                @param b end point
41                @param t if not NULL, returns parameter value of intersections
42                @param coplanar if not NULL, returns true if plane and line segments are coplanar.
43        */
44        Vector3 FindIntersection(const Vector3 &a,
45                                     const Vector3 &b,
46                                                         float *t = NULL,
47                                                         bool *coplanar = NULL) const;
48
49        /** Finds value of intersection parameter t on line segment from a to b.
50            @returns 0 if coplanar, else parameter t
51        */
52        float FindT(const Vector3 &a, const Vector3 &b) const;
53
54        operator const float*() const
55        {
56                return (const float*) this;
57        }
58
59        float& operator[] (const int inx)
60        {
61                return (&mNormal.x)[inx];
62        }
63
64        const float &operator[] (const int inx) const
65        {
66                return *(&mNormal.x + inx);
67        }
68
69        ///////////
70        //-- friends
71
72        friend bool     PlaneIntersection(const Plane3 &a, const Plane3 &b, const Plane3 &c, Vector3 &result);
73
74        friend bool PlaneIntersection(const Plane3 &p1, const Plane3 &p2);
75       
76
77        friend std::ostream &operator<<(std::ostream &s, const Plane3 &p)
78        {       
79                s << p.mNormal << " " << p.mD;
80                return s;
81        }
82
83
84        ///////////////
85
86        Vector3 mNormal;
87        float mD;
88};
89
90
91}
92#endif
Note: See TracBrowser for help on using the repository browser.