Unity世界坐标系的旋转规则是ZXY,自身坐标系的旋转规则是YXZ,可以理解为:
LocalToWorldMatrix:Rot(y) * Rot(x) * Rot(z) * P(localPosition)
WorldToLocalMatrix: Inverse of LocalToWorldMatrix
P(-localPosition) * Rot(-z) * Rot(-x) * Rot(-y)
Quaternion.Euler(Vector3(x, y, z)): Reture a rotation in Rot(z) * Rot(x) * Rot(y)
Transform has three similar methods: TransformPoint, TransformDirection and TransformVector. The difference comes to which aspects of the transform are used or not used.
TransformPoint: considering position, rotation and scale, used to get the world position.
TransformDirection: considering rotation only, used to transform a direction
TransformVector: considering rotaion and scale only, similar to TransformDirection but with magnitude taking scale into consideration.
Matrix4x4 has three similar methods: MultiplyPoint, MultiplyVector, MultiplyPoint3x4. The difference:
MultiplyPoint: transform a position.
MultiplyPoint3x4: This function is a faster version of MultiplyPoint; but it can only handle regular 3D transformations. MultiplyPoint is slower, but can handle projective transformations as well.
MultiplyVector: transform a direction, only the rotation part is taken into consideration.
本文详细探讨了Unity中坐标变换的规则,包括世界坐标系与自身坐标系的旋转顺序,如LocalToWorldMatrix与WorldToLocalMatrix的计算。同时,介绍了Quaternion.Euler()函数的旋转顺序以及Transform的三个关键方法:TransformPoint、TransformDirection和TransformVector的功能区别。此外,还讲解了Matrix4x4的MultiplyPoint、MultiplyPoint3x4和MultiplyVector方法在处理位置、方向和向量时的不同之处。

6645

被折叠的 条评论
为什么被折叠?



