| TGX 1.0.8 A tiny 2D/3D graphics library optimized for 32 bits microcontrollers.

Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | List of all members
tgx::Mat4< T > Struct Template Reference

Generic 4x4 matrix [specializations fMat4, dMat4]. More...

`#include <Mat4.h>`

## Public Member Functions
| Mat4 ()
| Default constructor. More...
constexpr | Mat4 (T x1, T y1, T z1, T t1, T x2, T y2, T z2, T t2, T x3, T y3, T z3, T t3, T x4, T y4, T z4, T t4)
| Constructor from explicit values.
| Mat4 (const T *mat)
| Constructor from an array (with column major ordering same as `M`).
| Mat4 (const Mat4 &mat)=default
| Copy constructor.
Mat4 & | operator= (const Mat4 &mat)=default
| Assignement operator.
| operator T* ()
| Implicit conversion to an array T[16].
void | setZero ()
| Set as the null matrix (all coefficients equal 0).
void | setIdentity ()
| Set as the identity matrix.
void | setOrtho (T left, T right, T bottom, T top, T zNear, T zFar)
| Set as an orthographic projection matrix. More...
void | setFrustum (T left, T right, T bottom, T top, T zNear, T zFar)
| Set as a perspective projection matrix. More...
void | setPerspective (T fovy, T aspect, T zNear, T zFar)
| Set as a perspective projection matrix. More...
void | setRotate (T angle, T x, T y, T z)
| Set as a rotation matrix. More...
void | setRotate (T angle, const Vec3< T > v)
| Set as a rotation matrix. More...
void | multRotate (T angle, T x, T y, T z)
| Pre-multiply this matrix by a rotation matrix. More...
void | multRotate (T angle, const Vec3< T > v)
| Pre-multiply this matrix by a rotation matrix. More...
void | setTranslate (T x, T y, T z)
| Set as a translation matrix. More...
void | setTranslate (const Vec3< T > v)
| Set as a translation matrix. More...
void | multTranslate (T x, T y, T z)
| Pre-multiply this matrix by a translation matrix. More...
void | multTranslate (const Vec3< T > v)
| Pre-multiply this matrix by a translation matrix. More...
void | setScale (T x, T y, T z)
| Set as a dilatation matrix. More...
void | setScale (const Vec3< T > v)
| Set as a dilatation matrix. More...
void | multScale (T x, T y, T z)
| Pre-multiply this matrix by a dilatation matrix. More...
void | multScale (const Vec3< T > v)
| Pre-multiply this matrix by a dilatation matrix. More...
void | invertYaxis ()
| invert the y axis, same as multScale({1,-1,1})
void | setLookAt (T eyeX, T eyeY, T eyeZ, T centerX, T centerY, T centerZ, T upX, T upY, T upZ)
| Set the matrix for a camera looking at a given direction. More...
void | setLookAt (const Vec3< T > eye, const Vec3< T > center, const Vec3< T > up)
| Set the matrix for a camera looking at a given direction. More...
TGX_INLINE Vec4< T > | mult (const Vec4< T > V) const
| Matrix-vector multiplication.
TGX_INLINE Vec4< T > | mult (const Vec3< T > &V, float w) const
| Matrix-vector multiplication.
TGX_INLINE Vec4< T > | mult0 (const Vec3< T > &V) const
| Matrix-vector multiplication (last component of vector set to w = 0).
TGX_INLINE Vec4< T > | mult1 (const Vec3< T > &V) const
| Matrix-vector multiplication (last component of vector set to w = 1)
void | operator*= (T a)
| Scalar multiplication.
void | transpose ()
| Transpose the matrix (in place)

## Public Attributes
T | M [16]
| The matrix array in column major ordering: More...

## Detailed Description

template<typename T>
struct tgx::Mat4< T >

Generic 4x4 matrix [specializations fMat4, dMat4].

The class encapsulate a 4x4 matrix with element of type `T` which must be a floating point type (either `float` or `double`). Such a matrix is used in 3D grpahics to represent a transformation (translation, rotation, dilatation...).

The matrix is internally represented by an public array `M[16]` in column major ordering:

+-----------------------------+
| M[0] | M[4] | M[8] | M[12] |
|------+------+-------+-------|
| M[1] | M[5] | M[9] | M[13] |
|------+------+-------+-------|
| M[2] | M[6] | M[10] | M[14] |
|------+------+-------+-------|
| M[3] | M[7] | M[11] | M[15] |
+-----------------------------+
tgx::Mat4::M
T M[16]
The matrix array in column major ordering:
Definition: Mat4.h:114

