Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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?

share|improve this question
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. –  MrCranky Sep 7 '10 at 9:01

1 Answer 1

up vote 1 down vote accepted

(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.

share|improve this answer
Wow, never noticed the E when I hovered over the variable, thanks haha –  Ilya Sep 5 '10 at 20:57
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. –  Steve H Sep 6 '10 at 2:38

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.