NGL  6.5
The NCCA Graphics Library
ngl::Mat4 Class Reference

Matrix Class to do simple matrix operations included operator overloaded functions for maths and matrix * vector type maths. More...

#include <Mat4.h>

+ Collaboration diagram for ngl::Mat4:

Public Member Functions

 Mat4 () noexcept
 ctor will always create an identity matrix More...
 
 Mat4 (Real _m[4][4]) noexcept
 ctor using 4x4 array, really useful when mixing with Imath as we can do Imath::Matrix44 <float> iMatrix; Mat4 nMatrix(iMatrix.x) More...
 
 Mat4 (Real _00, Real _01, Real _02, Real _03, Real _10, Real _11, Real _12, Real _13, Real _20, Real _21, Real _22, Real _23, Real _30, Real _31, Real _32, Real _33) noexcept
 ctor using individual elements More...
 
 Mat4 (const Mat4 &_m) noexcept
 copy ctor with reference object More...
 
 Mat4 (Real _m) noexcept
 copy ctor with Real useful for Mat4 m=1; for identity or Matrix m=3.5 for uniform scale More...
 
Mat4operator= (const Mat4 &_m) noexcept
 assignment operator More...
 
void setAtXY (GLint _x, GLint _y, Real _equals) noexcept
 set the value at m_m[_x][_y] to _equals More...
 
const Mat4null () noexcept
 clear the matrix to all 0 More...
 
const Mat4identity () noexcept
 make the matrix m the identity matrix
1 0 0 0
0 1 0 0
0 0 1 0
0 0 0 1
More...
 
Mat4 operator* (const Mat4 &_m) const noexcept
 operator for matrix multiplication More...
 
const Mat4operator*= (const Mat4 &_m) noexcept
 operator to mult this matrix by value _m More...
 
Mat4 operator+ (const Mat4 &_m) const noexcept
 operator to add two matrices together More...
 
const Mat4operator+= (const Mat4 &_m) noexcept
 += operator More...
 
Mat4 operator* (const Real _i) const noexcept
 operator to mult matrix by a scalar More...
 
const Mat4operator*= (const Real _i) noexcept
 *= operator with a scalar value More...
 
const Mat4transpose () noexcept
 method to transpose the matrix More...
 
void rotateX (const Real _deg) noexcept
 set this matrix to a rotation matrix in the X axis for value _deg note the matrix should be set to identity before doing this More...
 
void rotateY (const Real _deg) noexcept
 set this matrix to a rotation matrix in the Y axis for value _deg note the matrix should be set to identity before doing this More...
 
void rotateZ (const Real _deg) noexcept
 set this matrix to a rotation matrix in the Z axis for value _deg note the matrix should be set to identity before doing this More...
 
void scale (const Real _x, const Real _y, const Real _z) noexcept
 set the matrix scale values More...
 
void translate (const Real _x, const Real _y, const Real _z) noexcept
 set the matrix as a translation matrix More...
 
Real determinant () const noexcept
 get the determinant of the matrix More...
 
void subMatrix3x3 (const int _i, const int _j, Real o_mat[]) const noexcept
 get a sub 3x3 matrix used in determinant and Inverse calculations More...
 
void as3x3Array (Real _d[9]) const noexcept
 return the data as a 3x3 matrix More...
 
Mat4 inverse () noexcept
 get the inverse of the matrix More...
 
Quaternion asQuaternion () const noexcept
 convert this matrix to a Quaternion More...
 
Vec4 operator* (const Vec4 &_v) const noexcept
 multiply this by a Vec4 More...
 
void euler (const Real _angle, const Real _x, const Real _y, const Real _z) noexcept
 axis / angle rotation using the Euler method More...
 
RealopenGL () noexcept
 accesor to the openGL matrix More...
 
Mat4 Adjacent (const Mat4 &_mat) noexcept
 returns a matrix adjacent to the matrix passed in More...
 
Mat4 Adjacent () noexcept
 returns the ajacent matrix to this More...
 
Vec3 getLeftVector () const noexcept
 get the left vector of the matrix (-ve 1st Row) More...
 
Vec3 getRightVector () const noexcept
 get the right vector of the matrix ( 1nd Row) More...
 
Vec3 getUpVector () const noexcept
 get the up vector of the matrix (2nd Row) More...
 
Vec3 getDownVector () const noexcept
 get the down vector of the matrix ( -ve 2nd Row) More...
 
Vec3 getForwardVector () const noexcept
 get the forward vector of the matrix (-ve 3rd Row) More...
 
Vec3 getBackVector () const noexcept
 get the back vector of the matrix ( 3nd Row) More...
 

Public Attributes

union {
   Real   m_m [4][4]
 matrix element m_m as a 4x4 array mapped by union to m_nn elements and m_openGL More...
 
   std::array< Real, 16 >   m_openGL
 The matrix in m_openGL 16 Real array format usefull for OpenGL fv formats mapped to m_m[][] elements and m_xx elements. More...
 
   struct {
      struct {
         Real   m_00
 individual matrix element maps to m_m[0][0] or m_openGL[0] More...
 
         Real   m_01
 individual matrix element maps to m_m[0][1] or m_openGL[1] More...
 
         Real   m_02
 individual matrix element maps to m_m[0][2] or m_openGL[2] More...
 
         Real   m_03
 individual matrix element maps to m_m[0][3] or m_openGL[3] More...
 
         Real   m_10
 individual matrix element maps to m_m[1][0] or m_openGL[4] More...
 
         Real   m_11
 individual matrix element maps to m_m[1][1] or m_openGL[5] More...
 
         Real   m_12
 individual matrix element maps to m_m[1][2] or m_openGL[6] More...
 
         Real   m_13
 individual matrix element maps to m_m[1][3] or m_openGL[7] More...
 
         Real   m_20
 individual matrix element maps to m_m[2][0] or m_openGL[8] More...
 
         Real   m_21
 individual matrix element maps to m_m[2][1] or m_openGL[9] More...
 
         Real   m_22
 individual matrix element maps to m_m[2][2] or m_openGL[10] More...
 
         Real   m_23
 individual matrix element maps to m_m[2][3] or m_openGL[11] More...
 
         Real   m_30
 individual matrix element maps to m_m[3][0] or m_openGL[12] More...
 
         Real   m_31
 individual matrix element maps to m_m[3][1] or m_openGL[13] More...
 
         Real   m_32
 individual matrix element maps to m_m[3][2] or m_openGL[14] More...
 
         Real   m_33
 individual matrix element maps to m_m[3][3] or m_openGL[15] More...
 
      } 
 
   } 
 
}; 
 

Friends

class Vec4
 
class Transformation
 
class Quaternion
 
class Camera
 

Detailed Description

Matrix Class to do simple matrix operations included operator overloaded functions for maths and matrix * vector type maths.

Note
for clarity here is the martix offsets m_openGL[n] and the m_00 / [][] versions I tend to draw this out a lot so thought I would put it here to save me doing it again [y][x] i [y][x] i [y][x] i [y][x] i [ (0,0) 0 m_00 | (0,1) 4 m_10 | (0,2) 8 m_20 | (0,3) 12 m_30] [ (1,0) 1 m_01 | (1,1) 5 m_11 | (1,2) 9 m_21 | (1,3) 13 m_31] [ (2,0) 2 m_02 | (2,1) 6 m_12 | (2,2) 10 m_22 | (2,3) 14 m_32] [ (3,0) 3 m_03 | (3,1) 7 m_13 | (3,2) 11 m_23 | (3,3) 15 m_33] you will note that the m_ values are transposed so be wary
Author
Jonathan Macey
Version
3.0
Date
Last Revision 28/09/09 Updated to NCCA Coding standard

Definition at line 58 of file Mat4.h.

Constructor & Destructor Documentation

ngl::Mat4::Mat4 ( )
noexcept

ctor will always create an identity matrix

Definition at line 36 of file Mat4.cpp.

References m_00, m_11, m_22, m_33, and m_m.

ngl::Mat4::Mat4 ( Real  _m[4][4])
noexcept

ctor using 4x4 array, really useful when mixing with Imath as we can do Imath::Matrix44 <float> iMatrix; Mat4 nMatrix(iMatrix.x)

Parameters
[in]_m[4][4]the input array for the matrix

Definition at line 45 of file Mat4.cpp.

References m_m.

ngl::Mat4::Mat4 ( Real  _00,
Real  _01,
Real  _02,
Real  _03,
Real  _10,
Real  _11,
Real  _12,
Real  _13,
Real  _20,
Real  _21,
Real  _22,
Real  _23,
Real  _30,
Real  _31,
Real  _32,
Real  _33 
)
noexcept

ctor using individual elements

Parameters
[in]_000th element (etc you get the deal)

Definition at line 57 of file Mat4.cpp.

References m_00, m_01, m_02, m_03, m_10, m_11, m_12, m_13, m_20, m_21, m_22, m_23, m_30, m_31, m_32, and m_33.

ngl::Mat4::Mat4 ( const Mat4 _m)
noexcept

