Unity矩阵乘法的区别

本文详细探讨了Unity中坐标变换的规则,包括世界坐标系与自身坐标系的旋转顺序,如LocalToWorldMatrix与WorldToLocalMatrix的计算。同时,介绍了Quaternion.Euler()函数的旋转顺序以及Transform的三个关键方法:TransformPoint、TransformDirection和TransformVector的功能区别。此外,还讲解了Matrix4x4的MultiplyPoint、MultiplyPoint3x4和MultiplyVector方法在处理位置、方向和向量时的不同之处。

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值