Claire's Game Engine
Full C++ Engine using OpenGL
Loading...
Searching...
No Matches
Matrix4 Class Reference

Matrix4 represents a 4x4 matrix used for transformations in 3D space. It supports various operations such as matrix multiplication, inversion, and extracting different transformation components (e.g., translation, rotation, scale). This matrix can also be constructed for specific transformations like scaling, rotating, and translating, as well as for creating projection matrices for rendering. More...

#include <Matrix4.h>

Public Member Functions

 Matrix4 ()
 Default constructor for Matrix4. Initializes the matrix as an identity matrix by default.
 
 Matrix4 (float inMat[4][4])
 Constructor that initializes the matrix with a 4x4 float array.
 
const float * GetAsFloatPtr () const
 Returns the matrix as a const float pointer for direct access to the raw data.
 
Matrix4operator*= (const Matrix4 &right)
 Multiplies the current matrix by another matrix (a * b).
 
void Invert ()
 Inverts the matrix (calculates its inverse). This operation is computationally expensive and should be used carefully.
 
Vector3 GetTranslation () const
 Extracts the translation vector from the matrix (the position).
 
Vector3 GetXAxis () const
 Extracts the X-axis direction vector from the matrix (usually for orientation).
 
Vector3 GetYAxis () const
 Extracts the Y-axis direction vector from the matrix (usually for orientation).
 
Vector3 GetZAxis () const
 Extracts the Z-axis direction vector from the matrix (usually for orientation).
 
Vector3 GetScale () const
 Extracts the scaling factors from the matrix (how much the object is scaled along each axis).
 

Static Public Member Functions

static Matrix4 CreateScale (float xScale, float yScale, float zScale)
 Creates a scaling matrix using individual scale factors for each axis.
 
static Matrix4 CreateScale (const Vector3 &scaleVector)
 Creates a scaling matrix using a Vector3 to specify the scale for each axis.
 
static Matrix4 CreateScale (float scale)
 Creates a uniform scaling matrix where all axes are scaled by the same factor.
 
static Matrix4 CreateRotationX (float theta)
 Creates a rotation matrix for rotation around the X-axis.
 
static Matrix4 CreateRotationY (float theta)
 Creates a rotation matrix for rotation around the Y-axis.
 
static Matrix4 CreateRotationZ (float theta)
 Creates a rotation matrix for rotation around the Z-axis.
 
static Matrix4 CreateTranslation (const Vector3 &trans)
 Creates a translation matrix that moves an object by a given translation vector.
 
static Matrix4 CreateSimpleViewProj (float width, float height)
 Creates a simple orthogonal view projection matrix. Typically used for 2D rendering or simple orthographic projections.
 
static Matrix4 CreateFromQuaternion (const Quaternion &q)
 Creates a rotation matrix from a quaternion representation.
 
static Matrix4 CreateLookAt (const Vector3 &eye, const Vector3 &target, const Vector3 &up)
 Creates a "look-at" matrix for setting up camera orientation.
 
static Matrix4 CreateOrtho (float width, float height, float near, float far)
 Creates an orthographic projection matrix (used for 2D rendering).
 
static Matrix4 CreatePerspectiveFOV (float fovY, float width, float height, float near, float far)
 Creates a perspective projection matrix with a specified field of view.
 
static Matrix4 CreatePerspective (float left, float right, float bottom, float top, float near, float far)
 Creates a perspective projection matrix with specified frustum values.
 

Public Attributes

float mat [4][4]
 

Static Public Attributes

static const Matrix4 Identity
 Constant for the identity matrix (no transformation)
 

Friends

Matrix4 operator* (const Matrix4 &a, const Matrix4 &b)
 Multiplies two matrices and returns the resulting matrix.
 

Detailed Description

Matrix4 represents a 4x4 matrix used for transformations in 3D space. It supports various operations such as matrix multiplication, inversion, and extracting different transformation components (e.g., translation, rotation, scale). This matrix can also be constructed for specific transformations like scaling, rotating, and translating, as well as for creating projection matrices for rendering.

Constructor & Destructor Documentation

◆ Matrix4() [1/2]

Matrix4::Matrix4 ( )

Default constructor for Matrix4. Initializes the matrix as an identity matrix by default.

◆ Matrix4() [2/2]

Matrix4::Matrix4 ( float inMat[4][4])
explicit

Constructor that initializes the matrix with a 4x4 float array.

Parameters
inMatA 4x4 matrix to initialize the object with.

Member Function Documentation

◆ CreateFromQuaternion()

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

Creates a rotation matrix from a quaternion representation.

Parameters
qThe quaternion to convert to a matrix.
Returns
A new Matrix4 representing the rotation described by the quaternion.

◆ CreateLookAt()

Matrix4 Matrix4::CreateLookAt ( const Vector3 & eye,
const Vector3 & target,
const Vector3 & up )
static

Creates a "look-at" matrix for setting up camera orientation.

Parameters
eyeThe position of the camera.
targetThe point the camera is looking at.
upThe "up" vector that defines the orientation of the camera.
Returns
A new Matrix4 representing the view transformation for the camera.

◆ CreateOrtho()

Matrix4 Matrix4::CreateOrtho ( float width,
float height,
float near,
float far )
static

Creates an orthographic projection matrix (used for 2D rendering).

Parameters
widthThe width of the view frustum.
heightThe height of the view frustum.
nearThe near clipping plane.
farThe far clipping plane.
Returns
A new Matrix4 representing the orthographic projection transformation.

◆ CreatePerspective()

