Infinity Engine v0.6.20
C++ API Documentation
Loading...
Searching...
No Matches
Infinity::Types::Math::t_Matrix3< T > Struct Template Reference

Template structure representing a 3x3 matrix. More...

#include <Matrix3.hpp>

Public Member Functions

constexpr t_Matrix3 ()
 Default constructor.
 
constexpr t_Matrix3 (T v)
 Constructs a diagonal matrix with the same value on the diagonal.
 
constexpr t_Matrix3 (T v0, T v1, T v2, T v3, T v4, T v5, T v6, T v7, T v8)
 Constructs a matrix from nine individual elements.
 
constexpr t_Matrix3 (T v[9])
 Constructs a matrix from an array of nine elements.
 
constexpr t_Matrix3 (const t_Vector3< T > &c0, const t_Vector3< T > &c1, const t_Vector3< T > &c2)
 Constructs a matrix from three column vectors.
 
template<typename R >
 t_Matrix3 (const t_Matrix3< R > &rhs)
 Type-converting constructor.
 
constexpr size_t size () const
 Gets the total number of elements in the matrix.
 
constexpr size_t columns () const
 Gets the number of columns in the matrix.
 
constexpr size_t rows () const
 Gets the number of rows in the matrix.
 
t_Vector3< T > & operator[] (size_t c)
 Column access operator (mutable).
 
const t_Vector3< T > & operator[] (size_t c) const
 Column access operator (const).
 
T & operator() (size_t c, size_t r)
 Element access operator (mutable).
 
operator() (size_t c, size_t r) const
 Element access operator (const).
 
template<typename R >
t_Matrix3operator= (const t_Matrix3< R > &rhs)
 Type-converting assignment operator.
 
void set (T v0, T v1, T v2, T v3, T v4, T v5, T v6, T v7, T v8)
 Sets all nine matrix elements.
 
template<typename R >
void set (const t_Matrix3< R > &rhs)
 Sets this matrix equal to another matrix.
 
T * data ()
 Gets a pointer to the underlying data.
 
const T * data () const
 Gets a const pointer to the underlying data.
 
t_Matrix3 operator* (const t_Matrix3 &rhs) const
 Matrix multiplication operator.
 
t_Matrix3operator*= (const t_Matrix3 &rhs)
 Matrix multiplication assignment operator.
 
t_Matrix3 operator* (T scalar) const
 Scalar multiplication operator.
 
t_Matrix3operator*= (T scalar)
 Scalar multiplication assignment operator.
 
t_Vector3< T > operator* (const t_Vector3< T > &v) const
 Matrix-vector multiplication operator.
 
t_Matrix3 operator+ (const t_Matrix3 &rhs) const
 Matrix addition operator.
 
t_Matrix3operator+= (const t_Matrix3 &rhs)
 Matrix addition assignment operator.
 
t_Matrix3 operator- (const t_Matrix3 &rhs) const
 Matrix subtraction operator.
 
t_Matrix3operator-= (const t_Matrix3 &rhs)
 Matrix subtraction assignment operator.
 
t_Matrix3 operator/ (T scalar) const
 Scalar division operator.
 
t_Matrix3operator/= (T scalar)
 Scalar division assignment operator.
 
bool operator== (const t_Matrix3 &rhs) const
 Equality comparison operator.
 
bool operator!= (const t_Matrix3 &rhs) const
 Inequality comparison operator.
 
bool operator< (const t_Matrix3 &rhs) const
 Less-than comparison operator for ordering.
 
t_Matrix3 transpose () const
 Computes the transpose of this matrix.
 
t_Matrix3 operator- () const
 Unary negation operator.
 
 operator bool () const noexcept
 Boolean conversion operator.
 

Public Attributes

t_Vector3< T > value [3]
 Column vectors comprising the matrix.
 

Detailed Description

template<typename T>
struct Infinity::Types::Math::t_Matrix3< T >

Template structure representing a 3x3 matrix.

