MathFu
An open source project by FPL.
 All Classes Namespaces Files Functions Variables Typedefs Friends Groups Pages
mathfu::Matrix< T, rows, columns > Class Template Reference

Matrix stores a set of "rows" by "columns" elements of type T and provides functions that operate on the set of elements. More...

#include <matrix.h>

Detailed Description

template<class T, int rows, int columns>
class mathfu::Matrix< T, rows, columns >

Matrix stores a set of "rows" by "columns" elements of type T and provides functions that operate on the set of elements.

Template Parameters
Ttype of each element in the matrix.
rowsNumber of rows in the matrix.
columnsNumber of columns in the matrix.

Public Member Functions

 Matrix ()
 Construct a Matrix of uninitialized values.
 
 Matrix (const Matrix< T, rows, columns > &m)
 Construct a Matrix from another Matrix copying each element. /. More...
 
 Matrix (const T &s)
 Construct a Matrix from a single float. More...
 
 Matrix (const T &s00, const T &s10, const T &s01, const T &s11)
 Construct a Matrix from four floats. More...
 
 Matrix (const T &s00, const T &s10, const T &s20, const T &s01, const T &s11, const T &s21, const T &s02, const T &s12, const T &s22)
 Create a Matrix from nine floats. More...
 
 Matrix (const T &s00, const T &s10, const T &s20, const T &s30, const T &s01, const T &s11, const T &s21, const T &s31, const T &s02, const T &s12, const T &s22, const T &s32)
 Creates a Matrix from twelve floats. More...
 
 Matrix (const T &s00, const T &s10, const T &s20, const T &s30, const T &s01, const T &s11, const T &s21, const T &s31, const T &s02, const T &s12, const T &s22, const T &s32, const T &s03, const T &s13, const T &s23, const T &s33)
 Create a Matrix from sixteen floats. More...
 
 Matrix (const Vector< T, 4 > &column0, const Vector< T, 4 > &column1, const Vector< T, 4 > &column2, const Vector< T, 4 > &column3)
 Create 4x4 Matrix from 4, 4 element vectors. More...
 
 Matrix (const T *const a)
 Create a Matrix from the first row * column elements of an array. More...
 
 Matrix (const VectorPacked< T, rows > *const vectors)
 Create a Matrix from an array of "columns", "rows" element packed vectors. More...
 
const T & operator() (const int row, const int column) const
 Access an element of the matrix. More...
 
T & operator() (const int row, const int column)
 Access an element of the Matrix. More...
 
const T & operator() (const int i) const
 Access an element of the Matrix. More...
 
T & operator() (const int i)
 Access an element of the Matrix. More...
 
const T & operator[] (const int i) const
 Access an element of the Matrix. More...
 
T & operator[] (const int i)
 Access an element of the Matrix. More...
 
void Pack (VectorPacked< T, rows > *const vector) const
 Pack the matrix to an array of "rows" element vectors, one vector per matrix column. More...
 
Matrix< T, rows, columns > operator- () const
 Negate this Matrix. More...
 
Matrix< T, rows, columns > operator+ (const Matrix< T, rows, columns > &m) const
 Add a Matrix to this Matrix. More...
 
Matrix< T, rows, columns > operator- (const Matrix< T, rows, columns > &m) const
 Subtract a Matrix from this Matrix. More...
 
Matrix< T, rows, columns > operator+ (const T &s) const
 Add a scalar to each element of this Matrix. More...
 
Matrix< T, rows, columns > operator- (const T &s) const
 Subtract a scalar from each element of this Matrix. More...
 
Matrix< T, rows, columns > operator* (const T &s) const
 Multiply each element of this Matrix with a scalar. More...
 
Matrix< T, rows, columns > operator/ (const T &s) const
 Divide each element of this Matrix with a scalar. More...
 
Matrix< T, rows, columns > operator* (const Matrix< T, rows, columns > &m) const
 Multiply this Matrix with another Matrix. More...
 
Matrix< T, rows, columns > & operator+= (const Matrix< T, rows, columns > &m)
 Add a Matrix to this Matrix (in-place). More...
 
Matrix< T, rows, columns > & operator-= (const Matrix< T, rows, columns > &m)
 Subtract a Matrix from this Matrix (in-place). More...
 
