4D matrix More...

#include <mat4.h>

Public Member Functions

 Mat4 ()
 Constructs a 4x4 matrix (zero'ed)
 
 Mat4 (const double *init_matrix)
 Constructs a 4x4 matrix (copied from a array of doubles)
 
 Mat4 (const float *init_matrix)
 Constructs a 4x4 matrix (copied from a array of floats)
 
 Mat4 (const int16_t *init_matrix)
 Constructs a 4x4 matrix (copied from a array of 16 bit integers)
 
 Mat4 (const int32_t *init_matrix)
 Constructs a 4x4 matrix (copied from a array of 32 bit integers)
 
 Mat4 (const int64_t *init_matrix)
 Constructs a 4x4 matrix (copied from a array of 64 bit integers)
 
 Mat4 (const int8_t *init_matrix)
 Constructs a 4x4 matrix (copied from a array of 8 bit integers)
 
 Mat4 (const Mat2< Type > &copy)
 Constructs a 4x4 matrix (copied from a 2d matrix)
 
 Mat4 (const Mat3< Type > &copy)
 Constructs a 4x4 matrix (copied from a 3d matrix)
 
 Mat4 (const Mat4< Type > &copy)=default
 Constructs a 4x4 matrix (copied)
 
Mat4< Type > & adjoint ()
 Calculate the adjoint (or known as adjugate) of this matrix.
 
void decompose (Vec3< Type > &out_position, Quaternionx< Type > &out_orientation, Vec3< Type > &out_scale) const
 Decompose matrix into position, orientation/rotation and scale.
 
double det () const
 Calculate the matrix determinant of this matrix.
 
Vec3< Type > get_euler (EulerOrder order) const
 Extract the euler angles (in radians) from a matrix (in column-major format)
 
Vec3< Type > get_transformed_point (const Vec3< Type > &vector) const
 Get a transformed point from the matrix (in column-major format)
 
Vec3< Type > get_translate () const
 Returns the translation coordinates for this matrix (in column-major format)
 
Mat4< Type > & inverse ()
 Calculate the matrix inverse of this matrix.
 
bool is_equal (const Mat4< Type > &other, Type epsilon) const
 Returns true if equal within the bounds of an epsilon.
 
 operator Type * ()
 Operator that returns the matrix as a array.
 
 operator Type const * () const
 Operator that returns the matrix as a array.
 
bool operator!= (const Mat4< Type > &other)
 Not-equal operator.
 
Mat4< Type > operator* (const Mat4< Type > &mult) const
 Multiplication operator.
 
Mat4< Type > operator+ (const Mat4< Type > &add_matrix) const
 Addition operator.
 
Mat4< Type > operator- (const Mat4< Type > &sub_matrix) const
 Subtraction operator.
 
Mat4< Type > & operator= (const Mat2< Type > &copy)
 Copy assignment operator.
 
Mat4< Type > & operator= (const Mat3< Type > &copy)
 Copy assignment operator.
 
Mat4< Type > & operator= (const Mat4< Type > &copy)=default
 Copy assignment operator.
 
bool operator== (const Mat4< Type > &other) const
 Equality operator.
 
Type & operator[] (int i)
 Operator that returns the matrix cell at the given index.
 
const Type & operator[] (int i) const
 Operator that returns the matrix cell at the given index.
 
Type & operator[] (unsigned int i)
 Operator that returns the matrix cell at the given index.
 
const Type & operator[] (unsigned int i) const
 Operator that returns the matrix cell at the given index.
 
Mat4< Type > & scale_self (const Vec3< Type > &scale)
 Scale this matrix.
 
Mat4< Type > & scale_self (Type x, Type y, Type z)
 Scale this matrix.
 
Mat4< Type > & set_translate (const Vec3< Type > &translation)
 Set this matrix translation values.
 
Mat4< Type > & set_translate (Type x, Type y, Type z)
 Set this matrix translation values.
 
Mat4< Type > & translate_self (const Vec3< Type > &translation)
 Translate this matrix.
 
Mat4< Type > & translate_self (Type x, Type y, Type z)
 Translate this matrix.
 
Mat4< Type > & transpose ()
 Calculate the transpose of this matrix.
 

Static Public Member Functions

static Mat4< Type > add (const Mat4< Type > &matrix_1, const Mat4< Type > &matrix_2)
 Add 2 matrices.
 
static Mat4< Type > adjoint (const Mat4< Type > &matrix)
 Calculate the adjoint (or known as Adjugate or Conjugate Transpose) of a matrix.
 
static Mat4< Type > frustum (Type left, Type right, Type bottom, Type top, Type z_near, Type z_far, Handedness handedness, ClipZRange clip_z)
 Create a frustum matrix.
 
static Mat4< Type > identity ()
 Create the identity matrix.
 
static Mat4< Type > inverse (const Mat4< Type > &matrix)
 Calculate the matrix inverse of a matrix.
 
static bool is_equal (const Mat4< Type > &first, const Mat4< Type > &second, Type epsilon)
 Returns true if equal within the bounds of an epsilon.
 
static Mat4< Type > look_at (Type eye_x, Type eye_y, Type eye_z, Type center_x, Type center_y, Type center_z, Type up_x, Type up_y, Type up_z)
 Create the "look at" matrix.
 
static Mat4< Type > look_at (Vec3< Type > eye, Vec3< Type > center, Vec3< Type > up)
 Create the "look at" matrix.
 
static Mat4< Type > multiply (const Mat4< Type > &matrix_1, const Mat4< Type > &matrix_2)
 Multiply 2 matrices.
 
static Mat4< Type > null ()
 Create a zero matrix.
 
static Mat4< Type > ortho (Type left, Type right, Type bottom, Type top, Type z_near, Type z_far, Handedness handedness, ClipZRange clip_z)
 Create a ortho matrix.
 
static Mat4< Type > ortho_2d (Type left, Type right, Type bottom, Type top, Handedness handedness, ClipZRange clip_z)
 Create a ortho_2d matrix.
 
static Mat4< Type > perspective (Type field_of_view_y_degrees, Type aspect, Type z_near, Type z_far, Handedness handedness, ClipZRange clip_z)
 Create a perspective matrix.
 
static Mat4< Type > rotate (const Angle &angle, Type x, Type y, Type z, bool normalize=true)
 Create a rotation matrix.
 
static Mat4< Type > rotate (const Angle &angle, Vec3< Type > rotation, bool normalize=true)
 Create a rotation matrix.
 
static Mat4< Type > rotate (const Angle &angle_x, const Angle &angle_y, const Angle &angle_z, EulerOrder order)
 Create a rotation matrix using euler angles.
 
static Mat4< Type > scale (const Vec3< Type > &xyz)
 Create a scale matrix.
 
static Mat4< Type > scale (Type x, Type y, Type z)
 Create a scale matrix.
 
static Mat4< Type > subtract (const Mat4< Type > &matrix_1, const Mat4< Type > &matrix_2)
 Subtract 2 matrices.
 
static Mat4< Type > translate (const Vec3< Type > &xyz)
 Create a translation matrix.
 
static Mat4< Type > translate (Type x, Type y, Type z)
 Create a translation matrix.
 
static Mat4< Type > transpose (const Mat4< Type > &matrix)
 Calculate the transpose of a matrix.
 

Public Attributes

Type matrix [16]
 The matrix (in column-major format)
 

Detailed Description

template<typename Type>
class clan::Mat4< Type >

4D matrix

These matrix templates are defined for: int (Mat4i), float (Mat4f), double (Mat4d)

Constructor & Destructor Documentation

◆ Mat4() [1/10]

template<typename Type>
clan::Mat4< Type >::Mat4 ( )
inline

Constructs a 4x4 matrix (zero'ed)

Referenced by add(), adjoint(), identity(), inverse(), multiply(), null(), subtract(), and transpose().

◆ Mat4() [2/10]

template<typename Type>
clan::Mat4< Type >::Mat4 ( const Mat4< Type > & copy)
default

Constructs a 4x4 matrix (copied)

◆ Mat4() [3/10]

template<typename Type>
clan::Mat4< Type >::Mat4 ( const Mat2< Type > & copy)
explicit

Constructs a 4x4 matrix (copied from a 2d matrix)

◆ Mat4() [4/10]

template<typename Type>
clan::Mat4< Type >::Mat4 ( const Mat3< Type > & copy)
explicit

Constructs a 4x4 matrix (copied from a 3d matrix)

◆ Mat4() [5/10]

template<typename Type>
clan::Mat4< Type >::Mat4 ( const float * init_matrix)
inlineexplicit

Constructs a 4x4 matrix (copied from a array of floats)

◆ Mat4() [6/10]

template<typename Type>
clan::Mat4< Type >::Mat4 ( const double * init_matrix)
inlineexplicit

Constructs a 4x4 matrix (copied from a array of doubles)

◆ Mat4() [7/10]

template<typename Type>
clan::Mat4< Type >::Mat4 ( const int64_t * init_matrix)
inlineexplicit

Constructs a 4x4 matrix (copied from a array of 64 bit integers)

◆ Mat4() [8/10]

template<typename Type>
clan::Mat4< Type >::Mat4 ( const int32_t * init_matrix)
inlineexplicit

Constructs a 4x4 matrix (copied from a array of 32 bit integers)

◆ Mat4() [9/10]

template<typename Type>
clan::Mat4< Type >::Mat4 ( const int16_t * init_matrix)
inlineexplicit

Constructs a 4x4 matrix (copied from a array of 16 bit integers)

◆ Mat4() [10/10]

template<typename Type>
clan::Mat4< Type >::Mat4 ( const int8_t * init_matrix)
inlineexplicit

Constructs a 4x4 matrix (copied from a array of 8 bit integers)

Member Function Documentation

◆ adjoint()

template<typename Type>
Mat4< Type > & clan::Mat4< Type >::adjoint ( )

Calculate the adjoint (or known as adjugate) of this matrix.

Returns
reference to this object

◆ decompose()

template<typename Type>
void clan::Mat4< Type >::decompose ( Vec3< Type > & out_position,
Quaternionx< Type > & out_orientation,
Vec3< Type > & out_scale ) const

Decompose matrix into position, orientation/rotation and scale.

◆ det()

template<typename Type>
double clan::Mat4< Type >::det ( ) const

Calculate the matrix determinant of this matrix.

Returns
The determinant

◆ frustum()

template<typename Type>
static Mat4< Type > clan::Mat4< Type >::frustum ( Type left,
Type right,
Type bottom,
Type top,
Type z_near,
Type z_far,
Handedness handedness,
ClipZRange clip_z )
static

Create a frustum matrix.

Matrix is created in the Column-Major matrix format (opengl native)

Returns
The matrix (in column-major format)

◆ get_euler()

template<typename Type>
Vec3< Type > clan::Mat4< Type >::get_euler ( EulerOrder order) const

Extract the euler angles (in radians) from a matrix (in column-major format)

Returns
The x,y,z angles (in radians)

◆ get_transformed_point()

template<typename Type>
Vec3< Type > clan::Mat4< Type >::get_transformed_point ( const Vec3< Type > & vector) const

Get a transformed point from the matrix (in column-major format)

Returns
The transformed point

◆ get_translate()

template<typename Type>
Vec3< Type > clan::Mat4< Type >::get_translate ( ) const
inline

Returns the translation coordinates for this matrix (in column-major format)

◆ inverse()

template<typename Type>
Mat4< Type > & clan::Mat4< Type >::inverse ( )

Calculate the matrix inverse of this matrix.

Creates a zero matrix if the determinent == 0

Returns
reference to this object

◆ is_equal() [1/2]

template<typename Type>
static bool clan::Mat4< Type >::is_equal ( const Mat4< Type > & first,
const Mat4< Type > & second,
Type epsilon )
inlinestatic

Returns true if equal within the bounds of an epsilon.

Parameters
first= Value A
second= Value B
epsilon= The epsilon (eg FLT_EPSILON/2, DBL_EPSILON/2)

Referenced by clan::Mat4< int >::is_equal().

◆ is_equal() [2/2]

template<typename Type>
bool clan::Mat4< Type >::is_equal ( const Mat4< Type > & other,
Type epsilon ) const
inline

Returns true if equal within the bounds of an epsilon.

Parameters
other= Other value
epsilon= The epsilon (eg FLT_EPSILON/2, DBL_EPSILON/2)

◆ look_at() [1/2]

template<typename Type>
static Mat4< Type > clan::Mat4< Type >::look_at ( Type eye_x,
Type eye_y,
Type eye_z,
Type center_x,
Type center_y,
Type center_z,
Type up_x,
Type up_y,
Type up_z )
static

Create the "look at" matrix.

Matrix is created in the Column-Major matrix format (opengl native)

Parameters
eye_x= Eye position X
eye_y= Eye position Y
eye_z= Eye position Z
center_x= Center X
center_y= Center Y
center_z= Center Z
up_x= Camera up direction X
up_y= Camera up direction Y
up_z= Camera up direction Z
Returns
The matrix (in column-major format)

Referenced by clan::Mat4< int >::look_at().

◆ look_at() [2/2]

template<typename Type>
static Mat4< Type > clan::Mat4< Type >::look_at ( Vec3< Type > eye,
Vec3< Type > center,
Vec3< Type > up )
inlinestatic

Create the "look at" matrix.

Matrix is created in the Column-Major matrix format (opengl native)

Parameters
eye= Eye position
center= Center position
up= Camera up direction
Returns
The matrix (in column-major format)

◆ operator Type *()

template<typename Type>
clan::Mat4< Type >::operator Type * ( )
inline

Operator that returns the matrix as a array.

◆ operator Type const *()

template<typename Type>
clan::Mat4< Type >::operator Type const * ( ) const
inline

Operator that returns the matrix as a array.

◆ operator!=()

template<typename Type>
bool clan::Mat4< Type >::operator!= ( const Mat4< Type > & other)
inline

Not-equal operator.

◆ operator*()

template<typename Type>
Mat4< Type > clan::Mat4< Type >::operator* ( const Mat4< Type > & mult) const

Multiplication operator.

◆ operator+()

template<typename Type>
Mat4< Type > clan::Mat4< Type >::operator+ ( const Mat4< Type > & add_matrix) const

Addition operator.

◆ operator-()

template<typename Type>
Mat4< Type > clan::Mat4< Type >::operator- ( const Mat4< Type > & sub_matrix) const

Subtraction operator.

◆ operator=() [1/3]

template<typename Type>
Mat4< Type > & clan::Mat4< Type >::operator= ( const Mat2< Type > & copy)

Copy assignment operator.

◆ operator=() [2/3]

template<typename Type>
Mat4< Type > & clan::Mat4< Type >::operator= ( const Mat3< Type > & copy)

Copy assignment operator.

◆ operator=() [3/3]

template<typename Type>
Mat4< Type > & clan::Mat4< Type >::operator= ( const Mat4< Type > & copy)
default

Copy assignment operator.

◆ operator==()

template<typename Type>
bool clan::Mat4< Type >::operator== ( const Mat4< Type > & other) const
inline

Equality operator.

◆ operator[]() [1/4]

template<typename Type>
Type & clan::Mat4< Type >::operator[] ( int i)
inline

Operator that returns the matrix cell at the given index.

◆ operator[]() [2/4]

template<typename Type>
const Type & clan::Mat4< Type >::operator[] ( int i) const
inline

Operator that returns the matrix cell at the given index.

◆ operator[]() [3/4]

template<typename Type>
Type & clan::Mat4< Type >::operator[] ( unsigned int i)
inline

Operator that returns the matrix cell at the given index.

◆ operator[]() [4/4]

template<typename Type>
const Type & clan::Mat4< Type >::operator[] ( unsigned int i) const
inline

Operator that returns the matrix cell at the given index.

◆ ortho()

template<typename Type>
static Mat4< Type > clan::Mat4< Type >::ortho ( Type left,
Type right,
Type bottom,
Type top,
Type z_near,
Type z_far,
Handedness handedness,
ClipZRange clip_z )
static

Create a ortho matrix.

Matrix is created in the Column-Major matrix format (opengl native)

Returns
The matrix (in column-major format)

◆ ortho_2d()

template<typename Type>
static Mat4< Type > clan::Mat4< Type >::ortho_2d ( Type left,
Type right,
Type bottom,
Type top,
Handedness handedness,
ClipZRange clip_z )
static

Create a ortho_2d matrix.

Matrix is created in the Column-Major matrix format (opengl native)

Returns
The matrix (in column-major format)

◆ perspective()

template<typename Type>
static Mat4< Type > clan::Mat4< Type >::perspective ( Type field_of_view_y_degrees,
Type aspect,
Type z_near,
Type z_far,
Handedness handedness,
ClipZRange clip_z )
static

Create a perspective matrix.

Matrix is created in the Column-Major matrix format (opengl native)

Returns
The matrix (in column-major format)

◆ rotate() [1/3]

template<typename Type>
static Mat4< Type > clan::Mat4< Type >::rotate ( const Angle & angle,
Type x,
Type y,
Type z,
bool normalize = true )
static

Create a rotation matrix.

Matrix is created in the Column-Major matrix format (opengl native)

Parameters
angle= Angle to rotate by
x= Amount to rotate in the X axis
y= Amount to rotate in the Y axis
z= Amount to rotate in the Z axis
normalize= true = Normalize x,y,z before creating rotation matrix
Returns
The matrix (in column-major format)

Referenced by clan::Mat4< int >::rotate().

◆ rotate() [2/3]

template<typename Type>
static Mat4< Type > clan::Mat4< Type >::rotate ( const Angle & angle,
Vec3< Type > rotation,
bool normalize = true )
inlinestatic

Create a rotation matrix.

Matrix is created in the Column-Major matrix format (opengl native)

Parameters
angle= Angle to rotate by
rotate= Amount to rotate in the XYZ axes
normalize= true = Normalize x,y,z before creating rotation matrix
Returns
The matrix (in column-major format)

◆ rotate() [3/3]

template<typename Type>
static Mat4< Type > clan::Mat4< Type >::rotate ( const Angle & angle_x,
const Angle & angle_y,
const Angle & angle_z,
EulerOrder order )
static

Create a rotation matrix using euler angles.

Matrix is created in the Column-Major matrix format (opengl native)

Returns
The matrix (in column-major format)

◆ scale() [1/2]

template<typename Type>
static Mat4< Type > clan::Mat4< Type >::scale ( const Vec3< Type > & xyz)
inlinestatic

Create a scale matrix.

Parameters
xyz= Scale XYZ
Returns
The matrix

◆ scale() [2/2]

template<typename Type>
static Mat4< Type > clan::Mat4< Type >::scale ( Type x,
Type y,
Type z )
static

Create a scale matrix.

Parameters
x= Scale X
y= Scale Y
z= Scale Z
Returns
The matrix

Referenced by clan::Mat4< int >::scale().

◆ scale_self() [1/2]

template<typename Type>
Mat4< Type > & clan::Mat4< Type >::scale_self ( const Vec3< Type > & scale)
inline

Scale this matrix.

This is faster than using: multiply(Mat4<Type>::scale(x,y,z) )

Parameters
scale= Scale XYZ
Returns
reference to this object

Referenced by clan::Mat4< int >::scale_self().

◆ scale_self() [2/2]

template<typename Type>
Mat4< Type > & clan::Mat4< Type >::scale_self ( Type x,
Type y,
Type z )

Scale this matrix.

This is faster than using: multiply(Mat4<Type>::scale(x,y,z) )

Parameters
x= Scale X
y= Scale Y
z= Scale Z
Returns
reference to this object

◆ set_translate() [1/2]

template<typename Type>
Mat4< Type > & clan::Mat4< Type >::set_translate ( const Vec3< Type > & translation)
inline

Set this matrix translation values.

Matrix is assumed to be in the Column-Major matrix format (opengl native)
This does not translate the matrix, see translate_self() if this is desired

Parameters
translation= Translate XYZ
Returns
reference to this object

◆ set_translate() [2/2]

template<typename Type>
Mat4< Type > & clan::Mat4< Type >::set_translate ( Type x,
Type y,
Type z )
inline

Set this matrix translation values.

Matrix is assumed to be in the Column-Major matrix format (opengl native)
This does not translate the matrix, see translate_self() if this is desired

Parameters
x= Translate X
y= Translate Y
z= Translate Z
Returns
reference to this object

◆ translate() [1/2]

template<typename Type>
static Mat4< Type > clan::Mat4< Type >::translate ( const Vec3< Type > & xyz)
inlinestatic

Create a translation matrix.

Matrix is created in the Column-Major matrix format (opengl native)

Parameters
xyz= Translate XYZ
Returns
The matrix (in column-major format)

◆ translate() [2/2]

template<typename Type>
static Mat4< Type > clan::Mat4< Type >::translate ( Type x,
Type y,
Type z )
static

Create a translation matrix.

Matrix is created in the Column-Major matrix format (opengl native)

Parameters
x= Translate X
y= Translate Y
z= Translate Z
Returns
The matrix (in column-major format)

Referenced by clan::Mat4< int >::translate().

◆ translate_self() [1/2]

template<typename Type>
Mat4< Type > & clan::Mat4< Type >::translate_self ( const Vec3< Type > & translation)
inline

Translate this matrix.

Matrix is assumed to be in the Column-Major matrix format (opengl native)
This is faster than using: multiply(Mat4<Type>::translate(x,y,z) )

Parameters
translation= Translate XYZ
Returns
reference to this object

Referenced by clan::Mat4< int >::translate_self().

◆ translate_self() [2/2]

template<typename Type>
Mat4< Type > & clan::Mat4< Type >::translate_self ( Type x,
Type y,
Type z )

Translate this matrix.

Matrix is assumed to be in the Column-Major matrix format (opengl native)
This is faster than using: multiply(Mat4<Type>::translate(x,y,z) )

Parameters
x= Translate X
y= Translate Y
z= Translate Z
Returns
reference to this object

◆ transpose()

template<typename Type>
Mat4< Type > & clan::Mat4< Type >::transpose ( )

Calculate the transpose of this matrix.

Returns
reference to this object

Member Data Documentation

◆ matrix

template<typename Type>
Type clan::Mat4< Type >::matrix[16]

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