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

3x3 transformation matrix More...

#include <Nimble/Matrix3.hpp>

Public Types

typedef T type
 Data-type of the matrix.
 

Public Member Functions

void clear ()
 Fills the matrix with zeroes.
 
Vector3T< T > column (int i) const
 Returns one column of the matrix As the matrix is is of row-major type, this method returns a copy of the values of the column. More...
 
T * data ()
 Gets a pointer to the data.
 
const T * data () const
 Gets a constant pointer to the data.
 
T & get (int r, int c)
 Gets one element from the matrix.
 
const T & get (int r, int c) const
 Gets one constant element from the matrix.
 
void getRotateAroundAxis (Vector3T< T > &axis, T &radians) const
 Assuming that this a rotation matrix, calculate rotation axis and angle.
 
bool getRotationXYZ (T &xa, T &ya, T &za)
 Assuming that this a rotation matrix, calculate rotation around XYZ axis.
 
void identity ()
 Makes the matrix an identity matrix.
 
void insert (const Matrix2T< T > &m)
 Inserts the argument matrix into the top-left corner of this matrix. More...
 
Matrix3T< T > inverse (bool *ok=0, T tolerance=1.0e-8) const
 Calculates the inverse of this matrix. More...
 
Matrix3T< T > inverse23 () const
 Calculate the inverse of this matrix. More...
 
void make (T v11, T v12, T v13, T v21, T v22, T v23, T v31, T v32, T v33)
 Copy argument values into this matrix.
 
 Matrix3T ()
 Constructs the matrix without initializing any values.
 
template<class K >
 Matrix3T (const K *x)
 Constructs a matrix and initializes it from memory.
 
 Matrix3T (const Vector3T< T > &a, const Vector3T< T > &b, const Vector3T< T > &c)
 Constructs a matrix and initializes it with the given rows.
 
 Matrix3T (T v11, T v12, T v13, T v21, T v22, T v23, T v31, T v32, T v33)
 Constructs a matrix and initializes it with the given values.
 
bool operator!= (const Matrix3T< T > &that) const
 Compares if two matrices are different.
 
Matrix3T< T > & operator*= (const Matrix3T< T > &that)
 Multiplies two matrices together. More...
 
bool operator== (const Matrix3T< T > &that) const
 Compares if two matrices are equal.
 
Vector3T< T > & operator[] (int i)
 Returns the ith row.
 
const Vector3T< T > & operator[] (int i) const
 Returns the ith row.
 
Vector2T< T > project (const Vector2T< T > &v) const
 Multiply the given point with the matrix and perform the homogenous divide.
 
Vector2T< T > project (const T &x, const T &y) const
 Multiply the given point with the matrix and perform the homogenous divide.
 
void rotateAroundAxis (const Vector3T< T > &axis, T radians)
 Create a rotation axis, based on rotation axis and angle.
 
void rotateX (T a)
 Create a rotation matrix, around X axis.
 
void rotateY (T a)
 Create a rotation matrix, around Y axis.
 
void rotateZ (T a)
 Create a rotation matrix, around Z axis.
 
Vector3T< T > & row (int i)
 Returns a reference to one row in the matrix.
 
const Vector3T< T > & row (int i) const
 Returns a constant reference to one row in the matrix.
 
void set (int r, int c, T v)
 Set the value of the given element.
 
void transpose ()
 Transposes the matrix.
 
Matrix3T transposed () const
 Returns a transposed matrix.
 
Matrix2T< T > upperLeft () const
 Get the 2x2 upper-left matrix.
 

Static Public Member Functions

static int columns ()
 Returns the number of columns in the matrix This function can be used when you build template-based functions. More...
 
static Nimble::Matrix3T< T > makeProjectionMatrix (const std::array< Nimble::Vector2T< T >, 4 > &vertices)
 Create a projection matrix which maps the unit square to given vertices.
 
static Matrix3T< T > makeRotation (T radians)
 Create a matrix that performs 2D rotation.
 
static Matrix3T< T > makeRotation (T radians, const Vector3T< T > &axis)
 Create a rotation matrix.
 
static Matrix3T< T > makeRotationAroundPoint (Vector2T< T > p, T radians)
 Rotate around a given point. More...
 
static Matrix3T< T > makeScale (const Vector2T< T > &v)
 Create a matrix that performs 2D scaling.
 
static Matrix3T< T > makeScale (const T &xscale, const T &yscale)
 Create a matrix that performs 2D scaling.
 