Matrix< T, rows, columns > & operator+= (const T &s)
 Add a scalar to each element of this Matrix (in-place). More...
 
Matrix< T, rows, columns > & operator-= (const T &s)
 Subtract a scalar from each element of this Matrix (in-place). More...
 
Matrix< T, rows, columns > & operator*= (const T &s)
 Multiply each element of this Matrix with a scalar (in-place). More...
 
Matrix< T, rows, columns > & operator/= (const T &s)
 Divide each element of this Matrix by a scalar (in-place). More...
 
Matrix< T, rows, columns > & operator*= (const Matrix< T, rows, columns > &m)
 Multiply this Matrix with another Matrix (in-place). More...
 
Matrix< T, rows, columns > Inverse () const
 Calculate the inverse of this Matrix. More...
 
bool InverseWithDeterminantCheck (Matrix< T, rows, columns > *const inverse) const
 Calculate the inverse of this Matrix. More...
 
Matrix< T, columns, rows > Transpose () const
 Calculate the transpose of this Matrix. More...
 
Vector< T, 2 > TranslationVector2D () const
 Get the 2-dimensional translation of a 2-dimensional affine transform. More...
 
Vector< T, 3 > TranslationVector3D () const
 Get the 3-dimensional translation of a 3-dimensional affine transform. More...
 

Static Public Member Functions

template<typename CompatibleT >
static Matrix< T, rows, columns > FromType (const CompatibleT &compatible)
 Load from any byte-wise compatible external matrix. More...
 
template<typename CompatibleT >
static CompatibleT ToType (const Matrix< T, rows, columns > &m)
 Load into any byte-wise compatible external matrix. More...
 
static Matrix< T, rows, columns > OuterProduct (const Vector< T, rows > &v1, const Vector< T, columns > &v2)
 Calculate the outer product of two Vectors. More...
 
static Matrix< T, rows, columns > HadamardProduct (const Matrix< T, rows, columns > &m1, const Matrix< T, rows, columns > &m2)
 Calculate the hadamard / component-wise product of two matrices. More...
 
static Matrix< T, rows, columns > Identity ()
 Calculate the identity Matrix. More...
 
static Matrix< T, 3 > FromTranslationVector (const Vector< T, 2 > &v)
 Create a 3x3 translation Matrix from a 2-dimensional Vector. More...
 
static Matrix< T, 4 > FromTranslationVector (const Vector< T, 3 > &v)
 Create a 4x4 translation Matrix from a 3-dimensional Vector. More...
 
static Matrix< T, rows > FromScaleVector (const Vector< T, rows-1 > &v)
 Create a square Matrix with the diagonal component set to v. More...
 
static Matrix< T, 4 > FromRotationMatrix (const Matrix< T, 3 > &m)
 Create a 4x4 Matrix from a 3x3 rotation Matrix. More...
 
static Matrix< T, 3 > ToRotationMatrix (const Matrix< T, 4 > &m)
 Extracts the 3x3 rotation Matrix from a 4x4 Matrix. More...
 
static Matrix< T, 4 > FromAffineTransform (const Matrix< T, 4, 3 > &affine)
 Constructs a Matrix<float, 4> from an AffineTransform. More...
 
static Matrix< T, 4, 3 > ToAffineTransform (const Matrix< T, 4 > &m)
 Converts a Matrix<float, 4> into an AffineTransform. More...
 
static Matrix< T, 3 > RotationX (const Vector< T, 2 > &v)
 Create a 3x3 rotation Matrix from a 2D normalized directional Vector around the X axis. More...
 
static Matrix< T, 3 > RotationY (const Vector< T, 2 > &v)
 Create a 3x3 rotation Matrix from a 2D normalized directional Vector around the Y axis. More...
 
static Matrix< T, 3 > RotationZ (const Vector< T, 2 > &v)
 Create a 3x3 rotation Matrix from a 2D normalized directional Vector around the Z axis. More...
 
static Matrix< T, 3 > RotationX (T angle)
 Create a 3x3 rotation Matrix from an angle (in radians) around the X axis. More...
 
static Matrix< T, 3 > RotationY (T angle)
 Create a 3x3 rotation Matrix from an angle (in radians) around the Y axis. More...
 