See also
  Vec2, Vec3, Vec4

## Constructor & Destructor Documentation

## ◆ Mat4()

template<typename T >

tgx::Mat4< T >::Mat4 | ( |  | ) |
| inline

Default constructor.

the matrix content is undefined.

## Member Function Documentation

## ◆ setOrtho()

template<typename T >

void tgx::Mat4< T >::setOrtho | ( | T | left,
|  | T | right,
|  | T | bottom,
|  | T | top,
|  | T | zNear,
|  | T | zFar
| ) |  |
| inline

Set as an orthographic projection matrix.

https://www.khronos.org/registry/OpenGL-Refpages/gl2.1/xhtml/glOrtho.xml

Parameters

  left,right | coordinates for the left and right vertical clipping planes
  bottom,top | coordinates for the bottom and top horizontal clipping planes.
  zNear,zFar | distances to the nearer and farther depth clipping planes.

## ◆ setFrustum()

template<typename T >

void tgx::Mat4< T >::setFrustum | ( | T | left,
|  | T | right,
|  | T | bottom,
|  | T | top,
|  | T | zNear,
|  | T | zFar
| ) |  |
| inline

Set as a perspective projection matrix.

https://www.khronos.org/registry/OpenGL-Refpages/gl2.1/xhtml/glFrustum.xml

Parameters

  left,right | coordinates for the left and right vertical clipping planes
  bottom,top | coordinates for the bottom and top horizontal clipping planes.
  zNear,zFar | distances to the nearer and farther depth clipping planes.

## ◆ setPerspective()

template<typename T >

void tgx::Mat4< T >::setPerspective | ( | T | fovy,
|  | T | aspect,
|  | T | zNear,
|  | T | zFar
| ) |  |
| inline

Set as a perspective projection matrix.

https://www.khronos.org/registry/OpenGL-Refpages/gl2.1/xhtml/gluPerspective.xml

Parameters

  fovy | field of view angle, in degrees, in the y direction.
  aspect | aspect ratio that determines the field of view in the x direction. The aspect ratio is the ratio of x (width) to y (height).
  zNear | distance from the viewer to the near clipping plane.
  zFar | distance from the viewer to the far clipping plane.

## ◆ setRotate() [1/2]

template<typename T >

void tgx::Mat4< T >::setRotate | ( | T | angle,
|  | T | x,
|  | T | y,
|  | T | z
| ) |  |
| inline

Set as a rotation matrix.

https://www.khronos.org/registry/OpenGL-Refpages/gl2.1/xhtml/glRotate.xml

Parameters

  angle | rotation angle in degrees.
  x,y,z | coordinates of the direction vector for the rotation.

## ◆ setRotate() [2/2]

template<typename T >

void tgx::Mat4< T >::setRotate | ( | T | angle,
|  | const Vec3< T > | v
| ) |  |
| inline

Set as a rotation matrix.

https://www.khronos.org/registry/OpenGL-Refpages/gl2.1/xhtml/glRotate.xml

Parameters

  angle | rotation angle in degrees.
  v | direction vector for the rotation.

## ◆ multRotate() [1/2]

template<typename T >

void tgx::Mat4< T >::multRotate | ( | T | angle,
|  | T | x,
|  | T | y,
|  | T | z
| ) |  |
| inline

Pre-multiply this matrix by a rotation matrix.

https://www.khronos.org/registry/OpenGL-Refpages/gl2.1/xhtml/glRotate.xml

Parameters

  angle | rotation angle in degrees.
  x,y,z | coordinates of the direction vector for the rotation.

## ◆ multRotate() [2/2]

template<typename T >

void tgx::Mat4< T >::multRotate | ( | T | angle,
|  | const Vec3< T > | v
| ) |  |
| inline

Pre-multiply this matrix by a rotation matrix.

https://www.khronos.org/registry/OpenGL-Refpages/gl2.1/xhtml/glRotate.xml

Parameters

  angle | rotation angle in degrees.
  v | direction vector for the rotation.

## ◆ setTranslate() [1/2]

template<typename T >

void tgx::Mat4< T >::setTranslate | ( | T | x,
|  | T | y,
|  | T | z
| ) |  |
| inline

Set as a translation matrix.

https://www.khronos.org/registry/OpenGL-Refpages/gl2.1/xhtml/glTranslate.xml

Parameters

  x,y,z | coordinates of the translation vector.

## ◆ setTranslate() [2/2]

template<typename T >

void tgx::Mat4< T >::setTranslate | ( | const Vec3< T > | v | ) |
| inline

Set as a translation matrix.

