In my 2d XNA game, because SpriteBatch
treats world space as client space and has positive Y axis down and negative up, I've built my game's world space with that coordinate system too. However, I've hit a snag when I try to rotate a position around the origin using a matrix.
var p1 = new Vector2(95f, 40f);
var m = Matrix.CreateRotationZ(MathHelper.ToRadians(90));
var p2 = Vector2.TransformNormal(p1, m);
This results in p2.X == -40 and p2.Y == 95. If there's an object that is positioned relative to another object and that other object rotates, the child object gets swung around the parent object in the opposite direction because the matrix works in the positive Y axis up and negative down coordinate system.
What's the best way to account for this? Negate the Y value before and after transforming?
EDIT: To get more detailed I am trying to do a transformation like this, where child rotates with parent:
I though I would be able to multiply the matrices from the child object up through each of its parents' transform matrices in order to get its final world position, scale, and rotation that can be passed to SpriteBatch.Draw
. Unfortunately the combined translations and rotations don't work out properly with the inverted Y axis.