Allolib  1.0
C++ Components For Interactive Multimedia
al::Matrix4< T > Class Template Reference

#include <C:/Users/Andres/source/repos/casm_viewer/external/tinc/external/allolib/include/al/math/al_Matrix4.hpp>

Inheritance diagram for al::Matrix4< T >:
al::Mat< 4, double >

Public Types

typedef Mat< 4, T > Base
 

Public Member Functions

 Matrix4 ()
 Default constructor creates an identity matrix.
 
 Matrix4 (const T &r1c1, const T &r1c2, const T &r1c3, const T &r1c4, const T &r2c1, const T &r2c2, const T &r2c3, const T &r2c4, const T &r3c1, const T &r3c2, const T &r3c3, const T &r3c4, const T &r4c1, const T &r4c2, const T &r4c3, const T &r4c4)
 
 Matrix4 (const Vec< 3, T > &xaxis, const Vec< 3, T > &yaxis, const Vec< 3, T > &zaxis, const Vec< 3, T > &position)
 
 Matrix4 (const T *src)
 
 Matrix4 (const Mat< 4, T > &src)
 
Quat< T > toQuat () const
 Get a quaternion representation.
 
Matrix4fromQuat (Quat< T > &q)
 Set from quaternion.
 
Matrix4fromQuatTransposed (Quat< T > &q)
 
Vec< 4, T > transform (const Vec< 4, T > &vCol) const
 Computes product of matrix multiplied by column vector, r = m * vCol. More...
 
Vec< 4, T > transform (const Vec< 3, T > &vCol) const
 Computes product of matrix multiplied by column vector, r = m * vCol.
 
const double * elems () const
 Get read-only pointer to elements.
 
double * elems ()
 Get read-write pointer to elements.
 
double & operator[] (int i)
 Set element at index with no bounds checking.
 
const double & operator[] (int i) const
 Get element at index with no bounds checking.
 
double & operator() (int i, int j)
 Set element at row i, column j.
 
const double & operator() (int i, int j) const
 Get element at row i, column j.
 
Vec< N, double > col (int i) const
 Return column i as vector.
 
Vec< N, double > row (int i) const
 Return row i as vector.
 
Vec< N, double > diagonal () const
 Return diagonal.
 
Mattranspose ()
 Transpose elements.
 
Mat< M, double > sub (int row=0, int col=0) const
 Get an MxM submatrix.
 
Mat< N - 1, double > submatrix (int row, int col) const
 Returns a submatrix by removing one row and column.
 
Vec< N *N, double > & vec ()
 Return matrix punned as a vector.
 
Matoperator*= (const Mat &v)
 
Matoperator*= (const double &v)
 
Matoperator+= (const Mat &v)
 
Matoperator+= (const double &v)
 
Matoperator-= (const Mat &v)
 
Matoperator-= (const double &v)
 
Matoperator/= (const double &v)
 
Mat operator- () const
 
Mat operator- (const Mat &v) const
 
Mat operator- (const double &v) const
 
Mat operator+ (const Mat &v) const
 
Mat operator+ (const double &v) const
 
Mat operator* (const Mat &v) const
 
Mat operator* (const double &v) const
 
Mat operator/ (const double &v) const
 
Matset (const double &v)
 Set all elements to value.
 
Matset (const Mat< N, U > &v)
 Set elements from another matrix.
 
Matset (const U *arr)
 Set elements in column-major order from C array.
 
Matset (const U *arr, int numElements, int matOffset, int matStride=1)
 Set elements in column-major order from C array. More...
 
Matset (const double &r1c1, const double &r1c2, const double &r2c1, const double &r2c2, int row=0, int col=0)
 Set 2-by-2 (sub)matrix from arguments.
 
Matset (const double &r1c1, const double &r1c2, const double &r1c3, const double &r2c1, const double &r2c2, const double &r2c3, const double &r3c1, const double &r3c2, const double &r3c3, int row=0, int col=0)
 Set 3-by-3 (sub)matrix from arguments.
 
Matset (const double &r1c1, const double &r1c2, const double &r1c3, const double &r1c4, const double &r2c1, const double &r2c2, const double &r2c3, const double &r2c4, const double &r3c1, const double &r3c2, const double &r3c3, const double &r3c4, const double &r4c1, const double &r4c2, const double &r4c3, const double &r4c4, int row=0, int col=0)
 Set 4-by-4 (sub)matrix from arguments.
 
MatsetCol2 (const double &v1, const double &v2, int col=0, int row=0)
 Set a (sub)column.
 
MatsetCol3 (const double &v1, const double &v2, const double &v3, int col=0, int row=0)
 Set a (sub)column.
 
