SLProject 4.0.000
SLMat4< T > Class Template Reference

4x4 matrix template class More...

#include <SLMat4.h>

Public Member Functions

 SLMat4 ()
 Sets identity matrix. More...
 
 SLMat4 (const SLMat4 &A)
 Sets mat by other SLMat4. More...
 
 SLMat4 (const SLMat3f &A)
 Sets mat by other SLMat3. More...
 
 SLMat4 (const T *M)
 Sets mat by array. More...
 
 SLMat4 (T M0, T M4, T M8, T M12, T M1, T M5, T M9, T M13, T M2, T M6, T M10, T M14, T M3, T M7, T M11, T M15)
 
 SLMat4 (T tx, T ty, T tz)
 Sets translate matrix. More...
 
 SLMat4 (T degAng, T axis_x, T axis_y, T axis_z)
 Sets rotation matrix. More...
 
 SLMat4 (T scale_xyz)
 Sets scaling matrix. More...
 
 SLMat4 (const SLVec3< T > &translationVec)
 Sets translate matrix. More...
 
 SLMat4 (const SLVec3< T > &fromUnitVec, const SLVec3< T > &toUnitVec)
 Sets rotation matrix. More...
 
 SLMat4 (const SLVec3< T > &translation, const SLMat3< T > &rotation, const SLVec3< T > &scale)
 Set matrix by translation, rotation & scale. More...
 
void setMatrix (const SLMat4 &A)
 Set matrix by other 4x4 matrix. More...
 
void setMatrix (const SLMat3f &A)
 Set matrix by other 3x3 matrix. More...
 
void setMatrix (const SLMat4 *A)
 Set matrix by other matrix pointer. More...
 
void setMatrix (const T *M)
 Set matrix by float[16] array. More...
 
void setMatrix (T M0, T M4, T M8, T M12, T M1, T M5, T M9, T M13, T M2, T M6, T M10, T M14, T M3, T M7, T M11, T M15)
 Set matrix by components. More...
 
void setMatrix (const SLVec3< T > &translation, const SLMat3< T > &rotation, const SLVec3< T > &scale)
 Set matrix by translation, rotation & scale. More...
 
void setMatrix (const int16_t i, const SLfloat value)
 
void setRotation (const SLMat3< T > &rotation)
 Set 3x3 submatrix describing the rotational part. More...
 
void setTranslation (const SLVec3< T > &translation)
 Set vector as submatrix describing the translational part. More...
 
void m (int i, T val)
 
const T * m () const
 
m (int i) const
 
SLMat3< T > mat3 () const
 
SLMat4< T > & operator= (const SLMat4 &A)
 assignment operator More...
 
SLMat4< T > operator* (const SLMat4 &A) const
 matrix-matrix multiplication More...
 
SLMat4< T > & operator*= (const SLMat4 &A)
 matrix-matrix multiplication More...
 
SLMat4< T > operator+ (const SLMat4 &A) const
 matrix-matrix addition More...
 
SLVec3< T > operator* (const SLVec3< T > &v) const
 SLVec3 mult w. persp div. More...
 
SLVec4< T > operator* (const SLVec4< T > &v) const
 SLVec4 mult. More...
 
SLMat4< T > operator* (T a) const
 scalar mult More...
 
SLMat4< T > & operator*= (T a)
 scalar mult More...
 
SLMat4< T > operator/ (T a) const
 scalar division More...
 
SLMat4< T > & operator/= (T a)
 scalar division More...
 
T & operator() (int row, int col)
 
const T & operator() (int row, int col) const
 
SLbool isEqual (const SLMat4 &A, SLfloat epsilon=0.01f)
 Returns true if one element of the matrix differs more than epsilon. More...
 
void multiply (const SLMat4 &A)
 
SLVec3< T > multVec (SLVec3< T > v) const
 
SLVec4< T > multVec (SLVec4< T > v) const
 
void add (const SLMat4 &A)
 
void translate (T tx, T ty, T tz=0)
 
void translate (const SLVec2< T > &t)
 
void translate (const SLVec3< T > &t)
 
void rotate (T degAng, T axisx, T axisy, T axisz)
 
void rotate (T degAng, const SLVec3< T > &axis)
 
