3DRadSpace 0.1.0Alpha
3DRadSpace is a free, simple to use, rapid application development game engine.
Loading...
Searching...
No Matches
Engine3DRadSpace.Math::Matrix4x4 Struct Reference

Represents a row-major 4x4 matrix. Used for 3D affine transformations, rotations, and projections. More...

#include <Matrix4x4.hpp>

Public Member Functions

constexpr Matrix4x4 (float m[16])
 Creates a matrix from an array of 16 floats.
constexpr Matrix4x4 (float m11=1, float m12=0, float m13=0, float m14=0, float m21=0, float m22=1, float m23=0, float m24=0, float m31=0, float m32=0, float m33=1, float m34=0, float m41=0, float m42=0, float m43=0, float m44=1)
 Creates a matrix with the specified values. If no values are provided, it creates an identity matrix.
Matrix4x4 & Hadamard (const Matrix4x4 &m)
 Element-wise (Hadamard) multiplication of this matrix with another matrix.
Matrix4x4 operator+ (const Matrix4x4 &m) const noexcept
 Adds this matrix to another matrix and returns the result.
Matrix4x4 & operator+= (const Matrix4x4 &m) noexcept
 Adds another matrix to this matrix in-place.
Matrix4x4 operator- (const Matrix4x4 &m) const noexcept
 Subtracts another matrix from this matrix and returns the result.
Matrix4x4 & operator-= (const Matrix4x4 &m) noexcept
 Subtracts another matrix from this matrix in-place.
Matrix4x4 operator* (const Matrix4x4 &m) const noexcept
 Multiplies this matrix with another matrix (matrix product) and returns the result.
Matrix4x4 & operator*= (const Matrix4x4 &m) noexcept
 Multiplies this matrix with another matrix (matrix product) in-place.
Matrix4x4 operator* (float scalar) const noexcept
 Multiplies this matrix by a scalar and returns the result.
Matrix4x4 & operator*= (float scalar) noexcept
 Multiplies this matrix by a scalar in-place.
Matrix4x4 & Transpose ()
 Transposes this matrix in-place.
Matrix4x4 & Invert ()
 Inverts this matrix in-place.
float & operator[] (unsigned index)
 Returns a reference to the element at the specified index in the matrix, allowing for both reading and writing.
float Trace () const noexcept
 Returns the trace of this matrix.
float Determinant () const noexcept
 Returns the determinant of this matrix.
Vector3 Forward () const noexcept
 Returns the forward direction vector encoded in this matrix.
Vector3 Backward () const noexcept
 Returns the backward direction vector encoded in this matrix.
Vector3 Up () const noexcept
 Returns the up direction vector encoded in this matrix.
Vector3 Down () const noexcept
 Returns the down direction vector encoded in this matrix.
Vector3 Left () const noexcept
 Returns the left direction vector encoded in this matrix.
Vector3 Right () const noexcept
 Returns the right direction vector encoded in this matrix.
Vector3 Translation () const noexcept
 Returns the translation vector encoded in this matrix.

Static Public Member Functions

static Matrix4x4 CreateTranslation (const Vector3 &pos)
 Creates a 3D translation matrix.
static Matrix4x4 CreateScale (const Vector3 &scale)
 Creates a 3D scaling matrix.
static Matrix4x4 CreateRotationX (float theta)
 Creates a rotation matrix around the X-axis.
static Matrix4x4 CreateRotationY (float theta)
 Creates a rotation matrix around the Y-axis.
static Matrix4x4 CreateRotationZ (float theta)
 Creates a rotation matrix around the Z-axis.
static Matrix4x4 CreateFromQuaternion (const Quaternion &q)
 Creates a rotation matrix from a quaternion.
static Matrix4x4 CreateRotationYawPitchRoll (float yaw, float pitch, float roll)
 Creates a rotation matrix from yaw, pitch, and roll angles.
static Matrix4x4 CreateLookAtView (const Vector3 &pos, const Vector3 &look_at, const Vector3 &up_dir)
 Creates a right-hand look at view matrix.
static Matrix4x4 CreatePerspectiveProjection (float aspectRatio, float FOV, float npd, float fpd)
 Creates a right-handed perspective projection matrix.
static Matrix4x4 CreateOrthographicProjection (const Point &screenSize, float npd, float fpd)
 Creates a right-handed orthographic projection matrix.
static Matrix4x4 CreateSphericalBillboard (const Vector3 &objectPos, const Vector3 &cameraPos, const Vector3 &cameraUp, const Vector3 &cameraForward)
 Creates a spherical billboard matrix that always faces the camera position.
