# 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:

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

From the OpenGL red book (page 68) v’ = M*v

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 an matrix and sets it to identity.

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()

Invert 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.