void rotate (const SLVec3< T > &fromUnitVec, const SLVec3< T > &toUnitVec)
 
void scale (T sxyz)
 
void scale (T sx, T sy, T sz)
 
void scale (const SLVec3< T > &sxyz)
 
void frustum (T l, T r, T b, T t, T n, T f)
 Defines a view frustum projection matrix equivalent to glFrustum. More...
 
void perspective (T fov, T aspect, T n, T f)
 Defines a perspective projection matrix with a field of view angle. More...
 
void perspectiveCenteredPP (T w, T h, T fx, T fy, T cx, T cy, T n, T f)
 Defines a projection matrix for a calibrated camera, the principle point has to be centered (from intrinsics matrix) More...
 
void ortho (T l, T r, T b, T t, T n, T f)
 Defines a orthographic projection matrix with a field of view angle. More...
 
void viewport (T x, T y, T ww, T wh, T n=0.0f, T f=1.0f)
 Defines the viewport matrix. More...
 
void lookAt (T EyeX, T EyeY, T EyeZ, T AtX=0, T AtY=0, T AtZ=0, T UpX=0, T UpY=0, T UpZ=0)
 Defines the a view matrix as the corresponding gluLookAt function. More...
 
void lookAt (const SLVec3< T > &Eye, const SLVec3< T > &At=SLVec3< T >::ZERO, const SLVec3< T > &Up=SLVec3< T >::ZERO)
 Defines the a view matrix as the corresponding gluLookAt function. More...
 
void lookAt (SLVec3< T > *eye, SLVec3< T > *at, SLVec3< T > *up, SLVec3< T > *right) const
 Reads out of the matrix the look at parameters. More...
 
void lightAt (T PosX, T PosY, T PosZ, T AtX=0, T AtY=0, T AtZ=0, T UpX=0, T UpY=0, T UpZ=0)
 Defines the a model matrix for light positioning. More...
 
void lightAt (const SLVec3< T > &pos, const SLVec3< T > &At=SLVec3< T >::ZERO, const SLVec3< T > &Up=SLVec3< T >::ZERO)
 Defines the a model matrix for light positioning. More...
 
void posAtUp (T PosX, T PosY, T PosZ, T dirAtX=0, T dirAtY=0, T dirAtZ=0, T dirUpX=0, T dirUpY=0, T dirUpZ=0)
 Same as lightAt. More...
 
void posAtUp (const SLVec3< T > &pos, const SLVec3< T > &dirAt=SLVec3< T >::ZERO, const SLVec3< T > &dirUp=SLVec3< T >::ZERO)
 Same as lightAt. More...
 
SLVec3< T > translation () const
 
SLVec3< T > axisX () const
 
SLVec3< T > axisY () const
 
SLVec3< T > axisZ () const
 
void translation (T tx, T ty, T tz, SLbool keepLinear=true)
 Sets the translation with or without overwriting the linear submatrix. More...
 
void translation (const SLVec3< T > &t, SLbool keepLinear=true)
 
void rotation (T degAng, const SLVec3< T > &axis, SLbool keepTranslation=true)
 Sets the rotation with or without overwriting the translation. More...
 
void rotation (T degAng, T axisx, T axisy, T axisz, SLbool keepTranslation=true)
 
void rotation (const SLVec3< T > &fromUnitVec, const SLVec3< T > &toUnitVec)
 
void scaling (T sxyz, SLbool keepTrans=true)
 Sets the scaling with or without overwriting the translation. More...
 
void scaling (const SLVec3< T > &sxyz, SLbool keepTrans=true)
 
void scaling (T sx, T sy, T sz, SLbool keepTranslation=true)
 
void fromEulerAnglesZXZ (double angle1RAD, double angle2RAD, double angle3RAD, bool keepTranslation=true)
 
void fromEulerAnglesXYZ (double angle1RAD, double angle2RAD, double angle3RAD, bool keepTranslation=true)
 
void toEulerAnglesZYX (T &zRotRAD, T &yRotRAD, T &xRotRAD)
 
void toEulerAnglesXYZ (T &xRotRAD, T &yRotRAD, T &zRotRAD)
 
SLVec3< T > toEulerAngles (int order)
 