static Matrix4x4 CreateCylindricalBillboard (const Vector3 &objectPos, const Vector3 &cameraPos, const Vector3 &cameraUp, const Vector3 &cameraForward, const Vector3 &axis, std::optional< Vector3 > objectForward)
 Creates a cylindrical billboard matrix that rotates around a fixed axis to face the camera.
static Matrix4x4 Hadamard (const Matrix4x4 &a, const Matrix4x4 &b)
 Element-wise (Hadamard) product of two matrices.
static Matrix4x4 Transpose (const Matrix4x4 &m)
 Returns the transpose of the specified matrix.
static Matrix4x4 Invert (const Matrix4x4 &m)
 Returns the inverse of the specified matrix.

Public Attributes

float M11
float M12
float M13
float M14
float M21
float M22
float M23
float M24
float M31
float M32
float M33
float M34
float M41
float M42
float M43
float M44

Detailed Description

Represents a row-major 4x4 matrix. Used for 3D affine transformations, rotations, and projections.

Constructor & Destructor Documentation

◆ Matrix4x4() [1/2]

Matrix4x4::Matrix4x4 ( float m[16])
explicitconstexpr

Creates a matrix from an array of 16 floats.

Parameters
mThe array containing the 16 matrix elements in row-major order.

◆ Matrix4x4() [2/2]

Matrix4x4::Matrix4x4 ( float m11 = 1,
float m12 = 0,
float m13 = 0,
float m14 = 0,
float m21 = 0,
float m22 = 1,
float m23 = 0,
float m24 = 0,
float m31 = 0,
float m32 = 0,
float m33 = 1,
float m34 = 0,
float m41 = 0,
float m42 = 0,
float m43 = 0,
float m44 = 1 )
explicitconstexpr

Creates a matrix with the specified values. If no values are provided, it creates an identity matrix.

Parameters
m11The value for the first row, first column.
m12The value for the first row, second column.
m13The value for the first row, third column.
m14The value for the first row, fourth column.
m21The value for the second row, first column.
m22The value for the second row, second column.
m23The value for the second row, third column.
m24The value for the second row, fourth column.
m31The value for the third row, first column.
m32The value for the third row, second column.
m33The value for the third row, third column.
m34The value for the third row, fourth column.
m41The value for the fourth row, first column.
m42The value for the fourth row, second column.
m43The value for the fourth row, third column.
m44The value for the fourth row, fourth column.

Member Function Documentation

◆ Backward()

Vector3 Matrix4x4::Backward ( ) const
noexcept

Returns the backward direction vector encoded in this matrix.

Returns
The backward direction vector.

◆ CreateCylindricalBillboard()

Matrix4x4 Matrix4x4::CreateCylindricalBillboard ( const Vector3 & objectPos,
const Vector3 & cameraPos,
const Vector3 & cameraUp,
const Vector3 & cameraForward,
const Vector3 & axis,
std::optional< Vector3 > objectForward )
static

Creates a cylindrical billboard matrix that rotates around a fixed axis to face the camera.

Parameters
objectPosThe position of the object.
cameraPosThe position of the camera.
cameraUpThe up vector of the camera.
cameraForwardThe forward vector of the camera.
axisThe fixed rotation axis for the billboard.
objectForwardAn optional forward vector for the object, used to resolve ambiguity when the object is aligned with the axis.
Returns
The resulting billboard matrix.

◆ CreateFromQuaternion()

Matrix4x4 Matrix4x4::CreateFromQuaternion ( const Quaternion & q)
static

Creates a rotation matrix from a quaternion.

Parameters
qThe quaternion representing the rotation.
Returns
The resulting rotation matrix.

◆ CreateLookAtView()

Matrix4x4 Matrix4x4::CreateLookAtView ( const Vector3 & pos,
const Vector3 & look_at,
const Vector3 & up_dir )
static

Creates a right-hand look at view matrix.

Parameters
posCamera position
look_atCamera look direction
up_dirCamera normal
Returns
RH View matrix

◆ CreateOrthographicProjection()

Matrix4x4 Matrix4x4::CreateOrthographicProjection ( const Point & screenSize,
float npd,
float fpd )
static

Creates a right-handed orthographic projection matrix.

Parameters
screenSizeThe width and height of the projection view volume.
npdThe near plane distance.
fpdThe far plane distance.
Returns
The resulting orthographic projection matrix.

◆ CreatePerspectiveProjection()

