30 #ifndef PXFOUNDATION_PXQUAT_H 31 #define PXFOUNDATION_PXQUAT_H 91 const float a = angleRadians * 0.5f;
92 const float s =
PxSin(a);
118 return x==0.0f && y==0.0f && z==0.0f && w==1.0f;
134 const float unitTolerance = 1e-4f;
144 const float unitTolerance = 1e-2f;
153 return x == q.
x && y == q.
y && z == q.
z && w == q.
w;
161 const float quatEpsilon = 1.0e-8f;
162 const float s2 = x * x + y * y + z * z;
163 if(s2 < quatEpsilon * quatEpsilon)
166 axis =
PxVec3(1.0f, 0.0f, 0.0f);
171 axis =
PxVec3(x, y, z) * s;
193 return PxAcos(dot(q)) * 2.0f;
201 return x * x + y * y + z * z + w * w;
209 return x * v.
x + y * v.
y + z * v.
z + w * v.
w;
214 const float s = 1.0f / magnitude();
215 return PxQuat(x * s, y * s, z * s, w * s);
220 return PxSqrt(magnitudeSquared());
229 const float mag = magnitude();
232 const float imag = 1.0f / mag;
249 return PxQuat(-x, -y, -z, w);
263 const float x2 = x * 2.0f;
264 const float w2 = w * 2.0f;
265 return PxVec3((w * w2) - 1.0f + x * x2, (z * w2) + y * x2, (-y * w2) + z * x2);
271 const float y2 = y * 2.0f;
272 const float w2 = w * 2.0f;
273 return PxVec3((-z * w2) + x * y2, (w * w2) - 1.0f + y * y2, (x * w2) + z * y2);
279 const float z2 = z * 2.0f;
280 const float w2 = w * 2.0f;
281 return PxVec3((y * w2) + x * z2, (-x * w2) + y * z2, (w * w2) - 1.0f + z * z2);
289 const float vx = 2.0f * v.
x;
290 const float vy = 2.0f * v.
y;
291 const float vz = 2.0f * v.
z;
292 const float w2 = w * w - 0.5f;
293 const float dot2 = (x * vx + y * vy + z * vz);
294 return PxVec3((vx * w2 + (y * vz - z * vy) * w + x * dot2), (vy * w2 + (z * vx - x * vz) * w + y * dot2),
295 (vz * w2 + (x * vy - y * vx) * w + z * dot2));
303 const float vx = 2.0f * v.
x;
304 const float vy = 2.0f * v.
y;
305 const float vz = 2.0f * v.
z;
306 const float w2 = w * w - 0.5f;
307 const float dot2 = (x * vx + y * vy + z * vz);
308 return PxVec3((vx * w2 - (y * vz - z * vy) * w + x * dot2), (vy * w2 - (z * vx - x * vz) * w + y * dot2),
309 (vz * w2 - (x * vy - y * vx) * w + z * dot2));
326 const float tx = w * q.
x + q.
w * x + y * q.
z - q.
y * z;
327 const float ty = w * q.
y + q.
w * y + z * q.
x - q.
z * x;
328 const float tz = w * q.
z + q.
w * z + x * q.
y - q.
x * y;
330 w = w * q.
w - q.
x * x - y * q.
y - q.
z * z;
368 return PxQuat(w * q.
x + q.
w * x + y * q.
z - q.
y * z, w * q.
y + q.
w * y + z * q.
x - q.
z * x,
369 w * q.
z + q.
w * z + x * q.
y - q.
x * y, w * q.
w - x * q.
x - y * q.
y - z * q.
z);
375 return PxQuat(x + q.
x, y + q.
y, z + q.
z, w + q.
w);
381 return PxQuat(-x, -y, -z, -w);
386 return PxQuat(x - q.
x, y - q.
y, z - q.
z, w - q.
w);
391 return PxQuat(x * r, y * r, z * r, w * r);
403 #endif // #ifndef PXFOUNDATION_PXQUAT_H Definition: GuContactBuffer.h:37
PX_CUDA_CALLABLE PX_FORCE_INLINE float magnitudeSquared() const
This is the squared 4D vector length, should be 1 for unit quaternions.
Definition: PxQuat.h:199
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 PxQuat & operator*=(const PxQuat &q)
Definition: PxQuat.h:324
PX_CUDA_CALLABLE PX_FORCE_INLINE float dot(const PxQuat &v) const
returns the scalar product of this and other.
Definition: PxQuat.h:207
PX_CUDA_CALLABLE PX_INLINE float getAngle() const
Gets the angle between this quat and the identity quaternion.
Definition: PxQuat.h:181
PX_CUDA_CALLABLE PX_FORCE_INLINE PxQuat & operator*=(const float s)
Definition: PxQuat.h:356
PX_CUDA_CALLABLE PX_FORCE_INLINE float PxAtan2(float x, float y)
Arctangent of (x/y) with correct sign. Returns angle between -PI and PI in radians Unit: Radians...
Definition: PxMath.h:276
PX_CUDA_CALLABLE PX_FORCE_INLINE PxQuat & operator-=(const PxQuat &q)
Definition: PxQuat.h:347
PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec3 getBasisVector0() const
Definition: PxQuat.h:261
PX_CUDA_CALLABLE PX_INLINE PxQuat operator*(const PxQuat &q) const
Definition: PxQuat.h:366
static const float PxPi
Definition: PxMath.h:58
PX_CUDA_CALLABLE PX_FORCE_INLINE PxQuat operator+(const PxQuat &q) const
Definition: PxQuat.h:373
PX_CUDA_CALLABLE PX_INLINE float magnitude() const
Definition: PxQuat.h:218
#define PX_FORCE_INLINE
Definition: PxPreprocessor.h:351
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 float PxSin(float a)
trigonometry – all angles are in radians.
Definition: PxMath.h:170
PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec3 getBasisVector2() const
Definition: PxQuat.h:277
#define PX_SHARED_ASSERT(exp)
Definition: PxSharedAssert.h:39
float z
Definition: PxQuat.h:395
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 PxVec3 getBasisVector1() const
Definition: PxQuat.h:269
PX_CUDA_CALLABLE PX_FORCE_INLINE float PxSqrt(float a)
Square root.
Definition: PxMath.h:144
PX_CUDA_CALLABLE PX_INLINE float normalize()
maps to the closest unit quaternion.
Definition: PxQuat.h:227
float y
Definition: PxVec3.h:381
float w
Definition: PxQuat.h:395
float x
Definition: PxQuat.h:395
PX_CUDA_CALLABLE PX_FORCE_INLINE PxQuat operator*(float r) const
Definition: PxQuat.h:389
PX_CUDA_CALLABLE PX_FORCE_INLINE float PxRecipSqrt(float a)
reciprocal square root.
Definition: PxMath.h:156
PX_CUDA_CALLABLE PX_FORCE_INLINE float PxCos(float a)
Cosine of an angle (Unit: Radians)
Definition: PxMath.h:182
PX_CUDA_CALLABLE PX_FORCE_INLINE PxQuat(float nx, float ny, float nz, float nw)
Constructor. Take note of the order of the elements!
Definition: PxQuat.h:75
PX_CUDA_CALLABLE PX_FORCE_INLINE PxQuat(float r)
Constructor from a scalar: sets the real part w to the scalar value, and the imaginary parts (x...
Definition: PxQuat.h:68
PX_CUDA_CALLABLE PX_INLINE void toRadiansAndUnitAxis(float &angle, PxVec3 &axis) const
converts this quaternion to angle-axis representation
Definition: PxQuat.h:159
PX_CUDA_CALLABLE PX_FORCE_INLINE float magnitude() const
returns the magnitude
Definition: PxVec3.h:183
PX_CUDA_CALLABLE PX_FORCE_INLINE float PxAbs(float a)
abs returns the absolute value of its argument.
Definition: PxMath.h:107
PX_CUDA_CALLABLE PX_FORCE_INLINE PxQuat()
Default constructor, does not do any initialization.
Definition: PxQuat.h:55
PX_CUDA_CALLABLE bool isUnit() const
returns true if finite and magnitude is close to unit
Definition: PxQuat.h:132
PX_CUDA_CALLABLE PX_INLINE PxQuat getNormalized() const
Definition: PxQuat.h:212
PX_CUDA_CALLABLE PX_INLINE float getAngle(const PxQuat &q) const
Gets the angle between this quat and the argument.
Definition: PxQuat.h:191
PX_CUDA_CALLABLE PX_INLINE PxVec3 getImaginaryPart() const
Definition: PxQuat.h:255
3x3 matrix class
Definition: PxMat33.h:90
PX_CUDA_CALLABLE PX_INLINE void PX_UNUSED(T const &)
Definition: PxPreprocessor.h:466
PX_CUDA_CALLABLE PX_FORCE_INLINE bool PxIsFinite(float f)
returns true if the passed number is a finite floating point number as opposed to INF...
Definition: PxMath.h:292
PX_CUDA_CALLABLE PX_INLINE bool operator==(const PxQuat &q) const
returns true if the two quaternions are exactly equal
Definition: PxQuat.h:151
PX_CUDA_CALLABLE PX_FORCE_INLINE PxQuat(const PxQuat &v)
Copy ctor.
Definition: PxQuat.h:102
float y
Definition: PxQuat.h:395
PX_CUDA_CALLABLE PX_INLINE PxQuat(float angleRadians, const PxVec3 &unitAxis)
Creates from angle-axis representation.
Definition: PxQuat.h:88
PX_CUDA_CALLABLE PX_FORCE_INLINE const PxVec3 rotate(const PxVec3 &v) const
Definition: PxQuat.h:287
PX_CUDA_CALLABLE PX_FORCE_INLINE PxQuat operator-(const PxQuat &q) const
Definition: PxQuat.h:384
PX_CUDA_CALLABLE PX_FORCE_INLINE PxQuat & operator+=(const PxQuat &q)
Definition: PxQuat.h:338
PxIDENTITY
Definition: Px.h:82
PX_CUDA_CALLABLE PX_INLINE PxQuat(PxIDENTITY r)
identity constructor
Definition: PxQuat.h:60
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 bool isIdentity() const
returns true if quat is identity
Definition: PxQuat.h:116
PX_CUDA_CALLABLE PX_FORCE_INLINE const PxVec3 rotateInv(const PxVec3 &v) const
Definition: PxQuat.h:301
PX_CUDA_CALLABLE PX_FORCE_INLINE float PxAcos(float f)
Arccosine. Returns angle between 0 and PI in radians Unit: Radians.
Definition: PxMath.h:236
float z
Definition: PxVec3.h:381
PX_CUDA_CALLABLE PX_FORCE_INLINE PxQuat & operator=(const PxQuat &p)
Assignment operator.
Definition: PxQuat.h:315
#define PX_INLINE
Definition: PxPreprocessor.h:336
PX_CUDA_CALLABLE PX_FORCE_INLINE PxQuat operator-() const
Definition: PxQuat.h:379
#define PX_CUDA_CALLABLE
Definition: PxPreprocessor.h:460
3 Element vector class.
Definition: PxVec3.h:49
float x
Definition: PxVec3.h:381