LinearAlgebra
 All Classes Namespaces Files Functions Variables Typedefs Macros
Classes | Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
a3d::Matrix4< T, M > Struct Template Reference

A matrix of 16 values for 3d calculations in homogeneous coordinates. More...

Collaboration diagram for a3d::Matrix4< T, M >:
Collaboration graph
[legend]

Classes

struct  Interpolator
 Struct performing interpolation between two matrices. More...
 

Public Member Functions

 Matrix4 ()
 Creates an uninitialized matrix. More...
 
 Matrix4 (int i)
 Creates a unit matrix. More...
 
 Matrix4 (const Matrix4< T > &x)
 Copy constructor. More...
 
template<class T2 >
 Matrix4 (const Matrix4< T2 > &x)
 Copy constructor. More...
 
template<class T2 , class M2 >
 Matrix4 (const Vector4< T2, M2 > &v0, const Vector4< T2, M2 > &v1, const Vector4< T2, M2 > &v2, const Vector4< T2, M2 > &v3=Vector4< T2, M2 >(0, 0, 0, 1))
 Creates matrix from three or four column vectors. More...
 
template<class T2 , class M2 >
 Matrix4 (const Vector3< T2, M2 > &v0, const Vector3< T2, M2 > &v1, const Vector3< T2, M2 > &v2, const Vector3< T2, M2 > &v3=Vector3< T2, M2 >(0, 0, 0))
 Creates matrix from three or four column vectors. More...
 
template<class S >
 Matrix4 (S m00, S m01, S m02, S m03, S m10, S m11, S m12, S m13, S m20, S m21, S m22, S m23, S m30, S m31, S m32, S m33)
 Creates matrix from elements specified in row-major order. More...
 
template<class T2 , class M2 >
 Matrix4 (const Matrix3< T2, M2 > &x)
 Casting from Matrix3. More...
 
template<class T2 , class M2 >
 Matrix4 (const Quaternion< T2, M2 > &q)
 Casting from Quaternion. More...
 
void loadIdentity ()
 Make this matrix identity, i.e. More...
 
Matrix3< T, M > getScaleRotation () const
 
Vector3< T, M > getTranslation () const
 
bool separate (Vector3< T, M > &scale, Matrix3< T, M > &rotation, Vector3< T, M > &translation) const
 Separates the transform represented by this matrix into scale, translation and rotation. More...
 
Matrix4< T, M > transpose () const
 Creates a transposed version of the matrix. More...
 
determinant () const
 Calculates the determinant. More...
 
Matrix4< T, M > comatrix () const
 Calculates the comatrix. More...
 
Matrix4< T, M > inverse () const
 Returns the inverse of the matrix. More...
 
Matrix4< T, M > affineInverse () const
 Returns the inverse of the affine matrix. More...
 
Matrix4< T, M > & operator= (const Matrix4< T, M > &o)
 Copy operator. More...
 
template<class T2 , class M2 >
Matrix4< T, M > & operator= (const Matrix4< T2, M2 > &o)
 Copy operator. More...
 
 operator const T * () const
 Casts this matrix to an array representation. More...
 
 operator T * ()
 Casts this matrix to an array representation. More...
 
const T & operator() (int i, int j) const
 Index access (row,col) More...
 
const T & operator[] (int i) const
 Index operator. More...
 
T & operator() (int i, int j)
 Index access (row,col) More...
 
T & operator[] (int i)
 Index operator. More...
 

Static Public Member Functions

template<class T2 , class M2 >
static Matrix4< T, M > fromTranslation (const Vector3< T2, M2 > &v)
 Creates a translating matrix. More...
 
template<class S >
static Matrix4< T, M > fromArrayRM (const S *ma)
 Create a matrix from a array representation of an array in row-major mode. More...
 
template<class S >
static Matrix4< T, M > fromArrayCM (const S *ma)
 Create a matrix from a array representation of an array in column-major mode. More...
 

Public Attributes

m [16]
 Matrix cell data. More...
 

Detailed Description

template<class T, class M = Math<T>>
struct a3d::Matrix4< T, M >

A matrix of 16 values for 3d calculations in homogeneous coordinates.

Observe that the data is stored in column-major mode for easy interfacing with OpenGL. The interfaces are specified in row-major mode (for example the constructor and print operator).

Constructor & Destructor Documentation

template<class T, class M = Math<T>>
a3d::Matrix4< T, M >::Matrix4 ( )
inline

Creates an uninitialized matrix.

template<class T, class M = Math<T>>
a3d::Matrix4< T, M >::Matrix4 ( int  i)
inlineexplicit

Creates a unit matrix.

References a3d::Matrix4< T, M >::loadIdentity().

Here is the call graph for this function:

template<class T, class M = Math<T>>
a3d::Matrix4< T, M >::Matrix4 ( const Matrix4< T > &  x)
inline

Copy constructor.

References a3d::Matrix4< T, M >::m.

template<class T, class M = Math<T>>
template<class T2 >
a3d::Matrix4< T, M >::Matrix4 ( const Matrix4< T2 > &  x)
inline

Copy constructor.

References a3d::Matrix4< T, M >::m.

template<class T, class M = Math<T>>
template<class T2 , class M2 >
a3d::Matrix4< T, M >::Matrix4 ( const Vector4< T2, M2 > &  v0,
const Vector4< T2, M2 > &  v1,
const Vector4< T2, M2 > &  v2,
const Vector4< T2, M2 > &  v3 = Vector4<T2,M2>(0,0,0,1) 
)
inline

Creates matrix from three or four column vectors.

References a3d::Matrix4< T, M >::m.

template<class T, class M = Math<T>>
template<class T2 , class M2 >
a3d::Matrix4< T, M >::Matrix4 ( const Vector3< T2, M2 > &  v0,
const Vector3< T2, M2 > &  v1,
const Vector3< T2, M2 > &  v2,
const Vector3< T2, M2 > &  v3 = Vector3<T2,M2>(0,0,0) 
)
inline

Creates matrix from three or four column vectors.

References a3d::Matrix4< T, M >::m.

template<class T, class M = Math<T>>
template<class S >
a3d::Matrix4< T, M >::Matrix4 ( m00,
m01,
m02,
m03,
m10,
m11,
m12,
m13,
m20,
m21,
m22,
m23,
m30,
m31,
m32,
m33 
)
inline

Creates matrix from elements specified in row-major order.

References a3d::Matrix4< T, M >::m.

template<class T, class M = Math<T>>
template<class T2 , class M2 >
a3d::Matrix4< T, M >::Matrix4 ( const Matrix3< T2, M2 > &  x)
inlineexplicit
template<class T, class M = Math<T>>
template<class T2 , class M2 >
a3d::Matrix4< T, M >::Matrix4 ( const Quaternion< T2, M2 > &  q)
inlineexplicit

Member Function Documentation

template<class T, class M = Math<T>>
Matrix4<T,M> a3d::Matrix4< T, M >::affineInverse ( ) const
inline

Returns the inverse of the affine matrix.

This function will produce an unknown result if applied to a matrix that does not represent an affine transform.

References a3d::Matrix4< T, M >::fromTranslation(), a3d::Matrix4< T, M >::getScaleRotation(), and a3d::Matrix4< T, M >::getTranslation().

Here is the call graph for this function:

template<class T, class M = Math<T>>
Matrix4<T,M> a3d::Matrix4< T, M >::comatrix ( ) const
inline

Calculates the comatrix.

References A3D_WARNING_EXPENSIVE, and a3d::Matrix4< T, M >::m.

Referenced by a3d::Matrix4< T, M >::inverse().

template<class T, class M = Math<T>>
T a3d::Matrix4< T, M >::determinant ( ) const
inline

Calculates the determinant.

References A3D_WARNING_EXPENSIVE, and a3d::Matrix4< T, M >::m.

Referenced by a3d::Matrix4< T, M >::inverse().

template<class T, class M = Math<T>>
template<class S >
static Matrix4<T,M> a3d::Matrix4< T, M >::fromArrayCM ( const S *  ma)
inlinestatic

Create a matrix from a array representation of an array in column-major mode.

[ (00), (10), (20), (30), (01), ... ]

