Using world coordinates instead of screen coordinates... how?

Mar 2, 2008 at 5:58 AM
I'm having a profound moment of stupidity probably stemming from my atrophying knowledge of Matrix math. I noticed that any time I use methods like Body.ApplyForce or properties like Body.Position, the Vector2's I pass always have to be in screen coordinates. For example, (0, 1) would be "down" one unit. Unfortunately, in my 2D game, I have my coordinate system set up such that 0,0 is in the center of the screen and positive Y is in the "up" direction. Is there an easy way to tell the Physics simulator to use my coordinate system?

I know that I'm probably asking the wrong question, but I'm hoping someone can set me straight.
Mar 2, 2008 at 5:44 PM
What you need to remember is that the physics coordinates are separate from screen coordinates. They're only the same when you tell them to be, which would be in your drawing code. You're probably drawing the objects in the same "position" as they appear in the physics simulation.

Rather than: spriteBatch.Draw(..., body.Position, ...)
Try something like: spriteBatch.Draw(..., Vector2.Subtract(body.Position, cameraPosition), ...)

The same goes for rotation and scaling too. Some people rather use feet or meters rather than pixels for their physics coordinate system. (This is where the ConvertUnits class comes in handy.)

If you use the PhysicsSimulatorView, remember that it was made to interpret the physics coordinates as screen coordinates, (as you're probably doing now) so you will need to modify it to translate things as necessary. You may consider having it accept your camera object as a parameter to Draw().