#include <muu/matrix.h>
matrix struct
A matrix.
Template parameters | |
---|---|
Scalar | The matrix's scalar component type. |
Rows | The number of rows in the matrix. |
Columns | The number of columns in the matrix. |
Public types
-
using axis_angle_type = axis_
angle<scalar_ type> - The muu::
axis_angle with the same scalar_ type as this matrix. -
using column_type = vector<scalar_
type, rows> - The type of one column of this matrix.
-
using constants = muu::
constants<matrix> - Compile-time constants for this matrix.
-
using determinant_type = std::
conditional_t<is_ integral<scalar_ type>, impl::highest_ranked<make_ signed<scalar_ type>, int>, scalar_ type> - The scalar type used for determinants. Always signed.
-
using euler_type = euler_
angles<scalar_ type> - The muu::
euler_angles with the same scalar_ type as this matrix. -
using inverse_scalar_type = std::
conditional_t<is_ integral<scalar_ type>, double, scalar_ type> - The scalar type returned by inversion operations. Always floating-point.
-
using inverse_type = matrix<inverse_
scalar_ type, Rows, Columns> - The matrix type returned by inversion operations. Always floating-point.
-
using quaternion_type = quaternion<scalar_
type> - The muu::
quaternion with the same scalar_ type as this matrix. -
using row_type = vector<scalar_
type, columns> - The type of one row of this matrix.
- using scalar_type = Scalar
- The type of each scalar component stored in this matrix.
Public static variables
Constructors, destructors, conversion operators
- matrix() defaulted noexcept
- Default constructor. Values are not initialized.
- matrix(const matrix&) defaulted constexpr noexcept
- Copy constructor.
-
matrix(scalar_
type broadcast) explicit constexpr noexcept - Constructs a matrix by broadcasting a scalar value to all components.
-
template <typename... T>matrix(scalar_
type v0, scalar_ type v1, const T&... vals) constexpr noexcept - Constructs a matrix from (row-major-ordered) scalars.
- matrix(const matrix<S, R, C>& mat) explicit constexpr noexcept
- Enlarging/truncating/converting constructor.
-
template <typename T>matrix(const T& obj) constexpr noexcept
- Constructs a matrix from an implicitly bit-castable type.
- matrix(const vector<S0, D0>& col0, const vector<S1, D1>& col1, const Cols&... cols) explicit constexpr noexcept
- Constructs a matrix from a series of column vectors.
Public functions
Public variables
-
column_
type m - The values in the matrix (stored column-major).
Addition
- auto operator+() const -> matrix constexpr noexcept
- Returns a componentwise copy of a matrix.
- auto operator+=(const matrix& rhs) -> matrix& constexpr noexcept
- Componentwise adds another matrix to this one.
- auto operator+(const matrix& lhs, const matrix& rhs) -> matrix constexpr noexcept
- Returns the componentwise addition of two matrices.
Column accessors
-
template <size_t C>auto column() -> column_
type& constexpr noexcept - Gets a reference to a specific column.
-
template <size_t C>auto column() const -> constcolumn_
type& constexpr noexcept - Gets a const reference to a specific column.
-
auto translation_column() -> column_
type& constexpr noexcept - Returns a reference to the Translation column.
-
auto translation_column() const -> constcolumn_
type& constexpr noexcept - Returns a const reference to the Translation column.
-
auto w_column() -> column_
type& constexpr noexcept - Returns a reference to the W column (column 3).
-
auto w_column() const -> constcolumn_
type& constexpr noexcept - Returns a const reference to the W column (column 3).
-
auto x_column() -> column_
type& constexpr noexcept - Returns a reference to the X column (column 0).
-
auto x_column() const -> constcolumn_
type& constexpr noexcept - Returns a const reference to the X axis column (column 0).
-
auto y_column() -> column_
type& constexpr noexcept - Returns a reference to the Y column (column 1).
-
auto y_column() const -> constcolumn_
type& constexpr noexcept - Returns a const reference to the Y column (column 1).
-
auto z_column() -> column_
type& constexpr noexcept - Returns a reference to the Z column (column 2).
-
auto z_column() const -> constcolumn_
type& constexpr noexcept - Returns a const reference to the Z column (column 2).
Division
-
auto operator/=(scalar_
type rhs) -> matrix& constexpr noexcept - Componentwise multiplies this matrix by a scalar.
-
auto operator/(const matrix& lhs,
scalar_
type rhs) -> matrix constexpr noexcept - Returns the componentwise multiplication of a matrix by a scalar.
Equality (approximate)
-
template <typename T>static auto approx_equal(const matrix& m1, const matrix<T, rows, columns>& m2, epsilon_
type<scalar_ type, T> epsilon = default_ epsilon<scalar_ type, T>) -> bool constexpr noexcept - Returns true if two matrices are approximately equal.
-
static auto approx_zero(const matrix& m,
scalar_
type epsilon = default_ epsilon<scalar_ type>) -> bool constexpr noexcept - Returns true if all the scalar components in a matrix are approximately equal to zero.
-
template <typename T>auto approx_equal(const matrix<T, rows, columns>& m, epsilon_
type<scalar_ type, T> epsilon = default_ epsilon<scalar_ type, T>) const -> bool constexpr noexcept - Returns true if the matrix is approximately equal to another.
-
auto approx_zero(scalar_
type epsilon = default_ epsilon<scalar_ type>) const -> bool constexpr noexcept - Returns true if all the scalar components in the matrix are approximately equal to zero.
Equality (exact)
- static auto infinity_or_nan(const matrix& m) -> bool constexpr noexcept
- Returns true if any of the scalar components of a matrix are infinity or NaN.
- static auto zero(const matrix& m) -> bool constexpr noexcept
- Returns true if all the scalar components of a matrix are exactly zero.
- auto infinity_or_nan() const -> bool constexpr noexcept
- Returns true if any of the scalar components of the matrix are infinity or NaN.
- auto zero() const -> bool constexpr noexcept
- Returns true if all the scalar components of the matrix are exactly zero.
-
template <typename T>auto operator!=(const matrix& lhs, const matrix<T, rows, columns>& rhs) -> bool constexpr noexcept
- Returns true if two matrices are not exactly equal.
-
template <typename T>auto operator==(const matrix& lhs, const matrix<T, rows, columns>& rhs) -> bool constexpr noexcept
- Returns true if two matrices are exactly equal.
Inverse & Determinant
-
static auto determinant(const matrix& m) -> determinant_
type constexpr noexcept - Calculates the determinant of a matrix.
-
static auto invert(const matrix& m) -> inverse_
type constexpr noexcept - Returns the inverse of a matrix.
-
auto determinant() -> determinant_
type constexpr noexcept - Calculates the determinant of a matrix.
- auto invert() -> matrix& constexpr noexcept
- Inverts the matrix (in-place).
Multiplication
- auto operator*=(const matrix& rhs) -> matrix& constexpr noexcept
- Multiplies this matrix with another and assigns the result.
-
auto operator*=(scalar_
type rhs) -> matrix& constexpr noexcept - Componentwise multiplies this matrix by a scalar.
-
template <size_t C>auto operator*(const matrix& lhs, const matrix<scalar_
type, columns, C>& rhs) -> matrix<scalar_ type, rows, C> constexpr noexcept - Multiplies two matrices.
-
auto operator*(const matrix& lhs,
const vector<scalar_
type, columns>& rhs) -> column_ type constexpr noexcept - Multiplies a matrix and a column vector.
-
auto operator*(const vector<scalar_
type, rows>& lhs, const matrix& rhs) -> row_ type constexpr noexcept - Multiplies a row vector and a matrix.
-
auto operator*(const matrix& lhs,
scalar_
type rhs) -> matrix constexpr noexcept - Returns the componentwise multiplication of a matrix and a scalar.
-
auto operator*(scalar_
type lhs, const matrix& rhs) -> matrix constexpr noexcept - Returns the componentwise multiplication of a matrix and a scalar.
Orthonormalization
- static auto orthonormalize(const matrix&) -> matrix constexpr noexcept
- Orthonormalizes the 3x3 part of a rotation or transformation matrix.
- static auto orthonormalized(const matrix&) -> bool constexpr noexcept
- Returns true if the 3x3 part of a matrix is orthonormalized.
- auto orthonormalize() -> matrix& constexpr noexcept
- Orthonormalizes the 3x3 part of the matrix.
- auto orthonormalized() const -> bool constexpr noexcept
- Returns true if the 3x3 part of the matrix is orthonormalized.
Projection
-
template <math_static auto perspective_projection(scalar_
apis Mode = (math_apis:: directx | math_apis:: right_handed)> type vertical_fov, scalar_ type aspect_ratio, scalar_ type near_clip, scalar_ type far_clip) -> matrix constexpr noexcept - Creates a perspective projection matrix.
-
template <math_static auto perspective_projection(scalar_
apis Mode = (math_apis:: directx | math_apis:: right_handed)> type vertical_fov, const vector<scalar_ type, 2>& screen_size, scalar_ type near_clip, scalar_ type far_clip) -> matrix constexpr noexcept - Creates a perspective projection matrix.
Rotation
-
static auto from_2d_rotation(const matrix<scalar_
type, R, C>& rot) -> matrix constexpr noexcept - Creates a 2D rotation matrix from the lower 2x2 part of a matrix.
-
static auto from_3d_direction(const vector<scalar_
type, 3>& dir) -> matrix constexpr noexcept - Creates a 3D rotation matrix from a forward direction vector.
-
static auto from_3d_rotation(const matrix<scalar_
type, R, C>& rot) -> matrix constexpr noexcept - Creates a 3D rotation matrix from the lower 3x3 part of a matrix.
- static auto from_axes(const vector<Scalar, 2>& x, const vector<Scalar, 2>& y) -> matrix constexpr noexcept
- Creates a 2D rotation matrix from x and y axis vectors.
- static auto from_axes(const vector<Scalar, 3>& x, const vector<Scalar, 3>& y, const vector<Scalar, 3>& z) -> matrix constexpr noexcept
- Creates a 3D rotation matrix from x, y and z axis vectors.
-
static auto from_axis_angle(const vector<scalar_
type, 3>& axis, scalar_ type angle) -> matrix constexpr noexcept - Creates a 3D rotation matrix from an axis and an angle.
-
static auto from_axis_angle(const axis_
angle_ type& aa) -> matrix constexpr noexcept - Creates a 3D rotation matrix from an axis and an angle.
-
static auto from_euler(scalar_
type yaw, scalar_ type pitch, scalar_ type roll) -> matrix constexpr noexcept - Creates a 3D rotation matrix from a set of euler angles.
-
static auto from_euler(const euler_
type& angles) -> matrix constexpr noexcept - Creates a 3D rotation matrix from a set of euler angles.
-
static auto from_quaternion(const quaternion_
type& quat) -> matrix constexpr noexcept - Creates a 3D rotation matrix from a quaternion.
-
static auto from_rotation(const matrix<scalar_
type, 2, 2>& rot) -> matrix constexpr noexcept - Creates a 2D rotation matrix from a 2x2 matrix.
-
static auto from_rotation(const matrix<scalar_
type, 2, 3>& rot) -> matrix constexpr noexcept - Creates a 2D rotation matrix from a 2x3 matrix.
-
static auto from_rotation(const matrix<scalar_
type, 3, 3>& rot) -> matrix constexpr noexcept - Creates a 3D rotation matrix from a 3x3 matrix.
-
static auto from_rotation(const matrix<scalar_
type, 3, 4>& rot) -> matrix constexpr noexcept - Creates a 3D rotation matrix from a 3x4 matrix.
-
static auto from_rotation(const matrix<scalar_
type, 4, 4>& rot) -> matrix constexpr noexcept - Creates a 3D rotation matrix from a 4x4 matrix.
- auto has_2d_shear() const -> bool constexpr noexcept
- Returns true if a 2D rotation matrix contains shear.
- auto has_3d_shear() const -> bool constexpr noexcept
- Returns true if a 3D rotation matrix contains shear.
Scalar accessors
-
auto data() const -> constscalar_
type* constexpr noexcept - Returns a pointer to the first scalar component in the matrix.
-
auto data() -> scalar_
type* constexpr noexcept - Returns a pointer to the first scalar component in the matrix.
-
auto get() const -> constscalar_
type& constexpr noexcept - Gets a reference to the scalar component at a specific row and column.
-
auto get() -> scalar_
type& constexpr noexcept - Gets a reference to the scalar component at a specific row and column.
-
auto operator()(size_t r,
size_t c) const -> constscalar_
type& constexpr noexcept - Gets a reference to the scalar component at a specific row and column.
-
auto operator()(size_t r,
size_t c) -> scalar_
type& constexpr noexcept - Gets a reference to the scalar component at a specific row and column.
Scaling
-
static auto from_2d_scale(scalar_
type x, scalar_ type y) -> matrix constexpr noexcept - Creates a scale matrix from x and y scalar components.
-
template <size_t D>static auto from_2d_scale(const vector<scalar_
type, D>& scale) -> matrix constexpr noexcept - Creates a scale matrix from the x and y components of a vector of arbitrary size.
-
static auto from_3d_scale(scalar_
type x, scalar_ type y, scalar_ type z = Scalar{ 1 }) -> matrix constexpr noexcept - Creates a scale matrix from x, y and z scalar components.
-
template <size_t D>static auto from_3d_scale(const vector<scalar_
type, D>& scale) -> matrix constexpr noexcept - Creates a scale matrix from the x, y and z components of a vector of arbitrary size.
-
static auto from_scale(scalar_
type x, scalar_ type y) -> matrix constexpr noexcept - Creates a scale matrix from x and y scalar components.
-
static auto from_scale(scalar_
type x, scalar_ type y, scalar_ type z) -> matrix constexpr noexcept - Creates a scale matrix from x, y and z scalar components.
-
static auto from_scale(const vector<scalar_
type, 2>& scale) -> matrix constexpr noexcept - Creates a scale matrix from a 2D vector.
-
static auto from_scale(const vector<scalar_
type, 3>& scale) -> matrix constexpr noexcept - Creates a scale matrix from a 3D vector.
Subtraction
- auto operator-() const -> matrix constexpr noexcept
- Returns a componentwise negation of a matrix.
- auto operator-=(const matrix& rhs) -> matrix& constexpr noexcept
- Componentwise subtracts another matrix from this one.
- auto operator-(const matrix& lhs, const matrix& rhs) -> matrix constexpr noexcept
- Returns the componentwise subtraction of two matrices.
Transformation
-
static auto extract_2d_scale(const matrix& mat) -> vector<scalar_
type, 2> constexpr noexcept - Extracts the scale from a 2D transform matrix.
-
static auto extract_3d_scale(const matrix& mat) -> vector<scalar_
type, 3> constexpr noexcept - Extracts the scale from a 3D transform matrix.
-
static auto transform_direction(const matrix& xform,
const vector<scalar_
type, 3>& dir) -> vector<scalar_ type, 3> constexpr noexcept - Applies a matrix's 3d transformation to the given direction vector, ignorning translation and scale.
-
static auto transform_position(const matrix& xform,
const vector<scalar_
type, 3>& pos) -> vector<scalar_ type, 3> constexpr noexcept - Applies a matrix's 3d transformation to the given vector.
-
static auto transform_without_translating(const matrix& xform,
const vector<scalar_
type, 3>& v) -> vector<scalar_ type, 3> constexpr noexcept - Applies a matrix's 3d transformation to the given position or direction vector, ignorning translation.
-
auto extract_2d_scale() const -> vector<scalar_
type, 2> constexpr noexcept - Extracts the scale from a 2D transform matrix.
-
auto extract_3d_scale() const -> vector<scalar_
type, 3> constexpr noexcept - Extracts the scale from a 3D transform matrix.
-
auto transform_direction(const vector<scalar_
type, 3>& dir) const -> vector<scalar_ type, 3> constexpr noexcept - Applies a matrix's 3d transformation to the direction vector, ignorning translation and scale.
-
auto transform_position(const vector<scalar_
type, 3>& pos) const -> vector<scalar_ type, 3> constexpr noexcept - Applies the matrix's 3d transformation to the given vector.
-
auto transform_without_translating(const vector<scalar_
type, 3>& v) const -> vector<scalar_ type, 3> constexpr noexcept - Applies a matrix's 3d transformation to the position or direction vector, ignorning translation.
-
auto operator*(const matrix& xform,
const vector<scalar_
type, 3>& pos) -> vector<scalar_ type, 3> constexpr noexcept - Applies the matrix's 3d transformation to the vector.
Translation
-
static auto from_2d_translation(scalar_
type x, scalar_ type y) -> matrix constexpr noexcept - Creates a translation matrix from x and y scalar components.
-
template <size_t D>static auto from_2d_translation(const vector<scalar_
type, D>& xlat) -> matrix constexpr noexcept - Creates a translation matrix from the x and y components of a vector of arbitrary size.
-
static auto from_3d_translation(scalar_
type x, scalar_ type y, scalar_ type z = Scalar{}) -> matrix constexpr noexcept - Creates a translation matrix from x, y and z scalar components.
-
template <size_t D>static auto from_3d_translation(const vector<scalar_
type, D>& xlat) -> matrix constexpr noexcept - Creates a translation matrix from the x, y and z components of a vector of arbitrary size.
-
static auto from_translation(scalar_
type x, scalar_ type y) -> matrix constexpr noexcept - Creates a translation matrix from x and y scalar components.
-
static auto from_translation(scalar_
type x, scalar_ type y, scalar_ type z) -> matrix constexpr noexcept - Creates a translation matrix from x, y and z scalar components.
-
static auto from_translation(const vector<scalar_
type, 2>& xlat) -> matrix constexpr noexcept - Creates a translation matrix from a 2D vector.
-
static auto from_translation(const vector<scalar_
type, 3>& xlat) -> matrix constexpr noexcept - Creates a translation matrix from a 3D vector.
Transposition
Friends
-
template <typename Char, typename Traits>auto operator<<(std::
basic_ostream<Char, Traits>& os, const matrix& m) -> std:: basic_ostream<Char, Traits>& - Writes a matrix out to a text stream.
Function documentation
muu::matrix::matrix(scalar_ type broadcast) explicit constexpr noexcept
Constructs a matrix by broadcasting a scalar value to all components.
Parameters | |
---|---|
broadcast | The value used to initialize each of the matrix's scalar components. |
std::cout << matrix<int, 3, 3>{ 1 } << "\n";
{ 1, 1, 1, 1, 1, 1, 1, 1, 1 }
muu::matrix::matrix(scalar_ type v0,
scalar_ type v1,
const T&... vals) constexpr noexcept
Constructs a matrix from (row-major-ordered) scalars.
Template parameters | |
---|---|
T | Types convertible to scalar_ |
Parameters | |
v0 | Initial value for the matrix's first scalar component. |
v1 | Initial value for the matrix's second scalar component. |
vals | Initial values for the matrix's remaining scalar components. |
// explicitly-sized matrices: std::cout << matrix<int, 2, 3>{ 1, 2, 3, 4, 5, 6 } << "\n\n"; // 2x2, 2x3, 3x3, 3x4 and 4x4 matrices can be deduced automatically // from 4, 6, 9, 12 and 16 inputs (respectively): std::cout << matrix{ 1, 2, 3, 4 } << "\n\n"; std::cout << matrix{ 1, 2, 3, 4, 5, 6 } << "\n\n"; std::cout << matrix{ 1, 2, 3, 4, 5, 6, 7, 8, 9 } << "\n\n"; std::cout << matrix{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 } << "\n\n"; std::cout << matrix{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 } << "\n\n";
{ 1, 2, 3, 4 } { 1, 2, 3, 4, 5, 6 } { 1, 2, 3, 4, 5, 6, 7, 8, 9 } { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 } { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }
Any scalar components not covered by the constructor's parameters are initialized to zero.
muu::matrix::matrix(const matrix<S, R, C>& mat) explicit constexpr noexcept
Enlarging/truncating/converting constructor.
Template parameters | |
---|---|
S | Source matrix's scalar_ |
R | Source matrix's row count. |
C | Source matrix's column count. |
Parameters | |
mat | Source matrix. |
Copies source matrix's scalar components, casting if necessary:
matrix<int, 3, 3> m33 = { 1, 2, 3, 4, 5, 6, 7, 8, 9 }; std::cout << m33 << "\n\n"; matrix<int, 2, 2> m22 = { m33 }; std::cout << m22 << "\n\n"; matrix<int, 4, 4> m44 = { m33 }; std::cout << m44 << "\n\n";
{ 1, 2, 3, 4, 5, 6, 7, 8, 9 } { 1, 2, 4, 5 } { 1, 2, 3, 0, 4, 5, 6, 0, 7, 8, 9, 0, 0, 0, 0, 0 }
Any scalar components not covered by the constructor's parameters are initialized to zero.
template <typename Scalar, size_t Rows, size_t Columns>
template <typename S0, size_t D0, typename S1, size_t D1, typename... Cols>
muu::matrix::matrix(const vector<S0, D0>& col0,
const vector<S1, D1>& col1,
const Cols&... cols) explicit constexpr noexcept
template <typename S0, size_t D0, typename S1, size_t D1, typename... Cols>
Constructs a matrix from a series of column vectors.
Template parameters | |
---|---|
S0 | scalar_ |
D0 | Number of dimensions in the first column's initializer. |
S1 | scalar_ |
D1 | Number of dimensions in the second column's initializer. |
Cols | Any additional column initializers. |
Copies from the input columns, enlarging/truncating/casting as necessary:
matrix<int, 3, 3> m33{ vector{ 1, 2, 3 }, vector{ 4, 5, 6 }, vector{ 7, 8, 9 } }; std::cout << m33 << "\n\n"; matrix<int, 2, 2> m22{ vector{ 1, 2, 3 }, vector{ 4, 5, 6 } }; std::cout << m22 << "\n\n";
{ 1, 4, 7, 2, 5, 8, 3, 6, 9 } { 1, 4, 2, 5 }
Any scalar components not covered by the constructor's parameters are initialized to zero.
column_ type& muu::matrix::translation_column() constexpr noexcept
Returns a reference to the Translation column.
constcolumn_ type& muu::matrix::translation_column() const constexpr noexcept
Returns a const reference to the Translation column.
column_ type& muu::matrix::w_column() constexpr noexcept
Returns a reference to the W column (column 3).
constcolumn_ type& muu::matrix::w_column() const constexpr noexcept
Returns a const reference to the W column (column 3).
column_ type& muu::matrix::x_column() constexpr noexcept
Returns a reference to the X column (column 0).
constcolumn_ type& muu::matrix::x_column() const constexpr noexcept
Returns a const reference to the X axis column (column 0).
column_ type& muu::matrix::y_column() constexpr noexcept
Returns a reference to the Y column (column 1).
constcolumn_ type& muu::matrix::y_column() const constexpr noexcept
Returns a const reference to the Y column (column 1).
column_ type& muu::matrix::z_column() constexpr noexcept
Returns a reference to the Z column (column 2).
constcolumn_ type& muu::matrix::z_column() const constexpr noexcept
Returns a const reference to the Z column (column 2).
static bool muu::matrix::approx_equal(const matrix& m1,
const matrix<T, rows, columns>& m2,
epsilon_ type<scalar_ type, T> epsilon = default_ epsilon<scalar_ type, T>) constexpr noexcept
Returns true if two matrices are approximately equal.
static bool muu::matrix::approx_zero(const matrix& m,
scalar_ type epsilon = default_ epsilon<scalar_ type>) constexpr noexcept
Returns true if all the scalar components in a matrix are approximately equal to zero.
bool muu::matrix::approx_equal(const matrix<T, rows, columns>& m,
epsilon_ type<scalar_ type, T> epsilon = default_ epsilon<scalar_ type, T>) const constexpr noexcept
Returns true if the matrix is approximately equal to another.
bool muu::matrix::approx_zero(scalar_ type epsilon = default_ epsilon<scalar_ type>) const constexpr noexcept
Returns true if all the scalar components in the matrix are approximately equal to zero.
static determinant_ type muu::matrix::determinant(const matrix& m) constexpr noexcept
Calculates the determinant of a matrix.
static inverse_ type muu::matrix::invert(const matrix& m) constexpr noexcept
Returns the inverse of a matrix.
determinant_ type muu::matrix::determinant() constexpr noexcept
Calculates the determinant of a matrix.
matrix& muu::matrix::operator*=(const matrix& rhs) constexpr noexcept
Multiplies this matrix with another and assigns the result.
matrix<scalar_ type, rows, C> muu::matrix::operator*(const matrix& lhs,
const matrix<scalar_ type, columns, C>& rhs) constexpr noexcept
Multiplies two matrices.
Template parameters | |
---|---|
C | The number of columns in the RHS matrix. |
Parameters | |
lhs | The LHS matrix. |
rhs | The RHS matrix. |
Returns | The result of lhs * rhs . |
column_ type muu::matrix::operator*(const matrix& lhs,
const vector<scalar_ type, columns>& rhs) constexpr noexcept
Multiplies a matrix and a column vector.
Parameters | |
---|---|
lhs | The LHS matrix. |
rhs | The RHS column vector. |
Returns | The result of lhs * rhs . |
static matrix muu::matrix::orthonormalize(const matrix&) constexpr noexcept
Orthonormalizes the 3x3 part of a rotation or transformation matrix.
static bool muu::matrix::orthonormalized(const matrix&) constexpr noexcept
Returns true if the 3x3 part of a matrix is orthonormalized.
matrix& muu::matrix::orthonormalize() constexpr noexcept
Orthonormalizes the 3x3 part of the matrix.
bool muu::matrix::orthonormalized() const constexpr noexcept
Returns true if the 3x3 part of the matrix is orthonormalized.
template <typename Scalar, size_t Rows, size_t Columns>
template <math_ apis Mode = (math_apis:: directx | math_apis:: right_handed)>
static matrix muu::matrix::perspective_projection(scalar_ type vertical_fov,
scalar_ type aspect_ratio,
scalar_ type near_clip,
scalar_ type far_clip) constexpr noexcept
template <math_
Creates a perspective projection matrix.
Template parameters | |
---|---|
Mode | Select the combination of flags for your math/graphics API. |
Parameters | |
vertical_fov | Vertical field-of-view in radians. |
aspect_ratio | Screen aspect ratio (width / height ). |
near_clip | The camera's near-clip plane distance. |
far_clip | The camera's far-clip plane distance. |
template <typename Scalar, size_t Rows, size_t Columns>
template <math_ apis Mode = (math_apis:: directx | math_apis:: right_handed)>
static matrix muu::matrix::perspective_projection(scalar_ type vertical_fov,
const vector<scalar_ type, 2>& screen_size,
scalar_ type near_clip,
scalar_ type far_clip) constexpr noexcept
template <math_
Creates a perspective projection matrix.
Template parameters | |
---|---|
Mode | Select the combination of flags for your math/graphics API. |
Parameters | |
vertical_fov | Vertical field-of-view in radians. |
screen_size | The screen's size (width + height). |
near_clip | The camera's near-clip plane distance. |
far_clip | The camera's far-clip plane distance. |
static matrix muu::matrix::from_2d_rotation(const matrix<scalar_ type, R, C>& rot) constexpr noexcept
Creates a 2D rotation matrix from the lower 2x2 part of a matrix.
static matrix muu::matrix::from_3d_direction(const vector<scalar_ type, 3>& dir) constexpr noexcept
Creates a 3D rotation matrix from a forward direction vector.
static matrix muu::matrix::from_3d_rotation(const matrix<scalar_ type, R, C>& rot) constexpr noexcept
Creates a 3D rotation matrix from the lower 3x3 part of a matrix.
static matrix muu::matrix::from_axis_angle(const vector<scalar_ type, 3>& axis,
scalar_ type angle) constexpr noexcept
Creates a 3D rotation matrix from an axis and an angle.
static matrix muu::matrix::from_axis_angle(const axis_ angle_ type& aa) constexpr noexcept
Creates a 3D rotation matrix from an axis and an angle.
static matrix muu::matrix::from_euler(scalar_ type yaw,
scalar_ type pitch,
scalar_ type roll) constexpr noexcept
Creates a 3D rotation matrix from a set of euler angles.
static matrix muu::matrix::from_euler(const euler_ type& angles) constexpr noexcept
Creates a 3D rotation matrix from a set of euler angles.
static matrix muu::matrix::from_quaternion(const quaternion_ type& quat) constexpr noexcept
Creates a 3D rotation matrix from a quaternion.
static matrix muu::matrix::from_rotation(const matrix<scalar_ type, 2, 2>& rot) constexpr noexcept
Creates a 2D rotation matrix from a 2x2 matrix.
static matrix muu::matrix::from_rotation(const matrix<scalar_ type, 2, 3>& rot) constexpr noexcept
Creates a 2D rotation matrix from a 2x3 matrix.
static matrix muu::matrix::from_rotation(const matrix<scalar_ type, 3, 3>& rot) constexpr noexcept
Creates a 3D rotation matrix from a 3x3 matrix.
static matrix muu::matrix::from_rotation(const matrix<scalar_ type, 3, 4>& rot) constexpr noexcept
Creates a 3D rotation matrix from a 3x4 matrix.
static matrix muu::matrix::from_rotation(const matrix<scalar_ type, 4, 4>& rot) constexpr noexcept
Creates a 3D rotation matrix from a 4x4 matrix.
bool muu::matrix::has_2d_shear() const constexpr noexcept
Returns true if a 2D rotation matrix contains shear.
bool muu::matrix::has_3d_shear() const constexpr noexcept
Returns true if a 3D rotation matrix contains shear.
constscalar_ type& muu::matrix::get() const constexpr noexcept
Gets a reference to the scalar component at a specific row and column.
Template parameters | |
---|---|
R | The row of the scalar component to retrieve. |
C | The column of the scalar component to retrieve. |
Returns | A reference to the selected scalar component. |
scalar_ type& muu::matrix::get() constexpr noexcept
Gets a reference to the scalar component at a specific row and column.
Template parameters | |
---|---|
R | The row of the scalar component to retrieve. |
C | The column of the scalar component to retrieve. |
Returns | A reference to the selected scalar component. |
constscalar_ type& muu::matrix::operator()(size_t r,
size_t c) const constexpr noexcept
Gets a reference to the scalar component at a specific row and column.
Parameters | |
---|---|
r | The row of the scalar component to retrieve. |
c | The column of the scalar component to retrieve. |
Returns | A reference to the selected scalar component. |
scalar_ type& muu::matrix::operator()(size_t r,
size_t c) constexpr noexcept
Gets a reference to the scalar component at a specific row and column.
Parameters | |
---|---|
r | The row of the scalar component to retrieve. |
c | The column of the scalar component to retrieve. |
Returns | A reference to the selected scalar component. |
static matrix muu::matrix::from_2d_scale(scalar_ type x,
scalar_ type y) constexpr noexcept
Creates a scale matrix from x and y scalar components.
static matrix muu::matrix::from_2d_scale(const vector<scalar_ type, D>& scale) constexpr noexcept
Creates a scale matrix from the x and y components of a vector of arbitrary size.
static matrix muu::matrix::from_3d_scale(scalar_ type x,
scalar_ type y,
scalar_ type z = Scalar{ 1 }) constexpr noexcept
Creates a scale matrix from x, y and z scalar components.
static matrix muu::matrix::from_3d_scale(const vector<scalar_ type, D>& scale) constexpr noexcept
Creates a scale matrix from the x, y and z components of a vector of arbitrary size.
static matrix muu::matrix::from_scale(scalar_ type x,
scalar_ type y) constexpr noexcept
Creates a scale matrix from x and y scalar components.
static matrix muu::matrix::from_scale(scalar_ type x,
scalar_ type y,
scalar_ type z) constexpr noexcept
Creates a scale matrix from x, y and z scalar components.
static matrix muu::matrix::from_scale(const vector<scalar_ type, 2>& scale) constexpr noexcept
Creates a scale matrix from a 2D vector.
static matrix muu::matrix::from_scale(const vector<scalar_ type, 3>& scale) constexpr noexcept
Creates a scale matrix from a 3D vector.
static vector<scalar_ type, 2> muu::matrix::extract_2d_scale(const matrix& mat) constexpr noexcept
Extracts the scale from a 2D transform matrix.
static vector<scalar_ type, 3> muu::matrix::extract_3d_scale(const matrix& mat) constexpr noexcept
Extracts the scale from a 3D transform matrix.
static vector<scalar_ type, 3> muu::matrix::transform_direction(const matrix& xform,
const vector<scalar_ type, 3>& dir) constexpr noexcept
Applies a matrix's 3d transformation to the given direction vector, ignorning translation and scale.
Returns | The result of transforming the 3D direction by the matrix. |
---|
static vector<scalar_ type, 3> muu::matrix::transform_position(const matrix& xform,
const vector<scalar_ type, 3>& pos) constexpr noexcept
Applies a matrix's 3d transformation to the given vector.
Returns | The result of transforming the 3D position by the matrix. |
---|
static vector<scalar_ type, 3> muu::matrix::transform_without_translating(const matrix& xform,
const vector<scalar_ type, 3>& v) constexpr noexcept
Applies a matrix's 3d transformation to the given position or direction vector, ignorning translation.
Returns | The result of transforming the 3D vector by the matrix. |
---|
vector<scalar_ type, 2> muu::matrix::extract_2d_scale() const constexpr noexcept
Extracts the scale from a 2D transform matrix.
vector<scalar_ type, 3> muu::matrix::extract_3d_scale() const constexpr noexcept
Extracts the scale from a 3D transform matrix.
vector<scalar_ type, 3> muu::matrix::transform_direction(const vector<scalar_ type, 3>& dir) const constexpr noexcept
Applies a matrix's 3d transformation to the direction vector, ignorning translation and scale.
Returns | The result of transforming the 3D direction by the matrix. |
---|
vector<scalar_ type, 3> muu::matrix::transform_position(const vector<scalar_ type, 3>& pos) const constexpr noexcept
Applies the matrix's 3d transformation to the given vector.
Returns | The result of transforming the 3D position by the matrix. |
---|
vector<scalar_ type, 3> muu::matrix::transform_without_translating(const vector<scalar_ type, 3>& v) const constexpr noexcept
Applies a matrix's 3d transformation to the position or direction vector, ignorning translation.
Returns | The result of transforming the 3D vector by the matrix. |
---|
vector<scalar_ type, 3> muu::matrix::operator*(const matrix& xform,
const vector<scalar_ type, 3>& pos) constexpr noexcept
Applies the matrix's 3d transformation to the vector.
Returns | The result of transforming the 3D position by the matrix. |
---|
static matrix muu::matrix::from_2d_translation(scalar_ type x,
scalar_ type y) constexpr noexcept
Creates a translation matrix from x and y scalar components.
static matrix muu::matrix::from_2d_translation(const vector<scalar_ type, D>& xlat) constexpr noexcept
Creates a translation matrix from the x and y components of a vector of arbitrary size.
static matrix muu::matrix::from_3d_translation(scalar_ type x,
scalar_ type y,
scalar_ type z = Scalar{}) constexpr noexcept
Creates a translation matrix from x, y and z scalar components.
static matrix muu::matrix::from_3d_translation(const vector<scalar_ type, D>& xlat) constexpr noexcept
Creates a translation matrix from the x, y and z components of a vector of arbitrary size.
static matrix muu::matrix::from_translation(scalar_ type x,
scalar_ type y) constexpr noexcept
Creates a translation matrix from x and y scalar components.
static matrix muu::matrix::from_translation(scalar_ type x,
scalar_ type y,
scalar_ type z) constexpr noexcept
Creates a translation matrix from x, y and z scalar components.
static matrix muu::matrix::from_translation(const vector<scalar_ type, 2>& xlat) constexpr noexcept
Creates a translation matrix from a 2D vector.
static matrix muu::matrix::from_translation(const vector<scalar_ type, 3>& xlat) constexpr noexcept
Creates a translation matrix from a 3D vector.
determinant_ type determinant(const matrix<S, R, C>& m) constexpr noexcept
Calculates the determinant of a matrix.