3es
0.7
|
A 4D rotational quaternion class. More...
#include <3esquaternion.h>
Public Member Functions | |
Quaternion () | |
Default constructor: undefined initialisation behaviour. | |
Quaternion (bool) | |
The identity constructor. More... | |
Quaternion (const Quaternion< T > &other) | |
Copy constructor. More... | |
template<typename Q > | |
Quaternion (const Quaternion< Q > &other) | |
Copy constructor from a different numeric type. More... | |
Quaternion (const T &x, const T &y, const T &z, const T &w) | |
Per coordinate initialisation. More... | |
Quaternion (const Vector3< T > &v, const T &w) | |
Vector plus scalar initialisation. More... | |
Quaternion (const T *array4) | |
Initialisation from a array of at least length 4. More... | |
Quaternion (const Vector3< T > &from, const Vector3< T > &to) | |
Create the quaternion rotation transforming from => to . More... | |
T & | operator[] (int index) |
Index operator. More... | |
const T & | operator[] (int index) const |
Quaternion< T > & | operator= (const Quaternion< T > &other) |
Simple assignment operator. More... | |
template<typename Q > | |
Quaternion< T > & | operator= (const Quaternion< Q > &other) |
Simple assignment operator from a different numeric type. More... | |
bool | operator== (const Quaternion< T > &other) const |
Exact equality operator. More... | |
bool | operator!= (const Quaternion< T > &other) const |
Exact inequality operator. More... | |
bool | isEqual (const Quaternion< T > &other, const T &epsilon=Vector3< T >::Epsilon) |
Equality test with error. More... | |
bool | isIdentity () |
Checks if this quaternion is exactly identity. More... | |
void | getAxisAngle (Vector3< T > &axis, T &angle) const |
Converts this quaternion into a axis of rotation and the rotation angle around that axis (radians). More... | |
Quaternion< T > & | setAxisAngle (const Vector3< T > &axis, const T &angle) |
Sets this quaternion from an axis of rotation and the angle of rotation about that axis (radians). More... | |
Quaternion< T > & | invert () |
Inverts this quaternion, making the counter rotation. More... | |
Quaternion< T > | inverse () const |
Calculates and returns the inverse of this quaternion. More... | |
Quaternion< T > & | conjugate () |
Sets this quaternion to its conjugate. More... | |
Quaternion< T > | conjugated () const |
Calculates and returns the conjugate of this quaternion. More... | |
T | normalise (const T &epsilon=Vector3< T >::Epsilon) |
Attempts to normalise this quaternion. More... | |
Quaternion< T > | normalised (const T &epsilon=Vector3< T >::Epsilon) const |
Returns a normalised copy of this quaternion. More... | |
T | magnitude () const |
Returns the magnitude of this quaternion. | |
T | magnitudeSquared () const |
Returns the magnitude squared of this quaternion. | |
T | dot (const Quaternion< T > other) const |
Calculates the dot product of this and other . | |
Vector3< T > | transform (const Vector3< T > &v) const |
Transforms v by this quaternion rotation. More... | |
Quaternion< T > & | multiply (const T &scalar) |
Multiply all components of this quaternion by a scalar. More... | |
Quaternion< T > | operator*= (const Quaternion< T > &other) |
Quaternion< T > | operator*= (const T &scalar) |
Static Public Member Functions | |
static Quaternion< T > | slerp (const Quaternion< T > &from, const Quaternion< T > &to, const T &t) |
Performs a spherical linear interpolation of one quaternion to another. More... | |
Public Attributes | |
union { | |
struct { | |
T x | |
Direct data member access. | |
T y | |
T z | |
T w | |
} | |
T q [4] | |
Array representation of the vector members. | |
}; | |
Static Public Attributes | |
static const Quaternion< T > | identity |
The identity quaternion (0, 0, 0, 1). | |
A 4D rotational quaternion class.
|
inline |
The identity constructor.
The boolean parameter is ignored, being used only for overloading. General usage is to set it to true.
|
inline |
Copy constructor.
other | Vector to copy the value of. |
|
inline |
Copy constructor from a different numeric type.
other | Vector to copy the value of. |
|
inline |
Per coordinate initialisation.
x | The x coordinate. |
y | The y coordinate. |
z | The z coordinate. |
w | The w coordinate. |
|
inline |
Vector plus scalar initialisation.
v | Values for x, y and z. |
w | The w coordinate. |
|
inline |
Initialisation from a array of at least length 4.
No bounds checking is performed.
array4 | An array of at least length 4. Copies elements (0, 1, 2, 3). |
tes::Quaternion< T >::Quaternion | ( | const Vector3< T > & | from, |
const Vector3< T > & | to | ||
) |
Create the quaternion rotation transforming from
=> to
.
from | Starting vector. |
to | Target vector. |
Quaternion<T>& tes::Quaternion< T >::conjugate | ( | ) |
Sets this quaternion to its conjugate.
The conjugate is the same quaternion with x, y, z values negated.
Referenced by tes::Quaternion< float >::operator=().
Quaternion<T> tes::Quaternion< T >::conjugated | ( | ) | const |
Calculates and returns the conjugate of this quaternion.
The conjugate is the same quaternion with x, y, z values negated.
Referenced by tes::Quaternion< float >::operator=().
void tes::Quaternion< T >::getAxisAngle | ( | Vector3< T > & | axis, |
T & | angle | ||
) | const |
Converts this quaternion into a axis of rotation and the rotation angle around that axis (radians).
[out] | axis | Set to the axis of rotation. Set to (0, 0, 1) if this quaternion is identity or near zero length. |
[out] | angle | Set to the rotation angle (radians). Zero if this quaternion is identity. |
Referenced by tes::Quaternion< float >::operator=().
Quaternion<T> tes::Quaternion< T >::inverse | ( | ) | const |
Calculates and returns the inverse of this quaternion.
Referenced by tes::Quaternion< float >::operator=().
Quaternion<T>& tes::Quaternion< T >::invert | ( | ) |
Inverts this quaternion, making the counter rotation.
Referenced by tes::Quaternion< float >::operator=().
bool tes::Quaternion< T >::isEqual | ( | const Quaternion< T > & | other, |
const T & | epsilon = Vector3< T >::Epsilon |
||
) |
Equality test with error.
Defaults to using Epsilon
.
The vectors are considered equal of each individual component is within +/-
epsilon
of it's corresponding component in other
.
other | The vector to compare to. |
epsilon | The error tolerance. |
other
are equal with epsilon
. Referenced by tes::Quaternion< float >::operator=().
bool tes::Quaternion< T >::isIdentity | ( | ) |
Checks if this quaternion is exactly identity.
Referenced by tes::Quaternion< float >::operator=().
Quaternion<T>& tes::Quaternion< T >::multiply | ( | const T & | scalar | ) |
Multiply all components of this quaternion by a scalar.
Referenced by tes::Quaternion< float >::operator=().
T tes::Quaternion< T >::normalise | ( | const T & | epsilon = Vector3< T >::Epsilon | ) |
Attempts to normalise this quaternion.
Normalisation fails if the length of this quaternion is less than or equal to epsilon
. In this case, the quaternion becomes identity.
Referenced by tes::Quaternion< float >::operator=().
Quaternion<T> tes::Quaternion< T >::normalised | ( | const T & | epsilon = Vector3< T >::Epsilon | ) | const |
Returns a normalised copy of this quaternion.
Normalisation fails if the length of this quaternion is less than or equal to epsilon
.
Referenced by tes::Quaternion< float >::operator=().
bool tes::Quaternion< T >::operator!= | ( | const Quaternion< T > & | other | ) | const |
Exact inequality operator.
Compares each component with the same operator.
other | The vector to compare to. |
other
. Referenced by tes::Quaternion< float >::operator=().
|
inline |
Simple assignment operator.
other | Vector to copy the value of. |
|
inline |
Simple assignment operator from a different numeric type.
other | Vector to copy the value of. |
bool tes::Quaternion< T >::operator== | ( | const Quaternion< T > & | other | ) | const |
Exact equality operator.
Compares each component with the same operator.
other | The vector to compare to. |
other
. Referenced by tes::Quaternion< float >::operator=().
|
inline |
Index operator.
Not bounds checked.
index | Access coordinates by index; 0 = x, 1 = y, 2 = z. |
|
inline |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Quaternion<T>& tes::Quaternion< T >::setAxisAngle | ( | const Vector3< T > & | axis, |
const T & | angle | ||
) |
Sets this quaternion from an axis of rotation and the angle of rotation about that axis (radians).
axis | The axis of rotation. |
angle | The rotation angle (radians). |
Referenced by tes::Quaternion< float >::operator=(), tes::Capsule::setAxis(), tes::Cylinder::setAxis(), tes::Cone::setDirection(), tes::Arrow::setDirection(), and tes::Text3D::Text3D().
|
static |
Performs a spherical linear interpolation of one quaternion to another.
from | The quaternion rotation to interpolate from. |
to | The quaternion rotation to interpolate to. |
t | The interpolation "time", [0, 1]. |
Referenced by tes::Quaternion< float >::operator=().
Vector3<T> tes::Quaternion< T >::transform | ( | const Vector3< T > & | v | ) | const |
Transforms v
by this quaternion rotation.
Referenced by tes::Quaternion< float >::operator=().