cee::Mat4d

class Mat4d

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.

Public Functions

Mat4d()

Constructs a matrix and sets it to identity.

See also

setIdentity and isIdentity()

Mat4d(const Mat4d &other)

Constructs a matrix as a copy of other.

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.

Mat4d &operator=(const Mat4d &other)

Assigns other to this matrix and returns a reference to this matrix.

bool operator==(const Mat4d &rhs) const

Returns true if rhs is equal to this matrix; otherwise returns false.

bool operator!=(const Mat4d &rhs) const

Returns true if rhs is NOT equal to this matrix; otherwise returns false.

const Mat4d operator*(const Mat4d &rhs) const

Multiplies this matrix M with the matrix rhs, M = M*rhs.

bool isIdentity() const

Returns true if the matrix is an identity matrix.

void setIdentity()

Sets this matrix to an identity matrix.

bool isZero() const

Returns true if all values are zero.

void setZero()

Sets all values to zero.

bool invert()

Inverts the matrix. Returns false if the matrix is not invertible.

double rowCol(int row, int col) const

Returns the value at the give row and column indices.

void setRowCol(int row, int col, double value)

Sets the value value into the matrix at the given row and column indices.

double &operator()(int row, int col)

Returns the value at the give row and column.

double operator()(int row, int col) const

Returns the value at the give row and column indices.

const double *rawPointer() const

Returns the values of the matrix as a raw double array.

Public Static Functions

static Mat4d fromTranslation(const Vec3d &trans)

Creates a transformation matrix containing only translation.

static Mat4d fromScaling(const Vec3d &scale)

Creates a transformation matrix containing only scaling.

static Mat4d fromRotation(const Vec3d &axis, double angle)

Creates a transformation matrix containing only rotation.