mal-math
C++20 mathematics library.
|
Represents a quaternion with primitive type T. More...
#include "quaternion.hpp"
Public Types | |
using | type = T |
Alias for the primitive data type used in the quaternion. | |
Public Member Functions | |
constexpr | qua () |
Default constructor initializes the quaternion to its default state (1, 0, 0, 0). | |
constexpr | qua (T w, T x, T y, T z) |
Constructs a quaternion from its four components. | |
constexpr void | reset () |
Resets the quaternion to its default state (1, 0, 0, 0). | |
constexpr | qua (T radians, vec< 3, T > axis) |
Constructs a quaternion from an angle and rotation axis. | |
constexpr mat< 3, 3, T > | as_mat3 () const noexcept |
Converts the quaternion to a 3x3 rotation matrix. | |
constexpr mat< 4, 4, T > | as_mat4 () const noexcept |
Converts the quaternion to a 4x4 rotation matrix. | |
constexpr vec< 3, T > const & | axis () const noexcept |
Retrieves the axis of rotation from the quaternion. | |
constexpr T | radians () const noexcept |
Retrieves the angle of rotation from the quaternion. | |
constexpr qua< T > const & | operator+ () const noexcept |
Unary plus operator. | |
constexpr qua< T > | operator- () const noexcept |
Unary minus operator. Inverts the sign of each component. | |
template<Primitive U> | |
constexpr qua< T > & | operator*= (U const value) noexcept |
Multiplies the quaternion by a scalar value. | |
template<Primitive U> | |
constexpr qua< T > & | operator/= (U const value) noexcept |
Divides the components of the quaternion by a scalar value. | |
template<Primitive U> | |
constexpr qua< T > & | operator+= (qua< U > const &other) noexcept |
Adds another quaternion to this quaternion component-wise. | |
template<Primitive U> | |
constexpr qua< T > & | operator-= (qua< U > const &other) noexcept |
Subtracts another quaternion from this quaternion component-wise. | |
template<Primitive U> | |
constexpr qua< T > & | operator*= (qua< U > const &other) noexcept |
Multiplies this quaternion with another quaternion. | |
template<Primitive U> | |
constexpr qua< T > & | operator/= (qua< U > const &other) noexcept |
Divides this quaternion by another quaternion. | |
constexpr T & | operator[] (size_t i) |
Accesses a component of the quaternion by index. | |
constexpr T const & | operator[] (size_t i) const |
Accesses a component of the quaternion by index (const version). | |
Public Attributes | ||
union { | ||
struct { | ||
union { | ||
T x | ||
T r | ||
T s | ||
} | ||
union { | ||
T y | ||
T g | ||
T t | ||
} | ||
union { | ||
T z | ||
T b | ||
T p | ||
} | ||
union { | ||
T w | ||
T a | ||
T q | ||
} | ||
} | ||
std::array< T, size > data | ||
}; | ||
Unions allowing various ways to access quaternion components. | ||
Static Public Attributes | |
static constexpr size_t | size = 4 |
Represents the number of components in the quaternion. | |
Represents a quaternion with primitive type T.
T | Data type of the quaternion components (should be a primitive type). |
Definition at line 23 of file quaternion.hpp.
using mal_math::qua< T >::type = T |
Alias for the primitive data type used in the quaternion.
Definition at line 26 of file quaternion.hpp.
|
inlineconstexpr |
Default constructor initializes the quaternion to its default state (1, 0, 0, 0).
Definition at line 30 of file quaternion.hpp.
|
explicitconstexpr |
Constructs a quaternion from its four components.
Definition at line 7 of file quaternion.inl.
|
explicitconstexpr |
Constructs a quaternion from an angle and rotation axis.
radians | Angle of rotation in radians. |
axis | A 3D vector representing the axis of rotation. |
Definition at line 22 of file quaternion.inl.
|
nodiscardconstexprnoexcept |
Converts the quaternion to a 3x3 rotation matrix.
Definition at line 36 of file quaternion.inl.
|
nodiscardconstexprnoexcept |
Converts the quaternion to a 4x4 rotation matrix.
Definition at line 64 of file quaternion.inl.
|
nodiscardconstexprnoexcept |
Retrieves the axis of rotation from the quaternion.
Definition at line 69 of file quaternion.inl.
|
constexprnoexcept |
Multiplies this quaternion with another quaternion.
U | Primitive type of the other quaternion. |
other | The other quaternion to multiply with this one. |
Definition at line 132 of file quaternion.inl.
|
constexprnoexcept |
Multiplies the quaternion by a scalar value.
U | Primitive type of the scalar. |
value | Scalar value to multiply the quaternion with. |
Definition at line 92 of file quaternion.inl.
|
nodiscardconstexprnoexcept |
Unary plus operator.
Definition at line 80 of file quaternion.inl.
|
constexprnoexcept |
Adds another quaternion to this quaternion component-wise.
U | Primitive type of the other quaternion. |
other | The other quaternion to be added to this one. |
Definition at line 112 of file quaternion.inl.
|
nodiscardconstexprnoexcept |
Unary minus operator. Inverts the sign of each component.
Definition at line 85 of file quaternion.inl.
|
constexprnoexcept |
Subtracts another quaternion from this quaternion component-wise.
U | Primitive type of the other quaternion. |
other | The other quaternion to be subtracted from this one. |
Definition at line 122 of file quaternion.inl.
|
constexprnoexcept |
Divides this quaternion by another quaternion.
U | Primitive type of the other quaternion. |
other | The divisor quaternion. |
Definition at line 145 of file quaternion.inl.
|
constexprnoexcept |
Divides the components of the quaternion by a scalar value.
U | Primitive type of the scalar. |
value | Scalar value to divide the quaternion components by. |
Definition at line 102 of file quaternion.inl.
|
nodiscardconstexpr |
Accesses a component of the quaternion by index.
i | Index of the component (0-based). |
Definition at line 155 of file quaternion.inl.
|
nodiscardconstexpr |
Accesses a component of the quaternion by index (const version).
i | Index of the component (0-based). |
Definition at line 161 of file quaternion.inl.
|
nodiscardconstexprnoexcept |
Retrieves the angle of rotation from the quaternion.
Definition at line 74 of file quaternion.inl.
|
constexpr |
Resets the quaternion to its default state (1, 0, 0, 0).
Definition at line 15 of file quaternion.inl.
union { ... } mal_math::qua< T > |
Unions allowing various ways to access quaternion components.
T mal_math::qua< T >::a |
Definition at line 160 of file quaternion.hpp.
T mal_math::qua< T >::b |
Definition at line 156 of file quaternion.hpp.
std::array<T, size> mal_math::qua< T >::data |
Definition at line 163 of file quaternion.hpp.
T mal_math::qua< T >::g |
Definition at line 152 of file quaternion.hpp.
T mal_math::qua< T >::p |
Definition at line 156 of file quaternion.hpp.
T mal_math::qua< T >::q |
Definition at line 160 of file quaternion.hpp.
T mal_math::qua< T >::r |
Definition at line 148 of file quaternion.hpp.
T mal_math::qua< T >::s |
Definition at line 148 of file quaternion.hpp.
|
staticconstexpr |
Represents the number of components in the quaternion.
Definition at line 28 of file quaternion.hpp.
T mal_math::qua< T >::t |
Definition at line 152 of file quaternion.hpp.
T mal_math::qua< T >::w |
Definition at line 160 of file quaternion.hpp.
T mal_math::qua< T >::x |
Definition at line 148 of file quaternion.hpp.
T mal_math::qua< T >::y |
Definition at line 152 of file quaternion.hpp.
T mal_math::qua< T >::z |
Definition at line 156 of file quaternion.hpp.