PxTransform.h
Go to the documentation of this file.
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-2018 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
32 
36 #include "foundation/PxQuat.h"
37 #include "foundation/PxPlane.h"
38 
39 #if !PX_DOXYGEN
40 namespace physx
41 {
42 #endif
43 
49 {
50  public:
53 
55  {
56  }
57 
58  PX_CUDA_CALLABLE PX_FORCE_INLINE explicit PxTransform(const PxVec3& position) : q(PxIdentity), p(position)
59  {
60  }
61 
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_ASSERT(orientation.isSane());
70  }
71 
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_ASSERT(q0.isSane());
80  }
81 
82  PX_CUDA_CALLABLE PX_FORCE_INLINE explicit PxTransform(const PxMat44& m); // defined in PxMat44.h
83 
88  {
89  return p == t.p && q == t.q;
90  }
91 
93  {
94  PX_ASSERT(x.isSane());
95  return transform(x);
96  }
97 
100  {
101  *this = *this * other;
102  return *this;
103  }
104 
106  {
107  PX_ASSERT(isFinite());
108  return PxTransform(q.rotateInv(-p), q.getConjugate());
109  }
110 
112  {
113  PX_ASSERT(isFinite());
114  return q.rotate(input) + p;
115  }
116 
118  {
119  PX_ASSERT(isFinite());
120  return q.rotateInv(input - p);
121  }
122 
124  {
125  PX_ASSERT(isFinite());
126  return q.rotate(input);
127  }
128 
130  {
131  PX_ASSERT(isFinite());
132  return q.rotateInv(input);
133  }
134 
137  {
138  PX_ASSERT(src.isSane());
139  PX_ASSERT(isSane());
140  // src = [srct, srcr] -> [r*srct + t, r*srcr]
141  return PxTransform(q.rotate(src.p) + p, q * src.q);
142  }
143 
149  {
150  return p.isFinite() && q.isFinite() && q.isUnit();
151  }
152 
159  {
160  return isFinite() && q.isSane();
161  }
162 
167  {
168  return p.isFinite() && q.isFinite();
169  }
170 
173  {
174  PX_ASSERT(src.isSane());
175  PX_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 
186  {
187  PxVec3 transformedNormal = rotate(plane.n);
188  return PxPlane(transformedNormal, plane.d - p.dot(transformedNormal));
189  }
190 
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
Definition: GuContactBuffer.h:37
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 PX_INLINE PxQuat getConjugate() const
Definition: PxQuat.h:247
PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec3 transformInv(const PxVec3 &input) const
Definition: PxTransform.h:117
Definition: Px.h:84
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
PX_CUDA_CALLABLE PX_INLINE bool isFinite() const
returns true if all 3 elems of the vector are finite (not NAN or INF, etc.)
Definition: PxVec3.h:156
PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec3 rotate(const PxVec3 &input) const
Definition: PxTransform.h:123
PxU8 plane[sizeof(PxPlaneGeometry)]
Definition: PxGeometryHelpers.h:219
PX_CUDA_CALLABLE PX_FORCE_INLINE float dot(const PxVec3 &v) const
returns the scalar product of this and other.
Definition: PxVec3.h:276
#define PX_FORCE_INLINE
Definition: PxPreprocessor.h:364
This is a quaternion class. For more information on quaternion mathematics consult a mathematics sour...
Definition: PxQuat.h:49
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 PX_FORCE_INLINE PxTransform(float x, float y, float z, PxQuat aQ=PxQuat(PxIdentity))
Definition: PxTransform.h:72
PX_CUDA_CALLABLE bool isValid() const
returns true if finite and q is a unit quaternion
Definition: PxTransform.h:148
PxQuat q
Definition: PxTransform.h:51
Representation of a plane.
Definition: PxPlane.h:50
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 bool isFinite(float a)
platform-specific finiteness check (not INF or NAN)
Definition: PxUnixIntrinsics.h:127
PX_CUDA_CALLABLE PX_FORCE_INLINE PxTransform()
Definition: PxTransform.h:54
PX_CUDA_CALLABLE PX_FORCE_INLINE PxPlane transform(const PxPlane &plane) const
transform plane
Definition: PxTransform.h:185
Definition: Px.h:78
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_FORCE_INLINE PxTransform(const PxQuat &orientation)
Definition: PxTransform.h:67
PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec3 transform(const PxVec3 &input) const
Definition: PxTransform.h:111
4x4 matrix class
Definition: PxMat44.h:54
PX_CUDA_CALLABLE PX_FORCE_INLINE PxTransform(const PxVec3 &p0, const PxQuat &q0)
Definition: PxTransform.h:77
PX_CUDA_CALLABLE PX_FORCE_INLINE PxTransform operator*(const PxTransform &x) const
Definition: PxTransform.h:92
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
class representing a rigid euclidean transform as a quaternion and a vector
Definition: PxTransform.h:48
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 PxTransform(PxIDENTITY r)
Definition: PxTransform.h:62
PX_CUDA_CALLABLE PX_INLINE PxQuat getNormalized() const
Definition: PxQuat.h:212
PX_CUDA_CALLABLE PX_INLINE PxTransform & operator*=(PxTransform &other)
Equals matrix multiplication.
Definition: PxTransform.h:99
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_INLINE void PX_UNUSED(T const &)
Definition: PxPreprocessor.h:479
PX_CUDA_CALLABLE PX_FORCE_INLINE PxPlane inverseTransform(const PxPlane &plane) const
inverse-transform plane
Definition: PxTransform.h:195
PX_CUDA_CALLABLE PX_FORCE_INLINE PxTransform(const PxVec3 &position)
Definition: PxTransform.h:58
PX_CUDA_CALLABLE PX_FORCE_INLINE const PxVec3 rotate(const PxVec3 &v) const
Definition: PxQuat.h:287
#define PX_ASSERT(exp)
Definition: PxAssert.h:61
PxIDENTITY
Definition: Px.h:82
PX_CUDA_CALLABLE bool isFinite() const
returns true if all elements are finite (not NAN or INF, etc.)
Definition: PxQuat.h:124
PX_CUDA_CALLABLE PX_FORCE_INLINE const PxVec3 rotateInv(const PxVec3 &v) const
Definition: PxQuat.h:301
#define PX_INLINE
Definition: PxPreprocessor.h:349
#define PX_CUDA_CALLABLE
Definition: PxPreprocessor.h:473
PxVec3 p
Definition: PxTransform.h:52
3 Element vector class.
Definition: PxVec3.h:49
PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec3 rotateInv(const PxVec3 &input) const
Definition: PxTransform.h:129
PX_CUDA_CALLABLE PX_FORCE_INLINE PxTransform getInverse() const
Definition: PxTransform.h:105