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

Revision 2944, 2.1 KB checked in by mattausch, 16 years ago (diff)

nopt not working yet

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