Antkeeper  0.0.1
Classes | Namespaces | Functions
math/matrix.hpp File Reference
#include <engine/math/vector.hpp>
#include <cstddef>
#include <format>
#include <iterator>
#include <tuple>
#include <type_traits>
#include <utility>

Go to the source code of this file.

Classes

struct  math::matrix< T, N, M >
 n by m column-major matrix. More...
 
struct  std::tuple_size< math::matrix< T, N, M > >
 Provides access to the number of columns in a matrix as a compile-time constant expression. More...
 
struct  std::tuple_element< I, math::matrix< T, N, M > >
 Provides compile-time indexed access to the type of the columns in a matrix using a tuple-like interface. More...
 
struct  std::formatter< math::matrix< T, N, M > >
 Specialization of std::formatter for math::matrix. More...
 

Namespaces

 math
 Mathematical functions and data types.
 
 math::matrix_types
 Matrix types.
 
 math::types
 Linear algebra data types.
 
 math::operators
 Mathematical operators.
 

Typedefs

template<class T >
using math::matrix_types::mat2x2 = matrix< T, 2, 2 >
 n by m matrix. More...
 
template<class T >
using math::matrix_types::mat2x3 = matrix< T, 2, 3 >
 n by m matrix. More...
 
template<class T >
using math::matrix_types::mat2x4 = matrix< T, 2, 4 >
 n by m matrix. More...
 
template<class T >
using math::matrix_types::mat3x2 = matrix< T, 3, 2 >
 n by m matrix. More...
 
template<class T >
using math::matrix_types::mat3x3 = matrix< T, 3, 3 >
 n by m matrix. More...
 
template<class T >
using math::matrix_types::mat3x4 = matrix< T, 3, 4 >
 n by m matrix. More...
 
template<class T >
using math::matrix_types::mat4x2 = matrix< T, 4, 2 >
 n by m matrix. More...
 
template<class T >
using math::matrix_types::mat4x3 = matrix< T, 4, 3 >
 n by m matrix. More...
 
template<class T >
using math::matrix_types::mat4x4 = matrix< T, 4, 4 >
 n by m matrix. More...
 
template<class T >
using math::matrix_types::mat2 = mat2x2< T >
 n by n square matrix. More...
 
template<class T >
using math::matrix_types::mat3 = mat3x3< T >
 n by n square matrix. More...
 
template<class T >
using math::matrix_types::mat4 = mat4x4< T >
 n by n square matrix. More...
 
template<std::size_t N, std::size_t M>
using math::matrix_types::fmat = matrix< float, N, M >
 n by m matrix of single-precision floating-point numbers. More...
 
using math::matrix_types::fmat2x2 = fmat< 2, 2 >
 n by m matrix of single-precision floating-point numbers. More...
 
using math::matrix_types::fmat2x3 = fmat< 2, 3 >
 n by m matrix of single-precision floating-point numbers. More...
 
using math::matrix_types::fmat2x4 = fmat< 2, 4 >
 n by m matrix of single-precision floating-point numbers. More...
 
using math::matrix_types::fmat3x2 = fmat< 3, 2 >
 n by m matrix of single-precision floating-point numbers. More...
 
using math::matrix_types::fmat3x3 = fmat< 3, 3 >
 n by m matrix of single-precision floating-point numbers. More...
 
using math::matrix_types::fmat3x4 = fmat< 3, 4 >
 n by m matrix of single-precision floating-point numbers. More...
 
using math::matrix_types::fmat4x2 = fmat< 4, 2 >
 n by m matrix of single-precision floating-point numbers. More...
 
using math::matrix_types::fmat4x3 = fmat< 4, 3 >
 n by m matrix of single-precision floating-point numbers. More...
 
using math::matrix_types::fmat4x4 = fmat< 4, 4 >
 n by m matrix of single-precision floating-point numbers. More...
 
using math::matrix_types::fmat2 = fmat2x2
 n by n square matrix of single-precision floating-point numbers. More...
 
using math::matrix_types::fmat3 = fmat3x3
 n by n square matrix of single-precision floating-point numbers. More...
 
using math::matrix_types::fmat4 = fmat4x4
 n by n square matrix of single-precision floating-point numbers. More...
 
template<std::size_t N, std::size_t M>
using math::matrix_types::dmat = matrix< double, N, M >
 n by m matrix of double-precision floating-point numbers. More...
 
using math::matrix_types::dmat2x2 = dmat< 2, 2 >
 n by m matrix of double-precision floating-point numbers. More...
 
using math::matrix_types::dmat2x3 = dmat< 2, 3 >
 n by m matrix of double-precision floating-point numbers. More...
 
using math::matrix_types::dmat2x4 = dmat< 2, 4 >
 n by m matrix of double-precision floating-point numbers. More...
 
using math::matrix_types::dmat3x2 = dmat< 3, 2 >
 n by m matrix of double-precision floating-point numbers. More...
 
using math::matrix_types::dmat3x3 = dmat< 3, 3 >
 n by m matrix of double-precision floating-point numbers. More...
 
using math::matrix_types::dmat3x4 = dmat< 3, 4 >
 n by m matrix of double-precision floating-point numbers. More...
 
using math::matrix_types::dmat4x2 = dmat< 4, 2 >
 n by m matrix of double-precision floating-point numbers. More...
 
using math::matrix_types::dmat4x3 = dmat< 4, 3 >
 n by m matrix of double-precision floating-point numbers. More...
 
using math::matrix_types::dmat4x4 = dmat< 4, 4 >
 n by m matrix of double-precision floating-point numbers. More...
 
using math::matrix_types::dmat2 = dmat2x2
 n by n square matrix of double-precision floating-point numbers. More...
 
using math::matrix_types::dmat3 = dmat3x3
 n by n square matrix of double-precision floating-point numbers. More...
 
using math::matrix_types::dmat4 = dmat4x4
 n by n square matrix of double-precision floating-point numbers. More...
 

Functions

template<class T , std::size_t N, std::size_t M>
constexpr matrix< T, N, M > math::add (const matrix< T, N, M > &a, const matrix< T, N, M > &b) noexcept
 Adds two matrices. More...
 
template<class T , std::size_t N, std::size_t M>
constexpr matrix< T, N, M > math::add (const matrix< T, N, M > &a, T b) noexcept
 Adds a matrix and a scalar. More...
 
template<class T , std::size_t N>
constexpr T math::determinant (const matrix< T, N, N > &m) noexcept
 Calculates the determinant of a square matrix. More...
 
template<class T , std::size_t N, std::size_t M>
constexpr matrix< T, N, M > math::componentwise_mul (const matrix< T, N, M > &a, const matrix< T, N, M > &b) noexcept
 Performs a component-wise multiplication of two matrices. More...
 
template<class T , std::size_t N, std::size_t M>
constexpr matrix< T, N, M > math::div (const matrix< T, N, M > &a, const matrix< T, N, M > &b) noexcept
 Divides a matrix by a matrix. More...
 
template<class T , std::size_t N, std::size_t M>
constexpr matrix< T, N, M > math::div (const matrix< T, N, M > &a, T b) noexcept
 Divides a matrix by a scalar. More...
 
template<class T , std::size_t N, std::size_t M>
constexpr matrix< T, N, M > math::div (T a, const matrix< T, N, M > &b) noexcept
 Divides a scalar by a matrix. More...
 
template<class T , std::size_t N>
constexpr matrix< T, N, N > math::inverse (const matrix< T, N, N > &m) noexcept
 Calculates the inverse of a square matrix. More...
 
template<class T >
constexpr mat4< T > math::look_at_rh (const vec3< T > &position, const vec3< T > &target, const vec3< T > &up)
 Constructs a right-handed viewing transformation matrix. More...
 
template<class T >
constexpr std::tuple< mat4< T >, mat4< T > > math::look_at_rh_inv (const vec3< T > &position, const vec3< T > &target, const vec3< T > &up)
 Constructs a right-handed viewing transformation matrix and its inverse. More...
 
template<class T , std::size_t N, std::size_t M, std::size_t P>
constexpr matrix< T, P, M > math::mul (const matrix< T, N, M > &a, const matrix< T, P, N > &b) noexcept
 Multiplies two matrices. More...
 
template<class T , std::size_t N, std::size_t M>
constexpr matrix< T, N, M > math::mul (const matrix< T, N, M > &a, T b) noexcept
 Multiplies a matrix by a scalar. More...
 
template<class T , std::size_t N, std::size_t M>
constexpr matrix< T, N, M >::column_vector_type math::mul (const matrix< T, N, M > &a, const typename matrix< T, N, M >::row_vector_type &b) noexcept
 Calculates the product of a matrix and a row vector. More...
 
template<class T , std::size_t N, std::size_t M>
constexpr matrix< T, N, M >::row_vector_type math::mul (const typename matrix< T, N, M >::column_vector_type &a, const matrix< T, N, M > &b) noexcept
 Calculates the product of a column vector and a matrix. More...
 
template<class T >
mat3< T > math::rotate (T angle, const vector< T, 3 > &axis)
 Constructs a rotation matrix. More...
 
template<class T >
mat3< T > math::rotate_x (T angle)
 Produces a matrix which rotates Cartesian coordinates about the x-axis by a given angle. More...
 
template<class T >
mat3< T > math::rotate_y (T angle)
 Produces a matrix which rotates Cartesian coordinates about the y-axis by a given angle. More...
 
template<class T >
mat3< T > math::rotate_z (T angle)
 Produces a matrix which rotates Cartesian coordinates about the z-axis by a given angle. More...
 
template<class T >
constexpr mat4< T > math::scale (const vec3< T > &v)
 Constructs a scale matrix. More...
 
template<class T , std::size_t N, std::size_t M>
constexpr matrix< T, N, M > math::sub (const matrix< T, N, M > &a, const matrix< T, N, M > &b) noexcept
 Subtracts a matrix from another matrix. More...
 
template<class T , std::size_t N, std::size_t M>
constexpr matrix< T, N, M > math::sub (const matrix< T, N, M > &a, T b) noexcept
 Subtracts a scalar from matrix. More...
 
template<class T , std::size_t N, std::size_t M>
constexpr matrix< T, N, M > math::sub (T a, const matrix< T, N, M > &b) noexcept
 Subtracts a matrix from a scalar. More...
 
template<class T , std::size_t N>
constexpr T math::trace (const matrix< T, N, N > &m) noexcept
 Calculates the trace of a square matrix. More...
 
template<class T >
constexpr mat4< T > math::translate (const vec3< T > &v)
 Constructs a translation matrix. More...
 
template<class T , std::size_t N, std::size_t M>
constexpr matrix< T, M, N > math::transpose (const matrix< T, N, M > &m) noexcept
 Calculates the transpose of a matrix. More...
 
template<class T , std::size_t N, std::size_t M>
constexpr matrix< T, N, M > math::operators::operator+ (const matrix< T, N, M > &a, const matrix< T, N, M > &b) noexcept
 
template<class T , std::size_t N, std::size_t M>
constexpr matrix< T, N, M > math::operators::operator/ (const matrix< T, N, M > &a, const matrix< T, N, M > &b) noexcept
 Divides a matrix by a matrix. More...
 
template<class T , std::size_t N, std::size_t M>
constexpr matrix< T, N, M > math::operators::operator/ (const matrix< T, N, M > &a, T b) noexcept
 Divides a matrix by a scalar. More...
 
template<class T , std::size_t N, std::size_t M>
constexpr matrix< T, N, M > math::operators::operator/ (T a, const matrix< T, N, M > &b) noexcept
 Divides a scalar by a matrix. More...
 
template<class T , std::size_t N, std::size_t M, std::size_t P>
constexpr matrix< T, P, M > math::operators::operator* (const matrix< T, N, M > &a, const matrix< T, P, N > &b) noexcept
 Multiplies two matrices. More...
 
template<class T , std::size_t N, std::size_t M>
constexpr matrix< T, N, M >::column_vector_type math::operators::operator* (const matrix< T, N, M > &a, const typename matrix< T, N, M >::row_vector_type &b) noexcept
 Calculates the product of a matrix and a row vector. More...
 
template<class T , std::size_t N, std::size_t M>
constexpr matrix< T, N, M >::row_vector_type math::operators::operator* (const typename matrix< T, N, M >::column_vector_type &a, const matrix< T, N, M > &b) noexcept
 Calculates the product of a column vector and a matrix. More...
 
template<class T , std::size_t N, std::size_t M>
constexpr matrix< T, N, M > math::operators::operator- (const matrix< T, N, M > &a, const matrix< T, N, M > &b) noexcept
 Subtracts a matrix from another matrix. More...
 
template<class T , std::size_t N, std::size_t M>
constexpr matrix< T, N, M > math::operators::operator- (const matrix< T, N, M > &a, T b) noexcept
 Subtracts a scalar from matrix. More...
 
template<class T , std::size_t N, std::size_t M>
constexpr matrix< T, N, M > math::operators::operator- (T a, const matrix< T, N, M > &b) noexcept
 Subtracts a matrix from a scalar. More...
 
template<std::size_t I, class T , std::size_t N, std::size_t M>
constexpr matrix< T, N, M >::column_vector_type & math::get (matrix< T, N, M > &m) noexcept
 Extracts the Ith column from a matrix. More...
 
template<std::size_t I, class T , std::size_t N, std::size_t M>
constexpr matrix< T, N, M >::column_vector_type && math::get (matrix< T, N, M > &&m) noexcept
 Extracts the Ith column from a matrix. More...
 
template<std::size_t I, class T , std::size_t N, std::size_t M>
constexpr const matrix< T, N, M >::column_vector_type & math::get (const matrix< T, N, M > &m) noexcept
 Extracts the Ith column from a matrix. More...
 
template<std::size_t I, class T , std::size_t N, std::size_t M>
constexpr const matrix< T, N, M >::column_vector_type && math::get (const matrix< T, N, M > &&m) noexcept
 Extracts the Ith column from a matrix. More...
 
template<class T , std::size_t N, std::size_t M>
constexpr matrix< T, N, M > math::operators::operator+ (const matrix< T, N, M > &a, T b) noexcept
 
template<class T , std::size_t N, std::size_t M>
constexpr matrix< T, N, M > math::operators::operator+ (T a, const matrix< T, N, M > &b) noexcept
 
template<class T , std::size_t N, std::size_t M>
constexpr matrix< T, N, M > math::operators::operator* (const matrix< T, N, M > &a, T b) noexcept
 Multiplies a matrix by a scalar. More...
 
template<class T , std::size_t N, std::size_t M>
constexpr matrix< T, N, M > math::operators::operator* (T a, const matrix< T, N, M > &b) noexcept
 Multiplies a matrix by a scalar. More...
 
template<class T , std::size_t N, std::size_t M>
constexpr matrix< T, N, M > & math::operators::operator+= (matrix< T, N, M > &a, const matrix< T, N, M > &b) noexcept
 Adds two values and stores the result in the first value. More...
 
template<class T , std::size_t N, std::size_t M>
constexpr matrix< T, N, M > & math::operators::operator+= (matrix< T, N, M > &a, T b) noexcept
 Adds two values and stores the result in the first value. More...
 
template<class T , std::size_t N, std::size_t M>
constexpr matrix< T, N, M > & math::operators::operator-= (matrix< T, N, M > &a, const matrix< T, N, M > &b) noexcept
 Subtracts the first value by the second value and stores the result in the first value. More...
 
template<class T , std::size_t N, std::size_t M>
constexpr matrix< T, N, M > & math::operators::operator-= (matrix< T, N, M > &a, T b) noexcept
 Subtracts the first value by the second value and stores the result in the first value. More...
 
template<class T , std::size_t N>
constexpr matrix< T, N, N > & math::operators::operator*= (matrix< T, N, N > &a, const matrix< T, N, N > &b) noexcept
 Multiplies two values and stores the result in the first value. More...
 
template<class T , std::size_t N, std::size_t M>
constexpr matrix< T, N, M > & math::operators::operator*= (matrix< T, N, M > &a, T b) noexcept
 Multiplies two values and stores the result in the first value. More...
 
template<class T , std::size_t N, std::size_t M>
constexpr matrix< T, N, M > & math::operators::operator/= (matrix< T, N, M > &a, const matrix< T, N, M > &b) noexcept
 Divides the first value by the second value and stores the result in the first value. More...
 
template<class T , std::size_t N, std::size_t M>
constexpr matrix< T, N, M > & math::operators::operator/= (matrix< T, N, M > &a, T b) noexcept
 Divides the first value by the second value and stores the result in the first value. More...