GL Studio API
Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
GlsMatrix< Type, DIM > Class Template Reference

#include <gls_matrix.h>

Inheritance diagram for GlsMatrix< Type, DIM >:
GlsMatrixAffine< double > GlsMatrixAffine< float >

Public Member Functions

 GlsMatrix ()
 
 GlsMatrix (const CStyleMatrix m)
 
 GlsMatrix (const Type *m)
 
 GlsMatrix (const GlsMatrix< Type, DIM > &m)
 
virtual ~GlsMatrix ()
 
void Dump () const
 
void Clear ()
 
Type * Data ()
 
const Type * Data () const
 
void MakeIdentity ()
 
Type Determinant () const
 
GlsMatrix< Type, DIM > Inverse () const
 
void Invert ()
 
GlsMatrix< Type, DIM > Transposition () const
 
void Transpose ()
 
bool IsDiagonal () const
 
bool IsIdentity () const
 
bool IsScalar () const
 
bool IsSingular () const
 
bool IsSymmetric () const
 
bool IsSkewSymmetric () const
 
bool IsLowerTriangular () const
 
bool IsUpperTriangular () const
 

Protected Member Functions

void Initialize ()
 
int Pivot (unsigned row)
 
bool closeValues (Type lv, Type rv) const
 

Protected Attributes

Type _data [DIM *DIM]
 
Type * _matrix [DIM]
 

Static Protected Attributes

static const double PRECISION = 1e-7
 

Detailed Description

template<class Type, int DIM = 4>
class disti::GlsMatrix< Type, DIM >

The GlsMatrix class provides support for an n x n square matrix of any numeric type. Most basic matrix operations are supported. Internally, the matrix terms are stored contiguously in column-major order so that the matrix data can be passed to OpenGL matrix operations. However, instances of this class can be treated as row-major matrices since the API performs the conversion to column-major ordering for the user.

Constructor & Destructor Documentation

GlsMatrix ( )

Default constructor. The new matrix will be the identity matrix.

GlsMatrix ( const CStyleMatrix  m)

Constructor. This will transpose m so that the matrix is stored in column-major order, but a caller can pass one in that is in row-major order, which is more intuitive.

Parameters
ma row-major, two-dimensional array to initialize the matrix with.
GlsMatrix ( const Type *  m)

Constructor.

Parameters
ma column-major, one-dimensional array containing all values to initialize the matrix with.
GlsMatrix ( const GlsMatrix< Type, DIM > &  m)

Copy Constructor.

Parameters
mmatrix to copy.
~GlsMatrix ( )
virtual

Destructor.

Member Function Documentation

void Clear ( )
inline

Zero out the matrix so that all terms are equal to zero.

bool closeValues ( Type  lv,
Type  rv 
) const
inlineprotected

Decides if the two values are close together determined by the constant PRECISION. The formula is lv - PRECISION < rv < lv + PRECISION

Parameters
lvleft value
rvright value
Type* Data ( )
inline

Provides access to the raw column-major matrix data as a one dimensional array in a format suitable for Open GL matrix operations.

const Type* Data ( ) const
inline

Provides access to the raw column-major matrix data as a one dimensional array in a format suitable for Open GL matrix operations.

Type Determinant ( ) const

Calculates the determinant of the matrix.

Returns
the calculated value of the determinant.
void Dump ( ) const

Dump the contents of the matrix to standard output.

void Initialize ( )
inlineprotected

This should be called from all constructors, as it initializes the matrix column index so that matrix elements can be addressed in two dimensions, but a multiplication is not incurred when doing so.

GlsMatrix< Type, DIM > Inverse ( ) const

Calculates the inverse of this matrix. The inverse of matrix A is B if AB = BA = I, where I is the identity matrix. The inverse of a matrix is the notion corresponding to the reciprocal of a nonzero real number.

Returns
the inverse of this matrix.
void Invert ( )
inline

Sets this matrix equal to its inverse.