copy ctor with reference object

Definition at line 82 of file Mat4.cpp.

References m_m.

ngl::Mat4::Mat4 ( Real  _m)
noexcept

copy ctor with Real useful for Mat4 m=1; for identity or Matrix m=3.5 for uniform scale

Definition at line 93 of file Mat4.cpp.

References m_00, m_11, m_22, m_33, and m_m.

Member Function Documentation

Mat4 ngl::Mat4::Adjacent ( const Mat4 _mat)
noexcept

returns a matrix adjacent to the matrix passed in

Returns
the adjacent matrix

Definition at line 630 of file Mat4.cpp.

References m_00, m_01, m_02, m_03, m_10, m_11, m_12, m_13, m_20, m_21, m_22, m_23, m_30, m_31, m_32, and m_33.

Mat4 ngl::Mat4::Adjacent ( )
noexcept

returns the ajacent matrix to this

Returns
the adjacent matrix

Definition at line 657 of file Mat4.cpp.

References m_00, m_01, m_02, m_03, m_10, m_11, m_12, m_13, m_20, m_21, m_22, m_23, m_30, m_31, m_32, m_33, and m_m.

void ngl::Mat4::as3x3Array ( Real  _d[9]) const
noexcept

return the data as a 3x3 matrix

Parameters
[out]_dthe data from the sub matrix

Definition at line 547 of file Mat4.cpp.

References m_m.

Quaternion ngl::Mat4::asQuaternion ( ) const
noexcept

convert this matrix to a Quaternion

Returns
the matrix as a Quaternion

Definition at line 563 of file Mat4.cpp.

References m_openGL, NGL_ASSERT, and Quaternion.

Real ngl::Mat4::determinant ( ) const
noexcept

get the determinant of the matrix

Returns
the determinat

Definition at line 494 of file Mat4.cpp.

References m_m.

+ Here is the caller graph for this function:

void ngl::Mat4::euler ( const Real  _angle,
const Real  _x,
const Real  _y,
const Real  _z 
)
noexcept

axis / angle rotation using the Euler method

Parameters
[in]_anglethe angle in degree to rotate
[in]_xpart of the axis should be normalised before call
[in]_ypart of the axis should be normalised before call
[in]_zpart of the axis should be normalised before call

Definition at line 512 of file Mat4.cpp.

References m_m, ngl::Vec3::m_x, ngl::Vec3::m_y, ngl::Vec3::m_z, ngl::Vec3::normalize(), and ngl::radians().

+ Here is the call graph for this function:

Vec3 ngl::Mat4::getBackVector ( ) const
noexcept

get the back vector of the matrix ( 3nd Row)

Returns
the up vector

Definition at line 745 of file Mat4.cpp.

References m_openGL.

Vec3 ngl::Mat4::getDownVector ( ) const
noexcept

get the down vector of the matrix ( -ve 2nd Row)

Returns
the up vector

Definition at line 733 of file Mat4.cpp.

References m_openGL.

Vec3 ngl::Mat4::getForwardVector ( ) const
noexcept

get the forward vector of the matrix (-ve 3rd Row)

Returns
the up vector

Definition at line 739 of file Mat4.cpp.

References m_openGL.

Vec3 ngl::Mat4::getLeftVector ( ) const
noexcept

get the left vector of the matrix (-ve 1st Row)

Returns
the up vector

Definition at line 715 of file Mat4.cpp.

References m_openGL.

Vec3 ngl::Mat4::getRightVector ( ) const
noexcept

get the right vector of the matrix ( 1nd Row)

Returns
the up vector

Definition at line 720 of file Mat4.cpp.

References m_openGL.

Vec3 ngl::Mat4::getUpVector ( ) const
noexcept

get the up vector of the matrix (2nd Row)

Returns
the up vector

Definition at line 726 of file Mat4.cpp.

References m_openGL.

const Mat4 & ngl::Mat4::identity ( )
noexcept

make the matrix m the identity matrix
1 0 0 0
0 1 0 0
0 0 1 0
0 0 0 1

Definition at line 114 of file Mat4.cpp.

References m_00, m_11, m_22, m_33, and m_m.

+ Here is the caller graph for this function:

Mat4 ngl::Mat4::inverse ( )
noexcept

get the inverse of the matrix

Returns
a new matrix the inverse of the current matrix (warning no error checking )

Definition at line 684 of file Mat4.cpp.

References determinant(), m_00, m_01, m_02, m_03, m_10, m_11, m_12, m_13, m_20, m_21, m_22, m_23, m_30, m_31, m_32, and m_33.

