# Math::Quaternion struct#include <Spore/MathUtils.h>

A vector of 4 float values (x, y, z, w) representing a quaternion rotation, similar to a Vector4.

### Contents

• Reference

Quaternions an be multiplied to chain rotations: `q1 * q2` means applying rotation `r2` followed by rotation `r2`. You can use the Quaternion::FromRotation() and Quaternion::FromEuler() to build quaternion rotations. It has a value of (0, 0, 0, 1) by default.

## Base classes

struct Vector4
A vector of 4 float values (x, y, z, w).

## Public static functions

static auto FromRotation(const Vector3& axis, float angle) -> Quaternion
Constructs a Quaternion that represents a rotation of the given angle (in radians) around a certain axis.
static auto FromEuler(const Vector3& angles) -> Quaternion
Constructs a Quaternion that represents a rotation, given in euler angles in radians.
static auto GetRotationTo(const Vector3& from, const Vector3& to, const Vector3& fallbackAxis = Vector3::ZERO) -> Quaternion
Returns the quaternion the rotation between two vectors.

## Constructors, destructors, conversion operators

float x, float y, float z, float w)
)

## Public functions

auto Inverse() const -> Quaternion
Returns the inverse to this quaternion: that's another quaternion that, when multiplied with this one, gives the identity.
auto ToMatrix() const -> Matrix3
Builds a 3x3 rotation matrix equivalent to this quaternion rotation.
auto ToEuler() const -> Vector3
Returns the euler angles (in radians) that represent the same rotation as this quaternion.

## Function documentation

### static Quaternion Math::Quaternion::FromRotation(const Vector3& axis, float angle)

Constructs a Quaternion that represents a rotation of the given angle (in radians) around a certain axis.

Parameters
axis The axis of rotation. Only the direction matters, the length is ignored.
angle The angle of rotation, in radians.

### static Quaternion Math::Quaternion::FromEuler(const Vector3& angles)

Constructs a Quaternion that represents a rotation, given in euler angles in radians.

Parameters
angles Rotation around X (roll), Y (pitch) and Z (yaw) axes, in radians

The quaternion will be constructed as if the rotations were applied in Z, Y, X order.

### static Quaternion Math::Quaternion::GetRotationTo(const Vector3& from, const Vector3& to, const Vector3& fallbackAxis = Vector3::ZERO)

Returns the quaternion the rotation between two vectors.

Parameters
from Vector to rotate from.
to Vector to rotate to.
fallbackAxis If the two vectors are parallel but opposite, this method returns a 180 degrees rotation around the fallback axis.

This means that applying the returned quaternion to the vector `from` produces the vector `to` (assuming they have the same length).

The operation will be applied to normalized versions of the vectors, so their length does not matter.

### Vector3 Math::Quaternion::ToEuler() const

Returns the euler angles (in radians) that represent the same rotation as this quaternion.

It returns a vector with the rotation around the X (roll), Y (pitch) and Z (yaw) axes.