bool IsDiagonal ( ) const
inline

Determines if this is a diagonal matrix. An n x n matrix A = [Aij] is called a diagonal matrix if Aij = 0 for i != j. Thus, for a diagonal matrix, the terms off the main diagonal are all zero.

Returns
true if the matrix is a diagonal matrix, false otherwise.
bool IsIdentity ( ) const
inline

Determines if this matrix is equal to the identity matrix. The identity matrix is I = [Aij], where Aii = 1 and Aij = 0 for i != j. Thus, for the identity matrix, the terms off the main diagonal are all zero, and the terms on the main diagonal are all one.

Returns
true if the matrix is the identity matrix, false otherwise.
bool IsLowerTriangular ( ) const
inline

Determines if this matrix is lower triangular. An n x n matrix A = [Aij] is lower triangular if Aij = 0 for i < j.

Returns
true if the matrix is lower triangular, false otherwise.
bool IsScalar ( ) const
inline

Determines if this is a scalar matrix. A scalar matrix is a diagonal matrix whose diagonal terms are equal.

Returns
true if the matrix is a scalar matrix, false otherwise.
bool IsSingular ( ) const
inline

Determines if this matrix is singular, or non-invertible. A singular matrix has no inverse.

Returns
true if the matrix is singular, false otherwise.
bool IsSkewSymmetric ( ) const
inline

Determines if this matrix is skew symmetric. A matrix is skew symmetric if its transpose is equal to its negative, i.e. -A = A'.

Returns
true if the matrix is skew symmetric, false otherwise.
bool IsSymmetric ( ) const
inline

Determines if this matrix is symmetric. A matrix is symmetric if it is equal to its transpose, i.e. A = A'.

Returns
true if the matrix is symmetric, false otherwise.
bool IsUpperTriangular ( ) const
inline

Determines if this matrix is upper triangular. An n x n matrix A = [Aij] is upper triangular if Aij = 0 for i > j.

Returns
true if the matrix is upper triangular, false otherwise.
void MakeIdentity ( )
inline

Set this matrix to the identity matrix. The identity matrix is I = [Aij], where Aii = 1 and Aij = 0 for i != j. Thus, for the identity matrix, the terms off the main diagonal are all zero, and the terms on the main diagonal are all one.

int Pivot ( unsigned  row)
protected

Pivoting is used in conjunction with Gauss-Jordan reduction to find the inverse of a matrix and in Gaussian Elimination to find the determinant of a matrix. It involves the elementary row operation of interchanging rows (or columns in our column-major matrix). Only the row passed in and rows below it are considered. The row passed in will be swapped with another row below it by selecting the desired pivot element. The pivot is the largest term (in magnitude) in the column equal to row for any of the considered rows. This will always put the largest (in magnitude) term from the column on the diagonal of the matrix.

Parameters
rowis the current row to pivot about. Rows above this are not considered during pivoting, as these rows should already be in their proper form.
void Transpose ( )
inline

Sets this matrix equal to its transpose.

GlsMatrix< Type, DIM > Transposition ( ) const
inline

Calculates the transpose of this matrix. The transpose of a matrix is obtained by interchanging its rows and columns.

Returns
the transpose of this matrix.

Member Data Documentation

Type _data[DIM *DIM]
protected

This is the actual matrix data stored in column-major ordering in a one-dimensional array of the appropriate size to store all matrix terms. The data is stored in this manner so that it can be passed to OpenGL matrix operations, which expect matrices to be ordered this way.

Type* _matrix[DIM]
protected

A column index array. Each element in this array "points" to a column of the matrix within the above data. By using this index, we can address matrix terms using two dimensions, column and row, without incurring a multiplication. Eg. matrix[0] points to a column within data, which is the address of the first term in the column. We can further address into the column and access a particular row by adding another dimension, eg. matrix[0][1]. The indices must be set up at construction time.

const double PRECISION = 1e-7
staticprotected

A very tiny number, close to zero. Used to compare floats


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