RavEngine
Loading...
Searching...
No Matches
PxTransform.h
1//
2// Redistribution and use in source and binary forms, with or without
3// modification, are permitted provided that the following conditions
4// are met:
5// * Redistributions of source code must retain the above copyright
6// notice, this list of conditions and the following disclaimer.
7// * Redistributions in binary form must reproduce the above copyright
8// notice, this list of conditions and the following disclaimer in the
9// documentation and/or other materials provided with the distribution.
10// * Neither the name of NVIDIA CORPORATION nor the names of its
11// contributors may be used to endorse or promote products derived
12// from this software without specific prior written permission.
13//
14// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
15// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
18// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25//
26// Copyright (c) 2008-2021 NVIDIA Corporation. All rights reserved.
27// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
28// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
29
30#ifndef PXFOUNDATION_PXTRANSFORM_H
31#define PXFOUNDATION_PXTRANSFORM_H
36#include "foundation/PxQuat.h"
37#include "foundation/PxPlane.h"
38
39#if !PX_DOXYGEN
40namespace physx
41{
42#endif
43
49{
50 public:
51 PxQuat q;
52 PxVec3 p;
53
54 PX_CUDA_CALLABLE PX_FORCE_INLINE PxTransform()
55 {
56 }
57
58 PX_CUDA_CALLABLE PX_FORCE_INLINE explicit PxTransform(const PxVec3& position) : q(PxIdentity), p(position)
59 {
60 }
61
62 PX_CUDA_CALLABLE PX_FORCE_INLINE explicit PxTransform(PxIDENTITY r) : q(PxIdentity), p(PxZero)
63 {
64 PX_UNUSED(r);
65 }
66
67 PX_CUDA_CALLABLE PX_FORCE_INLINE explicit PxTransform(const PxQuat& orientation) : q(orientation), p(0)
68 {
69 PX_SHARED_ASSERT(orientation.isSane());
70 }
71
72 PX_CUDA_CALLABLE PX_FORCE_INLINE PxTransform(float x, float y, float z, PxQuat aQ = PxQuat(PxIdentity))
73 : q(aQ), p(x, y, z)
74 {
75 }
76
77 PX_CUDA_CALLABLE PX_FORCE_INLINE PxTransform(const PxVec3& p0, const PxQuat& q0) : q(q0), p(p0)
78 {
79 PX_SHARED_ASSERT(q0.isSane());
80 }
81
82 PX_CUDA_CALLABLE PX_FORCE_INLINE explicit PxTransform(const PxMat44& m); // defined in PxMat44.h
83
87 PX_CUDA_CALLABLE PX_INLINE bool operator==(const PxTransform& t) const
88 {
89 return p == t.p && q == t.q;
90 }
91
92 PX_CUDA_CALLABLE PX_FORCE_INLINE PxTransform operator*(const PxTransform& x) const
93 {
94 PX_SHARED_ASSERT(x.isSane());
95 return transform(x);
96 }
97
99 PX_CUDA_CALLABLE PX_INLINE PxTransform& operator*=(PxTransform& other)
100 {
101 *this = *this * other;
102 return *this;
103 }
104
105 PX_CUDA_CALLABLE PX_FORCE_INLINE PxTransform getInverse() const
106 {
107 PX_SHARED_ASSERT(isFinite());
108 return PxTransform(q.rotateInv(-p), q.getConjugate());
109 }
110
111 PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec3 transform(const PxVec3& input) const
112 {
113 PX_SHARED_ASSERT(isFinite());
114 return q.rotate(input) + p;
115 }
116
117 PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec3 transformInv(const PxVec3& input) const
118 {
119 PX_SHARED_ASSERT(isFinite());
120 return q.rotateInv(input - p);
121 }
122
123 PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec3 rotate(const PxVec3& input) const
124 {
125 PX_SHARED_ASSERT(isFinite());
126 return q.rotate(input);
127 }
128
129 PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec3 rotateInv(const PxVec3& input) const
130 {
131 PX_SHARED_ASSERT(isFinite());
132 return q.rotateInv(input);
133 }
134
136 PX_CUDA_CALLABLE PX_FORCE_INLINE PxTransform transform(const PxTransform& src) const
137 {
138 PX_SHARED_ASSERT(src.isSane());
139 PX_SHARED_ASSERT(isSane());
140 // src = [srct, srcr] -> [r*srct + t, r*srcr]
141 return PxTransform(q.rotate(src.p) + p, q * src.q);
142 }
143
148 PX_CUDA_CALLABLE bool isValid() const
149 {
150 return p.isFinite() && q.isFinite() && q.isUnit();
151 }
152
158 PX_CUDA_CALLABLE bool isSane() const
159 {
160 return isFinite() && q.isSane();
161 }
162
166 PX_CUDA_CALLABLE PX_FORCE_INLINE bool isFinite() const
167 {
168 return p.isFinite() && q.isFinite();
169 }
170
172 PX_CUDA_CALLABLE PX_FORCE_INLINE PxTransform transformInv(const PxTransform& src) const
173 {
174 PX_SHARED_ASSERT(src.isSane());
175 PX_SHARED_ASSERT(isFinite());
176 // src = [srct, srcr] -> [r^-1*(srct-t), r^-1*srcr]
177 PxQuat qinv = q.getConjugate();
178 return PxTransform(qinv.rotate(src.p - p), qinv * src.q);
179 }
180
185 PX_CUDA_CALLABLE PX_FORCE_INLINE PxPlane transform(const PxPlane& plane) const
186 {
187 PxVec3 transformedNormal = rotate(plane.n);
188 return PxPlane(transformedNormal, plane.d - p.dot(transformedNormal));
189 }
190
195 PX_CUDA_CALLABLE PX_FORCE_INLINE PxPlane inverseTransform(const PxPlane& plane) const
196 {
197 PxVec3 transformedNormal = rotateInv(plane.n);
198 return PxPlane(transformedNormal, plane.d + p.dot(plane.n));
199 }
200
205 {
206 return PxTransform(p, q.getNormalized());
207 }
208};
209
210#if !PX_DOXYGEN
211} // namespace physx
212#endif
213
215#endif // #ifndef PXFOUNDATION_PXTRANSFORM_H
4x4 matrix class
Definition PxMat44.h:55
Representation of a plane.
Definition PxPlane.h:49
This is a quaternion class. For more information on quaternion mathematics consult a mathematics sour...
Definition PxQuat.h:50
PX_CUDA_CALLABLE PX_FORCE_INLINE const PxVec3 rotate(const PxVec3 &v) const
Definition PxQuat.h:287
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 PxVec3 rotateInv(const PxVec3 &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 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:49
PX_CUDA_CALLABLE PX_INLINE PxTransform & operator*=(PxTransform &other)
Equals matrix multiplication.
Definition PxTransform.h:99
PX_CUDA_CALLABLE PX_FORCE_INLINE PxTransform getNormalized() const
return a normalized transform (i.e. one in which the quaternion has unit magnitude)
Definition PxTransform.h:204
PX_CUDA_CALLABLE PX_FORCE_INLINE PxPlane inverseTransform(const PxPlane &plane) const
inverse-transform plane
Definition PxTransform.h:195
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:158
PX_CUDA_CALLABLE PX_FORCE_INLINE PxPlane transform(const PxPlane &plane) const
transform plane
Definition PxTransform.h:185
PX_CUDA_CALLABLE PX_FORCE_INLINE PxTransform transformInv(const PxTransform &src) const
Transform transform from parent (returns compound transform: first src, then this->inverse)
Definition PxTransform.h:172
PX_CUDA_CALLABLE PX_FORCE_INLINE PxTransform transform(const PxTransform &src) const
Transform transform to parent (returns compound transform: first src, then *this)
Definition PxTransform.h:136
PX_CUDA_CALLABLE PX_INLINE bool operator==(const PxTransform &t) const
returns true if the two transforms are exactly equal
Definition PxTransform.h:87
PX_CUDA_CALLABLE bool isValid() const
returns true if finite and q is a unit quaternion
Definition PxTransform.h:148
PX_CUDA_CALLABLE PX_FORCE_INLINE bool isFinite() const
returns true if all elems are finite (not NAN or INF, etc.)
Definition PxTransform.h:166
3 Element vector class.
Definition PxVec3.h:50
#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
PxIDENTITY
Definition Px.h:99