t_Matrix3 provides a column-major 3x3 matrix implementation suitable for representing 2D transformations in homogeneous coordinates and 3D rotations/scales. The matrix is stored as three column vectors, following the convention used by modern graphics APIs and mathematics libraries.

Common applications in procedural generation:

  • 2D transformations (rotation, scale, translation in homogeneous coordinates)
  • 3D rotation matrices (without translation)
  • Normal matrix transformations (inverse transpose of model matrix)
  • Texture coordinate transformations
  • Basis transformations and coordinate system changes
  • Tensor operations in procedural algorithms

Matrix layout (column-major):

[ m00 m01 m02 ] [ value[0].x value[1].x value[2].x ]
[ m10 m11 m12 ] = [ value[0].y value[1].y value[2].y ]
[ m20 m21 m22 ] [ value[0].z value[1].z value[2].z ]
t_Vector3< T > value[3]
Column vectors comprising the matrix.
Definition Matrix3.hpp:91

The template parameter allows instantiation with different numeric types (float, double) to match precision requirements.

Example usage:

// Identity matrix (default constructor)
Matrix3 identity;
// Rotation matrix (2D rotation by 45 degrees)
float angle = M_PI / 4.0f;
Matrix3 rotation(
std::cos(angle), std::sin(angle), 0,
-std::sin(angle), std::cos(angle), 0,
0, 0, 1
);
// Scale matrix
Matrix3 scale(
2.0f, 0, 0,
0, 3.0f, 0,
0, 0, 1.0f
);
// Matrix multiplication
Matrix3 transform = scale * rotation;
// Transform a vector
Vector3 point(1, 0, 1);
Vector3 transformed = transform * point;
// Transpose for converting between row/column major
Matrix3 transposed = transform.transpose();
Template structure representing a 3x3 matrix.
Definition Matrix3.hpp:83
t_Matrix3 transpose() const
Computes the transpose of this matrix.
Definition Matrix3.hpp:646
Template structure representing a 3-component vector.
Definition Vector3.hpp:82
Template Parameters
TThe numeric type for matrix elements (float, double).
Note
Matrices are stored in column-major order for compatibility with OpenGL and modern graphics APIs.
Matrix-vector multiplication treats vectors as column vectors.
See also
Matrix3, Matrix3d
t_Vector3

Constructor & Destructor Documentation

◆ t_Matrix3() [1/6]

template<typename T >
constexpr Infinity::Types::Math::t_Matrix3< T >::t_Matrix3 ( )
inlineconstexpr

Default constructor.

Constructs an identity matrix:

[ 1 0 0 ]
[ 0 1 0 ]
[ 0 0 1 ]

◆ t_Matrix3() [2/6]

template<typename T >
constexpr Infinity::Types::Math::t_Matrix3< T >::t_Matrix3 ( v)
inlineexplicitconstexpr

Constructs a diagonal matrix with the same value on the diagonal.

Creates a matrix with v on the diagonal and zeros elsewhere:

[ v 0 0 ]
[ 0 v 0 ]
[ 0 0 v ]
Parameters
vThe value for all diagonal elements.
Matrix3 scaleMatrix(2.0f); // Uniform scale by 2

◆ t_Matrix3() [3/6]

template<typename T >
constexpr Infinity::Types::Math::t_Matrix3< T >::t_Matrix3 ( v0,
v1,
v2,
v3,
v4,
v5,
v6,
v7,
v8 
)
inlineconstexpr

Constructs a matrix from nine individual elements.

Elements are specified in row-major order for readability, but stored in column-major order internally.

Parameters
v0Element at row 0, column 0.
v1Element at row 0, column 1.
v2Element at row 0, column 2.
v3Element at row 1, column 0.
v4Element at row 1, column 1.
v5Element at row 1, column 2.
v6Element at row 2, column 0.
v7Element at row 2, column 1.
v8Element at row 2, column 2.
// Identity matrix
Matrix3 identity(
1, 0, 0,
0, 1, 0,
0, 0, 1
);

