I'm using XNA and am having a simple issue which I can't figure out. I'm just messing around and want to get a firm grasp of local/world space coordinates.

        Matrix rotateCharacter= Matrix.CreateRotationZ(MathHelper.ToRadians(45.0f));

        Matrix moveCharacter = Matrix.CreateTranslation(new Vector3(10,10,0));

        Matrix multMat =Matrix.Identity * rotateCharacter * moveCharacter ;

        Matrix WorldToB = Matrix.Invert(multMat);

        Vector2 worldCoord = new Vector2(10, 10);
        Vector2 worldToB = Vector2.Transform(worldCoord, WorldToB);

So all I'm doing here in my example is initially rotating my sprite's local axis around the world origin and then translating it out into world space. Thus, a world space coordinate of something like (10,10) would be 0,0 (my pixel's starting coordinate) in the local space (worldToB should be (0,0)). However, this is not occurring I guess as my inverted matrix is incorrect. Can anyone give me an answer of what I'm doing wrong exactly?

  • \$\begingroup\$ One bit of advice to give, if you're just starting out in debugging this sort of thing: always test with non-zero co-ordinates (both for input and expected outputs). There's a lot of times when the math effectively cancels out with zero co-ordinates, and it looks like it's working when in fact it's not. E.g. (0,0,5) can be rotated about the z axis without affecting the output, but (3, 4, 5) will always be affected. In general, once you're beyond simple maths, use visual representations of co-ordinates and co-ordinate frames to debug how things are changing and where things are going wrong. \$\endgroup\$
    – MrCranky
    Commented Sep 7, 2010 at 9:01

1 Answer 1


(worldToB should be (0,0)). However, this is not occurring

But the vector2 worldToB does end up being 0,0 in your code above..., within the realm of floating point error anyways.

The actual value of worldToB.X is -0.0000002843... on my computer which for all practical purposes is 0.0f.

  • \$\begingroup\$ Wow, never noticed the E when I hovered over the variable, thanks haha \$\endgroup\$
    – Ilya
    Commented Sep 5, 2010 at 20:57
  • \$\begingroup\$ You're welcome, glad to help. I've made that mistake many times. Hey, it looks like your understanding of matrices has grown alot in this last week. good going. \$\endgroup\$
    – Steve H
    Commented Sep 6, 2010 at 2:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .