All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Pages
Nimble::Matrix4T< T > Class Template Reference

4x4 transformation matrix More...

#include <Nimble/Matrix4.hpp>

Public Types

typedef T type
 Data-type of the matrix.
 

Public Member Functions

void clear ()
 Fills the matrix with zeroes.
 
Vector4T< T > column (int i) const
 Returns the ith column vector.
 
template<class K >
void copy (const K *x)
 Fills the matrix by copying values from memory.
 
template<class K >
void copyTranspose (const K *x)
 Fills the matrix by copying transposed values from memory.
 
T * data ()
 Returns a pointer to the first element.
 
const T * data () const
 Returns a pointer to the first element.
 
get (int r, int c) const
 Gets the given matrix element.
 
void identity ()
 Sets the matrix to identity.
 
Matrix4T< T > inverse (bool *ok=0) const
 Returns the inverse of the matrix. More...
 
void make (T x11, T x12, T x13, T x14, T x21, T x22, T x23, T x24, T x31, T x32, T x33, T x34, T x41, T x42, T x43, T x44)
 Fills the matrix with given values.
 
template<class K >
 Matrix4T (const K *x)
 Constructs a matrix and fills it from memory.
 
 Matrix4T ()
 Constructs a matrix without initializing it.
 
 Matrix4T (T x11, T x12, T x13, T x14, T x21, T x22, T x23, T x24, T x31, T x32, T x33, T x34, T x41, T x42, T x43, T x44)
 Constructs a matrix and fills it with given values.
 
 Matrix4T (const Vector4T< T > &a, const Vector4T< T > &b, const Vector4T< T > &c, const Vector4T< T > &d)
 Constructs a matrix and initializes it with given row vectors.
 
bool operator!= (const Matrix4T< T > &that) const
 Compares if two matrices differ.
 
Matrix4T< T > & operator*= (const Matrix4T< T > &that)
 Multiplies two matrices together.
 
Matrix4T< T > & operator*= (T s)
 Multiplies the matrix with a scalar.
 
bool operator== (const Matrix4T< T > &that) const
 Compares if two matrices are equal.
 
Vector4T< T > & operator[] (int i)
 void setDiagonal(const Vector3T<T> &v) { m[0][0] = v[0]; m[1][1] = v[1]; m[2][2] = v[2]; m[3][3] = (T) 1.0; } More...
 
const Vector4T< T > & operator[] (int i) const
 Returns the ith row. More...
 
Matrix4T< T > orthoNormalize () const
 Returns an orthonormalized version of this matrix. More...
 
Vector3T< T > project (const Vector4T< T > &v) const
 Apply the matrix on a 4D vector. More...
 
Vector3T< T > project (const Vector3T< T > &v) const
 Apply the matrix on a 3D vector. More...
 
Vector2T< T > project (const Vector2T< T > &v) const
 Apply the matrix on a 2D vector which is interpreted as [x y 0 1]. More...
 
Matrix3T< T > rotation () const
 Returns the upper-left 3x3 matrix.
 
Vector4T< T > & row (int i)
 Returns the ith row.
 
const Vector4T< T > & row (int i) const
 Returns the ith row.
 
void scalingMatrix (const Vector3T< T > &)
 Sets the matrix to a scaling matrix.
 
void setColumn (int i, const Vector4T< T > &v)
 Sets the ith column vector.
 
void setDiagonal (const Vector4T< T > &v)
 Sets the diagonal to given vector.
 
void setRotation (const Nimble::Matrix3T< T > &that)
 Replaces the upper-left 3x3 matrix.
 
void setTranslation (const Vector3T< T > &v)
 Sets the translation part of a 4x4 transformation matrix.
 
Vector3T< T > translation () const
 Returns the translation part of a 4x4 matrix.
 
Matrix4T< T > & transpose ()
 Transposes the matrix.
 
void transpose (Matrix4T< T > &ret) const
 Make a transpose of a matrix to a given matrix.
 
Matrix4T< T > transposed () const
 Returns a transposed matrix.
 
Matrix3T< T > upperLeft () const
 Get the 3x3 upper-left matrix.
 
Matrix2T< T > upperLeft2 () const
 Get the 2x2 upper-left matrix.
 

Static Public Member Functions

