4 dimensional matrix. More...
Public Member Functions | |
Mat4d () | |
Constructs an matrix and sets it to identity. More... | |
Mat4d (const Mat4d &other) | |
Constructs a matrix as a copy of other. More... | |
Mat4d (double m00, double m01, double m02, double m03, double m10, double m11, double m12, double m13, double m20, double m21, double m22, double m23, double m30, double m31, double m32, double m33) | |
Construct a matrix using the given matrix values. More... | |
Mat4d & | operator= (const Mat4d &other) |
Assigns other to this matrix and returns a reference to this matrix. More... | |
bool | operator== (const Mat4d &rhs) const |
Returns true if rhs is equal to this matrix; otherwise returns false. More... | |
bool | operator!= (const Mat4d &rhs) const |
Returns true if rhs is NOT equal to this matrix; otherwise returns false. More... | |
const Mat4d | operator* (const Mat4d &rhs) const |
Multiplies this matrix M with the matrix rhs, M = M*rhs. More... | |
bool | isIdentity () const |
Returns true if the matrix is an identity matrix. More... | |
void | setIdentity () |
Sets this matrix to an identity matrix. More... | |
bool | isZero () const |
Returns true if all values are zero. More... | |
void | setZero () |
Sets all values to zero. More... | |
bool | invert () |
Invert the matrix. Returns false if the matrix is not invertible. More... | |
double | rowCol (int row, int col) const |
Returns the value at the give row and column indices. More... | |
void | setRowCol (int row, int col, double value) |
Sets the value value into the matrix at the given row and column indices. More... | |
double & | operator() (int row, int col) |
Returns the value at the give row and column. More... | |
double | operator() (int row, int col) const |
Returns the value at the give row and column indices. More... | |
const double * | rawPointer () const |
Returns the values of the matrix as a raw double array. More... | |
Static Public Member Functions | |
static Mat4d | fromTranslation (const Vec3d &trans) |
Creates a transformation matrix containing only translation. More... | |
static Mat4d | fromScaling (const Vec3d &scale) |
Creates a transformation matrix containing only scaling. More... | |
static Mat4d | fromRotation (const Vec3d &axis, double angle) |
Creates a transformation matrix containing only rotation. More... | |
4 dimensional matrix.
Matrices are stored internally as a one dimensional array for performance reasons.
The internal indices into the 1D array are as follows:
| m00 m01 m02 m03 | | 0 4 8 12 | | m10 m11 m12 m13 | | 1 5 9 13 | | m20 m21 m22 m23 | | 2 6 10 14 | | m30 m31 m32 m33 | | 3 7 11 15 |
This is consistent with the way matrices are represented in OpenGL. To exemplify, translation values are stored in elements 12,13,14; see figure below
| 1 0 0 Tx | | 0 1 0 Ty | | 0 0 1 Tz | | 0 0 0 1 |
From the OpenGL red book (page 68) v' = M*v
| X'| | 1 0 0 Tx | | X | | Y'| | 0 1 0 Ty | | Y | | Z'| = | 0 0 1 Tz | * | Z | | 1 | | 0 0 0 1 | | 1 |
Beware when porting code that uses C style double array indexing. In this case, the first index given will correspond to the column, eg M[3][0] = Tx, M[3][1] = Ty, M[3][2] = Tz
To ease accessing the internal 1D array in implementations, the private eij constants can be used. These are consistent with the normal row column ordering, so that e02 accesses the element in the first row and the third column.
cee::Mat4d::Mat4d | ( | ) |
Constructs an matrix and sets it to identity.
cee::Mat4d::Mat4d | ( | const Mat4d & | other | ) |
Constructs a matrix as a copy of other.
cee::Mat4d::Mat4d | ( | double | m00, |
double | m01, | ||
double | m02, | ||
double | m03, | ||
double | m10, | ||
double | m11, | ||
double | m12, | ||
double | m13, | ||
double | m20, | ||
double | m21, | ||
double | m22, | ||
double | m23, | ||
double | m30, | ||
double | m31, | ||
double | m32, | ||
double | m33 | ||
) |
Construct a matrix using the given matrix values.
|
static |
Creates a transformation matrix containing only rotation.
|
static |
Creates a transformation matrix containing only scaling.
|
static |
Creates a transformation matrix containing only translation.
bool cee::Mat4d::invert | ( | ) |
Invert the matrix. Returns false if the matrix is not invertible.
bool cee::Mat4d::isIdentity | ( | ) | const |
Returns true if the matrix is an identity matrix.
bool cee::Mat4d::isZero | ( | ) | const |
Returns true if all values are zero.
bool cee::Mat4d::operator!= | ( | const Mat4d & | rhs | ) | const |
Returns true if rhs is NOT equal to this matrix; otherwise returns false.
double & cee::Mat4d::operator() | ( | int | row, |
int | col | ||
) |
Returns the value at the give row and column.
double cee::Mat4d::operator() | ( | int | row, |
int | col | ||
) | const |
Returns the value at the give row and column indices.
Multiplies this matrix M with the matrix rhs, M = M*rhs.
Assigns other to this matrix and returns a reference to this matrix.
bool cee::Mat4d::operator== | ( | const Mat4d & | rhs | ) | const |
Returns true if rhs is equal to this matrix; otherwise returns false.
const double * cee::Mat4d::rawPointer | ( | ) | const |
Returns the values of the matrix as a raw double array.
double cee::Mat4d::rowCol | ( | int | row, |
int | col | ||
) | const |
Returns the value at the give row and column indices.
void cee::Mat4d::setIdentity | ( | ) |
Sets this matrix to an identity matrix.
void cee::Mat4d::setRowCol | ( | int | row, |
int | col, | ||
double | value | ||
) |
Sets the value value into the matrix at the given row and column indices.
void cee::Mat4d::setZero | ( | ) |
Sets all values to zero.