void identity ()
 Sets the identity matrix. More...
 
void transpose ()
 Sets the transposed matrix by swaping around the main diagonal. More...
 
SLMat4< T > transposed ()
 Returns the transposed of the matrix and leaves the itself unchanged. More...
 
void invert ()
 Inverts the matrix. More...
 
SLMat4< T > inverted () const
 Computes the inverse of a 4x4 non-singular matrix. More...
 
SLMat3< T > inverseTransposed ()
 
trace () const
 
void compose (SLVec3f trans, SLVec3f rotEulerRAD, SLVec3f scale)
 
void decompose (SLVec3f &trans, SLVec4f &rotQuat, SLVec3f &scale)
 
void decompose (SLVec3f &trans, SLMat3f &rotMat, SLVec3f &scale)
 
void decompose (SLVec3f &trans, SLVec3f &rotEulerRAD, SLVec3f &scale)
 
void print (const SLchar *str=nullptr) const
 
SLstring toString () const
 

Static Public Member Functions

static void swap (T &a, T &b)
 

Private Attributes

_m [16]
 The 16 elements of the matrix. More...
 

Detailed Description

template<class T>
class SLMat4< T >

4x4 matrix template class

Implements a 4 by 4 matrix template class. An array of 16 floats or double is used instead of a 2D array [4][4] to be compliant with OpenGL. The index layout is as follows:

     | 0  4  8 12 |
     | 1  5  9 13 |
 M = | 2  6 10 14 |
     | 3  7 11 15 |

Vectors are interpreted as column vectors when applying matrix multiplications. This means a vector is as a single column, 4-row matrix. The result is that the transformations implemented by the matrices happens right-to-left e.g. if vector V is to be transformed by M1 then M2 then M3, the calculation would be M3 * M2 * M1 * V. The order that matrices are concatenated is vital since matrix multiplication is not commutative, i.e. you can get a different result if you concatenate in the wrong order. The use of column vectors and right-to-left ordering is the standard in most mathematical texts, and is the same as used in OpenGL. It is, however, the opposite of Direct3D, which has inexplicably chosen to differ from the accepted standard and uses row vectors and left-to-right matrix multiplication.

Constructor & Destructor Documentation

◆ SLMat4() [1/11]

template<class T >
SLMat4< T >::SLMat4

Sets identity matrix.

◆ SLMat4() [2/11]

template<class T >
SLMat4< T >::SLMat4 ( const SLMat4< T > &  A)

Sets mat by other SLMat4.

◆ SLMat4() [3/11]

template<class T >
SLMat4< T >::SLMat4 ( const SLMat3f A)

Sets mat by other SLMat3.

◆ SLMat4() [4/11]

template<class T >
SLMat4< T >::SLMat4 ( const T *  M)

Sets mat by array.

◆ SLMat4() [5/11]

template<class T >
SLMat4< T >::SLMat4 ( M0,
M4,
M8,
M12,
M1,
M5,
M9,
M13,
M2,
M6,
M10,
M14,
M3,
M7,
M11,
M15 
)

◆ SLMat4() [6/11]

template<class T >
SLMat4< T >::SLMat4 ( tx,
ty,
tz 
)

Sets translate matrix.

◆ SLMat4() [7/11]

template<class T >
SLMat4< T >::SLMat4 ( degAng,
axis_x,
axis_y,
axis_z 
)
explicit

Sets rotation matrix.

◆ SLMat4() [8/11]

template<class T >
SLMat4< T >::SLMat4 ( scale_xyz)
explicit

Sets scaling matrix.

◆ SLMat4() [9/11]

template<class T >
SLMat4< T >::SLMat4 ( const SLVec3< T > &  translationVec)
explicit

Sets translate matrix.

◆ SLMat4() [10/11]

template<class T >
SLMat4< T >::SLMat4 ( const SLVec3< T > &  fromUnitVec,
const SLVec3< T > &  toUnitVec 
)

Sets rotation matrix.

◆ SLMat4() [11/11]

template<class T >
SLMat4< T >::SLMat4 ( const SLVec3< T > &  translation,
const SLMat3< T > &  rotation,
const SLVec3< T > &  scale 
)

Set matrix by translation, rotation & scale.

Member Function Documentation

◆ add()

template<class T >
void SLMat4< T >::add ( const SLMat4< T > &  A)

Adds the matrix to an other matrix A.

◆ axisX()

template<class T >
SLVec3< T > SLMat4< T >::axisX ( ) const
inline

◆ axisY()

template<class T >
SLVec3< T > SLMat4< T >::axisY ( ) const
inline

◆ axisZ()

template<class T >
SLVec3< T > SLMat4< T >::axisZ ( ) const
inline

◆ compose()

template<class T >
void SLMat4< T >::compose ( SLVec3f  trans,
SLVec3f  rotEulerRAD,
SLVec3f  scale 
)

Composes the matrix from a translation vector, a rotation Euler angle vector and the scaling factors.

◆ decompose() [1/3]

template<class T >
void SLMat4< T >::decompose ( SLVec3f trans,
SLMat3f rotMat,
SLVec3f scale 
)

Decomposes the matrix into a translation vector, a 3x3 rotation matrix and the scaling factors using polar decomposition introduced by Ken Shoemake. See the paper in lib-SLExternal/Shoemake/polar-decomp.pdf

◆ decompose() [2/3]

template<class T >
void SLMat4< T >::decompose ( SLVec3f trans,
SLVec3f rotEulerRAD,
SLVec3f scale 
)

Decomposes the matrix into a translation vector, a rotation Euler angle vector and the scaling factors using polar decomposition introduced by Ken Shoemake. See the paper in lib-SLExternal/Shoemake/polar-decomp.pdf

◆ decompose() [3/3]

template<class T >
void SLMat4< T >::decompose ( SLVec3f trans,
SLVec4f rotQuat,
SLVec3f scale 
)

Decomposes the matrix into a translation vector, a rotation quaternion and the scaling factors using polar decomposition introduced by Ken Shoemake. See the paper in lib-SLExternal/Shoemake/polar-decomp.pdf

◆ fromEulerAnglesXYZ()

template<class T >
void SLMat4< T >::fromEulerAnglesXYZ ( double  angle1RAD,
double  angle2RAD,
double  angle3RAD,
bool  keepTranslation = true 
)

Sets the linear 3x3 submatrix as a rotation matrix from the 3 euler angles in radians around the z-axis, y-axis & x-axis. By default the translation components are set to 0. See: http://en.wikipedia.org/wiki/Euler_angles

◆ fromEulerAnglesZXZ()

template<class T >
void SLMat4< T >::fromEulerAnglesZXZ ( double  angle1RAD,
double  angle2RAD,
double  angle3RAD,
bool  keepTranslation = true 
)

Sets the linear 3x3 submatrix as a rotation matrix from the 3 euler angles in radians around the z-axis, x-axis & z-axis. By default the translation components are set to 0. See: http://en.wikipedia.org/wiki/Euler_angles

◆ frustum()

template<class T >
void SLMat4< T >::frustum ( l,
r,
b,
t,
n,
f 
)

Defines a view frustum projection matrix equivalent to glFrustum.

Defines a view frustum projection matrix equivalent to OpenGL's glFrustum.

The view frustum is the truncated view pyramid of a central projection that is defined with the folowing parameters:

Parameters
lDistance from the center of projection (COP) to the left border on the near clipping plane.
rDistance from the COP to the right border on the near clipping plane.
bDistance from the COP to the bottom border on the near clipping plane.
tDistance from the COP to the top border on the near clipping plane.
nDistance from the eye to near clipping plane of the view frustum.
fDistance from the eye to far clipping plane of the view frustum.

◆ identity()

template<class T >
void SLMat4< T >::identity

Sets the identity matrix.

◆ inverseTransposed()

template<class T >
SLMat3< T > SLMat4< T >::inverseTransposed

Computes the inverse transposed matrix of the upper left 3x3 matrix for the transformation of vertex normals.

◆ invert()

template<class T >
void SLMat4< T >::invert

Inverts the matrix.

◆ inverted()

template<class T >
SLMat4< T > SLMat4< T >::inverted

Computes the inverse of a 4x4 non-singular matrix.

◆ isEqual()

template<class T >
SLbool SLMat4< T >::isEqual ( const SLMat4< T > &  A,
SLfloat  epsilon = 0.01f 
)