◆ t_Matrix3() [4/6]

template<typename T >
constexpr Infinity::Types::Math::t_Matrix3< T >::t_Matrix3 ( v[9])
inlineexplicitconstexpr

Constructs a matrix from an array of nine elements.

Elements are read in row-major order from the array.

Parameters
vArray of 9 elements in row-major order.
float data[9] = {1, 0, 0, 0, 1, 0, 0, 0, 1};
T * data()
Gets a pointer to the underlying data.
Definition Matrix3.hpp:348

◆ t_Matrix3() [5/6]

template<typename T >
constexpr Infinity::Types::Math::t_Matrix3< T >::t_Matrix3 ( const t_Vector3< T > &  c0,
const t_Vector3< T > &  c1,
const t_Vector3< T > &  c2 
)
inlineconstexpr

Constructs a matrix from three column vectors.

Directly specifies the three columns of the matrix.

Parameters
c0First column vector.
c1Second column vector.
c2Third column vector.
Vector3 xAxis(1, 0, 0);
Vector3 yAxis(0, 1, 0);
Vector3 zAxis(0, 0, 1);
Matrix3 basis(xAxis, yAxis, zAxis);

◆ t_Matrix3() [6/6]

template<typename T >
template<typename R >
Infinity::Types::Math::t_Matrix3< T >::t_Matrix3 ( const t_Matrix3< R > &  rhs)
inlineexplicit

Type-converting constructor.

Constructs a matrix from another matrix with a different element type.

Template Parameters
RThe source element type.
Parameters
rhsMatrix to convert from.

Member Function Documentation

◆ columns()

template<typename T >
constexpr size_t Infinity::Types::Math::t_Matrix3< T >::columns ( ) const
inlineconstexpr

Gets the number of columns in the matrix.

Returns
3 (always 3 columns).

◆ data() [1/2]

template<typename T >
T * Infinity::Types::Math::t_Matrix3< T >::data ( )
inline

Gets a pointer to the underlying data.

Returns a pointer to the first element, allowing direct memory access. Elements are stored in column-major order.

Returns
Pointer to the first matrix element.

◆ data() [2/2]

template<typename T >
const T * Infinity::Types::Math::t_Matrix3< T >::data ( ) const
inline

Gets a const pointer to the underlying data.

Returns
Const pointer to the first matrix element.

◆ operator bool()

template<typename T >
Infinity::Types::Math::t_Matrix3< T >::operator bool ( ) const
inlineexplicitnoexcept

Boolean conversion operator.

Returns true if the matrix is non-zero (at least one column is non-zero).

Returns
true if matrix is non-zero, false if zero matrix.

◆ operator!=()

template<typename T >
bool Infinity::Types::Math::t_Matrix3< T >::operator!= ( const t_Matrix3< T > &  rhs) const
inline

Inequality comparison operator.

Parameters
rhsMatrix to compare against.
Returns
true if any element differs.

◆ operator()() [1/2]

template<typename T >
T & Infinity::Types::Math::t_Matrix3< T >::operator() ( size_t  c,
size_t  r 
)
inline

Element access operator (mutable).

Returns a reference to the element at the specified column and row.

Parameters
cColumn index (0, 1, or 2).
rRow index (0, 1, or 2).
Returns
Reference to the matrix element.
m(1, 2) = 5.0f; // Set element at column 1, row 2

◆ operator()() [2/2]

template<typename T >
T Infinity::Types::Math::t_Matrix3< T >::operator() ( size_t  c,
size_t  r 
) const
inline

Element access operator (const).

Returns the value of the element at the specified column and row.

Parameters
cColumn index (0, 1, or 2).
rRow index (0, 1, or 2).
Returns
Value of the matrix element.

◆ operator*() [1/3]

template<typename T >
t_Matrix3 Infinity::Types::Math::t_Matrix3< T >::operator* ( const t_Matrix3< T > &  rhs) const
inline

Matrix multiplication operator.

