Defines a 4-element quaternion that represents the orientation of an object in space. More...
Public Member Functions | |
Quaternion () | |
Constructs a quaternion initialized to (0, 0, 0, 1). | |
Quaternion () | |
Constructs a quaternion initialized to (0, 0, 0, 1). | |
Quaternion () | |
Constructs a quaternion initialized to (0, 0, 0, 1). | |
Quaternion (float xx, float yy, float zz, float ww) | |
Constructs a quaternion. More... | |
Quaternion ( var xx, var yy, var zz, var ww) | |
Constructs a quaternion. More... | |
Quaternion ( local xx, local yy, local zz, local ww) | |
Constructs a quaternion. More... | |
Quaternion (float *array) | |
Constructs a new quaternion from the values in the specified array. More... | |
Quaternion (const Mat4 &m) | |
Constructs a quaternion equal to the rotational part of the specified matrix. More... | |
Quaternion (const Vec3 &axis, float angle) | |
Constructs a quaternion equal to the rotation from the specified axis and angle. More... | |
Quaternion ( var axis, var angle) | |
Constructs a quaternion equal to the rotation from the specified axis and angle. More... | |
Quaternion ( local axis, local angle) | |
Constructs a quaternion equal to the rotation from the specified axis and angle. More... | |
Quaternion (const Quaternion ©) | |
Constructs a new quaternion that is a copy of the specified one. | |
~Quaternion () | |
Destructor. | |
bool | isIdentity () const |
Determines if this quaternion is equal to the identity quaternion. More... | |
bool | isZero () const |
Determines if this quaternion is all zeros. More... | |
void | conjugate () |
Sets this quaternion to the conjugate of itself. | |
var | conjugate () |
Sets this quaternion to the conjugate of itself. | |
local | conjugate () |
Sets this quaternion to the conjugate of itself. | |
Quaternion | getConjugated () const |
Gets the conjugate of this quaternion. | |
var | getConjugated () |
Gets the conjugate of this quaternion. | |
local | getConjugated () |
Gets the conjugate of this quaternion. | |
bool | inverse () |
Sets this quaternion to the inverse of itself. More... | |
var | inverse () |
Sets this quaternion to the inverse of itself. More... | |
local | inverse () |
Sets this quaternion to the inverse of itself. More... | |
Quaternion | getInversed () const |
Gets the inverse of this quaternion. More... | |
var | getInversed () |
Gets the inverse of this quaternion. More... | |
local | getInversed () |
Gets the inverse of this quaternion. More... | |
void | multiply (const Quaternion &q) |
Multiplies this quaternion by the specified one and stores the result in this quaternion. More... | |
local | multiply ( local q) |
Multiplies this quaternion by the specified one and stores the result in this quaternion. More... | |
void | normalize () |
Normalizes this quaternion to have unit length. More... | |
Quaternion | getNormalized () const |
Get the normalized quaternion. More... | |
void | set (float xx, float yy, float zz, float ww) |
Sets the elements of the quaternion to the specified values. More... | |
var | set ( var xx, var yy, var zz, var ww) |
Sets the elements of the quaternion to the specified values. More... | |
local | set ( local xx, local yy, local zz, local ww) |
Sets the elements of the quaternion to the specified values. More... | |
void | set (float *array) |
Sets the elements of the quaternion from the values in the specified array. More... | |
void | set (const Mat4 &m) |
Sets the quaternion equal to the rotational part of the specified matrix. More... | |
void | set (const Vec3 &axis, float angle) |
Sets the quaternion equal to the rotation from the specified axis and angle. More... | |
var | set ( var axis, var angle) |
Sets the quaternion equal to the rotation from the specified axis and angle. More... | |
local | set ( local axis, local angle) |
Sets the quaternion equal to the rotation from the specified axis and angle. More... | |
void | set (const Quaternion &q) |
Sets the elements of this quaternion to a copy of the specified quaternion. More... | |
void | setIdentity () |
Sets this quaternion to be equal to the identity quaternion. | |
var | setIdentity () |
Sets this quaternion to be equal to the identity quaternion. | |
local | setIdentity () |
Sets this quaternion to be equal to the identity quaternion. | |
float | toAxisAngle (Vec3 *e) const |
Converts this Quaternion to axis-angle notation. More... | |
var | toAxisAngle ( var e) |
Converts this Quaternion to axis-angle notation. More... | |
local | toAxisAngle ( local e) |
Converts this Quaternion to axis-angle notation. More... | |
const Quaternion | operator* (const Quaternion &q) const |
Calculates the quaternion product of this quaternion with the given quaternion. More... | |
Vec3 | operator* (const Vec3 &v) const |
Calculates the quaternion product of this quaternion with the given vec3. More... | |
Quaternion & | operator*= (const Quaternion &q) |
Multiplies this quaternion with the given quaternion. More... | |
Static Public Member Functions | |
static const Quaternion & | identity () |
Returns the identity quaternion. More... | |
var | identity () |
Returns the identity quaternion. More... | |
local | identity () |
Returns the identity quaternion. More... | |
static const Quaternion & | zero () |
Returns the quaternion with all zeros. More... | |
static void | createFromRotationMatrix (const Mat4 &m, Quaternion *dst) |
Creates a quaternion equal to the rotational part of the specified matrix and stores the result in dst. More... | |
var | createFromRotationMatrix ( var m, var dst) |
Creates a quaternion equal to the rotational part of the specified matrix and stores the result in dst. More... | |
local | createFromRotationMatrix ( local m, local dst) |
Creates a quaternion equal to the rotational part of the specified matrix and stores the result in dst. More... | |
static void | createFromAxisAngle (const Vec3 &axis, float angle, Quaternion *dst) |
Creates this quaternion equal to the rotation from the specified axis and angle and stores the result in dst. More... | |
local | createFromAxisAngle ( local axis, local angle, local dst) |
Creates this quaternion equal to the rotation from the specified axis and angle and stores the result in dst. More... | |
static void | multiply (const Quaternion &q1, const Quaternion &q2, Quaternion *dst) |
Multiplies the specified quaternions and stores the result in dst. More... | |
var | multiply ( var q1, var q2, var dst) |
Multiplies the specified quaternions and stores the result in dst. More... | |
local | multiply ( local q1, local q2, local dst) |
Multiplies the specified quaternions and stores the result in dst. More... | |
static void | lerp (const Quaternion &q1, const Quaternion &q2, float t, Quaternion *dst) |
Interpolates between two quaternions using linear interpolation. More... | |
local | lerp ( local q1, local q2, local t, local dst) |
Interpolates between two quaternions using linear interpolation. More... | |
static void | slerp (const Quaternion &q1, const Quaternion &q2, float t, Quaternion *dst) |
Interpolates between two quaternions using spherical linear interpolation. More... | |
var | slerp ( var q1, var q2, var t, var dst) |
Interpolates between two quaternions using spherical linear interpolation. More... | |
local | slerp ( local q1, local q2, local t, local dst) |
Interpolates between two quaternions using spherical linear interpolation. More... | |
static void | squad (const Quaternion &q1, const Quaternion &q2, const Quaternion &s1, const Quaternion &s2, float t, Quaternion *dst) |
Interpolates over a series of quaternions using spherical spline interpolation. More... | |
local | squad ( local q1, local q2, local s1, local s2, local t, local dst) |
Interpolates over a series of quaternions using spherical spline interpolation. More... | |
Public Attributes | |
float | x |
The x-value of the quaternion's vector component. | |
var | x |
The x-value of the quaternion's vector component. | |
local | x |
The x-value of the quaternion's vector component. | |
float | y |
The y-value of the quaternion's vector component. | |
var | y |
The y-value of the quaternion's vector component. | |
local | y |
The y-value of the quaternion's vector component. | |
float | z |
The z-value of the quaternion's vector component. | |
var | z |
The z-value of the quaternion's vector component. | |
local | z |
The z-value of the quaternion's vector component. | |
float | w |
The scalar component of the quaternion. | |
var | w |
The scalar component of the quaternion. | |
local | w |
The scalar component of the quaternion. | |
Static Public Attributes | |
static const Quaternion | ZERO |
equals to Quaternion(0,0,0, 0) | |
Defines a 4-element quaternion that represents the orientation of an object in space.
Quaternions are typically used as a replacement for euler angles and rotation matrices as a way to achieve smooth interpolation and avoid gimbal lock.
Note that this quaternion class does not automatically keep the quaternion normalized. Therefore, care must be taken to normalize the quaternion when necessary, by calling the normalize method. This class provides three methods for doing quaternion interpolation: lerp, slerp, and squad.
lerp (linear interpolation): the interpolation curve gives a straight line in quaternion space. It is simple and fast to compute. The only problem is that it does not provide constant angular velocity. Note that a constant velocity is not necessarily a requirement for a curve; slerp (spherical linear interpolation): the interpolation curve forms a great arc on the quaternion unit sphere. Slerp provides constant angular velocity; squad (spherical spline interpolation): interpolating between a series of rotations using slerp leads to the following problems:
Since squad is continuously differentiable, it remedies the first and third problems mentioned above. The slerp method provided here is intended for interpolation of principal rotations. It treats +q and -q as the same principal rotation and is at liberty to use the negative of either input. The resulting path is always the shorter arc.
The lerp method provided here interpolates strictly in quaternion space. Note that the resulting path may pass through the origin if interpolating between a quaternion and its exact negative.
As an example, consider the following quaternions:
q1 = (0.6, 0.8, 0.0, 0.0), q2 = (0.0, 0.6, 0.8, 0.0), q3 = (0.6, 0.0, 0.8, 0.0), and q4 = (-0.8, 0.0, -0.6, 0.0). For the point p = (1.0, 1.0, 1.0), the following figures show the trajectories of p using lerp, slerp, and squad.
Quaternion | ( | float | xx, |
float | yy, | ||
float | zz, | ||
float | ww | ||
) |
Constructs a quaternion.
The x component of the quaternion. The y component of the quaternion. The z component of the quaternion. The w component of the quaternion.
var Quaternion | ( | var | xx, |
var | yy, | ||
var | zz, | ||
var | ww | ||
) |
Constructs a quaternion.
The x component of the quaternion. The y component of the quaternion. The z component of the quaternion. The w component of the quaternion.
local Quaternion | ( | local | xx, |
local | yy, | ||
local | zz, | ||
local | ww | ||
) |
Constructs a quaternion.
The x component of the quaternion. The y component of the quaternion. The z component of the quaternion. The w component of the quaternion.
Quaternion | ( | float * | array | ) |
Constructs a new quaternion from the values in the specified array.
The values for the new quaternion.
var Quaternion | ( | var | array | ) |
Constructs a new quaternion from the values in the specified array.
The values for the new quaternion.
local Quaternion | ( | local | array | ) |
Constructs a new quaternion from the values in the specified array.
The values for the new quaternion.
Quaternion | ( | const Mat4 & | m | ) |
Constructs a quaternion equal to the rotational part of the specified matrix.
The matrix.
var Quaternion | ( | var | m | ) |
Constructs a quaternion equal to the rotational part of the specified matrix.
The matrix.
local Quaternion | ( | local | m | ) |
Constructs a quaternion equal to the rotational part of the specified matrix.
The matrix.
Quaternion | ( | const Vec3 & | axis, |
float | angle | ||
) |
Constructs a quaternion equal to the rotation from the specified axis and angle.
A vector describing the axis of rotation. The angle of rotation (in radians).
var Quaternion | ( | var | axis, |
var | angle | ||
) |
Constructs a quaternion equal to the rotation from the specified axis and angle.
A vector describing the axis of rotation. The angle of rotation (in radians).
local Quaternion | ( | local | axis, |
local | angle | ||
) |
Constructs a quaternion equal to the rotation from the specified axis and angle.
A vector describing the axis of rotation. The angle of rotation (in radians).
|
static |
Returns the identity quaternion.
The identity quaternion.
|
static |
Returns the identity quaternion.
The identity quaternion.
|
static |
Returns the identity quaternion.
The identity quaternion.
|
static |
Returns the quaternion with all zeros.
The quaternion.
|
static |
Returns the quaternion with all zeros.
The quaternion.
|
static |
Returns the quaternion with all zeros.
The quaternion.
bool isIdentity | ( | ) | const |
Determines if this quaternion is equal to the identity quaternion.
true if it is the identity quaternion, false otherwise.
var isIdentity | ( | ) |
Determines if this quaternion is equal to the identity quaternion.
true if it is the identity quaternion, false otherwise.
local isIdentity | ( | ) |
Determines if this quaternion is equal to the identity quaternion.
true if it is the identity quaternion, false otherwise.
bool isZero | ( | ) | const |
Determines if this quaternion is all zeros.
true if this quaternion is all zeros, false otherwise.
var isZero | ( | ) |
Determines if this quaternion is all zeros.
true if this quaternion is all zeros, false otherwise.
local isZero | ( | ) |
Determines if this quaternion is all zeros.
true if this quaternion is all zeros, false otherwise.
|
static |
Creates a quaternion equal to the rotational part of the specified matrix and stores the result in dst.
The matrix. A quaternion to save the result.
|
static |
Creates a quaternion equal to the rotational part of the specified matrix and stores the result in dst.
The matrix. A quaternion to save the result.
|
static |
Creates a quaternion equal to the rotational part of the specified matrix and stores the result in dst.
The matrix. A quaternion to save the result.
|
static |
Creates this quaternion equal to the rotation from the specified axis and angle and stores the result in dst.
A vector describing the axis of rotation. The angle of rotation (in radians). A quaternion to save the result.
|
static |
Creates this quaternion equal to the rotation from the specified axis and angle and stores the result in dst.
A vector describing the axis of rotation. The angle of rotation (in radians). A quaternion to save the result.
|
static |
Creates this quaternion equal to the rotation from the specified axis and angle and stores the result in dst.
A vector describing the axis of rotation. The angle of rotation (in radians). A quaternion to save the result.
bool inverse | ( | ) |
Sets this quaternion to the inverse of itself.
Note that the inverse of a quaternion is equal to its conjugate when the quaternion is unit-length. For this reason, it is more efficient to use the conjugate method directly when you know your quaternion is already unit-length.
true if the inverse can be computed, false otherwise.
var inverse | ( | ) |
Sets this quaternion to the inverse of itself.
Note that the inverse of a quaternion is equal to its conjugate when the quaternion is unit-length. For this reason, it is more efficient to use the conjugate method directly when you know your quaternion is already unit-length.
true if the inverse can be computed, false otherwise.
local inverse | ( | ) |
Sets this quaternion to the inverse of itself.
Note that the inverse of a quaternion is equal to its conjugate when the quaternion is unit-length. For this reason, it is more efficient to use the conjugate method directly when you know your quaternion is already unit-length.
true if the inverse can be computed, false otherwise.
Quaternion getInversed | ( | ) | const |
Gets the inverse of this quaternion.
Note that the inverse of a quaternion is equal to its conjugate when the quaternion is unit-length. For this reason, it is more efficient to use the conjugate method directly when you know your quaternion is already unit-length.
var getInversed | ( | ) |
Gets the inverse of this quaternion.
Note that the inverse of a quaternion is equal to its conjugate when the quaternion is unit-length. For this reason, it is more efficient to use the conjugate method directly when you know your quaternion is already unit-length.
local getInversed | ( | ) |
Gets the inverse of this quaternion.
Note that the inverse of a quaternion is equal to its conjugate when the quaternion is unit-length. For this reason, it is more efficient to use the conjugate method directly when you know your quaternion is already unit-length.
void multiply | ( | const Quaternion & | q | ) |
Multiplies this quaternion by the specified one and stores the result in this quaternion.
The quaternion to multiply.
var multiply | ( | var | q | ) |
Multiplies this quaternion by the specified one and stores the result in this quaternion.
The quaternion to multiply.
local multiply | ( | local | q | ) |
Multiplies this quaternion by the specified one and stores the result in this quaternion.
The quaternion to multiply.
|
static |
Multiplies the specified quaternions and stores the result in dst.
The first quaternion. The second quaternion. A quaternion to store the result in.
|
static |
Multiplies the specified quaternions and stores the result in dst.
The first quaternion. The second quaternion. A quaternion to store the result in.
|
static |
Multiplies the specified quaternions and stores the result in dst.
The first quaternion. The second quaternion. A quaternion to store the result in.
void normalize | ( | ) |
Normalizes this quaternion to have unit length.
If the quaternion already has unit length or if the length of the quaternion is zero, this method does nothing.
var normalize | ( | ) |
Normalizes this quaternion to have unit length.
If the quaternion already has unit length or if the length of the quaternion is zero, this method does nothing.
local normalize | ( | ) |
Normalizes this quaternion to have unit length.
If the quaternion already has unit length or if the length of the quaternion is zero, this method does nothing.
Quaternion getNormalized | ( | ) | const |
Get the normalized quaternion.
If the quaternion already has unit length or if the length of the quaternion is zero, this method simply copies this vector.
var getNormalized | ( | ) |
Get the normalized quaternion.
If the quaternion already has unit length or if the length of the quaternion is zero, this method simply copies this vector.
local getNormalized | ( | ) |
Get the normalized quaternion.
If the quaternion already has unit length or if the length of the quaternion is zero, this method simply copies this vector.
void set | ( | float | xx, |
float | yy, | ||
float | zz, | ||
float | ww | ||
) |
Sets the elements of the quaternion to the specified values.
The new x-value. The new y-value. The new z-value. The new w-value.
var set | ( | var | xx, |
var | yy, | ||
var | zz, | ||
var | ww | ||
) |
Sets the elements of the quaternion to the specified values.
The new x-value. The new y-value. The new z-value. The new w-value.
local set | ( | local | xx, |
local | yy, | ||
local | zz, | ||
local | ww | ||
) |
Sets the elements of the quaternion to the specified values.
The new x-value. The new y-value. The new z-value. The new w-value.
void set | ( | float * | array | ) |
Sets the elements of the quaternion from the values in the specified array.
An array containing the elements of the quaternion in the order x, y, z, w.
var set | ( | var | array | ) |
Sets the elements of the quaternion from the values in the specified array.
An array containing the elements of the quaternion in the order x, y, z, w.
local set | ( | local | array | ) |
Sets the elements of the quaternion from the values in the specified array.
An array containing the elements of the quaternion in the order x, y, z, w.
void set | ( | const Mat4 & | m | ) |
Sets the quaternion equal to the rotational part of the specified matrix.
The matrix.
var set | ( | var | m | ) |
Sets the quaternion equal to the rotational part of the specified matrix.
The matrix.
local set | ( | local | m | ) |
Sets the quaternion equal to the rotational part of the specified matrix.
The matrix.
void set | ( | const Vec3 & | axis, |
float | angle | ||
) |
Sets the quaternion equal to the rotation from the specified axis and angle.
The axis of rotation. The angle of rotation (in radians).
var set | ( | var | axis, |
var | angle | ||
) |
Sets the quaternion equal to the rotation from the specified axis and angle.
The axis of rotation. The angle of rotation (in radians).
local set | ( | local | axis, |
local | angle | ||
) |
Sets the quaternion equal to the rotation from the specified axis and angle.
The axis of rotation. The angle of rotation (in radians).
void set | ( | const Quaternion & | q | ) |
Sets the elements of this quaternion to a copy of the specified quaternion.
The quaternion to copy.
var set | ( | var | q | ) |
Sets the elements of this quaternion to a copy of the specified quaternion.
The quaternion to copy.
local set | ( | local | q | ) |
Sets the elements of this quaternion to a copy of the specified quaternion.
The quaternion to copy.
float toAxisAngle | ( | Vec3 * | e | ) | const |
Converts this Quaternion to axis-angle notation.
The axis is normalized.
The Vec3f which stores the axis.
The angle (in radians).
var toAxisAngle | ( | var | e | ) |
Converts this Quaternion to axis-angle notation.
The axis is normalized.
The Vec3f which stores the axis.
The angle (in radians).
local toAxisAngle | ( | local | e | ) |
Converts this Quaternion to axis-angle notation.
The axis is normalized.
The Vec3f which stores the axis.
The angle (in radians).
|
static |
Interpolates between two quaternions using linear interpolation.
The interpolation curve for linear interpolation between quaternions gives a straight line in quaternion space.
The first quaternion. The second quaternion. The interpolation coefficient. A quaternion to store the result in.
|
static |
Interpolates between two quaternions using linear interpolation.
The interpolation curve for linear interpolation between quaternions gives a straight line in quaternion space.
The first quaternion. The second quaternion. The interpolation coefficient. A quaternion to store the result in.
|
static |
Interpolates between two quaternions using linear interpolation.
The interpolation curve for linear interpolation between quaternions gives a straight line in quaternion space.
The first quaternion. The second quaternion. The interpolation coefficient. A quaternion to store the result in.
|
static |
Interpolates between two quaternions using spherical linear interpolation.
Spherical linear interpolation provides smooth transitions between different orientations and is often useful for animating models or cameras in 3D.
Note: For accurate interpolation, the input quaternions must be at (or close to) unit length. This method does not automatically normalize the input quaternions, so it is up to the caller to ensure they call normalize beforehand, if necessary.
The first quaternion. The second quaternion. The interpolation coefficient. A quaternion to store the result in.
|
static |
Interpolates between two quaternions using spherical linear interpolation.
Spherical linear interpolation provides smooth transitions between different orientations and is often useful for animating models or cameras in 3D.
Note: For accurate interpolation, the input quaternions must be at (or close to) unit length. This method does not automatically normalize the input quaternions, so it is up to the caller to ensure they call normalize beforehand, if necessary.
The first quaternion. The second quaternion. The interpolation coefficient. A quaternion to store the result in.
|
static |
Interpolates between two quaternions using spherical linear interpolation.
Spherical linear interpolation provides smooth transitions between different orientations and is often useful for animating models or cameras in 3D.
Note: For accurate interpolation, the input quaternions must be at (or close to) unit length. This method does not automatically normalize the input quaternions, so it is up to the caller to ensure they call normalize beforehand, if necessary.
The first quaternion. The second quaternion. The interpolation coefficient. A quaternion to store the result in.
|
static |
Interpolates over a series of quaternions using spherical spline interpolation.
Spherical spline interpolation provides smooth transitions between different orientations and is often useful for animating models or cameras in 3D.
Note: For accurate interpolation, the input quaternions must be unit. This method does not automatically normalize the input quaternions, so it is up to the caller to ensure they call normalize beforehand, if necessary.
The first quaternion. The second quaternion. The first control point. The second control point. The interpolation coefficient. A quaternion to store the result in.
|
static |
Interpolates over a series of quaternions using spherical spline interpolation.
Spherical spline interpolation provides smooth transitions between different orientations and is often useful for animating models or cameras in 3D.
Note: For accurate interpolation, the input quaternions must be unit. This method does not automatically normalize the input quaternions, so it is up to the caller to ensure they call normalize beforehand, if necessary.
The first quaternion. The second quaternion. The first control point. The second control point. The interpolation coefficient. A quaternion to store the result in.
|
static |
Interpolates over a series of quaternions using spherical spline interpolation.
Spherical spline interpolation provides smooth transitions between different orientations and is often useful for animating models or cameras in 3D.
Note: For accurate interpolation, the input quaternions must be unit. This method does not automatically normalize the input quaternions, so it is up to the caller to ensure they call normalize beforehand, if necessary.
The first quaternion. The second quaternion. The first control point. The second control point. The interpolation coefficient. A quaternion to store the result in.
|
inline |
Calculates the quaternion product of this quaternion with the given quaternion.
Note: this does not modify this quaternion.
The quaternion to multiply. The quaternion product.
|
inline |
Calculates the quaternion product of this quaternion with the given quaternion.
Note: this does not modify this quaternion.
The quaternion to multiply. The quaternion product.
|
inline |
Calculates the quaternion product of this quaternion with the given quaternion.
Note: this does not modify this quaternion.
The quaternion to multiply. The quaternion product.
Calculates the quaternion product of this quaternion with the given vec3.
The vec3 to multiply. The vec3 product.
|
inline |
Calculates the quaternion product of this quaternion with the given vec3.
The vec3 to multiply. The vec3 product.
|
inline |
Calculates the quaternion product of this quaternion with the given vec3.
The vec3 to multiply. The vec3 product.
|
inline |
Multiplies this quaternion with the given quaternion.
The quaternion to multiply. This quaternion, after the multiplication occurs.
|
inline |
Multiplies this quaternion with the given quaternion.
The quaternion to multiply. This quaternion, after the multiplication occurs.
|
inline |
Multiplies this quaternion with the given quaternion.
The quaternion to multiply. This quaternion, after the multiplication occurs.