quat

Header file: include/quat.h

quat is a quaternion with 4 scalars, a, b, c and d.

\(quat = a + bi + cj + dk\)

Class variables

Type

Name

Description

float

a

The first element of the quat.

float

b

The second element of the quat.

float

c

The third element of the quat.

float

d

The fourth element of the quat.

Class functions

Constructors

Name

Description

quat()

Construct a (0.0, 0.0, 0.0, 0.0) quaternion.

quat(float _a, float _b, float _c, float _d)

Construct a (_a, _b, _c, _d) quaternion.

quat(const float* _ptr)

Construct a quaternion from a pointer.

Operators

Name

Description

nml::quat& operator+=(const nml::quat& other)

Add a quat to the current quat.

nml::quat& operator-=(const nml::quat& other)

Substract a quat from the current quat.

nml::quat& operator*=(const nml::quat& other)

Multiply the current quat by a quat.

nml::quat& operator*=(const float other)

Multiply the current quat by a scalar.

nml::quat& operator/=(const float other)

Divide the current quat by a scalar.

nml::quat operator-()

Return the negative of the current quat.

float& operator[](size_t index)

Return a reference to a if index is 0, a reference to b if index is 1, a reference to c if index is 2 or a reference to d if index is 3, else, throw an exception.

const float operator[](size_t index) const

Return the value of a if index is 0, the value of b if index is 1, the value of c if index is 2 or the value of d if index is 3, else, throw an exception.

Functions

Name

Description

float length()

Return the length of the quaternion.

float* data()

Return a pointer to the quaternion’s elements.

Static Functions

Name

Description

nml::quat nml::quat::identity()

Return a (1.0, 0.0, 0.0, 0.0) identity quaternion.

Namespace functions

Operators

Name

Description

nml::quat operator+(nml::quat lhs, const nml::quat& rhs)

Return a quat that is the sum between two quat.

nml::quat operator-(nml::quat lhs, const nml::quat& rhs)

Return a quat that is the difference between two quat.

nml::quat operator*(nml::quat lhs, const nml::quat& rhs)

Return a quat that is the product between two quat.

nml::quat operator*(nml::quat lhs, const float rhs)

Return a quat that is the product between a quat and a scalar.

nml::quat operator*(float lhs, const nml::quat& rhs)

Return a quat that is the product between a scalar and a quat.

nml::quat operator/(nml::quat lhs, const float rhs)

Return a quat that is the quotient between a quat and a scalar.

bool operator==(const nml::quat& lhs, const nml::quat& rhs)

Return true if the two quat are identical, else, return false.

bool operator!=(const nml::quat& lhs, const nml::quat& rhs)

Return true if the two quat are different, else, return false.

Functions

Name

Description

nml::quat nml::conjugate(const nml::quat& qua)

Return the conjugate of a quaternion.

nml::quat nml::normalize(const nml::quat& qua)

Return a quat with the same direction as qua but with length 1.

float nml::dot(const nml::quat& a, const nml::quat& b)

Return the dot product between two quat.

quat nml::slerp(const nml::quat& a, const nml::quat& b, const float interpolationValue)

Return the spherical linear interpolation between two quat and an interpolation value.

nml::quat eulerAnglesToQuat(const nml::vec3& vec)

Return a quaternion from euler angles in radians.

nml::quat rotationMatrixToQuat(const nml::mat4& mat)

Return a quaternion from a rotation matrix.

std::string nml::to_string(const nml::quat& qua)

Return a quat as a string under the format “a + bi + cj + dk”.