Returns true if one element of the matrix differs more than epsilon.

◆ lightAt() [1/2]

template<class T >
void SLMat4< T >::lightAt ( const SLVec3< T > &  pos,
const SLVec3< T > &  At = SLVec3<T>::ZERO,
const SLVec3< T > &  Up = SLVec3<T>::ZERO 
)

Defines the a model matrix for light positioning.

Defines the a model matrix for positioning a light source.

Utility method for defining the transformation matrix for a spot light. There is no equivalent function for this purpose in OpenGL. /param pos Vector to the position of the light source. /param At Vector to a target point where a spot light shines to.

◆ lightAt() [2/2]

template<class T >
void SLMat4< T >::lightAt ( PosX,
PosY,
PosZ,
AtX = 0,
AtY = 0,
AtZ = 0,
UpX = 0,
UpY = 0,
UpZ = 0 
)

Defines the a model matrix for light positioning.

Defines the a model matrix for positioning a light at pos and shining at At

◆ lookAt() [1/3]

template<class T >
void SLMat4< T >::lookAt ( const SLVec3< T > &  Eye,
const SLVec3< T > &  At = SLVec3<T>::ZERO,
const SLVec3< T > &  Up = SLVec3<T>::ZERO 
)

Defines the a view matrix as the corresponding gluLookAt function.

Defines the view matrix with an eye position, a look at point and an up vector.

This method is equivalent to the OpenGL function gluLookAt.

Parameters
EyeVector to the position of the eye (view point).
AtVector to the target point.
UpVector that points from the viewpoint upwards. If Up is a zero vector a default up vector is calculated with a default look-right vector (VZ) that lies in the x-z plane.

◆ lookAt() [2/3]

template<class T >
void SLMat4< T >::lookAt ( SLVec3< T > *  eye,
SLVec3< T > *  at,
SLVec3< T > *  up,
SLVec3< T > *  ri 
) const

Reads out of the matrix the look at parameters.

This method retrieves the eye position the look at, up & right vector out of the view matrix. Attention: The look-at is normalized vector, not a point.

◆ lookAt() [3/3]

template<class T >
void SLMat4< T >::lookAt ( EyeX,
EyeY,
EyeZ,
AtX = 0,
AtY = 0,
AtZ = 0,
UpX = 0,
UpY = 0,
UpZ = 0 
)

Defines the a view matrix as the corresponding gluLookAt function.

Defines the view matrix with an eye position, a look at point and an up vector.

This method is equivalent to the OpenGL function gluLookAt.

◆ m() [1/3]

template<class T >
const T * SLMat4< T >::m ( ) const
inline

◆ m() [2/3]

template<class T >
T SLMat4< T >::m ( int  i) const
inline

◆ m() [3/3]

template<class T >
void SLMat4< T >::m ( int  i,
val 
)
inline

◆ mat3()

template<class T >
SLMat3< T > SLMat4< T >::mat3 ( ) const
inline

◆ multiply()

template<class T >
void SLMat4< T >::multiply ( const SLMat4< T > &  A)

Multiplies the matrix with a another matrix. Corresponds to the OpenGL function glMultMatrix*.

◆ multVec() [1/2]

template<class T >
SLVec3< T > SLMat4< T >::multVec ( SLVec3< T >  v) const

Matrix - 3D vector multiplication with perspective division

◆ multVec() [2/2]

template<class T >
SLVec4< T > SLMat4< T >::multVec ( SLVec4< T >  v) const

Matrix - 4D vector multiplication

◆ operator()() [1/2]

template<class T >
T & SLMat4< T >::operator() ( int  row,
int  col 
)
inline

◆ operator()() [2/2]

template<class T >
const T & SLMat4< T >::operator() ( int  row,
int  col 
) const
inline

◆ operator*() [1/4]

template<class T >
SLMat4< T > SLMat4< T >::operator* ( const SLMat4< T > &  A) const

matrix-matrix multiplication

Matrix - matrix multiplication

◆ operator*() [2/4]

template<class T >
SLVec3< T > SLMat4< T >::operator* ( const SLVec3< T > &  v) const

SLVec3 mult w. persp div.

Matrix - 3D vector multiplication with perspective division