+ Here is the call graph for this function:

const Mat4 & ngl::Mat4::null ( )
noexcept

clear the matrix to all 0

Definition at line 108 of file Mat4.cpp.

References m_m.

+ Here is the caller graph for this function:

Real* ngl::Mat4::openGL ( )
inlinenoexcept

accesor to the openGL matrix

Returns
a pointer to m_openGL[0]

Definition at line 239 of file Mat4.h.

+ Here is the caller graph for this function:

Mat4 ngl::Mat4::operator* ( const Mat4 _m) const
noexcept

operator for matrix multiplication

Parameters
[in]_mthe matrix to multiply the current one by
Returns
this*_m

Definition at line 125 of file Mat4.cpp.

References m_m.

Mat4 ngl::Mat4::operator* ( const Real  _i) const
noexcept

operator to mult matrix by a scalar

Parameters
[in]_ithe scalar to multiply by
Returns
this*_i

Definition at line 347 of file Mat4.cpp.

References m_openGL.

Vec4 ngl::Mat4::operator* ( const Vec4 _v) const
noexcept

multiply this by a Vec4

Parameters
[in]_vthe vector to multiply
Returns
Vector M*V

Definition at line 375 of file Mat4.cpp.

References m_00, m_01, m_02, m_03, m_10, m_11, m_12, m_13, m_20, m_21, m_22, m_23, m_30, m_31, m_32, m_33, ngl::Vec4::m_w, ngl::Vec4::m_x, ngl::Vec4::m_y, and ngl::Vec4::m_z.

const Mat4 & ngl::Mat4::operator*= ( const Mat4 _m)
noexcept

operator to mult this matrix by value _m

Parameters
[in]_mthe matrix to multiplt
Returns
a new matrix this*_m

Definition at line 213 of file Mat4.cpp.

References m_00, m_01, m_02, m_03, m_10, m_11, m_12, m_13, m_20, m_21, m_22, m_23, m_30, m_31, m_32, and m_33.

const Mat4 & ngl::Mat4::operator*= ( const Real  _i)
noexcept

*= operator with a scalar value

Parameters
[in]_ithe scalar to multiply by
Returns
the matrix*i

Definition at line 362 of file Mat4.cpp.

References m_m.

Mat4 ngl::Mat4::operator+ ( const Mat4 _m) const
noexcept

operator to add two matrices together

Parameters
[in]_mthe matrix to add
Returns
this+_m

Definition at line 308 of file Mat4.cpp.

References m_openGL.

const Mat4 & ngl::Mat4::operator+= ( const Mat4 _m)
noexcept

+= operator

Parameters
[in]_mthe matrix to add
Returns
this+m

Definition at line 334 of file Mat4.cpp.

References m_openGL.

Mat4 & ngl::Mat4::operator= ( const Mat4 _m)
noexcept

assignment operator

Definition at line 87 of file Mat4.cpp.

References m_m.

void ngl::Mat4::rotateX ( const Real  _deg)
noexcept

set this matrix to a rotation matrix in the X axis for value _deg note the matrix should be set to identity before doing this

Parameters
[in]_degthe value to be rotated by in degrees

Definition at line 406 of file Mat4.cpp.

References m_11, m_12, m_21, m_22, and ngl::radians().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ngl::Mat4::rotateY ( const Real  _deg)
noexcept

set this matrix to a rotation matrix in the Y axis for value _deg note the matrix should be set to identity before doing this

Parameters
[in]_degthe value to be rotated by in degrees

Definition at line 418 of file Mat4.cpp.

References m_00, m_02, m_20, m_22, and ngl::radians().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ngl::Mat4::rotateZ ( const Real  _deg)
noexcept

set this matrix to a rotation matrix in the Z axis for value _deg note the matrix should be set to identity before doing this

Parameters
[in]_degthe value to be rotated by in degrees

Definition at line 430 of file Mat4.cpp.

References m_00, m_01, m_10, m_11, and ngl::radians().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ngl::Mat4::scale ( const Real  _x,
const Real  _y,
const Real  _z 
)
noexcept

set the matrix scale values

Parameters
[in]_xthe scale value in the _x
[in]_ythe scale value in the _y
[in]_zthe scale value in the _z

Definition at line 450 of file Mat4.cpp.

References m_00, m_11, and m_22.

+ Here is the caller graph for this function:

void ngl::Mat4::setAtXY ( GLint  _x,
GLint  _y,
Real  _equals 
)
noexcept

set the value at m_m[_x][_y] to _equals