Performs standard matrix multiplication (this * rhs).

Parameters
rhsRight-hand side matrix.
Returns
Result of matrix multiplication.
Matrix3 a, b;
Matrix3 c = a * b; // Compose transformations

◆ operator*() [2/3]

template<typename T >
t_Vector3< T > Infinity::Types::Math::t_Matrix3< T >::operator* ( const t_Vector3< T > &  v) const
inline

Matrix-vector multiplication operator.

Transforms a vector by this matrix, treating the vector as a column vector.

Parameters
vVector to transform.
Returns
Transformed vector.
Matrix3 rotation = ...;
Vector3 point(1, 0, 0);
Vector3 rotated = rotation * point;

◆ operator*() [3/3]

template<typename T >
t_Matrix3 Infinity::Types::Math::t_Matrix3< T >::operator* ( scalar) const
inline

Scalar multiplication operator.

Multiplies all matrix elements by a scalar value.

Parameters
scalarScalar value to multiply by.
Returns
Scaled matrix.
Matrix3 scaled = m * 2.0f; // Double all elements

◆ operator*=() [1/2]

template<typename T >
t_Matrix3 & Infinity::Types::Math::t_Matrix3< T >::operator*= ( const t_Matrix3< T > &  rhs)
inline

Matrix multiplication assignment operator.

Multiplies this matrix by another matrix and stores the result.

Parameters
rhsRight-hand side matrix.
Returns
Reference to this matrix.

◆ operator*=() [2/2]

template<typename T >
t_Matrix3 & Infinity::Types::Math::t_Matrix3< T >::operator*= ( scalar)
inline

Scalar multiplication assignment operator.

Multiplies all elements of this matrix by a scalar.

Parameters
scalarScalar value to multiply by.
Returns
Reference to this matrix.

◆ operator+()

template<typename T >
t_Matrix3 Infinity::Types::Math::t_Matrix3< T >::operator+ ( const t_Matrix3< T > &  rhs) const
inline

Matrix addition operator.

Adds two matrices element-wise.

Parameters
rhsMatrix to add.
Returns
Sum of the matrices.

◆ operator+=()

template<typename T >
t_Matrix3 & Infinity::Types::Math::t_Matrix3< T >::operator+= ( const t_Matrix3< T > &  rhs)
inline

Matrix addition assignment operator.

Adds another matrix to this matrix element-wise.

Parameters
rhsMatrix to add.
Returns
Reference to this matrix.

◆ operator-() [1/2]

template<typename T >
t_Matrix3 Infinity::Types::Math::t_Matrix3< T >::operator- ( ) const
inline

Unary negation operator.

Returns a matrix with all elements negated.

Returns
Negated matrix.

◆ operator-() [2/2]

template<typename T >
t_Matrix3 Infinity::Types::Math::t_Matrix3< T >::operator- ( const t_Matrix3< T > &  rhs) const
inline

Matrix subtraction operator.

Subtracts one matrix from another element-wise.

Parameters
rhsMatrix to subtract.
Returns
Difference of the matrices.

◆ operator-=()

template<typename T >
t_Matrix3 & Infinity::Types::Math::t_Matrix3< T >::operator-= ( const t_Matrix3< T > &  rhs)
inline

Matrix subtraction assignment operator.

Subtracts another matrix from this matrix element-wise.

Parameters
rhsMatrix to subtract.
Returns
Reference to this matrix.

◆ operator/()

template<typename T >
t_Matrix3 Infinity::Types::Math::t_Matrix3< T >::operator/ ( scalar) const
inline

Scalar division operator.

Divides all matrix elements by a scalar value. For floating-point types, uses reciprocal multiplication for better performance.

Parameters
scalarScalar value to divide by.
Returns
Scaled matrix.
Warning
Division by zero is undefined behavior.

◆ operator/=()

template<typename T >
t_Matrix3 & Infinity::Types::Math::t_Matrix3< T >::operator/= ( scalar)
inline

