source: GTP/trunk/Lib/Illum/GPUObscurancesGT/include/PLANE.h @ 930

Revision 930, 2.1 KB checked in by igarcia, 18 years ago (diff)
Line 
1//////////////////////////////////////////////////////////////////////////////////////////
2//      PLANE.h
3//      Class declaration for a plane in 3d space
4//      You may use this code however you wish, but if you do, please credit me and
5//      provide a link to my website in a readme file or similar
6//      Downloaded from: www.paulsprojects.net
7//      Created:        20th July 2002
8//      Modified:       6th August 2002         -       Added "Normalize"
9//                              7th November 2002       -       Altered constructor layout
10//                                                                      -       Corrected "lerp"
11//////////////////////////////////////////////////////////////////////////////////////////     
12
13#ifndef PLANE_H
14#define PLANE_H
15
16class PLANE
17{
18public:
19        PLANE() :       normal(VECTOR3D(0.0f, 0.0f, 0.0f)), intercept(0.0f)
20        {}
21        PLANE(VECTOR3D newNormal, float newIntercept)   : normal(newNormal), intercept(newIntercept)
22        {}
23        PLANE(const PLANE & rhs)
24        {       normal=rhs.normal;      intercept=rhs.intercept;        }
25
26        ~PLANE() {}
27       
28        void SetNormal(const VECTOR3D & rhs) { normal=rhs; }
29        void SetIntercept(float newIntercept) { intercept=newIntercept; }
30        void SetFromPoints(const VECTOR3D & p0, const VECTOR3D & p1, const VECTOR3D & p2);
31
32        void CalculateIntercept(const VECTOR3D & pointOnPlane) { intercept=-normal.DotProduct(pointOnPlane); }
33       
34        void Normalize(void);
35
36        VECTOR3D GetNormal() { return normal; }
37        float GetIntercept() { return intercept; }
38       
39        //find point of intersection of 3 planes
40        bool Intersect3(const PLANE & p2, const PLANE & p3, VECTOR3D & result);
41
42        float GetDistance(const VECTOR3D & point) const;
43        int ClassifyPoint(const VECTOR3D & point) const;
44       
45        PLANE lerp(const PLANE & p2, float factor);
46
47        //operators
48        bool operator==(const PLANE & rhs) const;
49        bool operator!=(const PLANE & rhs) const
50        {               return!((*this)==rhs);  }
51
52        //unary operators
53        PLANE operator-(void) const {return PLANE(-normal, -intercept);}
54        PLANE operator+(void) const {return (*this);}
55
56        //member variables
57        VECTOR3D normal;        //X.N+intercept=0
58        float intercept;
59};
60
61//constants for ClassifyPoint()
62const int POINT_ON_PLANE=0;
63const int POINT_IN_FRONT_OF_PLANE=1;
64const int POINT_BEHIND_PLANE=2;
65
66#endif //PLANE_H
Note: See TracBrowser for help on using the repository browser.