static Matrix< T, 3 > RotationZ (T angle)
 Create a 3x3 rotation Matrix from an angle (in radians) around the Z axis. More...
 
static Matrix< T, 4, 4 > Perspective (T fovy, T aspect, T znear, T zfar, T handedness=1)
 Create a 4x4 perspective Matrix. More...
 
static Matrix< T, 4, 4 > Ortho (T left, T right, T bottom, T top, T znear, T zfar, T handedness=1)
 Create a 4x4 orthographic Matrix. More...
 
static Matrix< T, 4, 4 > LookAt (const Vector< T, 3 > &at, const Vector< T, 3 > &eye, const Vector< T, 3 > &up, T handedness=-1)
 Create a 3-dimensional camera Matrix. More...
 
static Vector< T, 3 > UnProject (const Vector< T, 3 > &window_coord, const Matrix< T, 4, 4 > &model_view, const Matrix< T, 4, 4 > &projection, const float window_width, const float window_height)
 Get the 3D position in object space from a window coordinate. More...
 

Static Public Attributes

static const int kRows = rows
 Number of rows in the matrix.
 
static const int kColumns = columns
 Number of columns in the matrix.
 
static const int kElements = rows * columns
 Total number of elements in the matrix.
 

Friends

Vector< T, columns > operator* (const Vector< T, rows > &v, const Matrix< T, rows, columns > &m)
 Multiply a Vector by a Matrix. More...
 

Related Functions

(Note that these are not member functions.)

template<class T , int rows, int columns>
Matrix< T, rows, columns > operator* (const T &s, const Matrix< T, columns, rows > &m)
 Multiply each element of a Matrix by a scalar. More...
 
template<class T , int rows, int columns>
Vector< T, rows > operator* (const Matrix< T, rows, columns > &m, const Vector< T, columns > &v)
 Multiply a Matrix by a Vector. More...
 
template<class T >
Vector< T, 3 > operator* (const Matrix< T, 4, 4 > &m, const Vector< T, 3 > &v)
 Multiply a 4x4 Matrix by a 3-dimensional Vector. More...
 

Constructor & Destructor Documentation

template<class T, int rows, int columns>
mathfu::Matrix< T, rows, columns >::Matrix ( const Matrix< T, rows, columns > &  m)
inline

Construct a Matrix from another Matrix copying each element. /.

Parameters
mMatrix that the data will be copied from.
template<class T, int rows, int columns>
mathfu::Matrix< T, rows, columns >::Matrix ( const T &  s)
inlineexplicit

Construct a Matrix from a single float.

Parameters
sScalar value used to initialize each element of the matrix.
template<class T, int rows, int columns>
mathfu::Matrix< T, rows, columns >::Matrix ( const T &  s00,
const T &  s10,
const T &  s01,
const T &  s11 
)
inline

Construct a Matrix from four floats.

Note
This method only works with a 2x2 Matrix.
Parameters
s00Value of the first row and column.
s10Value of the second row, first column.
s01Value of the first row, second column.
s11Value of the second row and column.
template<class T, int rows, int columns>
mathfu::Matrix< T, rows, columns >::Matrix ( const T &  s00,
const T &  s10,
const T &  s20,
const T &  s01,
const T &  s11,
const T &  s21,
const T &  s02,
const T &  s12,
const T &  s22 
)
inline

Create a Matrix from nine floats.

Note
This method only works with a 3x3 Matrix.
Parameters
s00Value of the first row and column.
s10Value of the second row, first column.
s20Value of the third row, first column.
s01Value of the first row, second column.
s11Value of the second row and column.
s21Value of the third row, second column.
s02Value of the first row, third column.
s12Value of the second row, third column.
s22Value of the third row and column.
template<class T, int rows, int columns>
mathfu::Matrix< T, rows, columns >::Matrix ( const T &  s00,
const T &  s10,
const T &  s20,
const T &  s30,
const T &  s01,
const T &  s11,
const T &  s21,
const T &  s31,
const T &  s02,
const T &  s12,
const T &  s22,
const T &  s32 
)
inline

Creates a Matrix from twelve floats.

