Jolt Physics
A multi core friendly Game Physics Engine
|
#include <Quat.h>
Public Member Functions | |
JPH_INLINE void | GetAxisAngle (Vec3 &outAxis, float &outAngle) const |
Get axis and angle that represents this quaternion, outAngle will always be in the range \([0, \pi]\). More... | |
Vec3 | GetEulerAngles () const |
Conversion to Euler angles. Rotation order is X then Y then Z (RotZ * RotY * RotX). Angles in radians. More... | |
JPH_INLINE Vec3 | operator* (Vec3Arg inValue) const |
Rotate a vector by this quaternion. More... | |
JPH_INLINE Vec3 | InverseRotate (Vec3Arg inValue) const |
Rotate a vector by the inverse of this quaternion. More... | |
JPH_INLINE Vec3 | RotateAxisX () const |
Rotate a the vector (1, 0, 0) with this quaternion. More... | |
JPH_INLINE Vec3 | RotateAxisY () const |
Rotate a the vector (0, 1, 0) with this quaternion. More... | |
JPH_INLINE Vec3 | RotateAxisZ () const |
Rotate a the vector (0, 0, 1) with this quaternion. More... | |
JPH_INLINE float | Dot (QuatArg inRHS) const |
Dot product. More... | |
JPH_INLINE Quat | Conjugated () const |
The conjugate [w, -x, -y, -z] is the same as the inverse for unit quaternions. More... | |
JPH_INLINE Quat | Inversed () const |
Get inverse quaternion. More... | |
JPH_INLINE Quat | EnsureWPositive () const |
Ensures that the W component is positive by negating the entire quaternion if it is not. This is useful when you want to store a quaternion as a 3 vector by discarding W and reconstructing it as sqrt(1 - x^2 - y^2 - z^2). More... | |
JPH_INLINE Quat | GetPerpendicular () const |
Get a quaternion that is perpendicular to this quaternion. More... | |
JPH_INLINE float | GetRotationAngle (Vec3Arg inAxis) const |
Get rotation angle around inAxis (uses Swing Twist Decomposition to get the twist quaternion and uses q(axis, angle) = [cos(angle / 2), axis * sin(angle / 2)]) More... | |
JPH_INLINE Quat | GetTwist (Vec3Arg inAxis) const |
JPH_INLINE void | GetSwingTwist (Quat &outSwing, Quat &outTwist) const |
JPH_INLINE Quat | LERP (QuatArg inDestination, float inFraction) const |
JPH_INLINE Quat | SLERP (QuatArg inDestination, float inFraction) const |
JPH_INLINE void | StoreFloat3 (Float3 *outV) const |
Store 3 as floats to memory (X, Y and Z component) More... | |
Constructors | |
Quat ()=default | |
Intentionally not initialized for performance reasons. More... | |
Quat (const Quat &inRHS)=default | |
Quat & | operator= (const Quat &inRHS)=default |
Quat (float inX, float inY, float inZ, float inW) | |
Quat (Vec4Arg inV) | |
Tests | |
bool | operator== (QuatArg inRHS) const |
Check if two quaternions are exactly equal. More... | |
bool | operator!= (QuatArg inRHS) const |
Check if two quaternions are different. More... | |
bool | IsClose (QuatArg inRHS, float inMaxDistSq=1.0e-12f) const |
If this quaternion is close to inRHS. Note that q and -q represent the same rotation, this is not checked here. More... | |
bool | IsNormalized (float inTolerance=1.0e-5f) const |
If the length of this quaternion is 1 +/- inTolerance. More... | |
bool | IsNaN () const |
If any component of this quaternion is a NaN (not a number) More... | |
Get components | |
JPH_INLINE float | GetX () const |
Get X component (imaginary part i) More... | |
JPH_INLINE float | GetY () const |
Get Y component (imaginary part j) More... | |
JPH_INLINE float | GetZ () const |
Get Z component (imaginary part k) More... | |
JPH_INLINE float | GetW () const |
Get W component (real part) More... | |
JPH_INLINE Vec3 | GetXYZ () const |
Get the imaginary part of the quaternion. More... | |
JPH_INLINE Vec4 | GetXYZW () const |
Get the quaternion as a Vec4. More... | |
JPH_INLINE void | SetX (float inX) |
Set individual components. More... | |
JPH_INLINE void | SetY (float inY) |
JPH_INLINE void | SetZ (float inZ) |
JPH_INLINE void | SetW (float inW) |
JPH_INLINE void | Set (float inX, float inY, float inZ, float inW) |
Set all components. More... | |
Length / normalization operations | |
JPH_INLINE float | LengthSq () const |
JPH_INLINE float | Length () const |
JPH_INLINE Quat | Normalized () const |
Normalize the quaternion (make it length 1) More... | |
Static Public Member Functions | |
static JPH_INLINE Quat | sRotation (Vec3Arg inAxis, float inAngle) |
Rotation from axis and angle. More... | |
static JPH_INLINE Quat | sFromTo (Vec3Arg inFrom, Vec3Arg inTo) |
template<class Random > | |
static Quat | sRandom (Random &inRandom) |
Random unit quaternion. More... | |
static Quat | sEulerAngles (Vec3Arg inAngles) |
Conversion from Euler angles. Rotation order is X then Y then Z (RotZ * RotY * RotX). Angles in radians. More... | |
static JPH_INLINE Quat | sLoadFloat3Unsafe (const Float3 &inV) |
Load 3 floats from memory (X, Y and Z component and then calculates W) reads 32 bits extra which it doesn't use. More... | |
Default quaternions | |
static JPH_INLINE Quat | sZero () |
static JPH_INLINE Quat | sIdentity () |
Public Attributes | |
Vec4 | mValue |
4 vector that stores [x, y, z, w] parts of the quaternion More... | |
Friends | |
ostream & | operator<< (ostream &inStream, QuatArg inQ) |
To String. More... | |
Additions / multiplications | |
JPH_INLINE void | operator+= (QuatArg inRHS) |
JPH_INLINE void | operator-= (QuatArg inRHS) |
JPH_INLINE void | operator*= (float inValue) |
JPH_INLINE void | operator/= (float inValue) |
JPH_INLINE Quat | operator- () const |
JPH_INLINE Quat | operator+ (QuatArg inRHS) const |
JPH_INLINE Quat | operator- (QuatArg inRHS) const |
JPH_INLINE Quat | operator* (QuatArg inRHS) const |
JPH_INLINE Quat | operator* (float inValue) const |
JPH_INLINE Quat | operator/ (float inValue) const |
Quat | operator* (float inValue, QuatArg inRHS) |
Quaternion class, quaternions are 4 dimensional vectors which can describe rotations in 3 dimensional space if their length is 1.
They are written as:
\(q = w + x \: i + y \: j + z \: k\)
or in vector notation:
\(q = [w, v] = [w, x, y, z]\)
Where:
w = the real part v = the imaginary part, (x, y, z)
Note that we store the quaternion in a Vec4 as [x, y, z, w] because that makes it easy to extract the rotation axis of the quaternion:
q = [cos(angle / 2), sin(angle / 2) * rotation_axis]
|
inlinedefault |
Intentionally not initialized for performance reasons.
|
default |
|
inline |
|
inlineexplicit |
|
inline |
The conjugate [w, -x, -y, -z] is the same as the inverse for unit quaternions.
|
inline |
Dot product.
|
inline |
Ensures that the W component is positive by negating the entire quaternion if it is not. This is useful when you want to store a quaternion as a 3 vector by discarding W and reconstructing it as sqrt(1 - x^2 - y^2 - z^2).
void Quat::GetAxisAngle | ( | Vec3 & | outAxis, |
float & | outAngle | ||
) | const |
Get axis and angle that represents this quaternion, outAngle will always be in the range \([0, \pi]\).
|
inline |
Conversion to Euler angles. Rotation order is X then Y then Z (RotZ * RotY * RotX). Angles in radians.
|
inline |
Get a quaternion that is perpendicular to this quaternion.
|
inline |
Get rotation angle around inAxis (uses Swing Twist Decomposition to get the twist quaternion and uses q(axis, angle) = [cos(angle / 2), axis * sin(angle / 2)])
Decomposes quaternion into swing and twist component:
\(q = q_{swing} \: q_{twist}\)
where \(q_{swing} \: \hat{x} = q_{twist} \: \hat{y} = q_{twist} \: \hat{z} = 0\)
In other words:
Swing Twist Decomposition: any quaternion can be split up as:
\[q = q_{swing} \: q_{twist}\]
where \(q_{twist}\) rotates only around axis v.
\(q_{twist}\) is:
\[q_{twist} = \frac{[q_w, q_{ijk} \cdot v \: v]}{\left|[q_w, q_{ijk} \cdot v \: v]\right|}\]
where q_w is the real part of the quaternion and q_i the imaginary part (a 3 vector).
The swing can then be calculated as:
\[q_{swing} = q \: q_{twist}^* \]
Where \(q_{twist}^*\) = complex conjugate of \(q_{twist}\)
|
inline |
Get W component (real part)
|
inline |
Get X component (imaginary part i)
|
inline |
Get the imaginary part of the quaternion.
|
inline |
Get Y component (imaginary part j)
|
inline |
Get Z component (imaginary part k)
|
inline |
Get inverse quaternion.
Rotate a vector by the inverse of this quaternion.
|
inline |
If this quaternion is close to inRHS. Note that q and -q represent the same rotation, this is not checked here.
|
inline |
If any component of this quaternion is a NaN (not a number)
|
inline |
If the length of this quaternion is 1 +/- inTolerance.
|
inline |
Length of quaternion.
|
inline |
Squared length of quaternion.
Linear interpolation between two quaternions (for small steps).
inFraction | is in the range [0, 1] |
inDestination | The destination quaternion |
|
inline |
Normalize the quaternion (make it length 1)
|
inline |
Check if two quaternions are different.
|
inline |
JPH_NAMESPACE_BEGIN Quat Quat::operator* | ( | QuatArg | inRHS | ) | const |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
Check if two quaternions are exactly equal.
Vec3 Quat::RotateAxisX | ( | ) | const |
Rotate a the vector (1, 0, 0) with this quaternion.
Vec3 Quat::RotateAxisY | ( | ) | const |
Rotate a the vector (0, 1, 0) with this quaternion.
Vec3 Quat::RotateAxisZ | ( | ) | const |
Rotate a the vector (0, 0, 1) with this quaternion.
|
inline |
Set all components.
|
inline |
|
inline |
Set individual components.
|
inline |
|
inline |
Conversion from Euler angles. Rotation order is X then Y then Z (RotZ * RotY * RotX). Angles in radians.
Create quaternion that rotates a vector from the direction of inFrom to the direction of inTo along the shortest path
|
inlinestatic |
Spherical linear interpolation between two quaternions.
inFraction | is in the range [0, 1] |
inDestination | The destination quaternion |
Load 3 floats from memory (X, Y and Z component and then calculates W) reads 32 bits extra which it doesn't use.
|
inlinestatic |
Random unit quaternion.
void Quat::StoreFloat3 | ( | Float3 * | outV | ) | const |
Store 3 as floats to memory (X, Y and Z component)
|
inlinestatic |
|
friend |
To String.
Vec4 Quat::mValue |
4 vector that stores [x, y, z, w] parts of the quaternion