FdkBaseLib 2.1.1
|
#include <Quat.h>
Public Types | |
using | value_type = T |
using | reference = T & |
using | const_reference = const T & |
Public Member Functions | |
Quat ()=default | |
Default constructor leaves garbage in contents. | |
Quat (T scalar) | |
Construct from a scalar and vector defaulted to 0. | |
Quat (T scalar, T x, T y, T z) | |
Constructor for specifying values. | |
template<typename R > | |
Quat (T scalar, const Vec3< R > &vec) | |
Constructor for specifying values. | |
template<typename R > | |
Quat (const Quat< R > &q) | |
Copy constructor supports type conversion. | |
Quat (const Mat4< T > &mat) | |
Constructor. Given a Matrix that represents a rotation, calculate the quaternion that is equivalent to that rotation. Given a matrix that represents a rotation, calculate the quaternion that is equivalent to that rotation. The last row and column of the Mat4 are ignored. | |
Quat (const Vec3< T > &originalVector, const Vec3< T > &newVector) | |
Constructor from two vectors. The quaternion will represent the angle between the two vectors. Constructor from two vectors. The quaternion will represent the angle between the two vectors. | |
operator Quat< fdk::half > () const | |
Returns value as a specific type: | |
operator Quat< float > () const | |
operator Quat< double > () const | |
Quat< fdk::half > | asQuath () const |
Quat< float > | asQuatf () const |
Quat< double > | asQuatd () const |
T * | array () |
Returns a pointer to the first element. | |
const T * | array () const |
void | set (T scalar, T x, T y, T z) |
Set individual quaternion values. | |
void | set (T scalar, const Vec3< T > &vec) |
Set individual quaternion values. | |
void | setFromAngleAxis (T radians, const Vec3< T > &vec) |
Set to an angle in radians and a vector to rotate around. | |
Quat | operator+ (const Quat &q) const |
Addition of two quaternions. This follows this rule: q1 + q2 = ( s1 + s2, vx1 + vx2, vy1 + vy2, vz1 + vz2 ) | |
Quat | operator* (const Quat &q) const |
Multiplication of two quaternions. This follows this rule: | |
Quat | operator* (T f) const |
Multiplication of a quaternion by a double number. This follows this rule: | |
Quat | conjugate () const |
Returns the conjugate of this quaternion. This follows this rule: q.conjugate = ( s - v ) | |
T | lengthSquared () const |
Returns the square of the length of the quaternion. This follows this rule: | |
T | length () const |
Returns the length of the quaternion. This follows this rule: | |
T | magnitude () const |
Returns the square of the magnitude of the quaternion. To avoid confusion, use length()/lengthSquared() instead. This follows this rule: | |
void | normalize () |
Normalize the quaternion to unit length. | |
Quat | normalized () |
Return a normalized version of this quaternion. | |
Quat | addInverse () const |
Returns the additive inverse of the quaternion. This is: q.addInverse = ( -s, -v.x, -v.y, -v.z ) | |
Quat | multInverse () const |
Returns the multiplicative inverse of the quaternion. This is: q.multInverse = ( 1 / q.magnitude ) * q.conjugate | |
Quat | slerp (const Quat &end_quat, T t) const |
Spherical linear interpolation. This method interpolates smoothly between two quaternions. The value t should be a number between 0.0 and 1.0. When t = 0.0, *this is returned. When t = 1.0, end_quat is returned. | |
Mat4< T > | matrix () const |
Return the transformation matrix that will represent the the Euler angle rotations that this quaternion embodies. Note - this method replaces all components of the matrix. Return the transformation matrix that will represent the the Euler angle rotations that this quaternion embodies. | |
Mat4< T > | rotationMatrix () const |
Return the transformation matrix that will represent the the Euler angle rotations that this quaternion embodies. Note - this method only affects the rotation part of the matrix. NOTE: The quaternion must be normalized before using this function. | |
void | append (fdk::Hash &hash) const |
Add this to a fdk::Hash object. | |
Static Public Member Functions | |
static Quat | addIdentity () |
Return the additive identity for quaternions (which is all zeros) | |
static Quat | multIdentity () |
Return the multiplicative identity for quaternions (which is 1,0,0,0) | |
static Quat | fromAngleAxis (T radians, const Vec3< T > &vec) |
Build a quaternion from an angle in radians and a vector to rotate around. | |
Public Attributes | |
Vec3< T > | v |
the vector part | |
T | s |
the scalar part | |
Static Public Attributes | |
static constexpr uint8_t | kNumElements = 4 |
static constexpr uint8_t | X = 0 |
static constexpr uint8_t | Y = 1 |
static constexpr uint8_t | Z = 2 |
static constexpr uint8_t | S = 3 |
An implementation of a way of representing rotations that avoid a lot of the problems that the standard rotation about the axis methods have.
Quaternions are a modification of the concept of a vector in space, but specially tailored for spherical space. The cool thing about quaternions is that they are perfectly suited to representing rotations and orientations of objects in three space.
Basically, in a quaternion there are four values: a scalar part and a vector part. q = ( s, v ). Typically, when dealing with rotations, the scalar part represents the rotation about an arbitrary axis. The axis is represented by a unit vector in the vector part.
Since the quaternion is a representation of a rotation, it can be converted into a Euler angle rotation matrix and a rotation matrix can be converted into a quaternion.
Multiplication of two quaternions. This follows this rule:
q1 q2 = ( s1 s2 - vx1 vx2 - vy1 vy2 - vz1 vz2, vy1 vz2 - vy2 vz1 + s1 vx2 + s2 vx1, vz1 vx2 - vz2 vx1 + s1 vy2 + s2 vy1, vx1 vy2 - vx2 vy1 + s1 vz2 + s2 vz1 ))
(I think this is the same as doing the two rotations one after another?)
References fdk::Quat< T >::s, and fdk::Quat< T >::v.
Multiplication of a quaternion by a double number. This follows this rule:
f * q = ( f * s, f * v.x, f * v.y, f * v.z )
|
inline |
Returns the square of the length of the quaternion. This follows this rule:
q.lengthSquared = s^2 + v.x^2 + v.y^2 + v.z^2
|
inline |
Returns the length of the quaternion. This follows this rule:
q.length = sqrt(s^2 + v.x^2 + v.y^2 + v.z^2 )
|
inline |
Returns the square of the magnitude of the quaternion. To avoid confusion, use length()/lengthSquared() instead. This follows this rule:
q.magnitude = q q.conjugate = s^2 + v.x^2 + v.y^2 + v.z^2
References fdk::Quat< T >::s, and fdk::Quat< T >::v.
Spherical linear interpolation. This method interpolates smoothly between two quaternions. The value t should be a number between 0.0 and 1.0. When t = 0.0, *this is returned. When t = 1.0, end_quat is returned.
Because of the way quaternions work, you can't just linearly interpolate between two of them. You must interpolate along the surface of a sphere. This method returns a quaternion that is between the current quaternion and the end_quat. The value of t (which should be between 0 and 1) determines the amount of interpolation.
©2024 The Foundry Visionmongers, Ltd. All Rights Reserved. |