Matrices are chiefly used to rotate vectors, since vector addition and multiplication respectively take care of translation and scaling. A single matrix can store a transformation in all three modes however, making it powerful in calculation-heavy areas like vertex rendering and 3D view set-up.
Matrix generation is best left to Source's pre-existing functions:
void AngleMatrix( QAngle angle, matrix_3x4_t& out ); // Rotation; can also use Quaternions or Radians void PositionMatrix( Vector position, matrix3x4_t& out ); // Translation void AngleMatrix( QAngle angle, Vector position, matrix3x4_t& out ); // Rotation + translation void SetScaleMatrix( float scale, matrix3x4_t& out ); // Scale
VectorRotate(), which accepts angles directly.
The mathematical notation for a matrix transformation is (vector * matrix). Source does not support that syntax, though it would be trivial to add, and instead it offers these functions:
void VectorTransform( Vector in1, matrix3x4_t in2, Vector out ); void VectorITransform( Vector in1, matrix3x4_t in2, Vector out ); // 'Inverse' of the above
There is an overload of
VectorRotate() that accepts a
matrix3x4_t. It seems to behave in the same way as
- Extract angles and vectors from a matrix.
MatrixAngles()has many overloads. There is no way to extract a scale.
void MatrixMultiply(matrix3x4_t in1, matrix3x4_t in2, matrix3x4_t out)
- Combines two matrices into one.
- Transposes a matrix. To do: What this is good for.
- Reverses a matrix, making it transform in the opposite direction(s). You could also use
VectorITransform()to apply the matrix.
- Instead of (matrix1 == matrix2).
- Confirm:Instead of (matrix1 = matrix2).