Main Index : Reference :

Matrix


Description

A 4x4 matrix class.

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] w);

  [vector] GetHPB();

  [vector] GetMulP([vector] p);
  [vector] GetMulV([vector] v);
  [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();
}

Explanation

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. See this tutorial for more information.

Members

SetV0( v )

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

SetV1( v )

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

SetV2( v )

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

SetV3( v )

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


GetV0( v )

[vector] GetV0(v);

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

GetV1( v )

[vector] GetV1(v);

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

GetV2( v )

[vector] GetV2(v);

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

GetV3( v )

[vector] GetV3(v);

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


SetTrans( t )

[bool] SetTrans([vector] t);

Sets up the matrix so that it represents a translation along the vector t. Returns TRUE if successful.

SetScale( s )

[bool] SetScale([vector] s);

Sets up the matrix to scale values by the vector s. Returns TRUE if successful.


SetRotX( s )

[bool] SetRotX([float] w);

Sets up the matrix so that it represents a rotation round the x-axis by the angle w. Returns TRUE if successful.

SetRotY( s )

[bool] SetRotY([float] w);

Sets up the matrix so that it represents a rotation round the y-axis by the angle w. Returns TRUE if successful.

SetRotZ( s )

[bool] SetRotZ([float] w);

Sets up the matrix so that it represents a rotation round the z-axis by the angle w. Returns TRUE if successful.


SetRotHPB( hpb )

[bool] SetRotHPB([vector] hpb);

Sets up the matrix so that it represents a rotation by the hpb angles hpb. Returns TRUE if successful.

SetRotAxis( axis, w )

[bool] SetRotAxis([vector] axis, [float] w);

Sets up the matrix so that it represents a rotation round the vector axis by the angle w. Returns TRUE if successful.


GetHPB()

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


GetMulP( p )

[vector] GetMulP([vector] p);

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

GetMulV( v )

[vector] GetMulV([vector] v);

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 mat is an object matrix and v is a vector inside the object, mat->GetMulV(v) will return v expressed in the parent object's space.

GetMulM( m )

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

MulM_R( m )

[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). Returns TRUE if successful.

MulM_L( m )

[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). Returns TRUE if successful.


Invert()

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


IsEQ( m )

[bool] IsEQ([Matrix] m);

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

IsNE( m )

[bool] IsNE([Matrix] m);

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


CopyTo( dest )

[bool] CopyTo([Matrix] dest);

Copies the values from the matrix to the matrix dest. Returns TRUE if successful.

GetClone()

[Matrix] GetClone();

Returns a copy of the matrix.

See also

Using matrices