2012-11-02 31 views
3

我开发的XNA(C#)游戏之间的不同,我想知道如何使用2.0版本改造。在我的想法,在此功能的工作原理是:什么Vector2.Transform()和Vector2.TransformNormal()在XNA(C#)

(假设向量源于Matrix.Identity

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

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

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

+0

您是否试过阅读文档?快速搜索显示“Transform”用于位置矢量,“TransformNormal”用于* normal *矢量。 –

+1

什么是_normal vectors_? – CuongKe

+0

我从这里阅读了简短描述:http://xboxforums.create.msdn.com/forums/p/58388/357821.aspx。但不太清楚 – CuongKe

回答

2

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

  • Transform()用于代表2D或3D空间中的位置的向量。这将详细地采用反转矩阵的转置(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); 
3

简单的回答是 -

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

Vector2.TransformNormal()只适用于比例和旋转部分向量的Matrix