Matrix4x4 Matrix4x4::CreatePerspectiveProjection ( float aspectRatio,
float FOV,
float npd,
float fpd )
static

Creates a right-handed perspective projection matrix.

Parameters
aspectRatioThe aspect ratio (width / height) of the viewport.
FOVThe vertical field of view in radians.
npdThe near plane distance.
fpdThe far plane distance.
Returns
The resulting perspective projection matrix.

◆ CreateRotationX()

Matrix4x4 Matrix4x4::CreateRotationX ( float theta)
static

Creates a rotation matrix around the X-axis.

Parameters
thetaThe rotation angle in radians.
Returns
The resulting rotation matrix.

◆ CreateRotationY()

Matrix4x4 Matrix4x4::CreateRotationY ( float theta)
static

Creates a rotation matrix around the Y-axis.

Parameters
thetaThe rotation angle in radians.
Returns
The resulting rotation matrix.

◆ CreateRotationYawPitchRoll()

Matrix4x4 Matrix4x4::CreateRotationYawPitchRoll ( float yaw,
float pitch,
float roll )
static

Creates a rotation matrix from yaw, pitch, and roll angles.

Parameters
yawThe yaw angle in radians (rotation around the Y-axis).
pitchThe pitch angle in radians (rotation around the X-axis).
rollThe roll angle in radians (rotation around the Z-axis).
Returns
The resulting rotation matrix.

◆ CreateRotationZ()

Matrix4x4 Matrix4x4::CreateRotationZ ( float theta)
static

Creates a rotation matrix around the Z-axis.

Parameters
thetaThe rotation angle in radians.
Returns
The resulting rotation matrix.

◆ CreateScale()

Matrix4x4 Matrix4x4::CreateScale ( const Vector3 & scale)
static

Creates a 3D scaling matrix.

Parameters
scaleThe scaling vector.
Returns
The resulting scaling matrix.

◆ CreateSphericalBillboard()

Matrix4x4 Matrix4x4::CreateSphericalBillboard ( const Vector3 & objectPos,
const Vector3 & cameraPos,
const Vector3 & cameraUp,
const Vector3 & cameraForward )
static

Creates a spherical billboard matrix that always faces the camera position.

Parameters
objectPosThe position of the object.
cameraPosThe position of the camera.
cameraUpThe up vector of the camera.
cameraForwardThe forward vector of the camera.
Returns
The resulting billboard matrix.

◆ CreateTranslation()

Matrix4x4 Matrix4x4::CreateTranslation ( const Vector3 & pos)
static

Creates a 3D translation matrix.

Parameters
posThe translation vector.
Returns
The resulting translation matrix.

◆ Determinant()

float Matrix4x4::Determinant ( ) const
noexcept

Returns the determinant of this matrix.

Returns
The determinant of the matrix.

◆ Down()

Vector3 Matrix4x4::Down ( ) const
noexcept

Returns the down direction vector encoded in this matrix.

Returns
The down direction vector.

◆ Forward()

Vector3 Matrix4x4::Forward ( ) const
noexcept

Returns the forward direction vector encoded in this matrix.

Returns
The forward direction vector.

◆ Hadamard() [1/2]

Matrix4x4 Matrix4x4::Hadamard ( const Matrix4x4 & a,
const Matrix4x4 & b )
static

Element-wise (Hadamard) product of two matrices.

Parameters
aThe first matrix.
bThe second matrix.
Returns
The resulting matrix after Hadamard multiplication.

◆ Hadamard() [2/2]

Matrix4x4 & Matrix4x4::Hadamard ( const Matrix4x4 & m)

Element-wise (Hadamard) multiplication of this matrix with another matrix.

Parameters
mThe matrix to multiply with.
Returns
A reference to this matrix after Hadamard multiplication.

◆ Invert() [1/2]

Matrix4x4 & Matrix4x4::Invert ( )

Inverts this matrix in-place.

Returns
A reference to this matrix after inversion.

◆ Invert() [2/2]

Matrix4x4 Matrix4x4::Invert ( const Matrix4x4 & m)
static

Returns the inverse of the specified matrix.

Parameters
mThe matrix to invert.
Returns
The inverted matrix.

◆ Left()

Vector3 Matrix4x4::Left ( ) const
noexcept

Returns the left direction vector encoded in this matrix.

Returns
The left direction vector.

◆ operator*() [1/2]

Matrix4x4 Matrix4x4::operator* ( const Matrix4x4 & m) const
noexcept

Multiplies this matrix with another matrix (matrix product) and returns the result.

Parameters
mThe matrix to multiply with.
Returns
The resulting matrix after multiplication.