MatsetCol4 (const double &v1, const double &v2, const double &v3, const double &v4, int col=0, int row=0)
 Set a (sub)column.
 
MatsetIdentity ()
 Set elements on diagonal to one and all others to zero.
 
double cofactor (int row, int col) const
 Get cofactor.
 
Mat< N, double > cofactorMatrix () const
 Get cofactor matrix.
 
double trace () const
 Get trace (sum of diagonal elements)
 
Mat< N, double > inversed () const
 
Matrotate (double angle, int dim1, int dim2)
 Rotate transformation matrix on a local plane (A' = AR) More...
 
MatrotateGlobal (double angle, int dim1, int dim2)
 Rotate submatrix on a global plane (A' = RA)
 
MatrotateGlobal (double angle, int dim1, int dim2)
 Rotate transformation matrix on a global plane (A' = RA)
 
Matscale (const Vec< N - 1, V > &amount)
 Scale transformation matrix.
 
Matscale (Vals... vals)
 Scale transformation matrix.
 
MatscaleGlobal (const Vec< N - 1, V > &amount)
 Scale transformation matrix global coordinates.
 
Mattranslate (const Vec< N - 1, V > &amount)
 Translate transformation matrix.
 
Mattranslate (const V &amount)
 Translate transformation matrix by same amount in all directions.
 
Mattranslate (Vals... vals)
 Translate transformation matrix.
 
void print (std::ostream &stream) const
 Print to file (stream)
 

Static Public Member Functions

static Matrix4 rotate (float angle, float x, float y, float z)
 
static Matrix4 rotate (float angle, const Vec< 3, T > &v)
 
static Matrix4 shearXY (T x, T y)
 Get a shear transformation matrix on the xy plane.
 
static Matrix4 shearYZ (T y, T z)
 Get a shear transformation matrix on the yz plane.
 
static Matrix4 shearZX (T z, T x)
 Get a shear transformation matrix on the zx plane.
 
static Matrix4 perspective (T l, T r, T b, T t, T n, T f)
 Get a perspective projection matrix. More...
 
static Matrix4 perspective (T fovy, T aspect, T near, T far)
 Get a perspective projection matrix. More...
 
static Matrix4 perspective (const Vec< 3, T > &nearBL, const Vec< 3, T > &nearBR, const Vec< 3, T > &nearTL, const Vec< 3, T > &eye, T near, T far)
 Calculate perspective projection from near plane and eye coordinates. More...
 
static Matrix4 perspectiveLeft (T fovy, T aspect, T near, T far, T eyeSep, T focal)
 Get a left-eye perspective projection matrix (for stereographics)
 
static Matrix4 perspectiveRight (T fovy, T aspect, T near, T far, T eyeSep, T focal)
 Get a right-eye perspective projection matrix (for stereographics)
 
static Matrix4 perspectiveOffAxis (T fovy, T aspect, T near, T far, T xShift, T focal)
 Get an off-axis perspective projection matrix (for stereographics)
 
static Matrix4 perspectiveOffAxis (T fovy, T aspect, T near, T far, T xShift, T yShift, T focal)
 Get an off-axis perspective projection matrix (for stereographics) More...
 
static Matrix4 unPerspective (T l, T r, T b, T t, T n, T f)
 
static Matrix4 ortho (T l, T r, T b, T t, T n, T f)
 Get an orthographic projection matrix. More...
 
static Matrix4 unOrtho (T l, T r, T b, T t, T n, T f)
 
static Matrix4 ortho2D (T l, T r, T b, T t)
 Get a two-dimensional orthographic projection matrix. More...
 
static Matrix4 lookAt (const Vec< 3, T > &ur, const Vec< 3, T > &uu, const Vec< 3, T > &uf, const Vec< 3, T > &eyePos)
 Get a viewing matrix based on an eye reference frame. More...
 
static Matrix4 lookAt (const Vec< 3, T > &eyePos, const Vec< 3, T > &at, const Vec< 3, T > &up)
 Get a viewing matrix based on look-at parameters. More...
 
static Matrix4 lookAtLeft (const Vec< 3, T > &ux, const Vec< 3, T > &uy, const Vec< 3, T > &uz, const Vec< 3, T > &pos, double eyeSep)
 Get a left-eye viewing matrix.
 
static Matrix4 lookAtRight (const Vec< 3, T > &ux, const Vec< 3, T > &uy, const Vec< 3, T > &uz, const Vec< 3, T > &pos, double eyeSep)
 Get a right-eye viewing matrix.
 
static Matrix4 lookAtOffAxis (const Vec< 3, T > &ux, const Vec< 3, T > &uy, const Vec< 3, T > &uz, const Vec< 3, T > &pos, double eyeShift)
 Get an off-axis viewing matrix.
 
static Matrix4 inverse (const Mat< 4, T > &m)
 Get the inverse of a matrix.
 
static Matrix4 translate (T x, T y, T z)
 
template<typename V >
static Matrix4 translate (const Vec< 3, V > &v)
 
static Matrix4 scale (T x, T y, T z)
 
template<typename V >
static Matrix4 scale (const Vec< 3, V > &v)
 
template<typename V >
static Matrix4 scale (const V &v)
 
static Matrix4 rotateXY (T theta)
 
static Matrix4 rotateYZ (T theta)
 
static Matrix4 rotateZX (T theta)
 
static Mat identity ()
 Get identity matrix.
 
static Mat rotation (double angle, int dim1, int dim2)
 Get a rotation transform matrix.
 
static Mat scaling (const Vec< N - 1, V > &v)
 Get a scaling transform matrix.
 
static Mat scaling (V v)
 Get a scaling transform matrix.
 
static Mat scaling (Vals... vals)
 Get a scaling transform matrix.
 
static Mat translation (const Vec< N - 1, V > &v)
 Get a translation transform matrix.
 
static Mat translation (Vals... vals)
 Get a translation transform matrix.
 
static Matpun (double *src)
 Returns C array type punned into a matrix.
 
static const Matpun (const double *src)
 
static int size ()
 Returns total number of elements.
 
static Matmultiply (Mat &r, const Mat &a, const Mat &b)
 Computes matrix product r = a * b. More...
 
static Vec< N, U > & multiply (Vec< N, U > &r, const Mat &m, const Vec< N, U > &vCol)
 Computes product of matrix multiplied by column vector, r = m * vCol.
 
static Vec< N, U > & multiply (Vec< N, U > &r, const Vec< N, U > &vRow, const Mat &m)
 Computes product of row vector multiplied by matrix, r = vRow * m.
 

Public Attributes

double mElems [N *N]
 Column-major array of elements.
 

Detailed Description

template<typename T = double>
class al::Matrix4< T >

4x4 Matrix (Homogenous Transform)

Definition at line 63 of file al_Matrix4.hpp.

Constructor & Destructor Documentation

◆ Matrix4() [1/2]

template<typename T = double>
al::Matrix4< T >::Matrix4 ( const T *  src)
inline
Parameters
[in]srcC-array to copy values from

Definition at line 99 of file al_Matrix4.hpp.

◆ Matrix4() [2/2]

template<typename T = double>
al::Matrix4< T >::Matrix4 ( const Mat< 4, T > &  src)
inline
Parameters
[in]srcmatrix to copy values from

Definition at line 102 of file al_Matrix4.hpp.

Member Function Documentation

◆ lookAt() [1/2]

template<typename T = double>
static Matrix4 al::Matrix4< T >::lookAt ( const Vec< 3, T > &  eyePos,
const Vec< 3, T > &  at,
const Vec< 3, T > &  up 
)
inlinestatic

Get a viewing matrix based on look-at parameters.

Parameters
[in]eyePoseye position
[in]atpoint being looked at
[in]upup vector

Definition at line 368 of file al_Matrix4.hpp.

◆ lookAt() [2/2]

template<typename T = double>
static Matrix4 al::Matrix4< T >::lookAt ( const Vec< 3, T > &  ur,
const Vec< 3, T > &  uu,
const Vec< 3, T > &  uf,
const Vec< 3, T > &  eyePos 
)
inlinestatic

Get a viewing matrix based on an eye reference frame.

Parameters
[in]ureye right unit direction vector
[in]uueye up unit direction vector
[in]ufeye forward unit direction vector
[in]eyePoseye position

Definition at line 356 of file al_Matrix4.hpp.

◆ multiply()

static Mat& al::Mat< N, double >::multiply ( Mat< 4, double > &  r,
const Mat< 4, double > &  a,
const Mat< 4, double > &  b 
)
inlinestaticinherited

Computes matrix product r = a * b.

Returns reference to result

Definition at line 305 of file al_Mat.hpp.

◆ ortho()

template<typename T = double>
static Matrix4 al::Matrix4< T >::ortho ( l,
r,
b,
t,
n,
f 
)
inlinestatic

Get an orthographic projection matrix.

Parameters
[in]lcoordinate of left clipping plane
[in]rcoordinate of right clipping plane
[in]bcoordinate of bottom clipping plane
[in]tcoordinate of top clipping plane
[in]ncoordinate of near clipping plane
[in]fcoordinate of far clipping plane

Definition at line 312 of file al_Matrix4.hpp.

◆ ortho2D()

template<typename T = double>
static Matrix4 al::Matrix4< T >::ortho2D ( l,
r,
b,
t 
)
inlinestatic

Get a two-dimensional orthographic projection matrix.

This is identical to ortho with -1, 1 for the near, far distances.

Parameters
[in]lcoordinate of left clipping plane
[in]rcoordinate of right clipping plane
[in]bcoordinate of bottom clipping plane
[in]tcoordinate of top clipping plane

Definition at line 341 of file al_Matrix4.hpp.

◆ perspective() [1/3]

template<typename T = double>
static Matrix4 al::Matrix4< T >::perspective ( const Vec< 3, T > &  nearBL,
const Vec< 3, T > &  nearBR,
const Vec< 3, T > &  nearTL,
const Vec< 3, T > &  eye,
near,
far 
)
inlinestatic

Calculate perspective projection from near plane and eye coordinates.

(nearBL, nearBR, nearTL, eye) all share the same coordinate system (nearBR,nearBL) and (nearTL,nearBL) should form a right angle (eye) can be set freely, allowing diverse off-axis projections

See also
Generalized Perspective Projection, Robert Kooima, 2009, EVL
Parameters
[in]nearBLbottom-left near-plane coordinate (world-space)
[in]nearBRbottom-right near-plane coordinate (world-space)
[in]nearTLtop-left near-plane coordinate (world-space)
[in]eyeeye coordinate (world-space)
[in]nearnear plane distance from eye
[in]farfar plane distance from eye

Definition at line 208 of file al_Matrix4.hpp.

◆ perspective() [2/3]

template<typename T = double>
static Matrix4 al::Matrix4< T >::perspective ( fovy,
aspect,
near,
far 
)
inlinestatic

Get a perspective projection matrix.

Parameters
[in]fovyfield of view angle, in degrees, in the y direction
[in]aspectaspect ratio
[in]neardistance from eye to near plane
[in]fardistance from eye to far plane

Definition at line 187 of file al_Matrix4.hpp.

◆ perspective() [3/3]

template<typename T = double>
static Matrix4 al::Matrix4< T >::perspective ( l,
r,
b,
t,
n,
f 
)
inlinestatic

Get a perspective projection matrix.

Parameters
[in]ldistance from center of near plane to left edge
[in]rdistance from center of near plane to right edge
[in]bdistance from center of near plane to bottom edge
[in]tdistance from center of near plane to top edge
[in]ndistance from eye to near plane
[in]fdistance from eye to far plane

Definition at line 168 of file al_Matrix4.hpp.

◆ perspectiveOffAxis()

template<typename T = double>
static Matrix4 al::Matrix4< T >::perspectiveOffAxis ( fovy,
aspect,
near,
far,
xShift,
yShift,
focal 
)
inlinestatic

Get an off-axis perspective projection matrix (for stereographics)

Parameters
[in]fovyfield of view angle, in degrees, in the y direction
[in]aspectaspect ratio
[in]nearnear clipping plane coordinate
[in]farfar clipping plane coordinate
[in]xShiftamount to shift off x-axis
[in]yShiftamount to shift off y-axis
[in]focalfocal length

Definition at line 273 of file al_Matrix4.hpp.

◆ rotate()

Mat& al::Mat< N, double >::rotate ( double  angle,
int  dim1,
int  dim2 
)
inlineinherited

Rotate transformation matrix on a local plane (A' = AR)

Parameters
[in]angleangle of rotation, in radians
[in]dim1local coordinate frame axis to rotate away from
[in]dim2local coordinate frame axis to rotate towards

Definition at line 470 of file al_Mat.hpp.

◆ set()

Mat& al::Mat< N, double >::set ( const U *  arr,
int  numElements,
int  matOffset,
int  matStride = 1 
)
inlineinherited

Set elements in column-major order from C array.

Parameters
[in]arr1D array from which to copy (stride=1)
[in]numElementsnumber of elements to copy
[in]matOffsetindex offset into matrix
[in]matStrideamount to stride through matrix

Definition at line 357 of file al_Mat.hpp.

◆ transform()

template<typename T = double>
Vec<4, T> al::Matrix4< T >::transform ( const Vec< 4, T > &  vCol) const
inline

Computes product of matrix multiplied by column vector, r = m * vCol.

This is typically what is required to project a vertex through a transform. For a better explanation,

See also
http://xkcd.com/184/ -g

Definition at line 420 of file al_Matrix4.hpp.


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