Quaternions represent rotation around an axis, defined by quaternion components x, y, z and w.
More...
#include <kanzi/core/math/quaternion.hpp>
|
Quaternion | conjugated () const |
| Get conjugated copy of this quaternion. More...
|
|
float | getW () const |
| Get the w component of the quaternion. More...
|
|
float | getX () const |
| Get the x component of the quaternion. More...
|
|
float | getY () const |
| Get the y component of the quaternion. More...
|
|
float | getZ () const |
| Get the z component of the quaternion. More...
|
|
KZ_NO_DISCARD Quaternion | normalized () const |
| Get normalized copy of this quaternion. More...
|
|
Quaternion | operator* (float scalar) const |
| Multiplies each quaternion component with a scalar and returns the result. More...
|
|
Quaternion & | operator*= (float scalar) |
| Multiplies each quaternion component with a scalar. More...
|
|
Quaternion | operator/ (float scalar) const |
| Divides each quaternion component with a scalar and returns the result. More...
|
|
Quaternion & | operator/= (float scalar) |
| Divides each quaternion component with a scalar. More...
|
|
float & | operator[] (size_t index) |
| Access individual components of a quaternion. More...
|
|
const float & | operator[] (size_t index) const |
| Access individual components of a quaternion. More...
|
|
| Quaternion () |
| Default constructor, initializes the quaternion components to identity, representing no rotation (x=0, y=0, z=0, w=1). More...
|
|
| Quaternion (const float x, const float y, const float z, const float w) |
| Constructor, initializes the quaternion components to x, y, z and w. More...
|
|
void | setW (float w) |
| Sets the w component of the quaternion. More...
|
|
void | setX (float x) |
| Sets the x component of the quaternion. More...
|
|
void | setY (float y) |
| Sets the y component of the quaternion. More...
|
|
void | setZ (float z) |
| Sets the z component of the quaternion. More...
|
|
Quaternions represent rotation around an axis, defined by quaternion components x, y, z and w.
Quaternions are compact, do not suffer from gimbal lock and can be easily interpolated. Kanzi Engine uses quaternions internally to represent all rotations. Quaternions are based on complex numbers and are not easy to understand intuitively. You almost never access or modify the individual components. In most cases you take existing rotations and use them to construct new rotations (e.g. to smoothly interpolate between two rotations). You can use the Quaternion operator * to rotate one rotation by another, or to rotate a vector by a rotation.
- See also
- operator*().
-
rotateVector().
kanzi::Quaternion::Quaternion |
( |
| ) |
|
|
inlineexplicit |
Default constructor, initializes the quaternion components to identity, representing no rotation (x=0, y=0, z=0, w=1).
kanzi::Quaternion::Quaternion |
( |
const float |
x, |
|
|
const float |
y, |
|
|
const float |
z, |
|
|
const float |
w |
|
) |
| |
|
inlineexplicit |
Constructor, initializes the quaternion components to x, y, z and w.
- Parameters
-
x | x component of the quaternion. |
y | y component of the quaternion. |
z | z component of the quaternion. |
w | w component of the quaternion. |
static Quaternion kanzi::Quaternion::createFromVector |
( |
Vector3 |
axis, |
|
|
float |
angleInRadians |
|
) |
| |
|
static |
Creates quaternion from axis and angle.
Use this to create a quaternion from axis of rotation and angle in radians.
- Parameters
-
axis | Axis components in Vector3(x, y, z). |
angleInRadians | Angle in radians. |
- Returns
- Rotated quaternion.
static Quaternion kanzi::Quaternion::createFromEulerAngles |
( |
Vector3 |
anglesInRadians | ) |
|
|
static |
Creates a quaternion from Euler angles.
Kanzi Engine represents Euler angles as Tait-Bryan angles where the rotations are applied in the order x, y and z.
- Parameters
-
anglesInRadians | Euler angles in radians. |
- Returns
- Rotated quaternion.
static Quaternion kanzi::Quaternion::createFromEulerAngles |
( |
float |
rotationX, |
|
|
float |
rotationY, |
|
|
float |
rotationZ |
|
) |
| |
|
static |
Creates a quaternion from Euler angles.
Kanzi Engine represents Euler angles as Tait-Bryan angles where the rotations are applied in the order x, y and z.
- Parameters
-
rotationX | Rotation angle around the x axis in radians. |
rotationY | Rotation angle around the y axis in radians. |
rotationZ | Rotation angle around the z axis in radians. |
- Returns
- Rotated quaternion.
Get normalized copy of this quaternion.
Normalized quaternion is called an unit quaternion. Calculates the magnitude from the dot product of the quaternion components, and divides all the quaternion components with the magnitude. Use this when rotating or transforming a vector with a quaternion, and when generating a rotation or transformation matrix from quaternion. Using unnormalized quaternion in calculations can lead to floating point rounding errors. The errors that result from using an unnormalized quaternion in calculations are proportional to the square of the quaternion's magnitude.
- Returns
- Normalized quaternion.
Quaternion kanzi::Quaternion::conjugated |
( |
| ) |
const |
|
inline |
Get conjugated copy of this quaternion.
Conjugation inverses the quaternion axis components x, y and z. Use this to get the inverse rotation of a quaternion.
- Returns
- Conjugated quaternion.
float kanzi::Quaternion::getX |
( |
| ) |
const |
|
inline |
Get the x component of the quaternion.
- Returns
- The x component.
float kanzi::Quaternion::getY |
( |
| ) |
const |
|
inline |
Get the y component of the quaternion.
- Returns
- The y component.
float kanzi::Quaternion::getZ |
( |
| ) |
const |
|
inline |
Get the z component of the quaternion.
- Returns
- The z component.
float kanzi::Quaternion::getW |
( |
| ) |
const |
|
inline |
Get the w component of the quaternion.
- Returns
- The w component.
void kanzi::Quaternion::setX |
( |
float |
x | ) |
|
|
inline |
Sets the x component of the quaternion.
- Parameters
-
x | The new value of the x component. |
void kanzi::Quaternion::setY |
( |
float |
y | ) |
|
|
inline |
Sets the y component of the quaternion.
- Parameters
-
y | The new value of the y component. |
void kanzi::Quaternion::setZ |
( |
float |
z | ) |
|
|
inline |
Sets the z component of the quaternion.
- Parameters
-
z | The new value of the z component. |
void kanzi::Quaternion::setW |
( |
float |
w | ) |
|
|
inline |
Sets the w component of the quaternion.
- Parameters
-
w | The new value of the w component. |
float& kanzi::Quaternion::operator[] |
( |
size_t |
index | ) |
|
|
inline |
Access individual components of a quaternion.
- Parameters
-
index | Index of the accessed component. Should be either 0, 1, 2, or 3. |
- Returns
- If index is 0, x component. If index is 1, y component. If index is 2, z component. If index is 3, w component.
const float& kanzi::Quaternion::operator[] |
( |
size_t |
index | ) |
const |
|
inline |
Access individual components of a quaternion.
- Parameters
-
index | Index of the accessed component. Should be either 0, 1, 2, or 3. |
- Returns
- If index is 0, x component. If index is 1, y component. If index is 2, z component. If index is 3, w component.
Quaternion kanzi::Quaternion::operator* |
( |
float |
scalar | ) |
const |
|
inline |
Multiplies each quaternion component with a scalar and returns the result.
- Parameters
-
scalar | Multiplier for each quaternion component. |
- Returns
- Result quaternion.
Quaternion& kanzi::Quaternion::operator*= |
( |
float |
scalar | ) |
|
|
inline |
Multiplies each quaternion component with a scalar.
- Parameters
-
scalar | Multiplier for each quaternion component. |
- Returns
- This quaternion.
Quaternion kanzi::Quaternion::operator/ |
( |
float |
scalar | ) |
const |
|
inline |
Divides each quaternion component with a scalar and returns the result.
- Parameters
-
scalar | Divisor for each quaternion component. |
- Returns
- Result quaternion.
Quaternion& kanzi::Quaternion::operator/= |
( |
float |
scalar | ) |
|
|
inline |
Divides each quaternion component with a scalar.
- Parameters
-
scalar | Divisor for each quaternion component. |
- Returns
- This quaternion.
The documentation for this class was generated from the following file: