VMTK
VMATH_NAMESPACE::Matrix4< T > Class Template Reference

#include <vmath.h>

Public Member Functions

 Matrix4 ()
 
 Matrix4 (const T *dt)
 
 Matrix4 (const T dt[4][4])
 
 Matrix4 (const Matrix4< T > &src)
 
 Matrix4 (Vector4< T > v[])
 
template<class FromT >
 Matrix4 (const Matrix4< FromT > &src)
 
void identity ()
 
Vector4< T > vectorProductMatrix (const Vector4< T > &v) const
 vectorProductMatrix: Multiplication function More...
 
bool operator== (const Matrix4< T > &rhs) const
 
bool operator!= (const Matrix4< T > &rhs) const
 
T & at (int x, int y)
 
const T & at (int x, int y) const
 
T & operator() (int i, int j)
 
const T & operator() (int i, int j) const
 
void setTranslation (const Vector3< T > &v)
 
void setTranslation (T nx, T ny, T nz)
 Sets translation part of matrix. More...
 
Vector3< T > getTranslation () const
 
void setRotation (const Matrix3< T > &m)
 
Vector3< T > getScale () const
 
void setScale (T s)
 
void setScale (T sx, T sy, T sz)
 
void setScale (const Vector3< T > &s)
 
Matrix4< T > & operator= (const Matrix4< T > &rhs)
 
template<class FromT >
Matrix4< T > & operator= (const Matrix4< FromT > &rhs)
 
Matrix4< T > & operator= (const T *rhs)
 
Matrix4< T > operator+ (const Matrix4< T > &rhs) const
 
Matrix4< T > operator- (const Matrix4< T > &rhs) const
 
Matrix4< T > operator+ (T rhs) const
 
Matrix4< T > operator- (T rhs) const
 
Matrix4< T > operator* (T rhs) const
 
Matrix4< T > operator/ (T rhs) const
 
Vector4< T > operator* (const Vector4< T > &rhs) const
 
Vector3< T > operator* (const Vector3< T > &rhs) const
 
Matrix4< T > operator* (Matrix4< T > rhs) const
 
det ()
 
Matrix4< T > inverse ()
 
Matrix4< T > transpose ()
 
Matrix4< T > lerp (T fact, const Matrix4< T > &rhs) const
 
 operator T* ()
 
 operator const T * () const
 
std::string toString () const
 

Static Public Member Functions

static Matrix4< T > createMat4FromMat3 (Matrix3< T > n)
 createMat4FromMat3 Creates 4x4 Matrix from 3x3 Matrix (Homogeneous Matrix). More...
 
static Vector4< T > vectorProductMatrix (const Vector4< T > v, Matrix4< T > m)
 vectorProductMatrix: Multiplication function More...
 
static Matrix4< T > createRotationAroundAxis (T xDeg, T yDeg, T zDeg)
 
static Vector3< T > getEulerAngles (Matrix4< T > R)
 
static Matrix4< T > createTranslation (T x, T y, T z, T w=1)
 Creates translation matrix. More...
 
static Matrix4< T > createScale (T sx, T sy, T sz)
 
static Matrix4< T > createLookAt (const Vector3< T > &eyePos, const Vector3< T > &centerPos, const Vector3< T > &upDir)
 
static Matrix4< T > createFrustum (T left, T right, T bottom, T top, T zNear, T zFar)
 
static Matrix4< T > createOrtho (T left, T right, T bottom, T top, T zNear, T zFar)
 
static Matrix4< T > Perspective_vmath (T fovy, T aspect, T n, T f)
 set up a perspective projection matrix More...
 
static Matrix4< T > Perspective (T verticalAngle, T aspectRatio, T nearPlane, T farPlane)
 set up a perspective projection matrix More...
 
template<class FromT >
static Matrix4< T > fromRowMajorArray (const FromT *arr)
 
template<class FromT >
static Matrix4< T > fromColumnMajorArray (const FromT *arr)
 

Public Attributes

data [16]
 Data stored in column major order.
 

Friends

std::ostream & operator<< (std::ostream &lhs, const Matrix4< T > &rhs)
 

Detailed Description

template<class T>
class VMATH_NAMESPACE::Matrix4< T >

Class for matrix 4x4

Note
Data stored in this matrix are in column major order. This arrangement suits OpenGL. If you're using row major matrix, consider using fromRowMajorArray as way for construction Matrix4<T> instance.

Definition at line 2312 of file vmath.h.

Constructor & Destructor Documentation

◆ Matrix4() [1/5]

template<class T>
VMATH_NAMESPACE::Matrix4< T >::Matrix4 ( )
inline

Creates identity matrix

Definition at line 2322 of file vmath.h.

◆ Matrix4() [2/5]

template<class T>
VMATH_NAMESPACE::Matrix4< T >::Matrix4 ( const T *  dt)
inline

Copy matrix values from array (these data must be in column major order!)

Definition at line 2332 of file vmath.h.

◆ Matrix4() [3/5]

template<class T>
VMATH_NAMESPACE::Matrix4< T >::Matrix4 ( const T  dt[4][4])
inline

Copy matrix values from bidimensional array.

Definition at line 2340 of file vmath.h.

Here is the call graph for this function:

◆ Matrix4() [4/5]

template<class T>
VMATH_NAMESPACE::Matrix4< T >::Matrix4 ( const Matrix4< T > &  src)
inline

Copy matrix values from array. Copy constructor.

Parameters
srcData source for new created instance of Matrix4.

Definition at line 2366 of file vmath.h.

Here is the call graph for this function:

◆ Matrix4() [5/5]

template<class T>
template<class FromT >
VMATH_NAMESPACE::Matrix4< T >::Matrix4 ( const Matrix4< FromT > &  src)
inline

Copy casting constructor.

Parameters
srcData source for new created instance of Matrix4.

Definition at line 2387 of file vmath.h.

Member Function Documentation

◆ at() [1/2]

template<class T>
T& VMATH_NAMESPACE::Matrix4< T >::at ( int  x,
int  y 
)
inline

Get reference to element at postion (x,y).

Parameters
xNumber of column (0..3)
yNumber of row (0..3)

Definition at line 2860 of file vmath.h.

Here is the caller graph for this function:

◆ at() [2/2]

template<class T>
const T& VMATH_NAMESPACE::Matrix4< T >::at ( int  x,
int  y 
) const
inline

Get constant reference to element at position (x,y).

Parameters
xNumber of column (0..3)
yNumber of row (0..3)

Definition at line 2872 of file vmath.h.

◆ createFrustum()

template<class T>
static Matrix4<T> VMATH_NAMESPACE::Matrix4< T >::createFrustum ( left,
right,
bottom,
top,
zNear,
zFar 
)
inlinestatic

Creates OpenGL compatible perspective projection according specified frustum parameters.

Parameters
leftSpecify the coordinate for the left vertical clipping plane,
rightSpecify the coordinate for the right vertical clipping plane.
bottomSpecify the coordinate for the bottom horizontal clipping plane,
topSpecify the coordinate for the top horizontal clipping plane.
zNearSpecify the distance to the near clipping plane. Distance must be positive.
zFarSpecify the distance to the far depth clipping plane. Distance must be positive.
Returns
Projection matrix for specified frustum.

Definition at line 2624 of file vmath.h.

Here is the call graph for this function:

◆ createLookAt()

template<class T>
static Matrix4<T> VMATH_NAMESPACE::Matrix4< T >::createLookAt ( const Vector3< T > &  eyePos,
const Vector3< T > &  centerPos,
const Vector3< T > &  upDir 
)
inlinestatic

Creates new view matrix to look from specified position eyePos to specified position centerPos

Parameters
eyePosA position of camera
centerPosA position where camera looks-at
upDirDirection of up vector
Returns
Resulting view matrix that looks from and at specific position.

Definition at line 2578 of file vmath.h.

Here is the call graph for this function:

◆ createMat4FromMat3()

template<class T>
static Matrix4<T> VMATH_NAMESPACE::Matrix4< T >::createMat4FromMat3 ( Matrix3< T >  n)
inlinestatic

createMat4FromMat3 Creates 4x4 Matrix from 3x3 Matrix (Homogeneous Matrix).

Parameters
n3x3 Matrix.
Returns
m: 4x4 Matrix.

Definition at line 2412 of file vmath.h.

Here is the call graph for this function:

◆ createOrtho()

template<class T>
static Matrix4<T> VMATH_NAMESPACE::Matrix4< T >::createOrtho ( left,
right,
bottom,
top,
zNear,
zFar 
)
inlinestatic

Creates OpenGL compatible orthographic projection matrix.

Parameters
leftSpecify the coordinate for the left vertical clipping plane,
rightSpecify the coordinate for the right vertical clipping plane.
bottomSpecify the coordinate for the bottom horizontal clipping plane,
topSpecify the coordinate for the top horizontal clipping plane.
zNearSpecify the distance to the nearer depth clipping plane. This value is negative if the plane is to be behind the viewer,
zFarSpecify the distance to the farther depth clipping plane. This value is negative if the plane is to be behind the viewer.
Returns
Othrographic projection matrix.

Definition at line 2682 of file vmath.h.

Here is the call graph for this function:

◆ createRotationAroundAxis()

template<class T>
static Matrix4<T> VMATH_NAMESPACE::Matrix4< T >::createRotationAroundAxis ( xDeg,
yDeg,
zDeg 
)
inlinestatic

Creates rotation matrix by rotation around axis.

Parameters
xDegAngle (in degrees) of rotation around axis X.
yDegAngle (in degrees) of rotation around axis Y.
zDegAngle (in degrees) of rotation around axis Z.

Definition at line 2461 of file vmath.h.

Here is the call graph for this function:

◆ createScale()

template<class T>
static Matrix4<T> VMATH_NAMESPACE::Matrix4< T >::createScale ( sx,
sy,
sz 
)
inlinestatic

Create scale matrix with sx, sy, and sz being values of matrix main diagonal.

Parameters
sxScale in X-axis
syScale in Y-axis
szScale in Z-axis
Returns
Transform matrix 4x4 with scale transformation.

Definition at line 2561 of file vmath.h.

Here is the call graph for this function:

◆ createTranslation()

template<class T>
static Matrix4<T> VMATH_NAMESPACE::Matrix4< T >::createTranslation ( x,
y,
z,
w = 1 
)
inlinestatic

Creates translation matrix.

Creates translation matrix.

Parameters
xX-direction translation
yY-direction translation
zZ-direction translation
wfor W-coordinate translation (implicitly set to 1)

Definition at line 2542 of file vmath.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ det()

template<class T>
T VMATH_NAMESPACE::Matrix4< T >::det ( )
inline

Computes determinant of matrix

Returns
Determinant of matrix
Note
This function does 3 * 4 * 6 muls, 3 * 6 adds.

Definition at line 3158 of file vmath.h.

◆ fromColumnMajorArray()

template<class T>
template<class FromT >
static Matrix4<T> VMATH_NAMESPACE::Matrix4< T >::fromColumnMajorArray ( const FromT *  arr)
inlinestatic

Creates new matrix 4x4 from array that represents such matrix 4x4 as array of tightly packed elements in column major order.

Parameters
arrAn array of elements for 4x4 matrix in column major order.
Returns
An instance of Matrix4<T> representing arr

Definition at line 2813 of file vmath.h.

◆ fromRowMajorArray()

template<class T>
template<class FromT >
static Matrix4<T> VMATH_NAMESPACE::Matrix4< T >::fromRowMajorArray ( const FromT *  arr)
inlinestatic

Creates new matrix 4x4 from array that represents such matrix 4x4 as array of tightly packed elements in row major order.

Parameters
arrAn array of elements for 4x4 matrix in row major order.
Returns
An instance of Matrix4<T> representing arr

Definition at line 2795 of file vmath.h.

◆ getScale()

template<class T>
Vector3<T> VMATH_NAMESPACE::Matrix4< T >::getScale ( ) const
inline

Gets matrix scale

Returns
Scales (i.e. first three values from matrix diagonal.

Definition at line 2955 of file vmath.h.

◆ identity()

template<class T>
void VMATH_NAMESPACE::Matrix4< T >::identity ( )
inline

Resets matrix to be identity matrix

Definition at line 2400 of file vmath.h.

◆ inverse()

template<class T>
Matrix4<T> VMATH_NAMESPACE::Matrix4< T >::inverse ( )
inline

Computes inverse matrix

Returns
Inverse matrix of this matrix.
Note
This is a little bit time consuming operation (16 * 6 * 3 muls, 16 * 5 adds + det() + mul() functions)

Definition at line 3187 of file vmath.h.

Here is the call graph for this function:

◆ lerp()

template<class T>
Matrix4<T> VMATH_NAMESPACE::Matrix4< T >::lerp ( fact,
const Matrix4< T > &  rhs 
) const
inline

Linear interpolation of two matrices

Parameters
factFactor of interpolation. For translation from positon of this matrix (lhs) to matrix rhs, values of factor goes from 0.0 to 1.0.
rhsSecond Matrix for interpolation
Note
However values of fact parameter are reasonable only in interval [0.0 , 1.0], you can pass also values outside of this interval and you can get result (extrapolation?)

Definition at line 3267 of file vmath.h.

◆ operator const T *()

template<class T>
VMATH_NAMESPACE::Matrix4< T >::operator const T * ( ) const
inline

Conversion to pointer operator

Returns
Constant Pointer to internally stored (in management of class Matrix4<T>) used for passing Matrix4<T> values to gl*[fd]v functions.

Definition at line 3289 of file vmath.h.

◆ operator T*()

template<class T>
VMATH_NAMESPACE::Matrix4< T >::operator T* ( )
inline

Conversion to pointer operator

Returns
Pointer to internally stored (in management of class Matrix4<T>) used for passing Matrix4<T> values to gl*[fd]v functions.

Definition at line 3279 of file vmath.h.

◆ operator!=()

template<class T>
bool VMATH_NAMESPACE::Matrix4< T >::operator!= ( const Matrix4< T > &  rhs) const
inline

Inequality test operator

Parameters
rhsRight hand side argument of binary operator.
Returns
not (lhs == rhs) :-P

Definition at line 2849 of file vmath.h.

◆ operator()() [1/2]

template<class T>
T& VMATH_NAMESPACE::Matrix4< T >::operator() ( int  i,
int  j 
)
inline

Get reference to element at position (i,j), with math matrix notation

Parameters
iNumber of row (1..4)
jNumber of column (1..4)

Definition at line 2884 of file vmath.h.

◆ operator()() [2/2]

template<class T>
const T& VMATH_NAMESPACE::Matrix4< T >::operator() ( int  i,
int  j 
) const
inline

Get constant reference to element at position (i,j), with math matrix notation

Parameters
iNumber of row (1..4)
jNumber of column (1..4)

Definition at line 2896 of file vmath.h.

◆ operator*() [1/4]

template<class T>
Matrix4<T> VMATH_NAMESPACE::Matrix4< T >::operator* ( rhs) const
inline

Multiplication operator

Parameters
rhsRight hand side argument of binary operator.

Definition at line 3085 of file vmath.h.

◆ operator*() [2/4]

template<class T>
Vector4<T> VMATH_NAMESPACE::Matrix4< T >::operator* ( const Vector4< T > &  rhs) const
inline

Multiplication operator

Parameters
rhsRight hand side argument of binary operator.

Definition at line 3110 of file vmath.h.

◆ operator*() [3/4]

template<class T>
Vector3<T> VMATH_NAMESPACE::Matrix4< T >::operator* ( const Vector3< T > &  rhs) const
inline

Multiplication operator

Parameters
rhsRight hand side argument of binary operator.

Definition at line 3123 of file vmath.h.

◆ operator*() [4/4]

template<class T>
Matrix4<T> VMATH_NAMESPACE::Matrix4< T >::operator* ( Matrix4< T >  rhs) const
inline

Multiplication operator

Parameters
rhsRight hand side argument of binary operator.

Definition at line 3134 of file vmath.h.

Here is the call graph for this function:

◆ operator+() [1/2]

template<class T>
Matrix4<T> VMATH_NAMESPACE::Matrix4< T >::operator+ ( const Matrix4< T > &  rhs) const
inline

Addition operator

Parameters
rhsRight hand side argument of binary operator.

Definition at line 3036 of file vmath.h.

◆ operator+() [2/2]

template<class T>
Matrix4<T> VMATH_NAMESPACE::Matrix4< T >::operator+ ( rhs) const
inline

Addition operator

Parameters
rhsRight hand side argument of binary operator.

Definition at line 3061 of file vmath.h.

◆ operator-() [1/2]

template<class T>
Matrix4<T> VMATH_NAMESPACE::Matrix4< T >::operator- ( const Matrix4< T > &  rhs) const
inline

Subtraction operator

Parameters
rhsRight hand side argument of binary operator.

Definition at line 3048 of file vmath.h.

◆ operator-() [2/2]

template<class T>
Matrix4<T> VMATH_NAMESPACE::Matrix4< T >::operator- ( rhs) const
inline

Subtraction operator

Parameters
rhsRight hand side argument of binary operator.

Definition at line 3073 of file vmath.h.

◆ operator/()

template<class T>
Matrix4<T> VMATH_NAMESPACE::Matrix4< T >::operator/ ( rhs) const
inline

Division operator

Parameters
rhsRight hand side argument of binary operator.

Definition at line 3097 of file vmath.h.

◆ operator=() [1/3]

template<class T>
Matrix4<T>& VMATH_NAMESPACE::Matrix4< T >::operator= ( const Matrix4< T > &  rhs)
inline

Copy operator

Parameters
rhsRight hand side argument of binary operator.

Definition at line 2995 of file vmath.h.

◆ operator=() [2/3]

template<class T>
template<class FromT >
Matrix4<T>& VMATH_NAMESPACE::Matrix4< T >::operator= ( const Matrix4< FromT > &  rhs)
inline

Copy casting operator

Parameters
rhsRight hand side argument of binary operator.

Definition at line 3006 of file vmath.h.

◆ operator=() [3/3]

template<class T>
Matrix4<T>& VMATH_NAMESPACE::Matrix4< T >::operator= ( const T *  rhs)
inline

Copy operator

Parameters
rhsRight hand side argument of binary operator.

Definition at line 3019 of file vmath.h.

◆ operator==()

template<class T>
bool VMATH_NAMESPACE::Matrix4< T >::operator== ( const Matrix4< T > &  rhs) const
inline

Equality test operator

Parameters
rhsRight hand side argument of binary operator.
Note
Test of equality is based of threshold EPSILON value. To be two values equal, must satisfy this condition all elements of matrix | lhs[i] - rhs[i] | < EPSILON, same for y-coordinate, z-coordinate, and w-coordinate.

Definition at line 2833 of file vmath.h.

◆ Perspective()

template<class T>
static Matrix4<T> VMATH_NAMESPACE::Matrix4< T >::Perspective ( verticalAngle,
aspectRatio,
nearPlane,
farPlane 
)
inlinestatic

set up a perspective projection matrix

Parameters
[in]verticalAnglefield of view angle, in degrees, in the y direction
[in]aspectRatioratio of x (width) and y (height)
[in]nearPlanenear clipping plane distance from the viewer
[in]farPlanefar clipping plane distance from the viewer
Returns
perspective projection matrix
Note
implemented by José Angel Ivan Rubianes Silva

Definition at line 2762 of file vmath.h.

Here is the call graph for this function:

◆ Perspective_vmath()

template<class T>
static Matrix4<T> VMATH_NAMESPACE::Matrix4< T >::Perspective_vmath ( fovy,
aspect,
n,
f 
)
inlinestatic

set up a perspective projection matrix

Parameters
[in]fovyfield of view angle, in degrees, in the y direction
[in]aspectratio of x (width) to y (height)
[in]nnear clipping plane distance from the viewer
[in]ffar clipping plane distance fromn the viewer
Returns
perspective projection matrix
Note
from OpenGL redbook implementation (gluPerspective)

Definition at line 2736 of file vmath.h.

◆ setRotation()

template<class T>
void VMATH_NAMESPACE::Matrix4< T >::setRotation ( const Matrix3< T > &  m)
inline

Sets rotation part (matrix 3x3) of matrix.

Parameters
mRotation part of matrix

Definition at line 2940 of file vmath.h.

Here is the call graph for this function:

◆ setScale() [1/3]

template<class T>
void VMATH_NAMESPACE::Matrix4< T >::setScale ( s)
inline

Sets matrix uniform scale values

Parameters
sUniform scale value

Definition at line 2962 of file vmath.h.

◆ setScale() [2/3]

template<class T>
void VMATH_NAMESPACE::Matrix4< T >::setScale ( sx,
sy,
sz 
)
inline

Sets matrix scale for all axes.

Parameters
sxX-axis scale factor
syY-axis scale factor
szZ-axis scale factor

Definition at line 2973 of file vmath.h.

◆ setScale() [3/3]

template<class T>
void VMATH_NAMESPACE::Matrix4< T >::setScale ( const Vector3< T > &  s)
inline

Sets matrix scale for all axes.

Parameters
sScale factors for X, Y, and Z coordinate.

Definition at line 2984 of file vmath.h.

◆ setTranslation() [1/2]

template<class T>
void VMATH_NAMESPACE::Matrix4< T >::setTranslation ( const Vector3< T > &  v)
inline

Sets translation part of matrix.

Parameters
vVector of translation to be set.

Definition at line 2908 of file vmath.h.

◆ setTranslation() [2/2]

template<class T>
void VMATH_NAMESPACE::Matrix4< T >::setTranslation ( nx,
ny,
nz 
)
inline

Sets translation part of matrix.

Parameters
nxX-axis element to be set.
nyY-axis element to be set.
nzZ-axis element to be set.

Definition at line 2922 of file vmath.h.

◆ toString()

template<class T>
std::string VMATH_NAMESPACE::Matrix4< T >::toString ( ) const
inline

Gets string representation.

Definition at line 3318 of file vmath.h.

◆ transpose()

template<class T>
Matrix4<T> VMATH_NAMESPACE::Matrix4< T >::transpose ( )
inline

Transpose matrix.

Definition at line 3245 of file vmath.h.

Here is the call graph for this function:

◆ vectorProductMatrix() [1/2]

template<class T>
Vector4<T> VMATH_NAMESPACE::Matrix4< T >::vectorProductMatrix ( const Vector4< T > &  v) const
inline

vectorProductMatrix: Multiplication function

Parameters
vvector4
Returns
v multiplied by currentMatrix (Matrix4)

Definition at line 2427 of file vmath.h.

◆ vectorProductMatrix() [2/2]

template<class T>
static Vector4<T> VMATH_NAMESPACE::Matrix4< T >::vectorProductMatrix ( const Vector4< T >  v,
Matrix4< T >  m 
)
inlinestatic

vectorProductMatrix: Multiplication function

Parameters
vrow vector4
mMatrix4
Returns
Vector4: v * m

Definition at line 2444 of file vmath.h.

Here is the call graph for this function:

Friends And Related Function Documentation

◆ operator<<

template<class T>
std::ostream& operator<< ( std::ostream &  lhs,
const Matrix4< T > &  rhs 
)
friend

Output to stream operator

Parameters
lhsLeft hand side argument of operator (commonly ostream instance).
rhsRight hand side argument of operator.
Returns
Left hand side argument - the ostream object passed to operator.

Definition at line 3301 of file vmath.h.


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