Note
This method only works with Matrix<float, 4, 3>.
Parameters
s00Value of the first row and column.
s10Value of the second row, first column.
s20Value of the third row, first column.
s30Value of the fourth row, first column.
s01Value of the first row, second column.
s11Value of the second row and column.
s21Value of the third row, second column.
s31Value of the fourth row, second column.
s02Value of the first row, third column.
s12Value of the second row, third column.
s22Value of the third row and column.
s32Value of the fourth row, third column.
template<class T, int rows, int columns>
mathfu::Matrix< T, rows, columns >::Matrix ( const T &  s00,
const T &  s10,
const T &  s20,
const T &  s30,
const T &  s01,
const T &  s11,
const T &  s21,
const T &  s31,
const T &  s02,
const T &  s12,
const T &  s22,
const T &  s32,
const T &  s03,
const T &  s13,
const T &  s23,
const T &  s33 
)
inline

Create a Matrix from sixteen floats.

Note
This method only works with a 4x4 Matrix.
Parameters
s00Value of the first row and column.
s10Value of the second row, first column.
s20Value of the third row, first column.
s30Value of the fourth row, first column.
s01Value of the first row, second column.
s11Value of the second row and column.
s21Value of the third row, second column.
s31Value of the fourth row, second column.
s02Value of the first row, third column.
s12Value of the second row, third column.
s22Value of the third row and column.
s32Value of the fourth row, third column.
s03Value of the first row, fourth column.
s13Value of the second row, fourth column.
s23Value of the third row, fourth column.
s33Value of the fourth row and column.
template<class T, int rows, int columns>
mathfu::Matrix< T, rows, columns >::Matrix ( const Vector< T, 4 > &  column0,
const Vector< T, 4 > &  column1,
const Vector< T, 4 > &  column2,
const Vector< T, 4 > &  column3 
)
inline

Create 4x4 Matrix from 4, 4 element vectors.

Note
This method only works with a 4x4 Matrix.
Parameters
column0Vector used for the first column.
column1Vector used for the second column.
column2Vector used for the third column.
column3Vector used for the fourth column.
template<class T, int rows, int columns>
mathfu::Matrix< T, rows, columns >::Matrix ( const T *const  a)
inlineexplicit

Create a Matrix from the first row * column elements of an array.

Parameters
aArray of values that the matrix will be iniitlized to.
template<class T, int rows, int columns>
mathfu::Matrix< T, rows, columns >::Matrix ( const VectorPacked< T, rows > *const  vectors)
inlineexplicit

Create a Matrix from an array of "columns", "rows" element packed vectors.

Parameters
vectorsArray of "columns", "rows" element packed vectors.

Member Function Documentation

template<class T, int rows, int columns>
static Matrix<T, 4> mathfu::Matrix< T, rows, columns >::FromAffineTransform ( const Matrix< T, 4, 3 > &  affine)
inlinestatic

Constructs a Matrix<float, 4> from an AffineTransform.

Parameters
affineAn AffineTransform reference to be used to construct a Matrix<float, 4> by adding in the 'w' row of [0, 0, 0, 1].
template<class T, int rows, int columns>
static Matrix<T, 4> mathfu::Matrix< T, rows, columns >::FromRotationMatrix ( const Matrix< T, 3 > &  m)
inlinestatic

Create a 4x4 Matrix from a 3x3 rotation Matrix.

This Matrix will have an empty or zero translation component.

Parameters
m3x3 rotation Matrix.
Returns
Matrix containing the result.
template<class T, int rows, int columns>
static Matrix<T, rows> mathfu::Matrix< T, rows, columns >::FromScaleVector ( const Vector< T, rows-1 > &  v)
inlinestatic

Create a square Matrix with the diagonal component set to v.

This is an affine transform matrix, so the dimension of the vector is one less than the dimension of the matrix.

Parameters
vVector containing components for scaling.
Returns
Matrix with v along the diagonal, and 1 in the bottom right.
template<class T, int rows, int columns>
static Matrix<T, 3> mathfu::Matrix< T, rows, columns >::FromTranslationVector ( const Vector< T, 2 > &  v)
inlinestatic

Create a 3x3 translation Matrix from a 2-dimensional Vector.

This matrix will have an empty or zero rotation component.

Parameters
vVector of size 2.
Returns
Matrix containing the result.
template<class T, int rows, int columns>
static Matrix<T, 4> mathfu::Matrix< T, rows, columns >::FromTranslationVector ( const Vector< T, 3 > &  v)
inlinestatic