https://www.khronos.org/registry/OpenGL-Refpages/gl2.1/xhtml/glTranslate.xml

Parameters

  v | the translation vector.

## ◆ multTranslate() [1/2]

template<typename T >

void tgx::Mat4< T >::multTranslate | ( | T | x,
|  | T | y,
|  | T | z
| ) |  |
| inline

Pre-multiply this matrix by a translation matrix.

https://www.khronos.org/registry/OpenGL-Refpages/gl2.1/xhtml/glTranslate.xml

Parameters

  x,y,z | coordinates of the translation vector.

## ◆ multTranslate() [2/2]

template<typename T >

void tgx::Mat4< T >::multTranslate | ( | const Vec3< T > | v | ) |
| inline

Pre-multiply this matrix by a translation matrix.

https://www.khronos.org/registry/OpenGL-Refpages/gl2.1/xhtml/glTranslate.xml

Parameters

  v | the translation vector.

## ◆ setScale() [1/2]

template<typename T >

void tgx::Mat4< T >::setScale | ( | T | x,
|  | T | y,
|  | T | z
| ) |  |
| inline

Set as a dilatation matrix.

https://www.khronos.org/registry/OpenGL-Refpages/gl2.1/xhtml/glScale.xml

Parameters

  x,y,z | scale factors along the x, y, and z axes respectively.

## ◆ setScale() [2/2]

template<typename T >

void tgx::Mat4< T >::setScale | ( | const Vec3< T > | v | ) |
| inline

Set as a dilatation matrix.

https://www.khronos.org/registry/OpenGL-Refpages/gl2.1/xhtml/glScale.xml

Parameters

  v | vector representing the scale factors along each axis.

## ◆ multScale() [1/2]

template<typename T >

void tgx::Mat4< T >::multScale | ( | T | x,
|  | T | y,
|  | T | z
| ) |  |
| inline

Pre-multiply this matrix by a dilatation matrix.

https://www.khronos.org/registry/OpenGL-Refpages/gl2.1/xhtml/glScale.xml

Parameters

  x,y,z | scale factors along the x, y, and z axes respectively.

## ◆ multScale() [2/2]

template<typename T >

void tgx::Mat4< T >::multScale | ( | const Vec3< T > | v | ) |
| inline

Pre-multiply this matrix by a dilatation matrix.

https://www.khronos.org/registry/OpenGL-Refpages/gl2.1/xhtml/glScale.xml

Parameters

  v | vector representing the scale factors along each axis.

## ◆ setLookAt() [1/2]

template<typename T >

void tgx::Mat4< T >::setLookAt | ( | T | eyeX,
|  | T | eyeY,
|  | T | eyeZ,
|  | T | centerX,
|  | T | centerY,
|  | T | centerZ,
|  | T | upX,
|  | T | upY,
|  | T | upZ
| ) |  |
| inline

Set the matrix for a camera looking at a given direction.

https://www.khronos.org/registry/OpenGL-Refpages/gl2.1/xhtml/gluLookAt.xml

The formula given by khronos is wrong ! The cross-product of two unit vectors is not normalized.

See https://stackoverflow.com/questions/30409318/lookat-matrix-distorts-when-looking-up-or-down

Parameters

  eyeX,eyeY,eyeZ | position of the eye point.
  centerX,centerY,centerZ | position of the reference point (the camera points toward this point).
  upX,upY,upZ | direction of the up vector.

## ◆ setLookAt() [2/2]

template<typename T >

void tgx::Mat4< T >::setLookAt | ( | const Vec3< T > | eye,
|  | const Vec3< T > | center,
|  | const Vec3< T > | up
| ) |  |
| inline

Set the matrix for a camera looking at a given direction.

https://www.khronos.org/registry/OpenGL-Refpages/gl2.1/xhtml/gluLookAt.xml

The formula given by khronos is wrong ! The cross-product of two unit vectors is not normalized.

See https://stackoverflow.com/questions/30409318/lookat-matrix-distorts-when-looking-up-or-down

Parameters

  eye | eye position.
  center | reference point (the camera points toward this point).
  up | up vector.

## Member Data Documentation

## ◆ M

template<typename T >

T tgx::Mat4< T >::M[16]

The matrix array in column major ordering:

+-----------------------------+
| M[0] | M[4] | M[8] | M[12] |
|------+------+-------+-------|
| M[1] | M[5] | M[9] | M[13] |
|------+------+-------+-------|
| M[2] | M[6] | M[10] | M[14] |
|------+------+-------+-------|
| M[3] | M[7] | M[11] | M[15] |
+-----------------------------+

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

- src/Mat4.h