XNA中的Vector2.Transform()和Vector2.TransformNormal()之间的区别是什么(C#)

时间:2012-11-02 01:48:17

标签: c# xna game-engine game-physics

我正在使用XNA(C#)开发游戏,我想知道如何使用2个版本的转换。在我的想法中,这个功能的作品是:

(假设向量来自Matrix.Identity

  • Vector2 resultVec = Vector2.Transform(sourceVector, destinationMatrix);用于位置向量转换。

  • Vector2 resultVec = Vector2.TransformNormal(sourceVector, destinationMatrix);用于转换速度向量

这是真的吗?谁知道详细解释,请帮忙!

2 个答案:

答案 0 :(得分:3)

简单的答案是 -

Vector2.Transform()将整个Matrix应用于向量

Vector2.TransformNormal()仅将Matrix的缩放和旋转部分应用于矢量。

答案 1 :(得分:2)

通过变换,函数将源向量与生成的矩阵相乘。

  • Transform()用于表示2D或3D空间中位置的向量。这将详细说明反转矩阵的Transpose(T运算符)代表您的坐标。

在数学中:retVec = T(M ^ -1) x srcVec

  • TransformNormal()用于方向,切线向量。这保留了矩阵。

在数学中:retVect = srcVec x M

将矢量从一个矩阵/坐标转换为另一个矩阵/坐标(比如M1到M2): retVec = Transform by M1 -> then transform by invert of M2

        Vector2 retVec = Vector2.Transform(vectorInSource, M1);

        Matrix invertDestMatrix = Matrix.Invert(M2);
        outVect= Vector2.Transform(retVec , invertDestMatrix);