◆ operator*() [2/2]

Matrix4x4 Matrix4x4::operator* ( float scalar) const
noexcept

Multiplies this matrix by a scalar and returns the result.

Parameters
scalarThe scalar value to multiply with.
Returns
The resulting scaled matrix.

◆ operator*=() [1/2]

Matrix4x4 & Matrix4x4::operator*= ( const Matrix4x4 & m)
noexcept

Multiplies this matrix with another matrix (matrix product) in-place.

Parameters
mThe matrix to multiply with.
Returns
A reference to this matrix after multiplication.

◆ operator*=() [2/2]

Matrix4x4 & Matrix4x4::operator*= ( float scalar)
noexcept

Multiplies this matrix by a scalar in-place.

Parameters
scalarThe scalar value to multiply with.
Returns
A reference to this matrix after scaling.

◆ operator+()

Matrix4x4 Matrix4x4::operator+ ( const Matrix4x4 & m) const
noexcept

Adds this matrix to another matrix and returns the result.

Parameters
mThe matrix to add.
Returns
The resulting matrix after addition.

◆ operator+=()

Matrix4x4 & Matrix4x4::operator+= ( const Matrix4x4 & m)
noexcept

Adds another matrix to this matrix in-place.

Parameters
mThe matrix to add.
Returns
A reference to this matrix after addition.

◆ operator-()

Matrix4x4 Matrix4x4::operator- ( const Matrix4x4 & m) const
noexcept

Subtracts another matrix from this matrix and returns the result.

Parameters
mThe matrix to subtract.
Returns
The resulting matrix after subtraction.

◆ operator-=()

Matrix4x4 & Matrix4x4::operator-= ( const Matrix4x4 & m)
noexcept

Subtracts another matrix from this matrix in-place.

Parameters
mThe matrix to subtract.
Returns
A reference to this matrix after subtraction.

◆ operator[]()

float & Matrix4x4::operator[] ( unsigned index)

Returns a reference to the element at the specified index in the matrix, allowing for both reading and writing.

Parameters
indexIndex, between 0 and 15.
Returns
A reference to the element at the specified index.

◆ Right()

Vector3 Matrix4x4::Right ( ) const
noexcept

Returns the right direction vector encoded in this matrix.

Returns
The right direction vector.

◆ Trace()

float Matrix4x4::Trace ( ) const
noexcept

Returns the trace of this matrix.

Returns
M11 + M22 + M33 + M44

◆ Translation()

Vector3 Matrix4x4::Translation ( ) const
noexcept

Returns the translation vector encoded in this matrix.

Returns
The translation vector.

◆ Transpose() [1/2]

Matrix4x4 & Matrix4x4::Transpose ( )

Transposes this matrix in-place.

Returns
A reference to this matrix after transposition.

◆ Transpose() [2/2]

Matrix4x4 Matrix4x4::Transpose ( const Matrix4x4 & m)
static

Returns the transpose of the specified matrix.

Parameters
mThe matrix to transpose.
Returns
The transposed matrix.

◆ Up()

Vector3 Matrix4x4::Up ( ) const
noexcept

Returns the up direction vector encoded in this matrix.

Returns
The up direction vector.

Member Data Documentation

◆ M11

float Engine3DRadSpace.Math::Matrix4x4::M11

◆ M12

float Engine3DRadSpace.Math::Matrix4x4::M12

◆ M13

float Engine3DRadSpace.Math::Matrix4x4::M13

◆ M14

float Engine3DRadSpace.Math::Matrix4x4::M14

◆ M21

float Engine3DRadSpace.Math::Matrix4x4::M21

◆ M22

float Engine3DRadSpace.Math::Matrix4x4::M22

◆ M23

float Engine3DRadSpace.Math::Matrix4x4::M23

◆ M24

float Engine3DRadSpace.Math::Matrix4x4::M24

◆ M31

float Engine3DRadSpace.Math::Matrix4x4::M31

◆ M32

float Engine3DRadSpace.Math::Matrix4x4::M32

◆ M33

float Engine3DRadSpace.Math::Matrix4x4::M33

◆ M34

float Engine3DRadSpace.Math::Matrix4x4::M34

◆ M41

float Engine3DRadSpace.Math::Matrix4x4::M41

◆ M42

float Engine3DRadSpace.Math::Matrix4x4::M42

◆ M43

float Engine3DRadSpace.Math::Matrix4x4::M43

◆ M44

float Engine3DRadSpace.Math::Matrix4x4::M44

The documentation for this struct was generated from the following files: