GL Studio API
|
#include <gls_matrix.h>
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 |
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.
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.
m | a row-major, two-dimensional array to initialize the matrix with. |
GlsMatrix | ( | const Type * | m | ) |
Constructor.
m | a column-major, one-dimensional array containing all values to initialize the matrix with. |
|
virtual |
Destructor.
|
inline |
Zero out the matrix so that all terms are equal to zero.
|
inlineprotected |
Decides if the two values are close together determined by the constant PRECISION. The formula is lv - PRECISION < rv < lv + PRECISION
lv | left value |
rv | right value |
|
inline |
Provides access to the raw column-major matrix data as a one dimensional array in a format suitable for Open GL matrix operations.
|
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.
void Dump | ( | ) | const |
Dump the contents of the matrix to standard output.
|
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.
|
inline |
Sets this matrix equal to its inverse.
|
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.
|
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.
|
inline |
Determines if this matrix is lower triangular. An n x n matrix A = [Aij] is lower triangular if Aij = 0 for i < j.
|
inline |
Determines if this is a scalar matrix. A scalar matrix is a diagonal matrix whose diagonal terms are equal.
|
inline |
Determines if this matrix is singular, or non-invertible. A singular matrix has no inverse.
|
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'.
|
inline |
Determines if this matrix is symmetric. A matrix is symmetric if it is equal to its transpose, i.e. A = A'.
|
inline |
Determines if this matrix is upper triangular. An n x n matrix A = [Aij] is upper triangular if Aij = 0 for i > j.
|
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.
|
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.
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. |
|
inline |
Sets this matrix equal to its transpose.
|
inline |
Calculates the transpose of this matrix. The transpose of a matrix is obtained by interchanging its rows and columns.
|
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.
|
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.
|
staticprotected |
A very tiny number, close to zero. Used to compare floats