Create a 4x4 translation Matrix from a 3-dimensional Vector.

This matrix will have an empty or zero rotation component.

Parameters
vThe vector of size 3.
Returns
Matrix containing the result.
template<class T, int rows, int columns>
template<typename CompatibleT >
static Matrix<T, rows, columns> mathfu::Matrix< T, rows, columns >::FromType ( const CompatibleT &  compatible)
inlinestatic

Load from any byte-wise compatible external matrix.

Format should be columns vectors, each holding rows values of type T.

Use this for safe conversion from external matrix classes. Often, external libraries will have their own matrix types that are, byte-for-byte, exactly the same as mathfu::Matrix. This function allows you to load a mathfu::Matrix from those external types, without potential aliasing bugs that are caused by casting.

Note
If your external type gives you access to a T*, then you can equivalently use the Matrix(const T*) constructor.
Parameters
compatiblereference to a byte-wise compatible matrix structure; array of columns x rows Ts.
Returns
compatible loaded as a mathfu::Matrix.
template<class T, int rows, int columns>
static Matrix<T, rows, columns> mathfu::Matrix< T, rows, columns >::HadamardProduct ( const Matrix< T, rows, columns > &  m1,
const Matrix< T, rows, columns > &  m2 
)
inlinestatic

Calculate the hadamard / component-wise product of two matrices.

Parameters
m1First Matrix.
m2Second Matrix.
Returns
Matrix containing the result.
template<class T, int rows, int columns>
static Matrix<T, rows, columns> mathfu::Matrix< T, rows, columns >::Identity ( )
inlinestatic

Calculate the identity Matrix.

Returns
Matrix containing the result.
template<class T, int rows, int columns>
Matrix<T, rows, columns> mathfu::Matrix< T, rows, columns >::Inverse ( ) const
inline

Calculate the inverse of this Matrix.

This calculates the inverse Matrix such that (m * m).Inverse() is the identity.

Returns
Matrix containing the result.
template<class T, int rows, int columns>
bool mathfu::Matrix< T, rows, columns >::InverseWithDeterminantCheck ( Matrix< T, rows, columns > *const  inverse) const
inline

Calculate the inverse of this Matrix.

This calculates the inverse Matrix such that (m * m).Inverse() is the identity. By contrast to Inverse() this returns whether the matrix is invertible.

The invertible check simply compares the calculated determinant with Constants<T>::GetDeterminantThreshold() to roughly determine whether the matrix is invertible. This simple check works in common cases but will fail for corner cases where the matrix is a combination of huge and tiny values that can't be accurately represented by the floating point datatype T. More extensive checks (relative to the input values) are possible but far more expensive, complicated and difficult to test.

Returns
Whether the matrix is invertible.
template<class T, int rows, int columns>
static Matrix<T, 4, 4> mathfu::Matrix< T, rows, columns >::LookAt ( const Vector< T, 3 > &  at,
const Vector< T, 3 > &  eye,
const Vector< T, 3 > &  up,
handedness = -1 
)
inlinestatic

Create a 3-dimensional camera Matrix.

Parameters
atThe look-at target of the camera.
eyeThe position of the camera.
upThe up vector in the world, for example (0, 1, 0) if the y-axis is up.
handedness1.0f for RH, -1.0f for LH.
Returns
3-dimensional camera Matrix. TODO: Change default handedness to +1 so that it matches Perspective().
template<class T, int rows, int columns>
const T& mathfu::Matrix< T, rows, columns >::operator() ( const int  row,
const int  column 
) const
inline

Access an element of the matrix.

Parameters
rowIndex of the row to access.
columnIndex of the column to access.
Returns
Const reference to the element.
template<class T, int rows, int columns>
T& mathfu::Matrix< T, rows, columns >::operator() ( const int  row,
const int  column 
)
inline

Access an element of the Matrix.

Parameters
rowIndex of the row to access.
columnIndex of the column to access.
Returns
Reference to the data that can be modified by the caller.
template<class T, int rows, int columns>
const T& mathfu::Matrix< T, rows, columns >::operator() ( const int  i) const
inline

Access an element of the Matrix.

Parameters
iIndex of the element to access in flattened memory. Where the column accessed is i / rows and the row is i % rows.
Returns
Reference to the data that can be modified by the caller.
template<class T, int rows, int columns>
T& mathfu::Matrix< T, rows, columns >::operator() ( const int  i)
inline

Access an element of the Matrix.

Parameters
iIndex of the element to access in flattened memory. Where the column accessed is i / rows and the row is i % rows.
Returns
Reference to the data that can be modified by the caller.
template<class T, int rows, int columns>
Matrix<T, rows, columns> mathfu::Matrix< T, rows, columns >::operator* ( const T &  s) const
inline

Multiply each element of this Matrix with a scalar.

Parameters
sScalar to multiply with this Matrix.
Returns
Matrix containing the result.
template<class T, int rows, int columns>
Matrix<T, rows, columns> mathfu::Matrix< T, rows, columns >::operator* ( const Matrix< T, rows, columns > &  m) const
inline

Multiply this Matrix with another Matrix.

Parameters
mMatrix to multiply with this Matrix.
Returns
Matrix containing the result.
template<class T, int rows, int columns>
Matrix<T, rows, columns>& mathfu::Matrix< T, rows, columns >::operator*= ( const T &  s)
inline

Multiply each element of this Matrix with a scalar (in-place).

Parameters
sScalar to multiply with each element of this Matrix.
Returns
Reference to this class.
template<class T, int rows, int columns>
Matrix<T, rows, columns>& mathfu::Matrix< T, rows, columns >::operator*= ( const Matrix< T, rows, columns > &  m)
inline

Multiply this Matrix with another Matrix (in-place).

Parameters
mMatrix to multiply with this Matrix.
Returns
Reference to this class.
template<class T, int rows, int columns>
Matrix<T, rows, columns> mathfu::Matrix< T, rows, columns >::operator+ ( const Matrix< T, rows, columns > &  m) const
inline

Add a Matrix to this Matrix.

Parameters
mMatrix to add to this Matrix.
Returns
Matrix containing the result.
template<class T, int rows, int columns>
Matrix<T, rows, columns> mathfu::Matrix< T, rows, columns >::operator+ ( const T &  s) const
inline

Add a scalar to each element of this Matrix.

Parameters
sScalar to add to this Matrix.
Returns
Matrix containing the result.
template<class T, int rows, int columns>
Matrix<T, rows, columns>& mathfu::Matrix< T, rows, columns >::operator+= ( const Matrix< T, rows, columns > &  m)
inline

Add a Matrix to this Matrix (in-place).

Parameters
mMatrix to add to this Matrix.
Returns
Reference to this class.
template<class T, int rows, int columns>
Matrix<T, rows, columns>& mathfu::Matrix< T, rows, columns >::operator+= ( const T &  s)
inline

Add a scalar to each element of this Matrix (in-place).

Parameters
sScalar to add to each element of this Matrix.
Returns
Reference to this class.
template<class T, int rows, int columns>
Matrix<T, rows, columns> mathfu::Matrix< T, rows, columns >::operator- ( ) const
inline

Negate this Matrix.

Returns
Matrix containing the result.
template<class T, int rows, int columns>
Matrix<T, rows, columns> mathfu::Matrix< T, rows, columns >::operator- ( const Matrix< T, rows, columns > &  m) const
inline

Subtract a Matrix from this Matrix.

Parameters
mMatrix to subtract from this Matrix.
Returns
Matrix containing the result.
template<class T, int rows, int columns>
Matrix<T, rows, columns> mathfu::Matrix< T, rows, columns >::operator- ( const T &  s) const
inline

Subtract a scalar from each element of this Matrix.

Parameters
sScalar to subtract from this matrix.
Returns
Matrix containing the result.
template<class T, int rows, int columns>
Matrix<T, rows, columns>& mathfu::Matrix< T, rows, columns >::operator-= ( const Matrix< T, rows, columns > &  m)
inline

Subtract a Matrix from this Matrix (in-place).

Parameters
mMatrix to subtract from this Matrix.
Returns
Reference to this class.
template<class T, int rows, int columns>
Matrix<T, rows, columns>& mathfu::Matrix< T, rows, columns >::operator-= ( const T &  s)
inline

Subtract a scalar from each element of this Matrix (in-place).

