#include <Matrix.h>
Collaboration diagram for gmtl::Matrix:
Public Types | |
typedef DATA_TYPE | DataType |
use this to declare single value types of the same type as this matrix. More... | |
enum | Params { Rows = ROWS, Cols = COLS } |
enum | XformState { IDENTITY = 1, ORTHOGONAL = 2, ORTHONORMAL = 4, AFFINE = 8, FULL = 16, XFORM_ERROR = 32 } |
describes the xforms that this matrix has been through. More... | |
Public Methods | |
Matrix () | |
Default Constructor (Identity constructor). More... | |
Matrix (const Matrix< DATA_TYPE, ROWS, COLS > &matrix) | |
copy constructor. More... | |
void | set (DATA_TYPE v00, DATA_TYPE v01, DATA_TYPE v10, DATA_TYPE v11) |
element wise setter for 2x2. More... | |
void | set (DATA_TYPE v00, DATA_TYPE v01, DATA_TYPE v02, DATA_TYPE v10, DATA_TYPE v11, DATA_TYPE v12) |
element wise setter for 2x3. More... | |
void | set (DATA_TYPE v00, DATA_TYPE v01, DATA_TYPE v02, DATA_TYPE v10, DATA_TYPE v11, DATA_TYPE v12, DATA_TYPE v20, DATA_TYPE v21, DATA_TYPE v22) |
element wise setter for 3x3. More... | |
void | set (DATA_TYPE v00, DATA_TYPE v01, DATA_TYPE v02, DATA_TYPE v03, DATA_TYPE v10, DATA_TYPE v11, DATA_TYPE v12, DATA_TYPE v13, DATA_TYPE v20, DATA_TYPE v21, DATA_TYPE v22, DATA_TYPE v23) |
element wise setter for 3x4. More... | |
void | set (DATA_TYPE v00, DATA_TYPE v01, DATA_TYPE v02, DATA_TYPE v03, DATA_TYPE v10, DATA_TYPE v11, DATA_TYPE v12, DATA_TYPE v13, DATA_TYPE v20, DATA_TYPE v21, DATA_TYPE v22, DATA_TYPE v23, DATA_TYPE v30, DATA_TYPE v31, DATA_TYPE v32, DATA_TYPE v33) |
element wise setter for 4x4. More... | |
void | set (const DATA_TYPE *data) |
set the matrix to the given data. More... | |
void | setTranspose (const DATA_TYPE *data) |
set the matrix to the transpose of the given data. More... | |
DATA_TYPE & | operator() (const unsigned row, const unsigned column) |
access [row, col] in the matrix. More... | |
const DATA_TYPE & | operator() (const unsigned row, const unsigned column) const |
access [row, col] in the matrix (const version). More... | |
RowAccessor | operator[] (const unsigned row) |
bracket operator. More... | |
const DATA_TYPE * | getData () const |
Get a DATA_TYPE pointer to the matrix data RETVAL: Returns a ptr to the head of the matrix data. More... | |
bool | isError () |
void | setError () |
Public Attributes | |
DATA_TYPE | mData [COLS *ROWS] |
Column major. More... | |
char | mState |
describes what xforms are in this matrix. More... |
C/C++ uses matrices in row major order. In other words the access indices look like: mat[row][col]
(0,0) (0,1) (0,2) (0,3) <=== Array
(1,0) (1,1) (1,2) (1,3) <=== Array
(2,0) (2,1) (2,2) (2,3) <=== Array
(3,0) (3,1) (3,2) (3,3) <=== Array
OpenGL ordering specifies that the matrix has to be column major in memory, so we need to access it more like:
NOTE: The given indexes are what the cells have to be called in C/C++ notation. Since we are putting the columns into memory back-to-back.
(0,0) (1,0) (2,0) (3,0)
(0,1) (1,1) (2,1) (3,1)
(0,2) (1,2) (2,2) (3,2)
(0,3) (1,3) (2,3) (3,3)
^ ^ ^ ^
====================== Arrays
So basically OpenGL ordering is the Transpose of the way C++ accesses the array
Definition at line 74 of file Matrix.h.
|
use this to declare single value types of the same type as this matrix.
|
|
Definition at line 80 of file Matrix.h.
|
|
describes the xforms that this matrix has been through.
Definition at line 110 of file Matrix.h.
00111 { 00112 IDENTITY = 1, 00113 ORTHOGONAL = 2, 00114 ORTHONORMAL = 4, 00115 AFFINE = 8, 00116 FULL = 16, 00117 XFORM_ERROR = 32 // error bit 00118 }; |
|
Default Constructor (Identity constructor).
Definition at line 121 of file Matrix.h. References FULL, gmtl::Math::Min, mState, and operator().
00122 { 00124 for (unsigned int r = 0; r < ROWS; ++r) 00125 for (unsigned int c = 0; c < COLS; ++c) 00126 this->operator()( r, c ) = (DATA_TYPE)0.0; 00127 00129 for (unsigned int x = 0; x < Math::Min( COLS, ROWS ); ++x) 00130 this->operator()( x, x ) = (DATA_TYPE)1.0; 00131 00133 mState = FULL; 00134 }; |
|
copy constructor.
Definition at line 137 of file Matrix.h.
|
|
Get a DATA_TYPE pointer to the matrix data RETVAL: Returns a ptr to the head of the matrix data.
Definition at line 347 of file Matrix.h. References mData.
00347 { return (DATA_TYPE*)mData; } |
|
Definition at line 349 of file Matrix.h. References mState, and XFORM_ERROR.
00350 { 00351 return mState & XFORM_ERROR; 00352 } |
|
access [row, col] in the matrix (const version).
Definition at line 323 of file Matrix.h. References gmtlASSERT, and mData.
00324 { 00325 gmtlASSERT( (row < ROWS) && (column < COLS) ); 00326 return mData[column*ROWS + row]; 00327 } |
|
access [row, col] in the matrix.
Definition at line 316 of file Matrix.h. References gmtlASSERT, and mData. Referenced by Matrix, and setTranspose.
00317 { 00318 gmtlASSERT( (row < ROWS) && (column < COLS) ); 00319 return mData[column*ROWS + row]; 00320 } |
|
bracket operator.
Definition at line 330 of file Matrix.h.
00331 { 00332 return RowAccessor(this, row); 00333 } |
|
set the matrix to the given data. This function is useful to copy matrix data from another math library.
"Example (to a matrix using an external math library):"pfMatrix other_matrix; other_matrix.setRot( 90, 1, 0, 0 ); gmtl::Matrix44f mat; mat.set( other_matrix.getFloatPtr() ); WARNING: this isn't really safe, size and datatype are not enforced by the compiler.
Definition at line 276 of file Matrix.h. References FULL, mData, and mState.
|
|
element wise setter for 4x4.
Definition at line 224 of file Matrix.h. References FULL, gmtlASSERT, mData, and mState.
00228 { 00229 gmtlASSERT( ROWS == 4 && COLS == 4 );// could be compile time... 00230 mData[0] = v00; 00231 mData[1] = v10; 00232 mData[2] = v20; 00233 mData[4] = v01; 00234 mData[5] = v11; 00235 mData[6] = v21; 00236 mData[8] = v02; 00237 mData[9] = v12; 00238 mData[10] = v22; 00239 00240 // right row 00241 mData[12] = v03; 00242 mData[13] = v13; 00243 mData[14] = v23; 00244 00245 // bottom row 00246 mData[3] = v30; 00247 mData[7] = v31; 00248 mData[11] = v32; 00249 mData[15] = v33; 00250 mState = FULL; 00251 } |
|
element wise setter for 3x4.
Definition at line 199 of file Matrix.h. References FULL, gmtlASSERT, mData, and mState.
00202 { 00203 gmtlASSERT( ROWS == 3 && COLS == 4 );// could be compile time... 00204 mData[0] = v00; 00205 mData[1] = v10; 00206 mData[2] = v20; 00207 mData[3] = v01; 00208 mData[4] = v11; 00209 mData[5] = v21; 00210 mData[6] = v02; 00211 mData[7] = v12; 00212 mData[8] = v22; 00213 00214 // right row 00215 mData[9] = v03; 00216 mData[10] = v13; 00217 mData[11] = v23; 00218 mState = FULL; 00219 } |
|
element wise setter for 3x3.
Definition at line 177 of file Matrix.h. References FULL, gmtlASSERT, mData, and mState.
00180 { 00181 gmtlASSERT( ROWS == 3 && COLS == 3 ); // could be at compile time... 00182 mData[0] = v00; 00183 mData[1] = v10; 00184 mData[2] = v20; 00185 00186 mData[3] = v01; 00187 mData[4] = v11; 00188 mData[5] = v21; 00189 00190 mData[6] = v02; 00191 mData[7] = v12; 00192 mData[8] = v22; 00193 mState = FULL; 00194 } |
|
element wise setter for 2x3.
Definition at line 161 of file Matrix.h. References FULL, gmtlASSERT, mData, and mState.
|
|
element wise setter for 2x2.
Definition at line 147 of file Matrix.h. References FULL, gmtlASSERT, mData, and mState. Referenced by Matrix.
|
|
Definition at line 353 of file Matrix.h. References mState, and XFORM_ERROR.
00354 { 00355 mState |= XFORM_ERROR; 00356 } |
|
set the matrix to the transpose of the given data. normally set() takes raw matrix data in column by column order, this function allows you to pass in row by row data. Normally you'll use this function if you want to use a float array to init the matrix (see code example).
"Example (to set a [15 -4 20] translation using float array):"float data[] = { 1, 0, 0, 15, 0, 1, 0, -4, 0, 0, 1, 20, 0, 0, 0, 1 }; gmtl::Matrix44f mat; mat.setTranspose( data ); WARNING: this isn't really safe, size and datatype are not enforced by the compiler.
Definition at line 306 of file Matrix.h. References FULL, mState, and operator().
00307 { 00309 for (unsigned int r = 0; r < ROWS; ++r) 00310 for (unsigned int c = 0; c < COLS; ++c) 00311 this->operator()( r, c ) = data[(r * COLS) + c]; 00312 mState = FULL; 00313 } |
|
Column major. In other words {Column1, Column2, Column3, Column4} in memory access element mData[column][row] Definition at line 362 of file Matrix.h. Referenced by getData, operator(), and set. |
|
describes what xforms are in this matrix.
Definition at line 365 of file Matrix.h. Referenced by isError, Matrix, set, setError, and setTranspose. |