RavEngine
Loading...
Searching...
No Matches
PxVecTransform.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_VEC_TRANSFORM_H
30#define PX_VEC_TRANSFORM_H
31
32#include "foundation/PxVecMath.h"
33#include "foundation/PxTransform.h"
34
35#if !PX_DOXYGEN
36namespace physx
37{
38#endif
39namespace aos
40{
41
43{
44 public:
45 QuatV q;
46 Vec3V p;
47
48 PX_FORCE_INLINE PxTransformV(const PxTransform& orientation)
49 {
50 // const PxQuat oq = orientation.q;
51 // const PxF32 f[4] = {oq.x, oq.y, oq.z, oq.w};
52 q = QuatVLoadXYZW(orientation.q.x, orientation.q.y, orientation.q.z, orientation.q.w);
53 // q = QuatV_From_F32Array(&oq.x);
54 p = V3LoadU(orientation.p);
55 }
56
57 PX_FORCE_INLINE PxTransformV(const Vec3VArg p0 = V3Zero(), const QuatVArg q0 = QuatIdentity()) : q(q0), p(p0)
58 {
59 PX_ASSERT(isSaneQuatV(q0));
60 }
61
62 PX_FORCE_INLINE PxTransformV operator*(const PxTransformV& x) const
63 {
64 PX_ASSERT(x.isSane());
65 return transform(x);
66 }
67
68 PX_FORCE_INLINE PxTransformV getInverse() const
69 {
70 PX_ASSERT(isFinite());
71 // return PxTransform(q.rotateInv(-p),q.getConjugate());
72 return PxTransformV(QuatRotateInv(q, V3Neg(p)), QuatConjugate(q));
73 }
74
75 PX_FORCE_INLINE void normalize()
76 {
77 p = V3Zero();
78 q = QuatIdentity();
79 }
80
81 PX_FORCE_INLINE void Invalidate()
82 {
83 p = V3Splat(FMax());
84 q = QuatIdentity();
85 }
86
87 PX_FORCE_INLINE Vec3V transform(const Vec3VArg input) const
88 {
89 PX_ASSERT(isFinite());
90 // return q.rotate(input) + p;
91 return QuatTransform(q, p, input);
92 }
93
94 PX_FORCE_INLINE Vec3V transformInv(const Vec3VArg input) const
95 {
96 PX_ASSERT(isFinite());
97 // return q.rotateInv(input-p);
98 return QuatRotateInv(q, V3Sub(input, p));
99 }
100
101 PX_FORCE_INLINE Vec3V rotate(const Vec3VArg input) const
102 {
103 PX_ASSERT(isFinite());
104 // return q.rotate(input);
105 return QuatRotate(q, input);
106 }
107
108 PX_FORCE_INLINE Vec3V rotateInv(const Vec3VArg input) const
109 {
110 PX_ASSERT(isFinite());
111 // return q.rotateInv(input);
112 return QuatRotateInv(q, input);
113 }
114
117 {
118 PX_ASSERT(src.isSane());
119 PX_ASSERT(isSane());
120 // src = [srct, srcr] -> [r*srct + t, r*srcr]
121 // return PxTransform(q.rotate(src.p) + p, q*src.q);
122 return PxTransformV(V3Add(QuatRotate(q, src.p), p), QuatMul(q, src.q));
123 }
124
125#if PX_LINUX && PX_CLANG
126#pragma clang diagnostic push
127#pragma clang diagnostic ignored "-Wbitwise-instead-of-logical" // bitwise intentionally chosen for performance
128#endif
129
134 {
135 // return p.isFinite() && q.isFinite() && q.isValid();
136 return isFiniteVec3V(p) & isFiniteQuatV(q) & isValidQuatV(q);
137 }
138
145 {
146 // return isFinite() && q.isSane();
147 return isFinite() & isSaneQuatV(q);
148 }
149
154 {
155 // return p.isFinite() && q.isFinite();
156 return isFiniteVec3V(p) & isFiniteQuatV(q);
157 }
158
159#if PX_LINUX && PX_CLANG
160#pragma clang diagnostic pop
161#endif
162
165 {
166 PX_ASSERT(src.isSane());
167 PX_ASSERT(isFinite());
168 // src = [srct, srcr] -> [r^-1*(srct-t), r^-1*srcr]
169 /*PxQuat qinv = q.getConjugate();
170 return PxTransform(qinv.rotate(src.p - p), qinv*src.q);*/
171 const QuatV qinv = QuatConjugate(q);
172 const Vec3V v = QuatRotate(qinv, V3Sub(src.p, p));
173 const QuatV rot = QuatMul(qinv, src.q);
174 return PxTransformV(v, rot);
175 }
176
177 static PX_FORCE_INLINE PxTransformV createIdentity()
178 {
179 return PxTransformV(V3Zero());
180 }
181};
182
183PX_FORCE_INLINE PxTransformV loadTransformA(const PxTransform& transform)
184{
185 const QuatV q0 = QuatVLoadA(&transform.q.x);
186 const Vec3V p0 = V3LoadA(&transform.p.x);
187
188 return PxTransformV(p0, q0);
189}
190
191PX_FORCE_INLINE PxTransformV loadTransformU(const PxTransform& transform)
192{
193 const QuatV q0 = QuatVLoadU(&transform.q.x);
194 const Vec3V p0 = V3LoadU(&transform.p.x);
195
196 return PxTransformV(p0, q0);
197}
198
200{
201 public:
202 Mat33V rot;
203 Vec3V p;
204
206 {
207 p = V3Zero();
208 rot = M33Identity();
209 }
210 PX_FORCE_INLINE PxMatTransformV(const Vec3VArg _p, const Mat33V& _rot)
211 {
212 p = _p;
213 rot = _rot;
214 }
215
217 {
218 p = other.p;
219 QuatGetMat33V(other.q, rot.col0, rot.col1, rot.col2);
220 }
221
222 PX_FORCE_INLINE PxMatTransformV(const Vec3VArg _p, const QuatV& quat)
223 {
224 p = _p;
225 QuatGetMat33V(quat, rot.col0, rot.col1, rot.col2);
226 }
227
228 PX_FORCE_INLINE Vec3V getCol0() const
229 {
230 return rot.col0;
231 }
232
233 PX_FORCE_INLINE Vec3V getCol1() const
234 {
235 return rot.col1;
236 }
237
238 PX_FORCE_INLINE Vec3V getCol2() const
239 {
240 return rot.col2;
241 }
242
243 PX_FORCE_INLINE void setCol0(const Vec3VArg col0)
244 {
245 rot.col0 = col0;
246 }
247
248 PX_FORCE_INLINE void setCol1(const Vec3VArg col1)
249 {
250 rot.col1 = col1;
251 }
252
253 PX_FORCE_INLINE void setCol2(const Vec3VArg col2)
254 {
255 rot.col2 = col2;
256 }
257
258 PX_FORCE_INLINE Vec3V transform(const Vec3VArg input) const
259 {
260 return V3Add(p, M33MulV3(rot, input));
261 }
262
263 PX_FORCE_INLINE Vec3V transformInv(const Vec3VArg input) const
264 {
265 return M33TrnspsMulV3(rot, V3Sub(input, p)); // QuatRotateInv(q, V3Sub(input, p));
266 }
267
268 PX_FORCE_INLINE Vec3V rotate(const Vec3VArg input) const
269 {
270 return M33MulV3(rot, input);
271 }
272
273 PX_FORCE_INLINE Vec3V rotateInv(const Vec3VArg input) const
274 {
275 return M33TrnspsMulV3(rot, input);
276 }
277
278 PX_FORCE_INLINE PxMatTransformV transformInv(const PxMatTransformV& src) const
279 {
280
281 const Vec3V v = M33TrnspsMulV3(rot, V3Sub(src.p, p));
282 const Mat33V mat = M33MulM33(M33Trnsps(rot), src.rot);
283 return PxMatTransformV(v, mat);
284 }
285};
286}
287#if !PX_DOXYGEN
288} // namespace physx
289#endif
290
291#endif
class representing a rigid euclidean transform as a quaternion and a vector
Definition PxTransform.h:49
Definition PxVecTransform.h:200
Definition PxVecTransform.h:43
PX_FORCE_INLINE PxTransformV transformInv(const PxTransformV &src) const
Transform transform from parent (returns compound transform: first src, then this->inverse)
Definition PxVecTransform.h:164
PX_FORCE_INLINE bool isValid() const
returns true if finite and q is a unit quaternion
Definition PxVecTransform.h:133
PX_FORCE_INLINE PxTransformV transform(const PxTransformV &src) const
Transform transform to parent (returns compound transform: first src, then *this)
Definition PxVecTransform.h:116
PX_FORCE_INLINE bool isFinite() const
returns true if all elems are finite (not NAN or INF, etc.)
Definition PxVecTransform.h:153
PX_FORCE_INLINE bool isSane() const
returns true if finite and quat magnitude is reasonably close to unit to allow for some accumulation ...
Definition PxVecTransform.h:144
#define PX_FORCE_INLINE
Definition PxPreprocessor.h:335
transform(pattern)
Definition docopt.py:72
Sorts an array of objects in ascending order, assuming that the predicate implements the < operator:
Definition PxBoxController.h:39
Definition PxVecMathAoSScalar.h:101
Definition PxVecMathAoSScalar.h:77
Definition PxVecMathAoSScalar.h:65