Quaternion represents a rotation in 3D space using four components (x, y, z, w). It supports construction from axis-angle, Euler angles, or component values, and provides utility functions for normalization, interpolation, and conversion to matrices.
More...
#include <Quaternion.h>
|
| Quaternion () |
| Default constructor initializes the quaternion to the identity quaternion. The identity quaternion represents no rotation and is defined as (0, 0, 0, 1).
|
|
| Quaternion (float inX, float inY, float inZ, float inW) |
| Constructs a quaternion using four float values representing the components (x, y, z, w).
|
|
| Quaternion (const Vector3 &axis, float angle) |
| Constructs a quaternion from an axis of rotation and an angle in radians. The axis is assumed to be normalized.
|
|
| Quaternion (float pitch, float yaw, float roll) |
| Constructs a quaternion from pitch, yaw, and roll (Euler angles). The pitch is rotation about the X-axis, yaw about the Y-axis, and roll about the Z-axis.
|
|
void | Set (float inX, float inY, float inZ, float inW) |
| Sets the quaternion components explicitly. This method is intended for direct initialization, not for converting axis/angle or Euler angles.
|
|
void | Conjugate () |
| Conjugates the quaternion, flipping the sign of the vector part (x, y, z).
|
|
void | Normalize () |
| Normalizes the quaternion, ensuring it has a unit length (i.e., it represents a valid rotation). This method alters the current quaternion.
|
|
float | LengthSqr () const |
| Computes and returns the squared length of the quaternion. The squared length is the sum of the squares of the quaternion components.
|
|
float | Length () const |
| Computes and returns the length (magnitude) of the quaternion. This is the square root of the squared length.
|
|
float | GetPitch () const |
| Computes the pitch (rotation around the X-axis) of the quaternion.
|
|
float | GetYaw () const |
| Computes the yaw (rotation around the Y-axis) of the quaternion.
|
|
float | GetRoll () const |
| Computes the roll (rotation around the Z-axis) of the quaternion.
|
|
Quaternion | operator+ (const Quaternion &p) |
|
class Matrix4 | AsMatrix () const |
| Converts the quaternion to a 4x4 matrix representation. The resulting matrix can be used for transforming 3D vectors by the quaternion's rotation.
|
|
|
static float | Dot (const Quaternion &a, const Quaternion &b) |
| Computes the dot product between two quaternions.
|
|
static Quaternion | Normalize (const Quaternion &q) |
| Returns a normalized version of the given quaternion. Normalization scales the quaternion so that its length is 1.
|
|
static Quaternion | Lerp (const Quaternion &a, const Quaternion &b, float f) |
| Performs linear interpolation (Lerp) between two quaternions.
|
|
static Quaternion | Slerp (const Quaternion &a, const Quaternion &b, float f) |
| Performs spherical linear interpolation (Slerp) between two quaternions.
|
|
static Quaternion | Concatenate (const Quaternion &q, const Quaternion &p) |
| Concatenates two quaternions (i.e., applies one rotation after the other). This is equivalent to multiplying the two quaternions.
|
|
static Quaternion | LookAt (const Vector3 &forward, const Vector3 &up) |
| Creates a quaternion representing the rotation to "look at" a target point. The resulting quaternion aligns the forward vector with the target direction, with the given up vector providing the direction of the "up" axis.
|
|
static Quaternion | LookAt (const Vector3 &origin, const Vector3 &target, const Vector3 &up) |
| Creates a quaternion representing the rotation to "look at" a target point from an origin. This is equivalent to creating a "look at" rotation from the origin to the target, with the up vector.
|
|
|
float | x |
|
float | y |
|
float | z |
|
float | w |
|
|
static const Quaternion | Identity |
| Identity quaternion: represents no rotation (used as a reference for default state).
|
|
Quaternion represents a rotation in 3D space using four components (x, y, z, w). It supports construction from axis-angle, Euler angles, or component values, and provides utility functions for normalization, interpolation, and conversion to matrices.
◆ Quaternion() [1/4]
Quaternion::Quaternion |
( |
| ) |
|
|
inline |
Default constructor initializes the quaternion to the identity quaternion. The identity quaternion represents no rotation and is defined as (0, 0, 0, 1).
◆ Quaternion() [2/4]
Quaternion::Quaternion |
( |
float | inX, |
|
|
float | inY, |
|
|
float | inZ, |
|
|
float | inW ) |
|
explicit |
Constructs a quaternion using four float values representing the components (x, y, z, w).
- Parameters
-
inX | The x component of the quaternion's vector part. |
inY | The y component of the quaternion's vector part. |
inZ | The z component of the quaternion's vector part. |
inW | The scalar component of the quaternion. |
◆ Quaternion() [3/4]
Quaternion::Quaternion |
( |
const Vector3 & | axis, |
|
|
float | angle ) |
|
explicit |
Constructs a quaternion from an axis of rotation and an angle in radians. The axis is assumed to be normalized.
- Parameters
-
axis | The normalized axis of rotation. |
angle | The rotation angle in radians. |
◆ Quaternion() [4/4]
Quaternion::Quaternion |
( |
float | pitch, |
|
|
float | yaw, |
|
|
float | roll ) |
|
explicit |
Constructs a quaternion from pitch, yaw, and roll (Euler angles). The pitch is rotation about the X-axis, yaw about the Y-axis, and roll about the Z-axis.
- Parameters
-
pitch | The rotation angle around the X-axis in radians. |
yaw | The rotation angle around the Y-axis in radians. |
roll | The rotation angle around the Z-axis in radians. |
◆ AsMatrix()
Matrix4 Quaternion::AsMatrix |
( |
| ) |
const |
Converts the quaternion to a 4x4 matrix representation. The resulting matrix can be used for transforming 3D vectors by the quaternion's rotation.
- Returns
- A Matrix4 object representing the quaternion as a rotation matrix.
◆ Concatenate()
Concatenates two quaternions (i.e., applies one rotation after the other). This is equivalent to multiplying the two quaternions.
- Parameters
-
q | The first quaternion (rotation to apply first). |
p | The second quaternion (rotation to apply after q). |
- Returns
- A new quaternion that represents the combined rotation.
◆ Conjugate()
void Quaternion::Conjugate |
( |
| ) |
|
Conjugates the quaternion, flipping the sign of the vector part (x, y, z).
◆ Dot()
Computes the dot product between two quaternions.
- Parameters
-
a | The first quaternion. |
b | The second quaternion. |
- Returns
- The dot product between quaternions a and b.
◆ GetPitch()
float Quaternion::GetPitch |
( |
| ) |
const |
Computes the pitch (rotation around the X-axis) of the quaternion.
- Returns
- The pitch angle in radians.
◆ GetRoll()
float Quaternion::GetRoll |
( |
| ) |
const |
Computes the roll (rotation around the Z-axis) of the quaternion.
- Returns
- The roll angle in radians.
◆ GetYaw()
float Quaternion::GetYaw |
( |
| ) |
const |
Computes the yaw (rotation around the Y-axis) of the quaternion.
- Returns
- The yaw angle in radians.
◆ Length()
float Quaternion::Length |
( |
| ) |
const |
Computes and returns the length (magnitude) of the quaternion. This is the square root of the squared length.
- Returns
- The length of the quaternion.
◆ LengthSqr()
float Quaternion::LengthSqr |
( |
| ) |
const |
Computes and returns the squared length of the quaternion. The squared length is the sum of the squares of the quaternion components.
- Returns
- The squared length of the quaternion.
◆ Lerp()
Performs linear interpolation (Lerp) between two quaternions.
- Parameters
-
a | The starting quaternion. |
b | The ending quaternion. |
f | The interpolation factor (from 0 to 1). |
- Returns
- The interpolated quaternion.
◆ LookAt() [1/2]
Creates a quaternion representing the rotation to "look at" a target point. The resulting quaternion aligns the forward vector with the target direction, with the given up vector providing the direction of the "up" axis.
- Parameters
-
forward | The forward vector to align the quaternion to. |
up | The up vector, typically (0, 1, 0). |
- Returns
- A quaternion that rotates an object to face the target direction.
◆ LookAt() [2/2]
Creates a quaternion representing the rotation to "look at" a target point from an origin. This is equivalent to creating a "look at" rotation from the origin to the target, with the up vector.
- Parameters
-
origin | The starting point (usually the camera or object position). |
target | The point to look at (the target position). |
up | The up vector (usually (0, 1, 0)). |
- Returns
- A quaternion representing the look-at rotation.
◆ Normalize() [1/2]
void Quaternion::Normalize |
( |
| ) |
|
Normalizes the quaternion, ensuring it has a unit length (i.e., it represents a valid rotation). This method alters the current quaternion.
◆ Normalize() [2/2]
Returns a normalized version of the given quaternion. Normalization scales the quaternion so that its length is 1.
- Parameters
-
q | The quaternion to normalize. |
- Returns
- A new quaternion that is the normalized version of q.
◆ operator+()
◆ Set()
void Quaternion::Set |
( |
float | inX, |
|
|
float | inY, |
|
|
float | inZ, |
|
|
float | inW ) |
Sets the quaternion components explicitly. This method is intended for direct initialization, not for converting axis/angle or Euler angles.
- Parameters
-
inX | The x component of the quaternion. |
inY | The y component of the quaternion. |
inZ | The z component of the quaternion. |
inW | The scalar component of the quaternion. |
◆ Slerp()
Performs spherical linear interpolation (Slerp) between two quaternions.
- Parameters
-
a | The starting quaternion. |
b | The ending quaternion. |
f | The interpolation factor (from 0 to 1). |
- Returns
- The interpolated quaternion.
◆ Identity
Identity quaternion: represents no rotation (used as a reference for default state).
The documentation for this class was generated from the following files: