标准 4x4 变换矩阵。
变换矩阵可以使用齐次坐标执行任意线性 3D 变换
(即平移、旋转、缩放、扭曲等)和透视变换。脚本中很少使用矩阵;通常
使用 Vector3、Quaternion 和 Transform 类的功能会更加简单直接。普通矩阵用于特殊情况,
如设置非标准摄像机投影。
参阅任何图形教材了解变换矩阵的深入说明。
在 Unity 中,Matrix4x4 由几个 Transform、Camera、Material 和 GL 函数使用。
Unity 中的矩阵是列主序的。数据访问方式如下:行 + (列*4)。矩阵可以
像 2D 数组一样进行索引,但是在 mat[a, b] 这类表达式中,a
引用行索引,而 b
引用
列索引(请注意,这是笛卡尔坐标相反的方式)。
decomposeProjection | 此属性采用投影矩阵,返回定义投影锥体的六个平面坐标。 |
determinant | 矩阵的行列式。 |
inverse | 此矩阵的逆矩阵(只读)。 |
isIdentity | 是否为单位矩阵? |
lossyScale | 尝试从矩阵获取缩放值。 |
rotation | 尝试从此矩阵获取旋转四元数。 |
this[int,int] | 访问 [row, column] 处的元素。 |
transpose | 返回此矩阵的转置(只读)。 |
GetColumn | 获取矩阵的某一列。 |
GetRow | 返回矩阵的某一行。 |
MultiplyPoint | 按此矩阵变换位置(普通)。 |
MultiplyPoint3x4 | 按此矩阵变换位置(快速)。 |
MultiplyVector | 按此矩阵变换方向。 |
SetColumn | 设置矩阵的某一列。 |
SetRow | 设置矩阵的某一行。 |
SetTRS | 将此矩阵设置为平移、旋转和缩放矩阵。 |
ToString | 对于此矩阵,返回整齐格式化的字符串。 |
TransformPlane | 返回在空间中变换的平面。 |
ValidTRS | 检查此矩阵是否为有效变换矩阵。 |
Frustum | 此函数返回一个投影矩阵,其视锥体的近平面由传入的坐标定义。 |
LookAt | 给定源点、目标点和向上矢量,计算一个变换矩阵,它对应于从源查看目标的摄像机,以便右侧矢量与向上矢量垂直。 |
Ortho | 创建正交投影矩阵。 |
Perspective | 创建透视投影矩阵。 |
Rotate | 创建旋转矩阵。 |
Scale | 创建缩放矩阵。 |
Translate | 创建平移矩阵。 |
TRS | 创建平移、旋转和缩放矩阵。 |
operator * | 使两个矩阵相乘。 |
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.