Matrix4 Matrix4::CreatePerspective ( float left,
float right,
float bottom,
float top,
float near,
float far )
static

Creates a perspective projection matrix with specified frustum values.

Parameters
leftThe left boundary of the near plane.
rightThe right boundary of the near plane.
bottomThe bottom boundary of the near plane.
topThe top boundary of the near plane.
nearThe near clipping plane.
farThe far clipping plane.
Returns
A new Matrix4 representing the perspective projection transformation.

◆ CreatePerspectiveFOV()

Matrix4 Matrix4::CreatePerspectiveFOV ( float fovY,
float width,
float height,
float near,
float far )
static

Creates a perspective projection matrix with a specified field of view.

Parameters
fovYThe vertical field of view (in radians).
widthThe width of the viewport.
heightThe height of the viewport.
nearThe near clipping plane.
farThe far clipping plane.
Returns
A new Matrix4 representing the perspective projection transformation.

◆ CreateRotationX()

Matrix4 Matrix4::CreateRotationX ( float theta)
static

Creates a rotation matrix for rotation around the X-axis.

Parameters
thetaThe angle (in radians) to rotate around the X-axis.
Returns
A new Matrix4 representing the rotation transformation.

◆ CreateRotationY()

Matrix4 Matrix4::CreateRotationY ( float theta)
static

Creates a rotation matrix for rotation around the Y-axis.

Parameters
thetaThe angle (in radians) to rotate around the Y-axis.
Returns
A new Matrix4 representing the rotation transformation.

◆ CreateRotationZ()

Matrix4 Matrix4::CreateRotationZ ( float theta)
static

Creates a rotation matrix for rotation around the Z-axis.

Parameters
thetaThe angle (in radians) to rotate around the Z-axis.
Returns
A new Matrix4 representing the rotation transformation.

◆ CreateScale() [1/3]

Matrix4 Matrix4::CreateScale ( const Vector3 & scaleVector)
static

Creates a scaling matrix using a Vector3 to specify the scale for each axis.

Parameters
scaleVectorThe scaling vector containing the scale for X, Y, and Z axes.
Returns
A new Matrix4 representing the scaling transformation.

◆ CreateScale() [2/3]

Matrix4 Matrix4::CreateScale ( float scale)
static

Creates a uniform scaling matrix where all axes are scaled by the same factor.

Parameters
scaleThe uniform scaling factor.
Returns
A new Matrix4 representing the uniform scaling transformation.

◆ CreateScale() [3/3]

Matrix4 Matrix4::CreateScale ( float xScale,
float yScale,
float zScale )
static

Creates a scaling matrix using individual scale factors for each axis.

Parameters
xScaleThe scale factor along the X-axis.
yScaleThe scale factor along the Y-axis.
zScaleThe scale factor along the Z-axis.
Returns
A new Matrix4 representing the scaling transformation.

◆ CreateSimpleViewProj()

Matrix4 Matrix4::CreateSimpleViewProj ( float width,
float height )
static

Creates a simple orthogonal view projection matrix. Typically used for 2D rendering or simple orthographic projections.

Parameters
widthThe width of the viewport or projection.
heightThe height of the viewport or projection.
Returns
A new Matrix4 representing a simple orthogonal projection.

◆ CreateTranslation()

Matrix4 Matrix4::CreateTranslation ( const Vector3 & trans)
static

Creates a translation matrix that moves an object by a given translation vector.

Parameters
transThe translation vector to apply to the object.
Returns
A new Matrix4 representing the translation transformation.

◆ GetAsFloatPtr()

const float * Matrix4::GetAsFloatPtr ( ) const

Returns the matrix as a const float pointer for direct access to the raw data.

Returns
A pointer to the raw float data of the matrix.

◆ GetScale()

Vector3 Matrix4::GetScale ( ) const

Extracts the scaling factors from the matrix (how much the object is scaled along each axis).

Returns
A Vector3 representing the scale along each axis.

◆ GetTranslation()

Vector3 Matrix4::GetTranslation ( ) const

Extracts the translation vector from the matrix (the position).

Returns
A Vector3 representing the translation part of the matrix.

◆ GetXAxis()

Vector3 Matrix4::GetXAxis ( ) const

Extracts the X-axis direction vector from the matrix (usually for orientation).

Returns
A normalized Vector3 representing the X-axis.

◆ GetYAxis()

Vector3 Matrix4::GetYAxis ( ) const

Extracts the Y-axis direction vector from the matrix (usually for orientation).

Returns
A normalized Vector3 representing the Y-axis.

◆ GetZAxis()

Vector3 Matrix4::GetZAxis ( ) const

Extracts the Z-axis direction vector from the matrix (usually for orientation).

Returns
A normalized Vector3 representing the Z-axis.

◆ Invert()

void Matrix4::Invert ( )

Inverts the matrix (calculates its inverse). This operation is computationally expensive and should be used carefully.

◆ operator*=()

Matrix4 & Matrix4::operator*= ( const Matrix4 & right)

Multiplies the current matrix by another matrix (a * b).

Parameters
rightThe matrix to multiply the current matrix by.
Returns
The updated matrix.

Friends And Related Symbol Documentation

◆ operator*

Matrix4 operator* ( const Matrix4 & a,
const Matrix4 & b )
friend

Multiplies two matrices and returns the resulting matrix.

Parameters
aThe first matrix.
bThe second matrix.
Returns
The result of multiplying matrix a with matrix b.

Member Data Documentation

◆ Identity

const Matrix4 Matrix4::Identity
static

Constant for the identity matrix (no transformation)

◆ mat

float Matrix4::mat[4][4]

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