Scalar division assignment operator.

Divides all elements of this matrix by a scalar.

Parameters
scalarScalar value to divide by.
Returns
Reference to this matrix.
Warning
Division by zero is undefined behavior.

◆ operator<()

template<typename T >
bool Infinity::Types::Math::t_Matrix3< T >::operator< ( const t_Matrix3< T > &  rhs) const
inline

Less-than comparison operator for ordering.

Performs lexicographic comparison of columns. Useful for using matrices as keys in ordered containers like std::map.

Parameters
rhsMatrix to compare against.
Returns
true if this matrix is lexicographically less than rhs.

◆ operator=()

template<typename T >
template<typename R >
t_Matrix3 & Infinity::Types::Math::t_Matrix3< T >::operator= ( const t_Matrix3< R > &  rhs)
inline

Type-converting assignment operator.

Assigns from a matrix with a different element type.

Template Parameters
RThe source element type.
Parameters
rhsMatrix to assign from.
Returns
Reference to this matrix.

◆ operator==()

template<typename T >
bool Infinity::Types::Math::t_Matrix3< T >::operator== ( const t_Matrix3< T > &  rhs) const
inline

Equality comparison operator.

Two matrices are equal if all their elements are equal.

Parameters
rhsMatrix to compare against.
Returns
true if all elements are equal.

◆ operator[]() [1/2]

template<typename T >
t_Vector3< T > & Infinity::Types::Math::t_Matrix3< T >::operator[] ( size_t  c)
inline

Column access operator (mutable).

Returns a reference to the specified column vector.

Parameters
cColumn index (0, 1, or 2).
Returns
Reference to the column vector.
m[0] = Vector3(1, 2, 3); // Set first column
t_Vector3< float > Vector3
Alias for t_Vector3<float>, the default 3D vector type.
Definition Vector3.hpp:580

◆ operator[]() [2/2]

template<typename T >
const t_Vector3< T > & Infinity::Types::Math::t_Matrix3< T >::operator[] ( size_t  c) const
inline

Column access operator (const).

Returns a const reference to the specified column vector.

Parameters
cColumn index (0, 1, or 2).
Returns
Const reference to the column vector.

◆ rows()

template<typename T >
constexpr size_t Infinity::Types::Math::t_Matrix3< T >::rows ( ) const
inlineconstexpr

Gets the number of rows in the matrix.

Returns
3 (always 3 rows).

◆ set() [1/2]

template<typename T >
template<typename R >
void Infinity::Types::Math::t_Matrix3< T >::set ( const t_Matrix3< R > &  rhs)
inline

Sets this matrix equal to another matrix.

Template Parameters
RThe source element type.
Parameters
rhsMatrix to copy from.

◆ set() [2/2]

template<typename T >
void Infinity::Types::Math::t_Matrix3< T >::set ( v0,
v1,
v2,
v3,
v4,
v5,
v6,
v7,
v8 
)
inline

Sets all nine matrix elements.

Elements are specified in row-major order for readability.

Parameters
v0through v8 Matrix elements in row-major order.

◆ size()

template<typename T >
constexpr size_t Infinity::Types::Math::t_Matrix3< T >::size ( ) const
inlineconstexpr

Gets the total number of elements in the matrix.

Returns
9 (always 3x3 = 9 elements).

◆ transpose()

template<typename T >
t_Matrix3 Infinity::Types::Math::t_Matrix3< T >::transpose ( ) const
inline

Computes the transpose of this matrix.

Returns a new matrix with rows and columns swapped. For rotation matrices, the transpose equals the inverse.

Returns
Transposed matrix.
Matrix3 m = ...;
Matrix3 mT = m.transpose();
// mT[i][j] == m[j][i]

Member Data Documentation

◆ value

template<typename T >
t_Vector3<T> Infinity::Types::Math::t_Matrix3< T >::value[3]

Column vectors comprising the matrix.

Stored in column-major order: value[0] is the first column, value[1] is the second column, value[2] is the third column.