4D matrix More...

#include <mat2.h>

Public Member Functions

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

Static Public Member Functions

static Mat4< Type > add (const Mat4< Type > &matrix_1, const Mat4< Type > &matrix_2)
 Add 2 matrices. More...
 
static Mat4< Type > adjoint (const Mat4< Type > &matrix)
 Calculate the adjoint (or known as Adjugate or Conjugate Transpose) of a matrix. More...
 
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. More...
 
static Mat4< Type > identity ()
 Create the identity matrix. More...
 
static Mat4< Type > inverse (const Mat4< Type > &matrix)
 Calculate the matrix inverse of a matrix. More...
 
static bool is_equal (const Mat4< Type > &first, const Mat4< Type > &second, Type epsilon)
 Returns true if equal within the bounds of an epsilon. More...
 
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. More...
 
static Mat4< Type > look_at (Vec3< Type > eye, Vec3< Type > center, Vec3< Type > up)
 Create the "look at" matrix. More...
 
static Mat4< Type > multiply (const Mat4< Type > &matrix_1, const Mat4< Type > &matrix_2)
 Multiply 2 matrices. More...
 
static Mat4< Type > null ()
 Create a zero matrix. More...
 
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. More...
 
static Mat4< Type > ortho_2d (Type left, Type right, Type bottom, Type top, Handedness handedness, ClipZRange clip_z)
 Create a ortho_2d matrix. More...
 
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. More...
 
static Mat4< Type > rotate (const Angle &angle, Type x, Type y, Type z, bool normalize=true)
 Create a rotation matrix. More...
 
static Mat4< Type > rotate (const Angle &angle, Vec3< Type > rotation, bool normalize=true)
 Create a rotation matrix. More...
 
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. More...
 
static Mat4< Type > scale (Type x, Type y, Type z)
 Create a scale matrix. More...
 
static Mat4< Type > scale (const Vec3< Type > &xyz)
 Create a scale matrix. More...
 
static Mat4< Type > subtract (const Mat4< Type > &matrix_1, const Mat4< Type > &matrix_2)
 Subtract 2 matrices. More...
 
static Mat4< Type > translate (Type x, Type y, Type z)
 Create a translation matrix. More...
 
static Mat4< Type > translate (const Vec3< Type > &xyz)
 Create a translation matrix. More...
 
static Mat4< Type > transpose (const Mat4< Type > &matrix)
 Calculate the transpose of a matrix. More...
 

Public Attributes

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

Detailed Description

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

4D matrix

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

Constructor & Destructor Documentation

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

Constructs a 4x4 matrix (zero'ed)

References clan::Mat4< Type >::matrix.

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

Constructs a 4x4 matrix (copied)

References clan::i, and clan::Mat4< Type >::matrix.

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

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

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

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

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

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

References clan::i, and clan::Mat4< Type >::matrix.

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

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

References clan::i, and clan::Mat4< Type >::matrix.

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)

References clan::i, and clan::Mat4< Type >::matrix.

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)

References clan::i, and clan::Mat4< Type >::matrix.

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)

References clan::i, and clan::Mat4< Type >::matrix.

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)

References clan::i, and clan::Mat4< Type >::matrix.

Member Function Documentation

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

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

Returns
reference to this object
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.

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

Calculate the matrix determinant of this matrix.

Returns
The determinant
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)
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)
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
template<typename Type>
Vec3<Type> clan::Mat4< Type >::get_translate ( ) const
inline

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

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
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)

References clan::i, and clan::Mat4< Type >::matrix.

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

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)

References clan::Mat4< Type >::is_equal().

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< Type >::look_at().

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)

References clan::Mat4< Type >::look_at(), clan::Vec3< Type >::x, clan::Vec3< Type >::y, and clan::Vec3< Type >::z.

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

Operator that returns the matrix as a array.

References clan::Mat4< Type >::matrix.

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

Operator that returns the matrix as a array.

References clan::Mat4< Type >::matrix.

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

Not-equal operator.

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

Multiplication operator.

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

Addition operator.

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

Subtraction operator.

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

Copy assignment operator.

References clan::Mat4< Type >::matrix.

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

Copy assignment operator.

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

Copy assignment operator.

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

Equality operator.

References clan::i, and clan::Mat4< Type >::matrix.

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

Operator that returns the matrix cell at the given index.

References clan::i.

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

Operator that returns the matrix cell at the given index.

References clan::i.

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

Operator that returns the matrix cell at the given index.

References clan::i.

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

Operator that returns the matrix cell at the given index.

References clan::i.

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)
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)
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)
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< Type >::rotate().

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)

References clan::Mat4< Type >::rotate(), clan::Vec3< Type >::x, clan::Vec3< Type >::y, and clan::Vec3< Type >::z.

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)
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< Type >::scale().

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

References clan::Mat4< Type >::scale(), clan::Vec3< Type >::x, clan::Vec3< Type >::y, and clan::Vec3< Type >::z.

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
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

References clan::Mat4< Type >::scale_self(), clan::Vec3< Type >::x, clan::Vec3< Type >::y, and clan::Vec3< Type >::z.

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

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

References clan::x, clan::y, and clan::z.

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

References clan::Vec3< Type >::x, clan::Vec3< Type >::y, and clan::Vec3< Type >::z.

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< Type >::translate().

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)

References clan::Mat4< Type >::translate(), clan::Vec3< Type >::x, clan::Vec3< Type >::y, and clan::Vec3< Type >::z.

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
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

References clan::Mat4< Type >::translate_self(), clan::Vec3< Type >::x, clan::Vec3< Type >::y, and clan::Vec3< Type >::z.

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

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

Calculate the transpose of this matrix.

Returns
reference to this object

Member Data Documentation


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