Parameters
sScalar to subtract from each element of this Matrix.
Returns
Reference to this class.
template<class T, int rows, int columns>
Matrix<T, rows, columns> mathfu::Matrix< T, rows, columns >::operator/ ( const T &  s) const
inline

Divide each element of this Matrix with a scalar.

Parameters
sScalar to divide this Matrix with.
Returns
Matrix containing the result.
template<class T, int rows, int columns>
Matrix<T, rows, columns>& mathfu::Matrix< T, rows, columns >::operator/= ( const T &  s)
inline

Divide each element of this Matrix by a scalar (in-place).

Parameters
sScalar to divide this Matrix by.
Returns
Reference to this class.
template<class T, int rows, int columns>
const T& mathfu::Matrix< T, rows, columns >::operator[] ( const int  i) const
inline

Access an element of the Matrix.

Parameters
iIndex of the element to access in flattened memory. Where the column accessed is i / rows and the row is i % rows.
Returns
Const reference to the data.
template<class T, int rows, int columns>
T& mathfu::Matrix< T, rows, columns >::operator[] ( const int  i)
inline

Access an element of the Matrix.

Parameters
iIndex of the element to access in flattened memory. Where the column accessed is i / rows and the row is i % rows.
Returns
Reference to the data that can be modified by the caller.
template<class T, int rows, int columns>
static Matrix<T, 4, 4> mathfu::Matrix< T, rows, columns >::Ortho ( left,
right,
bottom,
top,
znear,
zfar,
handedness = 1 
)
inlinestatic

Create a 4x4 orthographic Matrix.

Parameters
leftLeft extent.
rightRight extent.
bottomBottom extent.
topTop extent.
znearNear plane location.
zfarFar plane location.
handedness1.0f for RH, -1.0f for LH
Returns
4x4 orthographic Matrix.
template<class T, int rows, int columns>
static Matrix<T, rows, columns> mathfu::Matrix< T, rows, columns >::OuterProduct ( const Vector< T, rows > &  v1,
const Vector< T, columns > &  v2 
)
inlinestatic

Calculate the outer product of two Vectors.

Returns
Matrix containing the result.
template<class T, int rows, int columns>
void mathfu::Matrix< T, rows, columns >::Pack ( VectorPacked< T, rows > *const  vector) const
inline

Pack the matrix to an array of "rows" element vectors, one vector per matrix column.

Parameters
vectorArray of "columns" entries to write to.
template<class T, int rows, int columns>
static Matrix<T, 4, 4> mathfu::Matrix< T, rows, columns >::Perspective ( fovy,
aspect,
znear,
zfar,
handedness = 1 
)
inlinestatic

Create a 4x4 perspective Matrix.

Parameters
fovyField of view.
aspectAspect ratio.
znearNear plane location.
zfarFar plane location.
handedness1.0f for RH, -1.0f for LH
Returns
4x4 perspective Matrix.
template<class T, int rows, int columns>
static Matrix<T, 3> mathfu::Matrix< T, rows, columns >::RotationX ( const Vector< T, 2 > &  v)
inlinestatic

Create a 3x3 rotation Matrix from a 2D normalized directional Vector around the X axis.

Parameters
v2D normalized directional Vector.
Returns
Matrix containing the result.
template<class T, int rows, int columns>
static Matrix<T, 3> mathfu::Matrix< T, rows, columns >::RotationX ( angle)
inlinestatic

Create a 3x3 rotation Matrix from an angle (in radians) around the X axis.

Parameters
angleAngle (in radians).
Returns
Matrix containing the result.
template<class T, int rows, int columns>
static Matrix<T, 3> mathfu::Matrix< T, rows, columns >::RotationY ( const Vector< T, 2 > &  v)
inlinestatic

Create a 3x3 rotation Matrix from a 2D normalized directional Vector around the Y axis.

Parameters
v2D normalized directional Vector.
Returns
Matrix containing the result.
template<class T, int rows, int columns>
static Matrix<T, 3> mathfu::Matrix< T, rows, columns >::RotationY ( angle)
inlinestatic

Create a 3x3 rotation Matrix from an angle (in radians) around the Y axis.

