TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Plane.h
Go to the documentation of this file.
1 
12 #ifndef G3D_Plane_h
13 #define G3D_Plane_h
14 
15 #include "G3D/platform.h"
16 #include "G3D/Vector3.h"
17 #include "G3D/Vector4.h"
18 #include "G3D/debugAssert.h"
19 
20 namespace G3D {
21 
25 class Plane {
26 private:
27 
30  float _distance;
31 
35  Plane(const Vector3& n, float d) : _normal(n), _distance(d) {
36  }
37 
38 public:
39 
40  Plane() : _normal(Vector3::unitY()), _distance(0) {
41  }
42 
46  explicit Plane(const class Any& a);
47 
48  Any toAny() const;
49 
53  Plane
54  (const Point3& point0,
55  const Point3& point1,
56  const Point3& point2);
57 
62  Plane(
63  Vector4 point0,
64  Vector4 point1,
65  Vector4 point2);
66 
70  Plane
71  (const Vector3& normal,
72  const Point3& point);
73 
74  static Plane fromEquation(float a, float b, float c, float d);
75 
76  Plane(class BinaryInput& b);
77 
78  void serialize(class BinaryOutput& b) const;
79  void deserialize(class BinaryInput& b);
80 
81  virtual ~Plane() {}
82 
87  inline bool halfSpaceContains(Point3 point) const {
88  // Clamp to a finite range for testing
89  point = point.clamp(Vector3::minFinite(), Vector3::maxFinite());
90 
91  // We can get away with putting values *at* the limits of the float32 range into
92  // a dot product, since the dot product is carried out on float64.
93  return _normal.dot(point) >= _distance;
94  }
95 
100  inline bool halfSpaceContains(const Vector4& point) const {
101  if (point.w == 0) {
102  return _normal.dot(point.xyz()) > 0;
103  } else {
104  return halfSpaceContains(point.xyz() / point.w);
105  }
106  }
107 
112  inline bool halfSpaceContainsFinite(const Point3& point) const {
113  debugAssert(point.isFinite());
114  return _normal.dot(point) >= _distance;
115  }
116 
120  inline bool fuzzyContains(const Point3& point) const {
121  return fuzzyEq(point.dot(_normal), _distance);
122  }
123 
124  inline const Vector3& normal() const {
125  return _normal;
126  }
127 
131  inline float distance(const Vector3& x) const {
132  return (_normal.dot(x) - _distance);
133  }
134 
135  inline Point3 closestPoint(const Point3& x) const {
136  return x + (_normal * (-distance(x)));
137  }
138 
140  Vector3 center() const {
141  return _normal * _distance;
142  }
143 
148  void flip();
149 
155  void getEquation(Vector3& normal, double& d) const;
156  void getEquation(Vector3& normal, float& d) const;
157 
161  void getEquation(double& a, double& b, double& c, double& d) const;
162  void getEquation(float& a, float& b, float& c, float& d) const;
163 
164  std::string toString() const;
165 };
166 
167 } // namespace
168 
169 #endif
void flip()
Definition: Plane.cpp:126
const Vector3 & normal() const
Definition: Plane.h:124
Definition: Plane.h:25
Plane(const Vector3 &n, float d)
Definition: Plane.h:35
bool fuzzyContains(const Point3 &point) const
Definition: Plane.h:120
static const Vector3 & minFinite()
Definition: Vector3.cpp:126
Definition: BinaryInput.h:69
float w
Definition: Vector4.h:74
std::string toString() const
Definition: Plane.cpp:161
virtual ~Plane()
Definition: Plane.h:81
Vector3 clamp(const Vector3 &low, const Vector3 &high) const
Definition: Vector3.h:329
Definition: AABox.h:25
Point3 closestPoint(const Point3 &x) const
Definition: Plane.h:135
float __fastcall dot(const Vector3 &rkVector) const
Definition: Vector3.h:771
Any toAny() const
Definition: Plane.cpp:27
float _distance
Definition: Plane.h:30
Vector3 xyz() const
Definition: Vector4.cpp:233
Definition: Vector3.h:58
Easy loading and saving of human-readable configuration files.
Definition: Any.h:184
Vector3 center() const
Definition: Plane.h:140
void serialize(class BinaryOutput &b) const
Definition: Plane.cpp:39
#define debugAssert(exp)
Definition: debugAssert.h:160
Vector3 _normal
Definition: Plane.h:29
static Plane fromEquation(float a, float b, float c, float d)
Definition: Plane.cpp:117
float distance(const Vector3 &x) const
Definition: Plane.h:131
Definition: Vector4.h:39
bool isFinite() const
Definition: Vector3.h:652
bool halfSpaceContains(const Vector4 &point) const
Definition: Plane.h:100
static const Vector3 & maxFinite()
Definition: Vector3.cpp:127
Definition: BinaryOutput.h:52
bool halfSpaceContainsFinite(const Point3 &point) const
Definition: Plane.h:112
Plane()
Definition: Plane.h:40
void deserialize(class BinaryInput &b)
Definition: Plane.cpp:45
G3D::int16 x
Definition: Vector2int16.h:37
void getEquation(Vector3 &normal, double &d) const
Definition: Plane.cpp:138
bool halfSpaceContains(Point3 point) const
Definition: Plane.h:87
bool fuzzyEq(double a, double b)
Definition: g3dmath.h:857