Parameters
[in]_xthe x index into the array
[in]_ythe y index into the array
[in]_equalsthe value to set to
Todo:
replace this with function operator overload ()

Definition at line 103 of file Mat4.cpp.

References m_m.

void ngl::Mat4::subMatrix3x3 ( const int  _i,
const int  _j,
Real  o_mat[] 
) const
noexcept

get a sub 3x3 matrix used in determinant and Inverse calculations

Parameters
[in]_iindex value
[in]_jindex value
[in]o_matthe 3x3 matrix

Definition at line 458 of file Mat4.cpp.

References m_openGL.

void ngl::Mat4::translate ( const Real  _x,
const Real  _y,
const Real  _z 
)
noexcept

set the matrix as a translation matrix

Parameters
[in]_xthe _x translation value
[in]_ythe _y translation value
[in]_zthe _z translation value

Definition at line 442 of file Mat4.cpp.

References m_30, m_31, and m_32.

+ Here is the caller graph for this function:

const Mat4 & ngl::Mat4::transpose ( )
noexcept

method to transpose the matrix

Definition at line 389 of file Mat4.cpp.

References m_m.

+ Here is the caller graph for this function:

Friends And Related Function Documentation

friend class Camera
friend

Definition at line 286 of file Mat4.h.

friend class Quaternion
friend

Definition at line 285 of file Mat4.h.

friend class Transformation
friend

Definition at line 284 of file Mat4.h.

friend class Vec4
friend

Definition at line 61 of file Mat4.h.

Member Data Documentation

union { ... }
Real ngl::Mat4::m_00

individual matrix element maps to m_m[0][0] or m_openGL[0]

Definition at line 311 of file Mat4.h.

Real ngl::Mat4::m_01

individual matrix element maps to m_m[0][1] or m_openGL[1]

Definition at line 312 of file Mat4.h.

Real ngl::Mat4::m_02

individual matrix element maps to m_m[0][2] or m_openGL[2]

Definition at line 313 of file Mat4.h.

Real ngl::Mat4::m_03

individual matrix element maps to m_m[0][3] or m_openGL[3]

Definition at line 314 of file Mat4.h.

Real ngl::Mat4::m_10

individual matrix element maps to m_m[1][0] or m_openGL[4]

Definition at line 315 of file Mat4.h.

Real ngl::Mat4::m_11

individual matrix element maps to m_m[1][1] or m_openGL[5]

Definition at line 316 of file Mat4.h.

Real ngl::Mat4::m_12

individual matrix element maps to m_m[1][2] or m_openGL[6]

Definition at line 317 of file Mat4.h.

Real ngl::Mat4::m_13

individual matrix element maps to m_m[1][3] or m_openGL[7]

Definition at line 318 of file Mat4.h.

Real ngl::Mat4::m_20

individual matrix element maps to m_m[2][0] or m_openGL[8]

Definition at line 319 of file Mat4.h.

Real ngl::Mat4::m_21

individual matrix element maps to m_m[2][1] or m_openGL[9]

Definition at line 320 of file Mat4.h.

Real ngl::Mat4::m_22

individual matrix element maps to m_m[2][2] or m_openGL[10]

Definition at line 321 of file Mat4.h.

Real ngl::Mat4::m_23

individual matrix element maps to m_m[2][3] or m_openGL[11]

Definition at line 322 of file Mat4.h.

Real ngl::Mat4::m_30

individual matrix element maps to m_m[3][0] or m_openGL[12]

Definition at line 323 of file Mat4.h.

Real ngl::Mat4::m_31

individual matrix element maps to m_m[3][1] or m_openGL[13]

Definition at line 324 of file Mat4.h.

Real ngl::Mat4::m_32

individual matrix element maps to m_m[3][2] or m_openGL[14]

Definition at line 325 of file Mat4.h.

Real ngl::Mat4::m_33

individual matrix element maps to m_m[3][3] or m_openGL[15]

Definition at line 326 of file Mat4.h.

Real ngl::Mat4::m_m[4][4]

matrix element m_m as a 4x4 array mapped by union to m_nn elements and m_openGL

Definition at line 295 of file Mat4.h.

std::array<Real,16> ngl::Mat4::m_openGL
Initial value:
={{
1.0f,0.0f,0.0f,0.0f,
0.0f,1.0f,0.0f,0.0f,
0.0f,0.0f,1.0f,0.0f,
0.0f,0.0f,0.0f,1.0f
}}

The matrix in m_openGL 16 Real array format usefull for OpenGL fv formats mapped to m_m[][] elements and m_xx elements.

Definition at line 300 of file Mat4.h.


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