C++ documentation C documentation

A 3D matrix allows you to transform a Vector3D ie a point in 3D space. Commonly it is used to scale, translate, or rotate the point around the X, Y, and/or Z axes.

Matrices can also be multiplied together to produce a combination of the above transforms. You could create a matrix for a rotation around the X axis, and another for rotation around the Y axis, and yet another for a translation. These matrices can be multiplied together to produce a matrix that does all three transforms in one go and this is useful if you want to transform more than one point because you then only have to apply the resultant matrix to each point.

There is a lot of info 'out there' about matrices, eg Wikipedia etc, so I'm not going to give the whole maths lesson.

A C++ implementation is available via the Matrix3D class.

Function

- MAKE_IDENTITY_MATRIX3D - Create an identity matrix.
- matrix3d_Copy - Copy one matrix to another ie dst = src.
- matrix3d_Determinant - Returns the determinant of the matrix.
- matrix3d_Multiply - Multiply two matrices together. dst = dst * src.
- matrix3d_Set - Initialise a matrix with the given set of values.
- matrix3d_SetRotateX - Set the matrix to be a rotation around the X axis by the specified number of radians.
- matrix3d_SetRotateY - Set the matrix to be a rotation around the Y axis by the specified number of radians.
- matrix3d_SetRotateZ - Set the matrix to be a rotation around the Z axis by the specified number of radians.
- matrix3d_SetScale - Set the matrix to the given scaling factor in X, Y and Z.
- matrix3d_Transform - Transform a VECTOR3D by the given matrix.
- matrix3d_Add - Add two matrices together. dst = dst + src.
- matrix3d_Zero - Sets all elements of the matrix to 0.
- matrix3d_Unity - Sets all elements of the matrix to 0 but the diagonals to 1 :-
- matrix3d_Subtract - Subtract two matrices. dst = dst - src.

Create an identity matrix.

Example:

MATRIX3D identity = MAKE_IDENTITY_MATRIX3D();

An identity matrix has the value 1 along its diagonal and 0 everywhere else. It is called the identity matrix because if you multiply it with another matrix, or with a VECTOR3D, then it makes no changes.

Copy one matrix to another ie dst = src.

For example:

// Create an identity matrix

MATRIX3D identity = MAKE_IDENTITY_MATRIX3D();

// Create another matrix with unknown values

MATRIX3D another;

// another = identity

matrix3d_Copy(&another, &identity);

// Both now hold the identity matrix

Returns the determinant of the matrix.

Multiply two matrices together. dst = dst * src.

Initialise a matrix with the given set of values.

The resultant matrix is set to:-

[ m00 m01 m02 ]

[ m10 m11 m12 ]

[ m20 m21 m22 ]

Set the matrix to be a rotation around the X axis by the specified number of radians.

Set the matrix to be a rotation around the Y axis by the specified number of radians.

Set the matrix to be a rotation around the Z axis by the specified number of radians.

Set the matrix to the given scaling factor in X, Y and Z.

Transform a VECTOR3D by the given matrix.

Add two matrices together. dst = dst + src.

Sets all elements of the matrix to 0.

Sets all elements of the matrix to 0 but the diagonals to 1 :-

1,0,0

0,1,0

0,0,1

Subtract two matrices. dst = dst - src.