Matrix3x4 t: Difference between revisions
TomEdwards (talk | contribs) (Created page with '{{toc-right}} '''<code>matrix3x4_t</code>''' represents a matrix: a mathematical construct that allows Vectors to be [[Wikipedia:Transform…') |
TomEdwards (talk | contribs) No edit summary |
||
Line 5: | Line 5: | ||
Matrices are chiefly used to [[Wikipedia:Rotation matrix|rotate]] vectors, since vector [[Vector#Addition|addition]] and [[Vector#Multiplication|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. | Matrices are chiefly used to [[Wikipedia:Rotation matrix|rotate]] vectors, since vector [[Vector#Addition|addition]] and [[Vector#Multiplication|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. | ||
== | == Functions == | ||
=== Generation === | === Generation === | ||
Line 17: | Line 17: | ||
void SetScaleMatrix( float scale, matrix3x4_t& out ); // Scale | void SetScaleMatrix( float scale, matrix3x4_t& out ); // Scale | ||
</source> | </source> | ||
Use <code>MatrixMultiply()</code> to combine two matrices into one. You can do this any number of times. | |||
=== Application === | === Application === | ||
Line 22: | Line 24: | ||
{{tip|Unless re-using an existing matrix you are better off rotating a vector with <code>[[VectorRotate()]]</code>, which accepts angles directly.}} | {{tip|Unless re-using an existing matrix you are better off rotating a vector with <code>[[VectorRotate()]]</code>, 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: | The mathematical notation for a matrix transformation is (vector * matrix). Source does not support that syntax, though it would be trivial if you wanted to add it, and instead it offers these functions: | ||
<source lang=cpp> | <source lang=cpp> | ||
void VectorTransform( Vector in1, matrix3x4_t in2, Vector out ); | void VectorTransform( Vector in1, matrix3x4_t in2, Vector& out ); | ||
void VectorITransform( Vector in1, matrix3x4_t in2, Vector out ); // 'Inverse' of the above | void VectorITransform( Vector in1, matrix3x4_t in2, Vector& out ); // 'Inverse' of the above | ||
</source> | </source> | ||
There is an overload of <code>[[VectorRotate()]]</code> that accepts a <code>matrix3x4_t</code>. It seems to behave in the same way as <code>VectorTransform()</code>. | There is an overload of <code>[[VectorRotate()]]</code> that accepts a <code>matrix3x4_t</code>. It seems to behave in the same way as <code>VectorTransform()</code>. | ||
=== | === Other / utility === | ||
; <code>void MatrixAngles()</code> | ; <code>void MatrixAngles()</code> | ||
Line 37: | Line 39: | ||
; <code>void MatrixVectors()</code> | ; <code>void MatrixVectors()</code> | ||
: Extract angles and vectors from a matrix. <code>MatrixAngles()</code> has many overloads. There is no way to extract a scale. | : Extract angles and vectors from a matrix. <code>MatrixAngles()</code> has many overloads. There is no way to extract a scale. | ||
; <code>void MatrixTranspose()</code> | ; <code>void MatrixTranspose()</code> | ||
: [[Wikipedia:Transpose|Transposes]] a matrix. {{todo|What this is good for.}} | : [[Wikipedia:Transpose|Transposes]] a matrix. {{todo|What this is good for.}} |
Revision as of 14:31, 25 January 2010
matrix3x4_t
represents a matrix: a mathematical construct that allows Vectors to be transformed.
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.
Functions
Generation
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
Use MatrixMultiply()
to combine two matrices into one. You can do this any number of times.
Application

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 if you wanted to add it, 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 VectorTransform()
.
Other / utility
void MatrixAngles()
void MatrixPosition()
void MatrixVectors()
- Extract angles and vectors from a matrix.
MatrixAngles()
has many overloads. There is no way to extract a scale. void MatrixTranspose()
- Transposes a matrix. Todo: What this is good for.
void MatrixInvert()
- Reverses a matrix, making it transform in the opposite direction(s). You could also use
VectorITransform()
to apply the matrix. bool MatricesAreEqual()
- Instead of (matrix1 == matrix2).
void MatrixCopy()
Confirm:Instead of (matrix1 = matrix2).