Matrix4x4

主要用途变换

API

  1. public Matrix4x4(Vector4 column0, Vector4 column1, Vector4 column2, Vector4 column3); 构造函数,Unity矩阵按列填充.
    Matrix4x4 mat4x4 = new Matrix4x4(new Vector4(m00, m10, m20, m30),new Vector4(m01, m11, m21, m31),new Vector4(m02, m12, m22, m32),new Vector4(m03, m13, m23, m33))

    // m00 m01 m02 m03
    // m10 m11 m12 m13
    // m20 m21 m22 m23
    // m30 m31 m32 m33
  1. public float this[int index] { get; set; }、 public float this[int row, int column] { get; set; } 由于按列填充,则 index 为 00, 10 ,20,30, 01。。。顺序, 所以 this[1] == this[1, 0]

  2. public static Matrix4x4 zero { get; } o矩阵、 public static Matrix4x4 identity { get; } 单位矩阵

  3. public Matrix4x4 transpose { get; } 转置矩阵, 逆变换矩阵, m[i,j] = m'[j, i]

    1. public static Matrix4x4 Transpose(Matrix4x4 m);

  1. 变换
    1. public Quaternion rotation { get; } 旋转。
    2. public Vector3 lossyScale { get; } 缩放.
    3. public bool isIdentity { get; } 是否为单位Identity矩阵,
    4. GetColumn(3)或者 transpose.GetRow(3) 位置
    5. public static Matrix4x4 Rotate(Quaternion q);
    6. public static Matrix4x4 Scale(Vector3 vector);
    7. public static Matrix4x4 Translate(Vector3 vector);
  2. public float determinant { get; } 矩阵的'面积/体积/超体积' 相互垂直的话 等于scalex * scaley * scalez
    1. public static float Determinant(Matrix4x4 m);
  3. public FrustumPlanes decomposeProjection { get; }, 矩阵视椎体,
    1. public static Matrix4x4 Frustum(float left, float right, float bottom, float top, float zNear, float zFar);
    2. public static Matrix4x4 Frustum(FrustumPlanes fp);
    3. public static Matrix4x4 Ortho(float left, float right, float bottom, float top, float zNear, float zFar); 正交
    4. public static Matrix4x4 Perspective(float fov, float aspect, float zNear, float zFar); 透视
     public struct FrustumPlanes
     {
         public float left;
         public float right;
         public float bottom;
         public float top;
         public float zNear;
         public float zFar;
     }
  4. public Matrix4x4 inverse { get; } 逆矩阵.
    1. public static Matrix4x4 Inverse(Matrix4x4 m);
    2. public static bool Inverse3DAffine(Matrix4x4 input, ref Matrix4x4 result);
  5. public static Matrix4x4 LookAt(Vector3 from, Vector3 to, Vector3 up);
  6. public static Matrix4x4 LookAt(Vector3 from, Vector3 to, Vector3 up);
  7. public static Matrix4x4 TRS(Vector3 pos, Quaternion q, Vector3 s); 构造平移旋转缩放矩阵。
    1. 等同 Matrix4x4.Translate(transform.position) * Matrix4x4.Rotate(transform.rotation) * Matrix4x4.Scale(transform.lossyScale) = Matrix4x4.TRS(transform.position, transform.rotation, transform.lossyScale)
    2. public void SetTRS(Vector3 pos, Quaternion q, Vector3 s);
  8. 操作元素
    1. public Vector4 GetColumn(int index); 获取列,Unity按列填充, 也等同于传统意义的行
    2. public Vector4 GetRow(int index); 获取行,Unity按列填充, 也等同于传统意义的列
    3. public void SetColumn(int index, Vector4 column); 填充列, 也等同于传统意义的行
    4. public void SetRow(int index, Vector4 row); 填充行, 也等同于传统意义的列
  9. 乘, 实验效果一样???
    1. public Vector3 MultiplyPoint(Vector3 point); //返回由任意矩阵变化得到的位置v。如果这个矩阵是一个正规的3D变换矩阵,使用MultiplyPoint3x4比它更快。MultiplyPoint比较慢,但是能处理投影变换。
    2. public Vector3 MultiplyPoint3x4(Vector3 point); //不包含投影
    3. public Vector3 MultiplyVector(Vector3 vector); //只变换方向(旋转),仅考虑矩阵的旋转部分。
  10. public Plane TransformPlane(Plane plane); 平面转换
  11. public bool ValidTRS(); //是否为有效矩阵.

文章作者: Yonggang Long
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 Yonggang Long !
 上一篇
2022-08-10 Yonggang Long
下一篇 
2022-08-10 Yonggang Long
  目录