Matrix4x4 矩陣api介紹
Namespace: UnityEngine
Description 描述
A standard 4×4 transformation matrix.
一個標准的4×4變換矩陣。
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.
一個變換矩陣可以表達任意的線性3D變換(例如平移,旋轉,縮放,切變等)並且使用齊次坐標系進行投影變換。我們基本上不會在腳本中使用矩陣;通常都直接使用三維向量、四元數以及Transform對象的函數。在特殊的場合例如設置一個非標准化的攝像機投影時才使用純粹的矩陣。
Consult any graphics textbook for in depth explanation of transformation matrices.
參考任意一本圖形學對於變換矩陣的深入解釋。
In Unity, Matrix4x4 is used by several Transform, Camera, Material and GL functions.
在Unity中,Matrix4x4對象被很多Transform,Camera,Matierial和Gl中的函數使用。
Matrices in unity are column major. Data is accessed as: row + (column*4). Matrices can be indexed like 2D arrays but in an expression like mat[a, b], a refers to the row index, while b refers to the column index (note that this is the opposite way round to Cartesian coordinates).
Unity中的矩陣使用的是列優先。數據通過行+(列*4)的方式獲取。矩陣可以被索引為類似二維數組的形式,但是要以mat[a,b]這樣的表達式。其中a代表行號,b代表列號(注意這正好與笛卡爾坐標系相反)。
Static Variables 靜態變量
Variables 變量
determinant | The determinant of the matrix. 矩陣的決定因素。 |
inverse | The inverse of this matrix (Read Only). 這個矩陣的逆矩陣(只讀)。 |
isIdentity | Is this the identity matrix? 這個矩陣是單位矩陣嗎? |
this[int,int] | Access element at [row, column]. 獲取[行,列]所對應的元素。 |
transpose | Returns the transpose of this matrix (Read Only). 返回這個矩陣的轉置矩陣(只讀)。 |
Functions 方法
GetColumn | Get a column of the matrix. 獲取這個矩陣的一列。 |
GetRow | Returns a row of the matrix. 返回這個矩陣的一行。 |
MultiplyPoint | Transforms a position by this matrix (generic) 使用該矩陣對一個坐標(點)進行變換(普通) |
MultiplyPoint3x4 | Transforms a position by this matrix (fast). 使用該矩陣對一個坐標(點)進行變換(快速) |
MultiplyVector | Transforms a direction by this matrix. 使用該矩陣對一個方向(按方法名理解應該是向量吧,向量包含方向和大小,譯者注)進行變換 |
SetColumn | Sets a column of the matrix. 給這個矩陣的一列賦值。 |
SetRow | Sets a row of the matrix. 給這個矩陣的以行賦值。 |
SetTRS | Sets this matrix to a translation, rotation and scaling matrix. 把這個矩陣變為平移、旋轉和縮放矩陣。 |
ToString | Returns a nicely formatted string for this matrix. 返回一個該矩陣的漂亮的格式化字符串。 |
Static Functions 靜態方法
Ortho | Creates an orthogonal projection matrix. 創建一個正交投影矩陣。 |
Perspective | Creates a perspective projection matrix. 創建一個透視投影矩陣。 |
Scale | Creates a scaling matrix. 創建一個縮放矩陣。 |
TRS | Creates a translation, rotation and scaling matrix. 創建一個平移、旋轉和縮放矩陣。 |
Operators 運算符重載
operator * | Multiplies two matrices. 兩個矩陣相乘。 |
轉http://wiki.ceeger.com/script/unityengine/classes/matrix4x4/matrix4x4