template<class T, class M = Math<T>>
template<class S >
static Matrix4<T,M> a3d::Matrix4< T, M >::fromArrayRM ( const S *  ma)
inlinestatic

Create a matrix from a array representation of an array in row-major mode.

[ (00), (01), (02), (03), (10), ... ]

template<class T, class M = Math<T>>
template<class T2 , class M2 >
static Matrix4<T,M> a3d::Matrix4< T, M >::fromTranslation ( const Vector3< T2, M2 > &  v)
inlinestatic

Creates a translating matrix.

Referenced by a3d::Matrix4< T, M >::affineInverse().

template<class T, class M = Math<T>>
Matrix3<T,M> a3d::Matrix4< T, M >::getScaleRotation ( ) const
inline
template<class T, class M = Math<T>>
Vector3<T,M> a3d::Matrix4< T, M >::getTranslation ( ) const
inline
template<class T, class M = Math<T>>
Matrix4<T,M> a3d::Matrix4< T, M >::inverse ( ) const
inline

Returns the inverse of the matrix.

This function is not optimized and is therefore extremely inefficient.

References A3D_WARNING_EXPENSIVE, a3d::Matrix4< T, M >::comatrix(), and a3d::Matrix4< T, M >::determinant().

Referenced by a3d::Vector3< T, M >::fromScreenPosition().

Here is the call graph for this function:

template<class T, class M = Math<T>>
void a3d::Matrix4< T, M >::loadIdentity ( )
inline

Make this matrix identity, i.e.

ones in diagonal.

References a3d::Matrix4< T, M >::m.

Referenced by a3d::Matrix4< T, M >::Matrix4().

template<class T, class M = Math<T>>
a3d::Matrix4< T, M >::operator const T * ( ) const
inline

Casts this matrix to an array representation.

This makes it possible to provide for example a float matrix as an array argument in for example OpenGL.

References a3d::Matrix4< T, M >::m.

template<class T, class M = Math<T>>
a3d::Matrix4< T, M >::operator T * ( )
inline

Casts this matrix to an array representation.

This makes it possible to provide for example a float matrix as an array argument in for example OpenGL. Anything written in the returned array will end up in the matrix.

References a3d::Matrix4< T, M >::m.

template<class T, class M = Math<T>>
const T& a3d::Matrix4< T, M >::operator() ( int  i,
int  j 
) const
inline

Index access (row,col)

References a3d::Matrix4< T, M >::m.

template<class T, class M = Math<T>>
T& a3d::Matrix4< T, M >::operator() ( int  i,
int  j 
)
inline

Index access (row,col)

References a3d::Matrix4< T, M >::m.

template<class T, class M = Math<T>>
Matrix4<T,M>& a3d::Matrix4< T, M >::operator= ( const Matrix4< T, M > &  o)
inline

Copy operator.

References a3d::Matrix4< T, M >::m.

template<class T, class M = Math<T>>
template<class T2 , class M2 >
Matrix4<T,M>& a3d::Matrix4< T, M >::operator= ( const Matrix4< T2, M2 > &  o)
inline

Copy operator.

References a3d::Matrix4< T, M >::m.

template<class T, class M = Math<T>>
const T& a3d::Matrix4< T, M >::operator[] ( int  i) const
inline

Index operator.

Access element.

References a3d::Matrix4< T, M >::m.

template<class T, class M = Math<T>>
T& a3d::Matrix4< T, M >::operator[] ( int  i)
inline

Index operator.

Access element.

References a3d::Matrix4< T, M >::m.

template<class T, class M = Math<T>>
bool a3d::Matrix4< T, M >::separate ( Vector3< T, M > &  scale,
Matrix3< T, M > &  rotation,
Vector3< T, M > &  translation 
) const
inline

Separates the transform represented by this matrix into scale, translation and rotation.

Referenced by a3d::Matrix4< T, M >::Interpolator::Interpolator().

template<class T, class M = Math<T>>
Matrix4<T,M> a3d::Matrix4< T, M >::transpose ( ) const
inline

Creates a transposed version of the matrix.

References a3d::Matrix4< T, M >::m.

Member Data Documentation

template<class T, class M = Math<T>>
T a3d::Matrix4< T, M >::m[16]