RavEngine
Loading...
Searching...
No Matches
PxTransform.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_TRANSFORM_H
30#define PX_TRANSFORM_H
35#include "foundation/PxQuat.h"
36
37#if !PX_DOXYGEN
38namespace physx
39{
40#endif
41
46template<class Type>
48{
49 public:
52
53 PX_CUDA_CALLABLE PX_FORCE_INLINE PxTransformT()
54 {
55 }
56
57 PX_CUDA_CALLABLE PX_FORCE_INLINE explicit PxTransformT(const PxVec3T<Type>& position) : q(PxIdentity), p(position)
58 {
59 }
60
61 PX_CUDA_CALLABLE PX_FORCE_INLINE explicit PxTransformT(PxIDENTITY) : q(PxIdentity), p(PxZero)
62 {
63 }
64
65 PX_CUDA_CALLABLE PX_FORCE_INLINE explicit PxTransformT(const PxQuatT<Type>& orientation) : q(orientation), p(Type(0))
66 {
67 PX_ASSERT(orientation.isSane());
68 }
69
70 PX_CUDA_CALLABLE PX_FORCE_INLINE PxTransformT(Type x, Type y, Type z, PxQuatT<Type> aQ = PxQuatT<Type>(PxIdentity)) :
71 q(aQ), p(x, y, z)
72 {
73 }
74
75 PX_CUDA_CALLABLE PX_FORCE_INLINE PxTransformT(const PxVec3T<Type>& p0, const PxQuatT<Type>& q0) : q(q0), p(p0)
76 {
77 PX_ASSERT(q0.isSane());
78 }
79
80 PX_CUDA_CALLABLE PX_FORCE_INLINE explicit PxTransformT(const PxMat44T<Type>& m); // defined in PxMat44.h
81
82 PX_CUDA_CALLABLE PX_FORCE_INLINE void operator=(const PxTransformT& other)
83 {
84 p = other.p;
85 q = other.q;
86 }
87
88 PX_CUDA_CALLABLE PX_FORCE_INLINE PxTransformT(const PxTransformT& other)
89 {
90 p = other.p;
91 q = other.q;
92 }
93
97 PX_CUDA_CALLABLE PX_INLINE bool operator==(const PxTransformT& t) const
98 {
99 return p == t.p && q == t.q;
100 }
101
102 PX_CUDA_CALLABLE PX_FORCE_INLINE PxTransformT operator*(const PxTransformT& x) const
103 {
104 PX_ASSERT(x.isSane());
105 return transform(x);
106 }
107
109 PX_CUDA_CALLABLE PX_INLINE PxTransformT& operator*=(const PxTransformT& other)
110 {
111 *this = *this * other;
112 return *this;
113 }
114
115 PX_CUDA_CALLABLE PX_FORCE_INLINE PxTransformT getInverse() const
116 {
117 PX_ASSERT(isFinite());
118 return PxTransformT(q.rotateInv(-p), q.getConjugate());
119 }
120
121 PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec3T<Type> transform(const PxVec3T<Type>& input) const
122 {
123 PX_ASSERT(isFinite());
124 return q.rotate(input) + p;
125 }
126
127 PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec3T<Type> transformInv(const PxVec3T<Type>& input) const
128 {
129 PX_ASSERT(isFinite());
130 return q.rotateInv(input - p);
131 }
132
133 PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec3T<Type> rotate(const PxVec3T<Type>& input) const
134 {
135 PX_ASSERT(isFinite());
136 return q.rotate(input);
137 }
138
139 PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec3T<Type> rotateInv(const PxVec3T<Type>& input) const
140 {
141 PX_ASSERT(isFinite());
142 return q.rotateInv(input);
143 }
144
146 PX_CUDA_CALLABLE PX_FORCE_INLINE PxTransformT transform(const PxTransformT& src) const
147 {
148 PX_ASSERT(src.isSane());
149 PX_ASSERT(isSane());
150 // src = [srct, srcr] -> [r*srct + t, r*srcr]
151 return PxTransformT(q.rotate(src.p) + p, q * src.q);
152 }
153
157 PX_CUDA_CALLABLE bool isValid() const
158 {
159 return p.isFinite() && q.isFinite() && q.isUnit();
160 }
161
166 PX_CUDA_CALLABLE bool isSane() const
167 {
168 return isFinite() && q.isSane();
169 }
170
174 PX_CUDA_CALLABLE PX_FORCE_INLINE bool isFinite() const
175 {
176 return p.isFinite() && q.isFinite();
177 }
178
180 PX_CUDA_CALLABLE PX_FORCE_INLINE PxTransformT transformInv(const PxTransformT& src) const
181 {
182 PX_ASSERT(src.isSane());
183 PX_ASSERT(isFinite());
184 // src = [srct, srcr] -> [r^-1*(srct-t), r^-1*srcr]
185 const PxQuatT<Type> qinv = q.getConjugate();
186 return PxTransformT(qinv.rotate(src.p - p), qinv * src.q);
187 }
188
193 {
194 return PxTransformT(p, q.getNormalized());
195 }
196};
197
198typedef PxTransformT<float> PxTransform;
200
208struct PX_ALIGN_PREFIX(16) PxTransformPadded
209{
210 PxTransform transform;
211 PxU32 padding;
212}
213PX_ALIGN_SUFFIX(16);
214PX_COMPILE_TIME_ASSERT(sizeof(PxTransformPadded)==32);
215
216typedef PxTransformPadded PxTransform32;
217
218#if !PX_DOXYGEN
219} // namespace physx
220#endif
221
223#endif
224
4x4 matrix class
Definition PxMat44.h:55
This is a quaternion class. For more information on quaternion mathematics consult a mathematics sour...
Definition PxQuat.h:49
PX_CUDA_CALLABLE PX_FORCE_INLINE const PxVec3T< Type > rotateInv(const PxVec3T< Type > &v) const
Definition PxQuat.h:301
PX_CUDA_CALLABLE bool isSane() const
returns true if finite and magnitude is reasonably close to unit to allow for some accumulation of er...
Definition PxQuat.h:142
PX_CUDA_CALLABLE bool isUnit() const
returns true if finite and magnitude is close to unit
Definition PxQuat.h:132
PX_CUDA_CALLABLE PX_FORCE_INLINE const PxVec3T< Type > rotate(const PxVec3T< Type > &v) const
Definition PxQuat.h:287
PX_CUDA_CALLABLE bool isFinite() const
returns true if all elements are finite (not NAN or INF, etc.)
Definition PxQuat.h:124
class representing a rigid euclidean transform as a quaternion and a vector
Definition PxTransform.h:48
PX_CUDA_CALLABLE bool isSane() const
returns true if finite and quat magnitude is reasonably close to unit to allow for some accumulation ...
Definition PxTransform.h:166
PX_CUDA_CALLABLE PX_FORCE_INLINE PxTransformT transform(const PxTransformT &src) const
Transform transform to parent (returns compound transform: first src, then *this)
Definition PxTransform.h:146
PX_CUDA_CALLABLE PX_FORCE_INLINE PxTransformT transformInv(const PxTransformT &src) const
Transform transform from parent (returns compound transform: first src, then this->inverse)
Definition PxTransform.h:180
PX_CUDA_CALLABLE PX_FORCE_INLINE bool isFinite() const
returns true if all elems are finite (not NAN or INF, etc.)
Definition PxTransform.h:174
PX_CUDA_CALLABLE bool isValid() const
returns true if finite and q is a unit quaternion
Definition PxTransform.h:157
PX_CUDA_CALLABLE PX_INLINE PxTransformT & operator*=(const PxTransformT &other)
Equals matrix multiplication.
Definition PxTransform.h:109
PX_CUDA_CALLABLE PX_INLINE bool operator==(const PxTransformT &t) const
returns true if the two transforms are exactly equal
Definition PxTransform.h:97
PX_CUDA_CALLABLE PX_FORCE_INLINE PxTransformT getNormalized() const
return a normalized transform (i.e. one in which the quaternion has unit magnitude)
Definition PxTransform.h:192
class representing a rigid euclidean transform as a quaternion and a vector
Definition PxTransform.h:49
3 Element vector class.
Definition PxVec3.h:50
#define PX_FORCE_INLINE
Definition PxPreprocessor.h:335
#define PX_COMPILE_TIME_ASSERT(exp)
Definition PxPreprocessor.h:428
#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
PxIDENTITY
Definition Px.h:99