A matrix is a two-dimensional array of numbers. In 3ds Max, 4x3 matrices are used. For 3ds Max matrices, the first number is the number of rows (4) and the second number is the number of columns (3). Thus there are a total of 12 elements.
An instance of Matrix3 has a private data member that contains the values:
The layout of these elements is shown in the following diagram:
The following matrix is called the 'Identity Matrix'. This special matrix, when multiplied by a vector or another matrix, yields the original matrix.
The 3ds Max API provides several ways to create identity matrices. If a value of 1 is passed to the constructor of a Matrix3 it is initialized to the identity. For example
Matrix3 tmat(1); // Identity matrix
You may also use a method of Matrix3 to reset a matrix to the identity, for example:
tmat.IdentityMatrix(); // Reset to the identity matrix
You can verify if a matrix is equal to the identity by using:
BOOL isIdent = tmat.IsIdentity();
The following sections discuss the ways matrices can be used in transformations.
One thing that can be done is to multiply a vector (Point3) by a matrix (Matrix3). This results in a new vector as a result. This is often used to transform vectors from one coordinate space to another. There is a global function in the SDK that does this.
Point3 VectorTransform(constMatrix3& M, const Point3& V);
Transform the vector (Point3) with the specified matrix.
Note: In 3ds Max, all vectors are assumed to be row vectors. Under this assumption, multiplication of a vector with a matrix using the * operator can be written either way (Matrix*Vector or Vector*Matrix), for ease of use, and the result is the same -- the (row) vector transformed by the matrix.
It is often also very useful to compute the multiplication of a matrix by another matrix. This produces a matrix as the result. Matrix multiplication is associate but not commutative. That is, AB is not the same as BA, but (AB)C is the same as A(BC). This property is very useful since separate matrix transformations can be concatenated together and then all applied at once. 3ds Max provides several methods to perform matrix multiplication; each are operators of the Matrix3 class.
There is a program available in \MAXSDK\HOWTO\UTILITIES\TRANSFORMMATRIXVIZ\TMATTEST.CPP that shows visually how matrices are constructed for move/rotate/scale transformations. This program also shows the results of some of the INode methods that return transformation matrices (for example, GetNodeTM(), GetObjectTM(), etc.). Developers can load this project into VC++ and build it. Then copy TMATTEST.DLU into the STDPLUGS directory where 3ds Max can load it. To run it select TMatTest from the HowTo section of the Utilities menu. The program operates on the first object in the selection set. Create a node in the scene (for instance a Box) and experiment with animating the node, binding it to space warps, etc., and viewing the resulting matrices returned from the INode methods. You can also build transformations from scratch and apply them to the first selected object.