◆ operator*() [3/4]

template<class T >
SLVec4< T > SLMat4< T >::operator* ( const SLVec4< T > &  v) const

SLVec4 mult.

Matrix - 4D vector multiplication

◆ operator*() [4/4]

template<class T >
SLMat4< T > SLMat4< T >::operator* ( a) const

scalar mult

Scalar multiplication.

◆ operator*=() [1/2]

template<class T >
SLMat4< T > & SLMat4< T >::operator*= ( const SLMat4< T > &  A)

matrix-matrix multiplication

◆ operator*=() [2/2]

template<class T >
SLMat4< T > & SLMat4< T >::operator*= ( a)

scalar mult

Scalar multiplication.

◆ operator+()

template<class T >
SLMat4< T > SLMat4< T >::operator+ ( const SLMat4< T > &  A) const

matrix-matrix addition

◆ operator/()

template<class T >
SLMat4< T > SLMat4< T >::operator/ ( a) const

scalar division

Scalar division.

◆ operator/=()

template<class T >
SLMat4< T > & SLMat4< T >::operator/= ( a)

scalar division

Scalar division.

◆ operator=()

template<class T >
SLMat4< T > & SLMat4< T >::operator= ( const SLMat4< T > &  A)

assignment operator

Matrix assignment with instance

◆ ortho()

template<class T >
void SLMat4< T >::ortho ( l,
r,
b,
t,
n,
f 
)

Defines a orthographic projection matrix with a field of view angle.

Defines a ortographic projection matrix equivalent to OpenGL's glOrtho.

Parameters
lDistance from the center of projection (COP) to the left border on the near clipping plane.
rDistance from the COP to the right border on the near clipping plane.
bDistance from the COP to the bottom border on the near clipping plane.
tDistance from the COP to the top border on the near clipping plane.
nDistance from the eye to near clipping plane of the view frustum.
fDistance from the eye to far clipping plane of the view frustum.

◆ perspective()

template<class T >
void SLMat4< T >::perspective ( fov,
aspect,
n,
f 
)

Defines a perspective projection matrix with a field of view angle.

Defines a view frustum projection matrix for a perspective projection.

This method is equivalent to the OpenGL function gluPerspective except that instead of the window aspect the window width and height have to be passed.

Parameters
fovVertical field of view angle (zoom angle)
aspectaspect ratio of of the viewport = width / height
nDistance from the eye to near clipping plane of the view frustum.
fDistance from the eye to far clipping plane of the view frustum.

◆ perspectiveCenteredPP()

template<class T >
void SLMat4< T >::perspectiveCenteredPP ( w,
h,
fx,
fy,
cx,
cy,
n,
f 
)

Defines a projection matrix for a calibrated camera, the principle point has to be centered (from intrinsics matrix)

Defines a projection matrix for a calibrated camera (from intrinsics matrix) Attention: The principle point has to be centered

This should give an exact result. http://kgeorge.github.io/2014/03/08/calculating-opengl-perspective-matrix-from-opencv-intrinsic-matrix (see also https://stackoverflow.com/questions/22064084/how-to-create-perspective-projection-matrix-given-focal-points-and-camera-princ but the other solutions did not work as well)

◆ posAtUp() [1/2]

template<class T >
void SLMat4< T >::posAtUp ( const SLVec3< T > &  pos,
const SLVec3< T > &  dirAt = SLVec3<T>::ZERO,
const SLVec3< T > &  dirUp = SLVec3<T>::ZERO 
)

Same as lightAt.

◆ posAtUp() [2/2]

template<class T >
void SLMat4< T >::posAtUp ( PosX,
PosY,
PosZ,
dirAtX = 0,
dirAtY = 0,
dirAtZ = 0,
dirUpX = 0,
dirUpY = 0,
dirUpZ = 0 
)

Same as lightAt.

◆ print()

template<class T >
void SLMat4< T >::print ( const SLchar str = nullptr) const

Prints out the matrix row by row.

◆ rotate() [1/3]

template<class T >
void SLMat4< T >::rotate ( const SLVec3< T > &  fromUnitVec,
const SLVec3< T > &  toUnitVec 
)

Multiplies the matrix with a rotation matrix created with a rotation between two vectors.

◆ rotate() [2/3]

template<class T >
void SLMat4< T >::rotate ( degAng,
const SLVec3< T > &  axis 
)

Multiplies the matrix with a rotation matrix. Corresponds to the OpenGL function glRotate*.

◆ rotate() [3/3]

template<class T >
void SLMat4< T >::rotate ( degAng,
axisx,
axisy,
axisz 
)

Multiplies the matrix with a rotation matrix. Corresponds to the OpenGL function glRotate*.

◆ rotation() [1/3]

template<class T >
void SLMat4< T >::rotation ( const SLVec3< T > &  from,
const SLVec3< T > &  to 
)

Defines a rotation matrix that rotates the vector from to the vector to. Code and explanation comes from the paper "Efficiently build a matrix to ratate one vector to another" from Thomas Mueller and John Hughes in the Journal of Graphic Tools, volume 4.

◆ rotation() [2/3]

template<class T >
void SLMat4< T >::rotation ( degAng,
const SLVec3< T > &  axis,
SLbool  keepTranslation = true 
)

Sets the rotation with or without overwriting the translation.

Sets the linear 3x3 submatrix as a rotation matrix with a rotation of degAng degrees around an axis. By default the translation components are set to 0.

◆ rotation() [3/3]

template<class T >
void SLMat4< T >::rotation ( degAng,
axisx,
axisy,
axisz,
SLbool  keepTranslation = true 
)

Sets the linear 3x3 submatrix as a rotation matrix with a rotation of degAng degrees around an axis. By default the translation components are set to 0.

◆ scale() [1/3]

template<class T >
void SLMat4< T >::scale ( const SLVec3< T > &  s)

Multiplies the matrix with a scaling matrix. Corresponds to the OpenGL function glScale*.

◆ scale() [2/3]

template<class T >
void SLMat4< T >::scale ( sx,
sy,
sz 
)

Multiplies the matrix with a scaling matrix. Corresponds to the OpenGL function glScale*.

◆ scale() [3/3]

template<class T >
void SLMat4< T >::scale ( sxyz)

Multiplies the matrix with a scaling matrix. Corresponds to the OpenGL function glScale*.

◆ scaling() [1/3]

template<class T >
void SLMat4< T >::scaling ( const SLVec3< T > &  scale,
SLbool  keepTrans = true 
)

Sets the linear 3x3 submatrix as a scaling matrix with the scaling vector s. By default the translation components are set to 0.

◆ scaling() [2/3]

template<class T >
void SLMat4< T >::scaling ( sx,
sy,
sz,
SLbool  keepTranslation = true 
)

Sets the linear 3x3 submatrix as a scaling matrix with the scaling f_actors sx, sy and sz. By default the translation components are set to 0.

◆ scaling() [3/3]

template<class T >
void SLMat4< T >::scaling ( sxyz,
SLbool  keepTrans = true 
)

Sets the scaling with or without overwriting the translation.

Sets the linear 3x3 submatrix as a scaling matrix with the scaling vector s. By default the translation components are set to 0.

◆ setMatrix() [1/7]

template<class T >
void SLMat4< T >::setMatrix ( const int16_t  i,
const SLfloat  value 
)
inline

◆ setMatrix() [2/7]

template<class T >
void SLMat4< T >::setMatrix ( const SLMat3f A)

Set matrix by other 3x3 matrix.

◆ setMatrix() [3/7]

template<class T >
void SLMat4< T >::setMatrix ( const SLMat4< T > &  A)

Set matrix by other 4x4 matrix.

◆ setMatrix() [4/7]

template<class T >
void SLMat4< T >::setMatrix ( const SLMat4< T > *  A)

Set matrix by other matrix pointer.

◆ setMatrix() [5/7]

template<class T >
void SLMat4< T >::setMatrix ( const SLVec3< T > &  translation,
const SLMat3< T > &  rotation,
const SLVec3< T > &  scale 
)

Set matrix by translation, rotation & scale.

◆ setMatrix() [6/7]

template<class T >
void SLMat4< T >::setMatrix ( const T *  M)

Set matrix by float[16] array.

◆ setMatrix() [7/7]

