RavEngine
Loading...
Searching...
No Matches
GuVecPlane.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 GU_VEC_PLANE_H
30#define GU_VEC_PLANE_H
35#include "foundation/PxVec3.h"
36#include "foundation/PxPlane.h"
37#include "foundation/PxVecMath.h"
38
44namespace physx
45{
46namespace Gu
47{
48
49 class PlaneV
50 {
51 public:
58
62 PX_FORCE_INLINE PlaneV(const aos::FloatVArg nx, const aos::FloatVArg ny, const aos::FloatVArg nz, const aos::FloatVArg _d)
63 {
64 set(nx, ny, nz, _d);
65 }
66
67 PX_FORCE_INLINE PlaneV(const PxPlane& plane)
68 {
69 using namespace aos;
70 const Vec3V _n = V3LoadU(plane.n);
71 const FloatV _d = FLoad(plane.d);
72 nd = V4SetW(Vec4V_From_Vec3V(_n), _d);
73 }
74
75
79 PX_FORCE_INLINE PlaneV(const aos::Vec3VArg p0, const aos::Vec3VArg p1, const aos::Vec3VArg p2)
80 {
81 set(p0, p1, p2);
82 }
83
87 PX_FORCE_INLINE PlaneV(const aos::Vec3VArg _n, const aos::FloatVArg _d)
88 {
89 nd = aos::V4SetW(aos::Vec4V_From_Vec3V(_n), _d);
90 }
91
95 PX_FORCE_INLINE PlaneV(const PlaneV& plane) : nd(plane.nd)
96 {
97 }
98
105
110 {
111 nd = aos::V4Zero();
112 return *this;
113 }
114
115 PX_FORCE_INLINE PlaneV& set(const aos::FloatVArg nx, const aos::FloatVArg ny, const aos::FloatVArg nz, const aos::FloatVArg _d)
116 {
117
118 using namespace aos;
119 const Vec3V n= V3Merge(nx, ny, nz);
120 nd = V4SetW(Vec4V_From_Vec3V(n), _d);
121 return *this;
122 }
123
124 PX_FORCE_INLINE PlaneV& set(const aos::Vec3VArg _normal, aos::FloatVArg _d)
125 {
126 nd = aos::V4SetW(aos::Vec4V_From_Vec3V(_normal), _d);
127 return *this;
128 }
129
133 PlaneV& set(const aos::Vec3VArg p0, const aos::Vec3VArg p1, const aos::Vec3VArg p2)
134 {
135 using namespace aos;
136 const Vec3V edge0 = V3Sub(p1, p0);
137 const Vec3V edge1 = V3Sub(p2, p0);
138
139 const Vec3V n = V3Normalize(V3Cross(edge0, edge1));
140 // See comments in set() for computation of d
141 const FloatV d = FNeg(V3Dot(p0, n));
142 nd = V4SetW(Vec4V_From_Vec3V(n), d);
143 return *this;
144 }
145
146 /***
147 \brief Computes distance, assuming plane is normalized
148 \sa normalize
149 */
150 PX_FORCE_INLINE aos::FloatV distance(const aos::Vec3VArg p) const
151 {
152 // Valid for plane equation a*x + b*y + c*z + d = 0
153 using namespace aos;
154 const Vec3V n = Vec3V_From_Vec4V(nd);
155 return FAdd(V3Dot(p, n), V4GetW(nd));
156 }
157
158 PX_FORCE_INLINE aos::BoolV belongs(const aos::Vec3VArg p) const
159 {
160 using namespace aos;
161 const FloatV eps = FLoad(1.0e-7f);
162 return FIsGrtr(eps, FAbs(distance(p)));
163 }
164
168 PX_FORCE_INLINE aos::Vec3V project(const aos::Vec3VArg p) const
169 {
170 // Pretend p is on positive side of plane, i.e. plane.distance(p)>0.
171 // To project the point we have to go in a direction opposed to plane's normal, i.e.:
172 using namespace aos;
173 const Vec3V n = Vec3V_From_Vec4V(nd);
174 return V3Sub(p, V3Scale(n, V4GetW(nd)));
175
176 }
177
178 PX_FORCE_INLINE aos::FloatV signedDistanceHessianNormalForm(const aos::Vec3VArg point) const
179 {
180 using namespace aos;
181 const Vec3V n = Vec3V_From_Vec4V(nd);
182 return FAdd(V3Dot(n, point), V4GetW(nd));
183 }
184
185 PX_FORCE_INLINE aos::Vec3V getNormal() const
186 {
187 return aos::Vec3V_From_Vec4V(nd);
188 }
189
190 PX_FORCE_INLINE aos::FloatV getSignDist() const
191 {
192 return aos::V4GetW(nd);
193 }
194
199 {
200 // Project origin (0,0,0) to plane:
201 // (0) - normal * distance(0) = - normal * ((p|(0)) + d) = -normal*d
202 using namespace aos;
203 const Vec3V n = Vec3V_From_Vec4V(nd);
204 return V3Neg(V3Scale(n, V4GetW(nd)));
205 }
206
207 PX_FORCE_INLINE void normalize()
208 {
209 using namespace aos;
210 const Vec3V n = Vec3V_From_Vec4V(nd);
211 const FloatV denom = FRecip(V3Length(n));
212 V4Scale(nd, denom);
213 }
214
216 };
217}
218
219}
220
222#endif
Definition GuVecPlane.h:50
PX_FORCE_INLINE aos::Vec3V pointInPlane() const
find an arbitrary point in the plane
Definition GuVecPlane.h:198
PX_FORCE_INLINE PlaneV(const aos::FloatVArg nx, const aos::FloatVArg ny, const aos::FloatVArg nz, const aos::FloatVArg _d)
Constructor from a normal and a distance.
Definition GuVecPlane.h:62
PX_FORCE_INLINE ~PlaneV()
Destructor.
Definition GuVecPlane.h:102
aos::Vec4V nd
The normal to the plan , w store the distance from the origin.
Definition GuVecPlane.h:215
PX_FORCE_INLINE PlaneV(const aos::Vec3VArg _n, const aos::FloatVArg _d)
Constructor from a normal and a distance.
Definition GuVecPlane.h:87
PlaneV & set(const aos::Vec3VArg p0, const aos::Vec3VArg p1, const aos::Vec3VArg p2)
Computes the plane equation from 3 points.
Definition GuVecPlane.h:133
PX_FORCE_INLINE PlaneV & setZero()
Sets plane to zero.
Definition GuVecPlane.h:109
PX_FORCE_INLINE PlaneV(const aos::Vec3VArg p0, const aos::Vec3VArg p1, const aos::Vec3VArg p2)
Constructor from three points.
Definition GuVecPlane.h:79
PX_FORCE_INLINE aos::Vec3V project(const aos::Vec3VArg p) const
projects p into the plane
Definition GuVecPlane.h:168
PX_FORCE_INLINE PlaneV()
Constructor.
Definition GuVecPlane.h:55
PX_FORCE_INLINE PlaneV(const PlaneV &plane)
Copy constructor.
Definition GuVecPlane.h:95
Representation of a plane.
Definition PxPlane.h:49
#define PX_FORCE_INLINE
Definition PxPreprocessor.h:335
Sorts an array of objects in ascending order, assuming that the predicate implements the < operator:
Definition PxBoxController.h:39
Definition PxVecMathAoSScalar.h:90
Definition PxVecMathAoSScalar.h:52
Definition PxVecMathAoSScalar.h:77
Definition PxVecMathAoSScalar.h:65