Body: Vector2.Zero is not top left?

Sep 25, 2010 at 9:29 AM
Edited Sep 25, 2010 at 9:55 AM

When I construct something with a body at Vector2(0,0), it appears in the middle. Also, Vector2(0,10) goes upwards instead of downwards.

1) Why?

2) Exactly, what 'is' the middle? If I implemented a camera, would it construct at the center of the camera? Or would it construct at half of screen_width and screen_height?

3) How can we set this back the normal "0,0 is the top left"? So we can have FarseerPhysics' coordinates actually match the coordinate system that everyone else uses

Coordinator
Sep 25, 2010 at 9:53 AM
You are talking about the samples? 1. The position depends entirely on where you draw it. Vector2.Zero is the same in FPE 2 and 3, bit in 3 we draw (0,0) in the "middle" of the screen. 2. Don't remember exactly where the center is. Look around the samples. 3. You simply adjust the center of the camera (Look at the translation matrix in the samples) to be at the top left of the screen.
Sep 25, 2010 at 10:21 AM
Edited Sep 25, 2010 at 8:49 PM

Thanks for the prompt reply.

How would we get around the false-coordinate system?

 

I would be happy knowing the answer to this gentleman's post:

"

Hello!

Quick question: I am using screen management just same like in TestBed, and there I have:

public Vector2 ConvertScreenToWorld(int x, int y)
 {
      float u = x / (float)_viewportWidth;
      float v = (_viewportHeight - y) / (float)_viewportHeight;

      Vector2 p = new Vector2();
      p.X = (1.0f - u) * _lower.X + u * _upper.X;
      p.Y = (1.0f - v) * _lower.Y + v * _upper.Y;

 return p;
 }
Could somebody guide me how to get WorldToScreen conversion? It would be great, because I cannot put any texture on the body without it. Thanks in advance!
"

http://www.shiffman.net/teaching/nature/box2d-processing/
Sep 26, 2010 at 12:20 AM

All you need to do is multiply / divide by a set value whenever you convert between world and screen coordinates.

For example, you could divide by 100 whenever you set FarseerPhysics coordinates, so that a 128 x 128 texture ends up being 0.128 x 0.128 world units (meters, actually).

Then multiply by the same amount to convert it the other way. :)