RavEngine
Loading...
Searching...
No Matches
PxPlane.h
1// Redistribution and use in source and binary forms, with or without
2// modification, are permitted provided that the following conditions
3// are met:
4// * Redistributions of source code must retain the above copyright
5// notice, this list of conditions and the following disclaimer.
6// * Redistributions in binary form must reproduce the above copyright
7// notice, this list of conditions and the following disclaimer in the
8// documentation and/or other materials provided with the distribution.
9// * Neither the name of NVIDIA CORPORATION nor the names of its
10// contributors may be used to endorse or promote products derived
11// from this software without specific prior written permission.
12//
13// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
14// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
17// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24//
25// Copyright (c) 2008-2022 NVIDIA Corporation. All rights reserved.
26// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
27// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
28
29#ifndef PX_PLANE_H
30#define PX_PLANE_H
31
36#include "foundation/PxTransform.h"
37
38#if !PX_DOXYGEN
39namespace physx
40{
41#endif
42
49{
50 public:
54 PX_CUDA_CALLABLE PX_FORCE_INLINE PxPlane()
55 {
56 }
57
61 PX_CUDA_CALLABLE PX_FORCE_INLINE PxPlane(float nx, float ny, float nz, float distance) : n(nx, ny, nz), d(distance)
62 {
63 }
64
68 PX_CUDA_CALLABLE PX_FORCE_INLINE PxPlane(const PxVec3& normal, float distance) : n(normal), d(distance)
69 {
70 }
71
75 PX_CUDA_CALLABLE PX_FORCE_INLINE PxPlane(const PxVec3& point, const PxVec3& normal)
76 : n(normal), d(-point.dot(n)) // p satisfies normal.dot(p) + d = 0
77 {
78 }
79
83 PX_CUDA_CALLABLE PX_FORCE_INLINE PxPlane(const PxVec3& p0, const PxVec3& p1, const PxVec3& p2)
84 {
85 n = (p1 - p0).cross(p2 - p0).getNormalized();
86 d = -p0.dot(n);
87 }
88
92 PX_CUDA_CALLABLE PX_INLINE bool operator==(const PxPlane& p) const
93 {
94 return n == p.n && d == p.d;
95 }
96
97 PX_CUDA_CALLABLE PX_FORCE_INLINE float distance(const PxVec3& p) const
98 {
99 return p.dot(n) + d;
100 }
101
102 PX_CUDA_CALLABLE PX_FORCE_INLINE bool contains(const PxVec3& p) const
103 {
104 return PxAbs(distance(p)) < (1.0e-7f);
105 }
106
110 PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec3 project(const PxVec3& p) const
111 {
112 return p - n * distance(p);
113 }
114
118 PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec3 pointInPlane() const
119 {
120 return -n * d;
121 }
122
127 PX_CUDA_CALLABLE PX_FORCE_INLINE void normalize()
128 {
129 float denom = 1.0f / n.magnitude();
130 n *= denom;
131 d *= denom;
132 }
133
137 PX_CUDA_CALLABLE PX_FORCE_INLINE PxPlane transform(const PxTransform& pose) const
138 {
139 const PxVec3 transformedNormal = pose.rotate(n);
140 return PxPlane(transformedNormal, d - pose.p.dot(transformedNormal));
141 }
142
146 PX_CUDA_CALLABLE PX_FORCE_INLINE PxPlane inverseTransform(const PxTransform& pose) const
147 {
148 const PxVec3 transformedNormal = pose.rotateInv(n);
149 return PxPlane(transformedNormal, d + pose.p.dot(n));
150 }
151
153 float d;
154};
155
156#if !PX_DOXYGEN
157} // namespace physx
158#endif
159
161#endif
162
Representation of a plane.
Definition PxPlane.h:49
PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec3 project(const PxVec3 &p) const
projects p into the plane
Definition PxPlane.h:110
PX_CUDA_CALLABLE PX_INLINE bool operator==(const PxPlane &p) const
returns true if the two planes are exactly equal
Definition PxPlane.h:92
PX_CUDA_CALLABLE PX_FORCE_INLINE PxPlane(const PxVec3 &normal, float distance)
Constructor from a normal and a distance.
Definition PxPlane.h:68
PxVec3 n
The normal to the plane.
Definition PxPlane.h:152
PX_CUDA_CALLABLE PX_FORCE_INLINE PxPlane inverseTransform(const PxTransform &pose) const
inverse-transform plane
Definition PxPlane.h:146
PX_CUDA_CALLABLE PX_FORCE_INLINE PxPlane(const PxVec3 &p0, const PxVec3 &p1, const PxVec3 &p2)
Constructor from three points.
Definition PxPlane.h:83
PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec3 pointInPlane() const
find an arbitrary point in the plane
Definition PxPlane.h:118
PX_CUDA_CALLABLE PX_FORCE_INLINE PxPlane()
Constructor.
Definition PxPlane.h:54
float d
The distance from the origin.
Definition PxPlane.h:153
PX_CUDA_CALLABLE PX_FORCE_INLINE PxPlane(const PxVec3 &point, const PxVec3 &normal)
Constructor from a point on the plane and a normal.
Definition PxPlane.h:75
PX_CUDA_CALLABLE PX_FORCE_INLINE void normalize()
equivalent plane with unit normal
Definition PxPlane.h:127
PX_CUDA_CALLABLE PX_FORCE_INLINE PxPlane(float nx, float ny, float nz, float distance)
Constructor from a normal and a distance.
Definition PxPlane.h:61
PX_CUDA_CALLABLE PX_FORCE_INLINE PxPlane transform(const PxTransform &pose) const
transform plane
Definition PxPlane.h:137
class representing a rigid euclidean transform as a quaternion and a vector
Definition PxTransform.h:49
3 Element vector class.
Definition PxVec3.h:50
PX_CUDA_CALLABLE PX_FORCE_INLINE float dot(const PxVec3 &v) const
returns the scalar product of this and other.
Definition PxVec3.h:276
PX_CUDA_CALLABLE PX_FORCE_INLINE float magnitude() const
returns the magnitude
Definition PxVec3.h:183
#define PX_FORCE_INLINE
Definition PxPreprocessor.h:335
#define PX_INLINE
Definition PxPreprocessor.h:320
Sorts an array of objects in ascending order, assuming that the predicate implements the < operator:
Definition PxBoxController.h:39
PX_CUDA_CALLABLE PX_FORCE_INLINE float PxAbs(float a)
abs returns the absolute value of its argument.
Definition PxMath.h:109