| GL Studio C++ Runtime API

Public Types | 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>`

## Public Types
typedef Type | CStyleMatrix[DIM][DIM]
| Typedef for a 4x4 matrix stored as a 2D array.

## 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
Type & | operator() (unsigned row, unsigned col)
Type | operator() (unsigned row, unsigned col) const
bool | operator== (const GlsMatrix< Type, DIM > &rhs) const
bool | operator!= (const GlsMatrix< Type, DIM > &rhs) const
GlsMatrix< Type, DIM > & | operator= (const GlsMatrix< Type, DIM > &m)
GlsMatrix< Type, DIM > & | operator= (const CStyleMatrix m)
GlsMatrix< Type, DIM > | operator+ () const
GlsMatrix< Type, DIM > | operator- () const
GlsMatrix< Type, DIM > & | operator+= (const GlsMatrix< Type, DIM > &rhs)
GlsMatrix< Type, DIM > & | operator-= (const GlsMatrix< Type, DIM > &rhs)
GlsMatrix< Type, DIM > & | operator*= (const GlsMatrix< Type, DIM > &rhs)
GlsMatrix< Type, DIM > & | operator*= (Type scalar)
GlsMatrix< Type, DIM > & | operator/= (Type scalar)
GlsMatrix< Type, DIM > | operator+ (const GlsMatrix< Type, DIM > &rhs) const
GlsMatrix< Type, DIM > | operator- (const GlsMatrix< Type, DIM > &rhs) const
GlsMatrix< Type, DIM > | operator* (const GlsMatrix< Type, DIM > &rhs) const
GlsMatrix< Type, DIM > | operator* (Type scalar) const
GlsMatrix< Type, DIM > | operator/ (Type scalar) const
GlsMatrix< double, 4 > | operator* (const GlsMatrix< double, 4 > &rhs) const
GlsMatrix< float, 4 > | operator* (const GlsMatrix< float, 4 > &rhs) const
GlsMatrix< double, 4 > & | operator*= (const GlsMatrix< double, 4 > &rhs)
GlsMatrix< float, 4 > & | operator*= (const GlsMatrix< float, 4 > &rhs)

## 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() [1/4]

GlsMatrix

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

## ◆ GlsMatrix() [2/4]

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

  m | a row-major, two-dimensional array to initialize the matrix with.

## ◆ GlsMatrix() [3/4]

GlsMatrix | ( | const Type * | m | ) |

Constructor.

Parameters

  m | a column-major, one-dimensional array containing all values to initialize the matrix with.

## ◆ GlsMatrix() [4/4]

GlsMatrix | ( | const GlsMatrix< Type, DIM > & | m | ) |

Copy Constructor.

Parameters

  m | matrix to copy.

## ◆ ~GlsMatrix()

~GlsMatrix
| virtual

Destructor.

## Member Function Documentation

## ◆ Clear()

void Clear | ( |  | ) |
| inline

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

## ◆ closeValues()

bool closeValues | ( | Type | lv,
|  | Type | rv
| ) |  | const
| inline protected

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

Parameters

  lv | The left value.
  rv | The right value.

Returns
  Whether or not the two values are close together.

## ◆ Data() [1/2]

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.

Returns
  A pointer to the underlying matrix array.

## ◆ Data() [2/2]

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.

Returns
  A const pointer to the underlying matrix array.

## ◆ Determinant()

Type Determinant

Calculates the determinant of the matrix.

Returns
  the calculated value of the determinant.

## ◆ Dump()

void Dump

Dump the contents of the matrix to standard output.

## ◆ Initialize()

void Initialize
| inline protected

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.

## ◆ Inverse()

GlsMatrix< Type, DIM > Inverse

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.

## ◆ Invert()

void Invert
| inline

Sets this matrix equal to its inverse.

## ◆ IsDiagonal()

bool IsDiagonal
| 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.

## ◆ IsIdentity()

bool IsIdentity
| 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.

## ◆ IsLowerTriangular()

bool IsLowerTriangular
| 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.

## ◆ IsScalar()

bool IsScalar
| 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.

## ◆ IsSingular()

bool IsSingular
| 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.

## ◆ IsSkewSymmetric()

bool IsSkewSymmetric
| 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.

## ◆ IsSymmetric()

bool IsSymmetric
| 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.

## ◆ IsUpperTriangular()

bool IsUpperTriangular
| 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.

## ◆ MakeIdentity()

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.

## ◆ operator!=()

bool operator!= | ( | const GlsMatrix< Type, DIM > & | rhs | ) | const
| inline

Parameters

  rhs | The matrix to compare.

Returns
  whether or not the matrices are not equal.

## ◆ operator()() [1/2]

Type & operator() | ( | unsigned | row,
|  | unsigned | col
| ) |  |
| inline

Subscript operator (zero-based, no bounds checking).

Parameters

  row | The row of the element to retrieve.
  col | The column of the element to retrieve.

Returns
  A reference to the element at that position.

## ◆ operator()() [2/2]

Type operator() | ( | unsigned | row,
|  | unsigned | col
| ) |  | const
| inline

Subscript operator (zero-based, no bounds checking).

Parameters

  row | The row of the element to retrieve.
  col | The column of the element to retrieve.

Returns
  The value of the element at that position.

## ◆ operator*() [1/4]

GlsMatrix< double, 4 > operator* | ( | const GlsMatrix< double, 4 > & | rhs | ) | const
| inline

Mathematical * operator

Parameters

  rhs | The matrix to multiply by.

Returns
  The resulting matrix.

## ◆ operator*() [2/4]

GlsMatrix< float, 4 > operator* | ( | const GlsMatrix< float, 4 > & | rhs | ) | const
| inline

Mathematical * operator

Parameters

  rhs | The matrix to multiply by.

Returns
  The resulting matrix.

## ◆ operator*() [3/4]

GlsMatrix< Type, DIM > operator* | ( | const GlsMatrix< Type, DIM > & | rhs | ) | const
| inline

Parameters

  rhs | The matrix to multiply by.

Returns
  The resulting matrix.

## ◆ operator*() [4/4]

GlsMatrix< Type, DIM > operator* | ( | Type | scalar | ) | const
| inline

Parameters

  scalar | The value to multiply by.

Returns
  The resulting matrix.

## ◆ operator*=() [1/4]

GlsMatrix< double, 4 > & operator*= | ( | const GlsMatrix< double, 4 > & | rhs | ) |
| inline

Combined assignment *= operator

Parameters

  rhs | The matrix to multiply by.

Returns
  The resulting matrix (this).

## ◆ operator*=() [2/4]

GlsMatrix< float, 4 > & operator*= | ( | const GlsMatrix< float, 4 > & | rhs | ) |
| inline

Combined assignment *= operator

Parameters

  rhs | The matrix to multiply by.

Returns
  The resulting matrix (this).

## ◆ operator*=() [3/4]

GlsMatrix< Type, DIM > & operator*= | ( | const GlsMatrix< Type, DIM > & | rhs | ) |
| inline

Combined assignment *= operator

Parameters

  rhs | Matrix to multiply by.

Returns
  The resulting matrix (this).

## ◆ operator*=() [4/4]

GlsMatrix< Type, DIM > & operator*= | ( | Type | scalar | ) |
| inline

Combined assignment *= operator

Parameters

  scalar | Value to multiply by.

Returns
  The resulting matrix (this).

## ◆ operator+() [1/2]

GlsMatrix< Type, DIM > operator+ | ( |  | ) | const
| inline

Unary + operator

Returns
  This matrix.

## ◆ operator+() [2/2]

GlsMatrix< Type, DIM > operator+ | ( | const GlsMatrix< Type, DIM > & | rhs | ) | const
| inline

Parameters

  rhs | The matrix to add.

Returns
  The resulting matrix.

## ◆ operator+=()

GlsMatrix< Type, DIM > & operator+= | ( | const GlsMatrix< Type, DIM > & | rhs | ) |
| inline

Combined assignment += operator

Parameters

  rhs | Matrix to add.

Returns
  The resulting matrix (this).

## ◆ operator-() [1/2]

GlsMatrix< Type, DIM > operator-
| inline

Unary - operator

Returns
  Matrix with all elements multiplied by -1.

## ◆ operator-() [2/2]

GlsMatrix< Type, DIM > operator- | ( | const GlsMatrix< Type, DIM > & | rhs | ) | const
| inline

Parameters

  rhs | The matrix to subtract.

Returns
  The resulting matrix.

## ◆ operator-=()

GlsMatrix< Type, DIM > & operator-= | ( | const GlsMatrix< Type, DIM > & | rhs | ) |
| inline

Combined assignment -= operator

Parameters

  rhs | Matrix to subtract.

Returns
  The resulting matrix (this).

## ◆ operator/()

GlsMatrix< Type, DIM > operator/ | ( | Type | scalar | ) | const
| inline

Parameters

  scalar | The value to divide by.

Returns
  The resulting matrix.

## ◆ operator/=()

GlsMatrix< Type, DIM > & operator/= | ( | Type | scalar | ) |
| inline

Combined assignment /= operator

Parameters

  scalar | Value to divide by.

Returns
  The resulting matrix (this).

## ◆ operator=() [1/2]

GlsMatrix< Type, DIM > & operator= | ( | const CStyleMatrix | m | ) |
| inline

Assignment operator

Parameters

  m | The matrix to copy from.

Returns
  The resulting matrix (this).

## ◆ operator=() [2/2]

GlsMatrix< Type, DIM > & operator= | ( | const GlsMatrix< Type, DIM > & | m | ) |
| inline

Assignment operator

Parameters

  m | The matrix to copy from.

Returns
  The resulting matrix (this).

## ◆ operator==()

bool operator== | ( | const GlsMatrix< Type, DIM > & | rhs | ) | const
| inline

Parameters

  rhs | The matrix to compare.

Returns
  Whether or not the matrices are equal.

## ◆ Pivot()

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

  row | is the current row to pivot about. Rows above this are not considered during pivoting, as these rows should already be in their proper form.

Returns
  the row number index that was interchanged, if the pivot is different to the incoming row 0 if the pivot was successful on the incoming row -1 if no pivot is possible

## ◆ Transpose()

void Transpose
| inline

Sets this matrix equal to its transpose.

## ◆ Transposition()

GlsMatrix< Type, DIM > Transposition
| 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

## ◆ _data

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.

## ◆ _matrix

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.

## ◆ PRECISION

const double PRECISION = 1e-7
| static protected

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

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

- gls_matrix.h