Parameters
angleAngle (in radians).
Returns
Matrix containing the result.
template<class T, int rows, int columns>
static Matrix<T, 3> mathfu::Matrix< T, rows, columns >::RotationZ ( const Vector< T, 2 > &  v)
inlinestatic

Create a 3x3 rotation Matrix from a 2D normalized directional Vector around the Z axis.

Parameters
v2D normalized directional Vector.
Returns
Matrix containing the result.
template<class T, int rows, int columns>
static Matrix<T, 3> mathfu::Matrix< T, rows, columns >::RotationZ ( angle)
inlinestatic

Create a 3x3 rotation Matrix from an angle (in radians) around the Z axis.

Parameters
angleAngle (in radians).
Returns
Matrix containing the result.
template<class T, int rows, int columns>
static Matrix<T, 4, 3> mathfu::Matrix< T, rows, columns >::ToAffineTransform ( const Matrix< T, 4 > &  m)
inlinestatic

Converts a Matrix<float, 4> into an AffineTransform.

Parameters
mA Matrix<float, 4> reference to be converted into an AffineTransform by dropping the fixed 'w' row.
Returns
Returns an AffineTransform that contains the essential transformation data from the Matrix<float, 4>.
template<class T, int rows, int columns>
static Matrix<T, 3> mathfu::Matrix< T, rows, columns >::ToRotationMatrix ( const Matrix< T, 4 > &  m)
inlinestatic

Extracts the 3x3 rotation Matrix from a 4x4 Matrix.

This resulting Matrix will contain the upper-left 3x3 sub-matrix of the input Matrix.

Parameters
m4x4 Matrix.
Returns
rotation Matrix containing the result.
template<class T, int rows, int columns>
template<typename CompatibleT >
static CompatibleT mathfu::Matrix< T, rows, columns >::ToType ( const Matrix< T, rows, columns > &  m)
inlinestatic

Load into any byte-wise compatible external matrix.

Format should be columns vectors, each holding rows values of type T.

Use this for safe conversion to external matrix classes. Often, external libraries will have their own matrix types that are, byte-for-byte, exactly the same as mathfu::Matrix. This function allows you to load an external type from a mathfu::Matrix, without potential aliasing bugs that are caused by casting.

Parameters
mreference to mathfu::Matrix to convert.
Returns
CompatibleT loaded from m.
template<class T, int rows, int columns>
Vector<T, 2> mathfu::Matrix< T, rows, columns >::TranslationVector2D ( ) const
inline

Get the 2-dimensional translation of a 2-dimensional affine transform.

Note
2-dimensional affine transforms are represented by 3x3 matrices.
Returns
Vector with the first two components of column 2 of this Matrix.
template<class T, int rows, int columns>
Vector<T, 3> mathfu::Matrix< T, rows, columns >::TranslationVector3D ( ) const
inline

Get the 3-dimensional translation of a 3-dimensional affine transform.

Note
3-dimensional affine transforms are represented by 4x4 matrices.
Returns
Vector with the first three components of column 3.
template<class T, int rows, int columns>
Matrix<T, columns, rows> mathfu::Matrix< T, rows, columns >::Transpose ( ) const
inline

Calculate the transpose of this Matrix.

Returns
The transpose of the specified Matrix.
template<class T, int rows, int columns>
static Vector<T, 3> mathfu::Matrix< T, rows, columns >::UnProject ( const Vector< T, 3 > &  window_coord,
const Matrix< T, 4, 4 > &  model_view,
const Matrix< T, 4, 4 > &  projection,
const float  window_width,
const float  window_height 
)
inlinestatic

Get the 3D position in object space from a window coordinate.

Parameters
window_coordThe window coordinate. The z value is for depth. A window coordinate on the near plane will have 0 as the z value. And a window coordinate on the far plane will have 1 as the z value. z value should be with in [0, 1] here.
model_viewThe Model View matrix.
projectionThe projection matrix.
window_widthWidth of the window.
window_heightHeight of the window.
Returns
the mapped 3D position in object space.

Friends And Related Function Documentation

template<class T, int rows, int columns>
Vector<T, columns> operator* ( const Vector< T, rows > &  v,
const Matrix< T, rows, columns > &  m 
)
friend

Multiply a Vector by a Matrix.

Parameters
vVector to multiply.
mMatrix to multiply.
Returns
Matrix containing the result.

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