My Project
ParaPlane.h
1 #pragma once
2 // Original free version by:
3 // Magic Software, Inc.
4 // http://www.geometrictools.com/
5 // Copyright (c) 2000, All Rights Reserved
6 
7 #include "ParaVector3.h"
8 
9 namespace ParaEngine
10 {
11  class CShapeAABB;
12 
23  class Plane
24  {
25  public:
26  Vector3 normal;
27  float d;
32  enum Side
33  {
34  NO_SIDE,
35  POSITIVE_SIDE,
36  NEGATIVE_SIDE,
37  BOTH_SIDE
38  };
39 
40  public:
43  Plane ();
44  Plane (const Plane& rhs);
46  Plane (const Vector3& rkNormal, float fConstant);
48  Plane (float a, float b, float c, float d);
49  Plane (const Vector3& rkNormal, const Vector3& rkPoint);
50  Plane (const Vector3& rkPoint0, const Vector3& rkPoint1,
51  const Vector3& rkPoint2);
52 
53  Side getSide (const Vector3& rkPoint) const;
54 
59  Side getSide (const AxisAlignedBox& rkBox) const;
60 
65  Side getSide(const CShapeAABB& rkBox) const;
66 
76  Side getSide (const Vector3& centre, const Vector3& halfSize) const;
77 
86  float getDistance (const Vector3& rkPoint) const;
87 
89  void redefine(const Vector3& rkPoint0, const Vector3& rkPoint1,
90  const Vector3& rkPoint2);
91 
93  void redefine(const Vector3& rkNormal, const Vector3& rkPoint);
94 
95  inline Plane& Set(float nx, float ny, float nz, float _d){ normal.x = nx; normal.y = ny; normal.z = nz; d = _d; return *this; };
96  inline Plane& Set(const Vector3& p, const Vector3& _n){
97  redefine(_n, p);
98  return *this;
99  }
100  inline Plane& Set(const Vector3& p0, const Vector3& p1, const Vector3& p2){
101  redefine(p0, p1, p2);
102  return *this;
103  }
104 
112  Vector3 projectVector(const Vector3& v) const;
113 
123  float normalise(void);
124 
125 
126  inline float PlaneDotCoord(const Vector3& pV) const
127  {
128  return normal.dotProduct(pV) + d;
129  }
130 
131  inline float PlaneDotNormal(const Vector3& pV) const
132  {
133  return normal.dotProduct(pV);
134  }
135 
136  Plane PlaneTransform(const Matrix4& M) const;
137 
138  inline float a() const { return normal.x; };
139  inline float b() const { return normal.y; };
140  inline float c() const { return normal.z; };
141 
142  // Cast operators
143  operator Vector3() const;
144  operator Vector4() const;
145 
146  // Arithmetic operators
147  Plane operator*(const Matrix4& m) const;
148  Plane& operator*=(const Matrix4& m);
149  Plane operator-() const;
150 
151  operator const float*() const;
152  operator float*();
153 
155  bool operator==(const Plane& rhs) const
156  {
157  return (rhs.d == d && rhs.normal == normal);
158  }
159  bool operator!=(const Plane& rhs) const
160  {
161  return (rhs.d != d && rhs.normal != normal);
162  }
163 
164  friend std::ostream& operator<< (std::ostream& o, const Plane& p);
165  };
166 
167  typedef std::vector<Plane> PlaneList;
168 
169 } // namespace ParaEngine
170 
4-dimensional homogeneous vector.
Definition: ParaVector4.h:10
Vector3 projectVector(const Vector3 &v) const
Project a vector onto the plane.
Definition: ParaPlane.cpp:128
different physics engine has different winding order.
Definition: EventBinding.h:32
float getDistance(const Vector3 &rkPoint) const
This is a pseudo distance.
Definition: ParaPlane.cpp:50
Standard 3-dimensional vector.
Definition: ParaVector3.h:16
Side
The "positive side" of the plane is the half space to which the plane normal points.
Definition: ParaPlane.h:32
AABB-related code.
Definition: ShapeAABB.h:11
Class encapsulating a standard 4x4 homogeneous matrix.
Definition: ParaMatrix4.h:23
Defines a plane in 3D space.
Definition: ParaPlane.h:23
float normalise(void)
Normalizes the plane.
Definition: ParaPlane.cpp:144
bool operator==(const Plane &rhs) const
Comparison operator.
Definition: ParaPlane.h:155
A 3D box aligned with the x/y/z axes.
Definition: ParaAxisAlignedBox.h:16
float dotProduct(const Vector3 &vec) const
Calculates the dot (scalar) product of this vector with another.
Definition: ParaVector3.h:401
void redefine(const Vector3 &rkPoint0, const Vector3 &rkPoint1, const Vector3 &rkPoint2)
Redefine this plane based on 3 points.
Definition: ParaPlane.cpp:112
Plane()
Default constructor - sets everything to 0.
Definition: ParaPlane.cpp:16