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

RevLine 
[2755]1#ifndef __Plane3_H__
2#define __Plane3_H__
[2751]3
4#include "Vector3.h"
5
[2755]6
[2776]7namespace CHCDemoEngine
[2751]8{
9
[2944]10/** Class describing a plane in 3D space.
[2751]11*/
12class Plane3
13{
14public:
15
16        Plane3() {}
17
18        Plane3(const Vector3 &a, const Vector3 &b, const Vector3 &c);
[2944]19        /** Note: we assume that the normal vector is already normalized.
20        */
[2751]21        Plane3(const Vector3 &normal, const Vector3 &point);
22
[2755]23        inline void ReverseOrientation()
[2751]24        {
25                mNormal *= -1;
26                mD *= -1;
27        }
[2853]28        /** Get distance to a point.
[2755]29        */
30        inline float Distance(const Vector3 &v) const
[2751]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        */
[2911]38        int Side(const Vector3 &v, float threshold = 1e-6) const;
[2751]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
[2911]55        operator const float*() const
56        {
57                return (const float*) this;
58        }
[2751]59
[2911]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        }
[2944]69        /** Transforms the plane  with the matrix m.
70        */
71        void Transform(const Matrix4x4 &m);
[2911]72
[2944]73
[2755]74        ///////////
[2751]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);
[2911]80       
[2751]81
82        friend std::ostream &operator<<(std::ostream &s, const Plane3 &p)
83        {       
[2755]84                s << p.mNormal << " " << p.mD;
[2751]85                return s;
86        }
87
88
[2944]89//protected:
90
[2751]91        ///////////////
92
93        Vector3 mNormal;
94        float mD;
95};
96
[2911]97
[2751]98}
99#endif
Note: See TracBrowser for help on using the repository browser.