template<class T >
void SLMat4< T >::setMatrix ( M0,
M4,
M8,
M12,
M1,
M5,
M9,
M13,
M2,
M6,
M10,
M14,
M3,
M7,
M11,
M15 
)

Set matrix by components.

◆ setRotation()

template<class T >
void SLMat4< T >::setRotation ( const SLMat3< T > &  rotation)

Set 3x3 submatrix describing the rotational part.

Parameters
rotationSet 3x3 submatrix describing the rotational part

◆ setTranslation()

template<class T >
void SLMat4< T >::setTranslation ( const SLVec3< T > &  translation)

Set vector as submatrix describing the translational part.

Parameters
translationSet vector as submatrix describing the translational part

◆ swap()

template<class T >
static void SLMat4< T >::swap ( T &  a,
T &  b 
)
inlinestatic

◆ toEulerAngles()

template<class T >
SLVec3< T > SLMat4< T >::toEulerAngles ( int  order)

◆ toEulerAnglesXYZ()

template<class T >
void SLMat4< T >::toEulerAnglesXYZ ( T &  xRotRAD,
T &  yRotRAD,
T &  zRotRAD 
)

Gets one set of possible x-y-z euler angles that will generate this matrix Assumes that upper 3x3 is a rotation matrix Source: Essential Mathematics for Games and Interactive Applications A Programmer's Guide 2nd edition by James M. Van Verth and Lars M. Bishop

◆ toEulerAnglesZYX()

template<class T >
void SLMat4< T >::toEulerAnglesZYX ( T &  zRotRAD,
T &  yRotRAD,
T &  xRotRAD 
)

Gets one set of possible z-y-x euler angles that will generate this matrix Assumes that upper 3x3 is a rotation matrix Source: Essential Mathematics for Games and Interactive Applications A Programmer's Guide 2nd edition by James M. Van Verth and Lars M. Bishop

◆ toString()

template<class T >
SLstring SLMat4< T >::toString

Prints out the matrix row by row.

◆ trace()

template<class T >
T SLMat4< T >::trace
inline

Returns the trace of the matrix that is the sum of the diagonal components.

◆ translate() [1/3]

template<class T >
void SLMat4< T >::translate ( const SLVec2< T > &  t)

Multiplies the matrix with a translation matrix. Corresponds to the OpenGL function glTranslate*.

◆ translate() [2/3]

template<class T >
void SLMat4< T >::translate ( const SLVec3< T > &  t)

Multiplies the matrix with a translation matrix. Corresponds to the OpenGL function glTranslate*.

◆ translate() [3/3]

template<class T >
void SLMat4< T >::translate ( tx,
ty,
tz = 0 
)

Multiplies the matrix with a translation matrix. Corresponds to the OpenGL function glTranslate*.

◆ translation() [1/3]

template<class T >
SLVec3< T > SLMat4< T >::translation ( ) const
inline

◆ translation() [2/3]

template<class T >
void SLMat4< T >::translation ( const SLVec3< T > &  t,
SLbool  keepLinear = true 
)

Sets the translation components. By default the linear 3x3 submatrix containing rotations and scaling is reset to identity.

◆ translation() [3/3]

template<class T >
void SLMat4< T >::translation ( tx,
ty,
tz,
SLbool  keepLinear = true 
)

Sets the translation with or without overwriting the linear submatrix.

Sets the translation components. By default the linear 3x3 submatrix containing rotations and scaling is reset to identity.

◆ transpose()

template<class T >
void SLMat4< T >::transpose

Sets the transposed matrix by swaping around the main diagonal.

◆ transposed()

template<class T >
SLMat4< T > SLMat4< T >::transposed

Returns the transposed of the matrix and leaves the itself unchanged.

◆ viewport()

template<class T >
void SLMat4< T >::viewport ( x,
y,
ww,
wh,
n = 0.0f,
f = 1.0f 
)

Defines the viewport matrix.

Defines a viewport matrix as it will be produced by glViewport.

Parameters
xleft window coord. in px.
ytop window coord. in px.
wwwindow width in px.
whwindow height in px.
nnear depth range (default 0)
ffar depth range (default 1)

Member Data Documentation

◆ _m

template<class T >
T SLMat4< T >::_m[16]
private

The 16 elements of the matrix.


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