static Matrix3T< T > makeScaleAroundPoint (Vector2T< T > p, const T &xscale, const T &yscale)
 Create a matrix that performs uniform scaling around the given point.
 
static Matrix3T< T > makeTransformation (float rad, float sx, float sy, float tx, float ty)
 Returns a 2d transformation matrix that does scale, rotate & translation (in this order) More...
 
static Matrix3T< T > makeTranslation (const Vector2T< T > &v)
 Create a matrix that performs 2D translation.
 
static Matrix3T< T > makeTranslation (const T &x, const T &y)
 Create a matrix that performs 2D translation.
 
static Matrix3T< T > makeUniformScale (const T &s)
 Create a matrix that performs 2D scaling.
 
static Matrix3T< T > makeUniformScaleAroundPoint (Vector2T< T > p, T s)
 Create a matrix that performs uniform scaling around the given point.
 
static Nimble::Matrix3T< T > mapCorrespondingPoints (const std::array< Nimble::Vector2T< T >, 4 > &from, const std::array< Nimble::Vector2T< T >, 4 > &to, bool *ok=0)
 Create a projective matrix which maps from[i] to to[i] for i=0..3. More...
 
static int rows ()
 Returns the number of rows in the matrix This function can be used when you build template-based functions. More...
 

Static Public Attributes

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

Detailed Description

template<class T>
class Nimble::Matrix3T< T >

3x3 transformation matrix

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

Member Function Documentation

template<class T>
Vector3T<T> Nimble::Matrix3T< T >::column ( int  i) const
inline

Returns one column of the matrix As the matrix is is of row-major type, this method returns a copy of the values of the column.

Parameters
icolumn number
Returns
Copy of column i as a vector
template<class T>
static int Nimble::Matrix3T< T >::columns ( )
inlinestatic

Returns the number of columns in the matrix This function can be used when you build template-based functions.

Returns
3
template<class T>
void Nimble::Matrix3T< T >::insert ( const Matrix2T< T > &  b)
inline

Inserts the argument matrix into the top-left corner of this matrix.

Insert a 2x2 matrix to the upper-left corner of the 3x3 matrix.

Parameters
bmatrix to insert
template<class T>
Matrix3T< T > Nimble::Matrix3T< T >::inverse ( bool *  ok = 0,
tolerance = 1.0e-8 
) const
inline

Calculates the inverse of this matrix.

Parameters
okReturns the success value of the inversion operation
toleranceif determinant smaller than tolerance, abort
Returns
the inverted matrix
template<class T >
Matrix3T< T > Nimble::Matrix3T< T >::inverse23 ( ) const
inline

Calculate the inverse of this matrix.

This function is an optimized version of inverse() that assumes the bottom row of the matrix is 0 0 1.

Returns
inverted matrix
template<class T>
static Matrix3T<T> Nimble::Matrix3T< T >::makeRotationAroundPoint ( Vector2T< T >  p,
radians 
)
inlinestatic

Rotate around a given point.

Parameters
pThe center point of rotation
radiansThe amount of roration, in radians
Returns
New rotation matrix
template<class T>
static Matrix3T<T> Nimble::Matrix3T< T >::makeTransformation ( float  rad,
float  sx,
float  sy,
float  tx,
float  ty 
)
inlinestatic

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

Parameters
radrotation angle (counter-clockwise)
sxx scale
syy scale
txx translate
tyy translate
Returns
New transformation matrix
template<class T>
static Nimble::Matrix3T<T> Nimble::Matrix3T< T >::mapCorrespondingPoints ( const std::array< Nimble::Vector2T< T >, 4 > &  from,
const std::array< Nimble::Vector2T< T >, 4 > &  to,
bool *  ok = 0 
)
inlinestatic

Create a projective matrix which maps from[i] to to[i] for i=0..3.

Parameters
fromThe four source points
toThe four targets points
okif defined; set to true if the projection could be created
Returns
projection matrix
template<class T>
Matrix3T< T > & Nimble::Matrix3T< T >::operator*= ( const Matrix3T< T > &  that)
inline

Multiplies two matrices together.

Assign multiplication.

Parameters
thatmatrix to multiply with
Returns
Reference to self
template<class T>
static int Nimble::Matrix3T< T >::rows ( )
inlinestatic

Returns the number of rows in the matrix This function can be used when you build template-based functions.

Returns
3

Member Data Documentation

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

Identity matrix.