Una matriz de transformación 4x4 estándar.
A transformation matrix can perform arbitrary linear 3D transformations (i.e. translation, rotation, scale, shear etc.)
and perspective transformations using homogenous coordinates. You rarely use matrices in scripts; most
often using Vector3s, Quaternions and functionality of Transform class is more straightforward. Plain matrices are used in special cases
like setting up nonstandard camera projection.
In Unity, several Transform, Camera, Material, Graphics and GL functions use Matrix4x4.
Matrices in Unity are column major; i.e. the position of a transformation matrix is in the last column,
and the first three columns contain x, y, and z-axes. Data is accessed as:
row + (column*4)
. Matrices can be
indexed like 2D arrays but note that in an expression like mat[a, b]
, a
refers to the row index, while b
refers
to the column index.
using UnityEngine;
public class ExampleScript : MonoBehaviour { void Start() { // get matrix from the Transform var matrix = transform.localToWorldMatrix; // get position from the last column var position = new Vector3(matrix[0,3], matrix[1,3], matrix[2,3]); Debug.Log("Transform position from matrix is: " + position); } }
identity | Retorna la matriz de identidad (Lectura solamente). |
zero | Retorna una matriz con todos los elementos definidos a cero (Lectura solamente). |
decomposeProjection | This property takes a projection matrix and returns the six plane coordinates that define a projection frustum. |
determinant | The determinant of the matrix. (Read Only) |
inverse | The inverse of this matrix. (Read Only) |
isIdentity | Checks whether this is an identity matrix. (Read Only) |
lossyScale | Attempts to get a scale value from the matrix. (Read Only) |
rotation | Attempts to get a rotation quaternion from this matrix. |
this[int,int] | Acceder al elemento en [fila, columna]. |
transpose | Retorna la transpuesta de esta matriz (Lectura Solamente). |
GetColumn | Obtiene la columna de la matriz. |
GetRow | Devuelve una fila de la matriz. |
MultiplyPoint | Transforma una posición por esta matriz (genérico). |
MultiplyPoint3x4 | Transforma una posición por esta matriz (rápido). |
MultiplyVector | Transforma una dirección por esta matriz. |
SetColumn | Define una columna de la matriz. |
SetRow | Define una fila de la matriz. |
SetTRS | Define esta matriz a una matriz de traslación, rotación y de escala. |
ToString | Retorna un string formateado para esta matriz. |
TransformPlane | Returns a plane that is transformed in space. |
ValidTRS | Checks if this matrix is a valid transform matrix. |
Frustum | This function returns a projection matrix with viewing frustum that has a near plane defined by the coordinates that were passed in. |
LookAt | Create a "look at" matrix. |
Ortho | Create an orthogonal projection matrix. |
Perspective | Create a perspective projection matrix. |
Rotate | Creates a rotation matrix. |
Scale | Crea una matriz de escalamiento. |
Translate | Creates a translation matrix. |
TRS | Crea una matriz de translación, rotación y escala. |
operator * | Multiplica dos matrices. |