diff options
| author | git perforce import user <a@b> | 2016-10-25 12:29:14 -0600 |
|---|---|---|
| committer | Sheikh Dawood Abdul Ajees <Sheikh Dawood Abdul Ajees> | 2016-10-25 18:56:37 -0500 |
| commit | 3dfe2108cfab31ba3ee5527e217d0d8e99a51162 (patch) | |
| tree | fa6485c169e50d7415a651bf838f5bcd0fd3bfbd /KaplaDemo/samples/sampleViewer3/Vec/Plane.h | |
| download | physx-3.4-3dfe2108cfab31ba3ee5527e217d0d8e99a51162.tar.xz physx-3.4-3dfe2108cfab31ba3ee5527e217d0d8e99a51162.zip | |
Initial commit:
PhysX 3.4.0 Update @ 21294896
APEX 1.4.0 Update @ 21275617
[CL 21300167]
Diffstat (limited to 'KaplaDemo/samples/sampleViewer3/Vec/Plane.h')
| -rw-r--r-- | KaplaDemo/samples/sampleViewer3/Vec/Plane.h | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/KaplaDemo/samples/sampleViewer3/Vec/Plane.h b/KaplaDemo/samples/sampleViewer3/Vec/Plane.h new file mode 100644 index 00000000..db735926 --- /dev/null +++ b/KaplaDemo/samples/sampleViewer3/Vec/Plane.h @@ -0,0 +1,73 @@ +#ifndef PLANE_H +#define PLANE_H + +#include "Vec3.H" + +// Singe / VecReal Precision Vec 3 +// Matthias Mueller +// derived from Plane + +namespace M +{ + +class Plane +{ +public: + Plane() {} + Plane(VecReal nx, VecReal ny, VecReal nz, VecReal distance) + : n(nx, ny, nz) + , d(distance) + {} + + Plane(const Vec3& normal, VecReal distance) + : n(normal) + , d(distance) + {} + + Plane(const Vec3& point, const Vec3& normal) + : n(normal) + , d(-point.dot(n)) // p satisfies normal.dot(p) + d = 0 + { + } + + Plane(const Vec3& p0, const Vec3& p1, const Vec3& p2) + { + n = (p1 - p0).cross(p2 - p0).getNormalized(); + d = -p0.dot(n); + } + + VecReal distance(const Vec3& p) const + { + return p.dot(n) + d; + } + + bool contains(const Vec3& p) const + { + return vecAbs(distance(p)) < (1.0e-7f); + } + + Vec3 project(const Vec3 & p) const + { + return p - n * distance(p); + } + + Vec3 pointInPlane() const + { + return -n*d; + } + + void normalize() + { + VecReal denom = 1.0f / n.magnitude(); + n *= denom; + d *= denom; + } + + Vec3 n; //!< The normal to the plane + VecReal d; //!< The distance from the origin +}; + +} + +#endif + |