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]\). | |
Vec3 | GetEulerAngles () const |
Conversion to Euler angles. Rotation order is X then Y then Z (RotZ * RotY * RotX). Angles in radians. | |
JPH_INLINE Vec3 | operator* (Vec3Arg inValue) const |
Rotate a vector by this quaternion. | |
JPH_INLINE Vec3 | InverseRotate (Vec3Arg inValue) const |
Rotate a vector by the inverse of this quaternion. | |
JPH_INLINE Vec3 | RotateAxisX () const |
Rotate a the vector (1, 0, 0) with this quaternion. | |
JPH_INLINE Vec3 | RotateAxisY () const |
Rotate a the vector (0, 1, 0) with this quaternion. | |
JPH_INLINE Vec3 | RotateAxisZ () const |
Rotate a the vector (0, 0, 1) with this quaternion. | |
JPH_INLINE float | Dot (QuatArg inRHS) const |
Dot product. | |
JPH_INLINE Quat | Conjugated () const |
The conjugate [w, -x, -y, -z] is the same as the inverse for unit quaternions. | |
JPH_INLINE Quat | Inversed () const |
Get inverse quaternion. | |
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). | |
JPH_INLINE Quat | GetPerpendicular () const |
Get a quaternion that is perpendicular to this quaternion. | |
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)]) | |
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) | |
Constructors | |
Quat ()=default | |
Intentionally not initialized for performance reasons. | |
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. | |
bool | operator!= (QuatArg inRHS) const |
Check if two quaternions are different. | |
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. | |
bool | IsNormalized (float inTolerance=1.0e-5f) const |
If the length of this quaternion is 1 +/- inTolerance. | |
bool | IsNaN () const |
If any component of this quaternion is a NaN (not a number) | |
Get components | |
JPH_INLINE float | GetX () const |
Get X component (imaginary part i) | |
JPH_INLINE float | GetY () const |
Get Y component (imaginary part j) | |
JPH_INLINE float | GetZ () const |
Get Z component (imaginary part k) | |
JPH_INLINE float | GetW () const |
Get W component (real part) | |
JPH_INLINE Vec3 | GetXYZ () const |
Get the imaginary part of the quaternion. | |
JPH_INLINE Vec4 | GetXYZW () const |
Get the quaternion as a Vec4. | |
JPH_INLINE void | SetX (float inX) |
Set individual components. | |
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. | |
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) | |
Static Public Member Functions | |
static JPH_INLINE Quat | sRotation (Vec3Arg inAxis, float inAngle) |
Rotation from axis and angle. | |
static JPH_INLINE Quat | sFromTo (Vec3Arg inFrom, Vec3Arg inTo) |
template<class Random > | |
static Quat | sRandom (Random &inRandom) |
Random unit quaternion. | |
static Quat | sEulerAngles (Vec3Arg inAngles) |
Conversion from Euler angles. Rotation order is X then Y then Z (RotZ * RotY * RotX). Angles in radians. | |
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. | |
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 | |
Friends | |
ostream & | operator<< (ostream &inStream, QuatArg inQ) |
To String. | |
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