C++ documentation  C documentation

Matrix3D.h

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.

Function

MATRIX3D MAKE_IDENTITY_MATRIX3D

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.

matrix3d_Copy(MATRIX3D* dst, const MATRIX3D* src)

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

double matrix3d_Determinant(const MATRIX3D* matrix)

Returns the determinant of the matrix.

matrix3d_Multiply(MATRIX3D* dst, const MATRIX3D* src)

Multiply two matrices together. dst = dst * src.

matrix3d_Set(MATRIX3D* matrix,double m00,double m01,double m02,double m10,double m11,double m12,double m20,double m21,double m22

Initialise a matrix with the given set of values.
The resultant matrix is set to:-
[ m00 m01 m02 ]
[ m10 m11 m12 ]
[ m20 m21 m22 ]

matrix3d_SetRotateX(MATRIX3D* matrix, double radians)

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

matrix3d_SetRotateY(MATRIX3D* matrix, double radians)

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

matrix3d_SetRotateZ(MATRIX3D* matrix, double radians)

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

matrix3d_SetScale(MATRIX3D* matrix, double scale)

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

matrix3d_Transform(VECTOR3D* dst, const VECTOR3D* src, const MATRIX3D* matrix)

Transform a VECTOR3D by the given matrix.