Search code examples
c#xnagame-enginegame-physics

What's the different between Vector2.Transform() and Vector2.TransformNormal() in XNA(C#)


I am developing a game in XNA (C#), I am wondering how to use 2 versions of transformation. In my idea, the works of this functions are:

(Assume that vectors are originated from Matrix.Identity)

  • Vector2 resultVec = Vector2.Transform(sourceVector, destinationMatrix); is used for Position vectors transformation.

  • Vector2 resultVec = Vector2.TransformNormal(sourceVector, destinationMatrix); used for transforming Velocity vectors.

Is that true?. Who knows the explanation in detail, please help!


Solution

  • With transformation, functions will multiply the source vector with the produced matrices.

    • Transform() is used for vectors representing the positions in 2D or 3D space. This will, in detail, take the Transpose (T operator) of the Invert matrix represents your Coordinate.

    In Math: retVec = T(M ^ -1) x srcVec.

    • TransformNormal() used for direction, tangent vectors. This reserves the matrix.

    In Math: retVect = srcVec x M.

    To transform a vector from one matrix/coordinate to another (say M1 to 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);