一个向量乘以一个TRS矩阵似乎行不通
本文关键字:一个 行不通 向量 TRS | 更新日期: 2023-09-27 18:04:05
Unity 3D 5.4允许创建Matrix4x4,通过Matrix4x4设置其TRS值。SetTRS并将一个点乘以该矩阵来应用变换。我希望下面的代码打印出翻译后的点,但是翻译似乎没有发生。
m = Matrix4x4.identity;
m.SetTRS(new Vector3(-10f, 4f, 0f), Quaternion.Euler(new Vector3(0f, 0f, 0f)), Vector3.one);
Vector3 P = new Vector3(10f, 1f, 0f);
Debug.Log("P': " + m * P);
代码打印出
P': (10.0, 1.0, 0.0, 0.0)
不是P': (0.0, 5.0, 0.0, 0.0)
我错过了什么吗?
要将Vector3
点转换为Matrix4x4
,则需要使用Matrix4x4.MultiplyPoint()
或Matrix4x4.MultiplyPoint3x4()
。所以在你的情况下,我会尝试:
Debug.Log("P': " + m.MultiplyPoint3x4(P));
另外,作为提示- Quaternion
表示没有旋转可以由Quaternion.identity
表示,因此您不需要为此一直调用Quaternion.Euler()
(如果这是您的意图)。
希望这对你有帮助!如果您有任何问题,请告诉我。