# Matrix

A 4x4 matrix `class`.

A matrix in CINEMA 4D is 4x4 and looks like this: It contains four three-dimensional column vectors: `v0`, `v1`, `v2` and `v3`. The first row of the matrix is always `(1,0,0,0)` and cannot be changed.

Matrices can be used to represent the local coordinate systems of all objects. Then the vector `v0` represents the position and the vectors `v1`, `v2` and `v3` represent the directions of the three coordinate axes.

Understanding matrices is important when programming in 3D, or at least understanding how to use them. For more information, read the article "Using matrices".

## Definition

``````class Matrix
{
public:
Matrix();

bool SetV0(vector v);
bool SetV1(vector v);
bool SetV2(vector v);
bool SetV3(vector v);

vector GetV0();
vector GetV1();
vector GetV2();
vector GetV3();

bool SetTrans(vector t);
bool SetScale(vector s);
bool SetRotX(float w);
bool SetRotY(float w);
bool SetRotZ(float w);

bool SetRotHPB(vector hpb);
bool SetRotAxis(vector axis, float x);

vector GetHPB();

vector GetMulP(vector p);
vector GetMulV(vector p);
Matrix GetMulM(Matrix m);

bool MulM_R(Matrix m);
bool MulM_L(Matrix m);

bool Invert();

bool IsEQ(Matrix m);
bool IsNE(Matrix m);

bool CopyTo(Matrix dest);
Matrix GetClone();
};
``````

## Members

Constructor

#### bool SetV0(vector v)

Sets the `v0` vector of the matrix to `v`. This is the position in an object matrix. Returns `TRUE` if successful.

#### bool SetV1(vector v)

Sets the `v1` vector of the matrix to `v`. This is the x axis vector in an object matrix. Returns `TRUE` if successful.

#### bool SetV2(vector v)

Sets the `v2` vector of the matrix to `v`. This is the y axis vector in an object matrix. Returns `TRUE` if successful.

#### bool SetV3(vector v)

Sets the `v3` vector of the matrix to `v`. This is the z axis vector in an object matrix. Returns `TRUE` if successful.

#### vector GetV0()

Returns the `v0` vector of the matrix. This is the position in an object matrix.

#### vector GetV1()

Returns the `v1` vector of the matrix. This is the x axis vector in an object matrix.

#### vector GetV2()

Returns the `v2` vector of the matrix. This is the y axis vector in an object matrix.

#### vector GetV3()

Returns the `v3` vector of the matrix. This is the z axis vector in an object matrix.

#### bool SetTrans(vector t)

Sets up the matrix so that it represents a translation along the vector `t`.

##### Return
bool

`TRUE` if successful, otherwise `FALSE`.

#### bool SetScale(vector s)

Sets up the matrix to scale values by the vector `s`.

##### Return
bool

`TRUE` if successful, otherwise `FALSE`.

#### bool SetRotX(float w)

Sets up the matrix so that it represents a rotation round the x axis by the angle `w`.

##### Return
bool

`TRUE` if successful, otherwise `FALSE`.

#### bool SetRotY(float w)

Sets up the matrix so that it represents a rotation round the y axis by the angle `w`.

##### Return
bool

`TRUE` if successful, otherwise `FALSE`.

#### bool SetRotZ(float w)

Sets up the matrix so that it represents a rotation round the z axis by the angle `w`.

##### Return
bool

`TRUE` if successful, otherwise `FALSE`.

#### bool SetRotHPB(vector hpb)

Sets up the matrix so that it represents a rotation by the hpb angles `hpb`.

##### Return
bool

`TRUE` if successful, otherwise `FALSE`.

#### bool SetRotAxis(vector axis, float x)

Sets up the matrix so that it represents a rotation round the vector axis by the angle `w`.

##### Return
bool

`TRUE` if successful, otherwise `FALSE`.

#### vector GetHPB()

Returns the hpb angles derived from the matrix. If the matrix is an orthogonal object matrix, this is the object's rotation. Otherwise the result is undefined.

#### vector GetMulP(vector p)

Returns the product of the matrix and the point `p`. If the matrix `m` is an object matrix and `p` is a point inside the object, `m->GetMulP(p)` will return `p` expressed in the parent object's space.

#### vector GetMulV(vector p)

Returns the product of the matrix and the vector `p`. This is the same as GetMulP(), except that the `v0` vector of the matrix is disregarded. If the matrix `m` is an object matrix and `v` is a vector inside the object, `m->GetMulV(v)` will return `v` expressed in the parent object's space.

#### Matrix GetMulM(Matrix m)

Returns the product of the matrix and the matrix `m`. This is the same as first transforming `m`'s `v0` vector with GetMulP() and then its `v1`, `v2` and `v3` vectors with GetMulV(). The result is the matrix `m` expressed in the matrix's parent system.

#### bool MulM_R(Matrix m)

Multiplies the matrix with the matrix `m` from the right. Doing `mat->MulM_R(m)` is the same as doing `mat=mat->GetMulM(m)`.

##### Return
bool

`TRUE` if successful, otherwise `FALSE`.

#### bool MulM_L(Matrix m)

Multiplies the matrix with the matrix `m` from the left. Doing `mat->MulM_L(m)` is the same as doing `mat=m->GetMulM(mat)`.

##### Return
bool

`TRUE` if successful, otherwise `FALSE`.

#### bool Invert()

Inverts the matrix. Multiplying a global point with the inverse matrix will express the point in the local space of the original matrix. If the matrix is singular, i.e. if its determinant is 0.0, it cannot be inverted. Then the matrix will be set to the default identity matrix. Otherwise `TRUE` is returned.

##### Return
bool

`TRUE` if successful, otherwise `FALSE`.

#### bool IsEQ(Matrix m)

Returns `TRUE` if the matrix is equal to the matrix `m`.

##### Return
bool

`TRUE` if the matrix is equal to the passed matrix, otherwise `FALSE`.

#### bool IsNE(Matrix m)

Returns `TRUE` if the matrix isn't equal to the matrix `m`.

##### Return
bool

`TRUE` if the matrix is not equal to the passed matrix, otherwise `FALSE`.

#### bool CopyTo(Matrix dest)

Copies the values from the matrix to the matrix `dest`.

##### Return
bool

`TRUE` if successful, otherwise `FALSE`.

#### Matrix GetClone()

Returns a copy of the matrix.