Matrix3x4 t: Difference between revisions
Stoopdapoop (talk | contribs) No edit summary |
Thunder4ik (talk | contribs) m (→See also: clean up, replaced: See Also → See also) |
||
(5 intermediate revisions by 4 users not shown) | |||
Line 1: | Line 1: | ||
{{lang|$title=matrix3x4_t|Matrix3x4_t}} | |||
{{toc-right}} | {{toc-right}} | ||
{{ent|matrix3x4_t}} is a C++ class that represents a [[Wikipedia:Matrix (mathematics)|matrix]]: a mathematical construct that allows [[Vector]]s to be [[Wikipedia:Transformation (geometry)|transformed]]. | |||
Matrices are chiefly used to [[Wikipedia:Rotation matrix|rotate]] vectors, since translation and scaling are taken care of by vector [[Vector#Addition|addition]] and [[Vector#Multiplication|multiplication]] respectively. A single matrix can store a transformation in all four modes however, making them useful in transformation-intense operations like [[vertex]] rasterization. | |||
The [[VMatrix]] class offers an additional row to use (4x4) and allows you to utilize a few different functions. Matrices of that dimension in source are mainly required to describe perspective transformations during rendering. | |||
== Functions == | == Functions == | ||
=== Generation === | === Generation === | ||
Matrix generation is best left to Source's pre-existing functions: | Matrix generation is best left to Source's pre-existing functions: | ||
Line 23: | Line 21: | ||
=== Application === | === Application === | ||
{{tip|Unless re-using an existing matrix, you are better off rotating a vector with {{ent|VectorRotate()}}, which accepts angles directly.}} | |||
{{tip|Unless re-using an existing matrix you are better off rotating a vector with | |||
The mathematical notation for a matrix transformation is (vector * matrix). Source does not support that syntax, though it would be trivial to add if you so wanted, and instead offers these functions: | The mathematical notation for a matrix transformation is (vector * matrix). Source does not support that syntax, though it would be trivial to add if you so wanted, and instead offers these functions: | ||
Line 33: | Line 30: | ||
</source> | </source> | ||
There is an overload of | There is an overload of {{Ent|VectorRotate()}} that accepts a <tt>matrix3x4_t</tt>. It seems to behave in the same way as <tt>VectorTransform()</tt>. | ||
=== Other/Utility === | |||
; <code>void MatrixAngles()</code> | ; <code>void MatrixAngles()</code> | ||
; <code>void MatrixPosition()</code> | ; <code>void MatrixPosition()</code> | ||
Line 42: | Line 38: | ||
: 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. | : [[Wikipedia:Transpose|Transposes]] a matrix. This is useful to flip columns and rows of a matrix and a necessity when communicating between systems that define matrix operations differently (like client-side code in source and shaders may do). | ||
; <code>void MatrixInvert()</code> | ; <code>void MatrixInvert()</code> | ||
: Reverses a matrix, making it transform in the opposite direction(s). You could also use <code>VectorITransform()</code> to apply the matrix. | : Reverses a matrix, making it transform in the opposite direction(s). You could also use <code>VectorITransform()</code> to apply the matrix. | ||
Line 51: | Line 47: | ||
== See also == | == See also == | ||
*{{ent|Vector}} | |||
* | *{{ent|QAngle}} | ||
* | *{{ent|Quaternion}} | ||
* | *{{ent|RadianEuler}} | ||
* | [[Category:Glossary]][[Category:Structures]][[Category:Variables]] | ||
{{ |
Latest revision as of 01:05, 6 January 2024
matrix3x4_t is a C++ class that represents a matrix: a mathematical construct that allows Vectors to be transformed.
Matrices are chiefly used to rotate vectors, since translation and scaling are taken care of by vector addition and multiplication respectively. A single matrix can store a transformation in all four modes however, making them useful in transformation-intense operations like vertex rasterization.
The VMatrix class offers an additional row to use (4x4) and allows you to utilize a few different functions. Matrices of that dimension in source are mainly required to describe perspective transformations during rendering.
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

The mathematical notation for a matrix transformation is (vector * matrix). Source does not support that syntax, though it would be trivial to add if you so wanted, and instead 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. This is useful to flip columns and rows of a matrix and a necessity when communicating between systems that define matrix operations differently (like client-side code in source and shaders may do).
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).