static int columns ()
 Returns the number of columns (4)
 
static Matrix4T< T > makeRotation (T radians, const Vector3T< T > &axis)
 Create a rotation matrix. More...
 
static Matrix4T< T > makeScale (const Vector3T< T > &v)
 Create a non-uniform scaling matrix. More...
 
static Matrix4T< T > makeTranslation (const Vector2T< T > &v)
 
static Matrix4T< T > makeTranslation (const Vector3T< T > &v)
 Create a translation matrix. More...
 
static Matrix4T< T > makeTranslation (T x, T y, T z)
 Create a translation matrix. More...
 
static Matrix4T< T > makeUniformScale (const T &s)
 Create a uniform scaling matrix. More...
 
static Matrix4T< T > ortho3D (T left, T right, T bottom, T top, T nearPlane, T farPlane)
 Creates an orthogonal projection matrix in 3D This function works in a way similar to glOrtho (http://lmb.informatik.uni-freiburg.de/people/reisert/opengl/doc/glOrtho.html). More...
 
static Matrix4T< T > orthogonalProjection (T left, T right, T bottom, T top, T nearPlane, T farPlane)
 Creates an orthogonal projection matrix. More...
 
static Matrix4T< T > perspectiveProjection (T fovY, T aspect, T nearPlane, T farPlane)
 Creates a perspective projection matrix. More...
 
static int rows ()
 Returns the number of rows (4)
 
static Matrix4T< T > simpleProjection (T width, T height, T fovy=Nimble::Math::PI *0.5)
 Creates a new WPCV-matrix (window-projection-camera-view -matrix) Camera is positioned so that 0,0,0 is mapped to 0,0,0 and w,h,0 is mapped to w,h,0. More...
 
static Matrix4T< T > transformation (T angle, const Vector3T< T > &axis, const Vector3T< T > &scale, const Vector3T< T > &translation)
 Returns a 3d transformation matrix that does scale, rotate & translation (in this order) More...
 

Static Public Attributes

static const Matrix4T< T > IDENTITY
 Identity matrix. More...
 

Detailed Description

template<class T>
class Nimble::Matrix4T< T >

4x4 transformation matrix

This class is a row-major 4x4 matrix. The matrix functions (rotations etc.) assume right-handed coordinate system.

Examples:
AdvancedRenderingExample.cpp, and Widget3DExample.cpp.

Member Function Documentation

template<class T >
Matrix4T< T > Nimble::Matrix4T< T >::inverse ( bool *  ok = 0) const
inline

Returns the inverse of the matrix.

Inverts the matrix.

The boolean argument is set to true or false depending on how well the operation went.

Parameters
[out]ok(optional) false if the inversion fails, otherwise true
Returns
Inverse matrix
Examples:
PositionalSoundsExample.cpp, and Widget3DExample.cpp.
template<class T >
static Matrix4T<T> Nimble::Matrix4T< T >::makeRotation ( radians,
const Vector3T< T > &  axis 
)
inlinestatic

Create a rotation matrix.

Parameters
radiansangle in radians
axisaxis to rotate around
Returns
New rotation matrix
Examples:
Widget3DExample.cpp.
template<class T >
static Matrix4T<T> Nimble::Matrix4T< T >::makeScale ( const Vector3T< T > &  v)
inlinestatic

Create a non-uniform scaling matrix.

Parameters
vXYZ scaling factors
Returns
new Scaling matrix
template<class T >
static Matrix4T<T> Nimble::Matrix4T< T >::makeTranslation ( const Vector3T< T > &  v)
inlinestatic

Create a translation matrix.

Parameters
vTranslation vector
Returns
New translation matrix
template<class T >
static Matrix4T<T> Nimble::Matrix4T< T >::makeTranslation ( x,
y,
z 
)
inlinestatic

Create a translation matrix.

Parameters
xTranlation along X-axis
yTranlation along Y-axis
zTranlation along Z-axis
Returns
New translation matrix
template<class T >
static Matrix4T<T> Nimble::Matrix4T< T >::makeUniformScale ( const T &  s)
inlinestatic

Create a uniform scaling matrix.

Parameters
sScaling factor
Returns
new Scaling matrix
template<class T >
Vector4T<T>& Nimble::Matrix4T< T >::operator[] ( int  i)
inline

void setDiagonal(const Vector3T<T> &v) { m[0][0] = v[0]; m[1][1] = v[1]; m[2][2] = v[2]; m[3][3] = (T) 1.0; }

Returns the ith row

Parameters
irow number
Returns
Reference to the row
template<class T >
const Vector4T<T>& Nimble::Matrix4T< T >::operator[] ( int  i) const
inline

Returns the ith row.

Parameters
irow number
Returns
Const reference to the row
template<class T >
Matrix4T< T > Nimble::Matrix4T< T >::ortho3D ( left,
right,
bottom,
top,
nearPlane,
farPlane 
)
static

Creates an orthogonal projection matrix in 3D This function works in a way similar to glOrtho (http://lmb.informatik.uni-freiburg.de/people/reisert/opengl/doc/glOrtho.html).

Parameters
leftleft clipping plane
rightright clipping plane
bottombottom clipping plane
toptop clipping plane
nearPlanenear clipping plane
farPlanefar clipping plane
Returns
orthogonal projection matrix
template<class T >
static Matrix4T<T> Nimble::Matrix4T< T >::orthogonalProjection ( left,
right,
bottom,
top,
nearPlane,
farPlane 
)
inlinestatic

Creates an orthogonal projection matrix.

Parameters
leftLeft clip plane location
rightRight clip plane location
bottomBottom clip plane location
topTop clip plane location
nearPlaneNear clip plane location
farPlaneFar clip plane location
Returns
New projection matrix
template<class T >
Matrix4T<T> Nimble::Matrix4T< T >::orthoNormalize ( ) const
inline

Returns an orthonormalized version of this matrix.

Returns
Normalized matrix
template<class T >
static Matrix4T<T> Nimble::Matrix4T< T >::perspectiveProjection ( fovY,
aspect,
nearPlane,
farPlane 
)
inlinestatic

Creates a perspective projection matrix.

Parameters
fovYfield of view in degress in the Y direction
aspectaspect ratio (width / height)
nearPlanedistance to the near clipping plane, always positive
farPlanedistance to the far clipping plane, always positive
Returns
New projection matrix
Examples:
Widget3DExample.cpp.
template<class T >
Vector3T<T> Nimble::Matrix4T< T >::project ( const Vector4T< T > &  v) const
inline

Apply the matrix on a 4D vector.

Parameters
vhomogenous 3D vector
Returns
projected 3D vector
template<class T >
Vector3T<T> Nimble::Matrix4T< T >::project ( const Vector3T< T > &  v) const
inline

Apply the matrix on a 3D vector.

Parameters
v3D vector
Returns
transformed 3D vector
template<class T >
Vector2T<T> Nimble::Matrix4T< T >::project ( const Vector2T< T > &  v) const
inline

Apply the matrix on a 2D vector which is interpreted as [x y 0 1].

Parameters
v2D vector
Returns
transformed 2D vector
template<class T >
static Matrix4T<T> Nimble::Matrix4T< T >::simpleProjection ( width,
height,
fovy = Nimble::Math::PI*0.5 
)
inlinestatic

Creates a new WPCV-matrix (window-projection-camera-view -matrix) Camera is positioned so that 0,0,0 is mapped to 0,0,0 and w,h,0 is mapped to w,h,0.

The projection matrix doesn't have the third row, no depth information, so no near/far values needed. (0,0,0) is lower left bottom, (w,h,0) is in right top, z increases towards the camera

Parameters
widthWidth of the viewport
heightHeight of the viewport
fovyField of view in y-direction in radians
Returns
New projection matrix
template<typename T >
Matrix4T< T > Nimble::Matrix4T< T >::transformation ( angle,
const Vector3T< T > &  axis,
const Vector3T< T > &  scale,
const Vector3T< T > &  translation 
)
inlinestatic

Returns a 3d transformation matrix that does scale, rotate & translation (in this order)

Parameters
anglerotation angle (counter-clockwise)
axisrotation axis (normalized)
scale3D scale
translation3D translation
Returns
New transformation matrix

Member Data Documentation

template<class T >
const Matrix4T< T > Nimble::Matrix4T< T >::IDENTITY
static

Identity matrix.