2
\$\begingroup\$

I know that for Box2d I need to translate pixels to meters which is easy peasy. However my problem is what is the orientation of Box2D coordinates system? Is this the same as screen one (right += x, bottom += y) or it is like cartesian (right +=x, bottom -= y) ?

Also, does Box2D coordination system use negative values?

Thank you.

\$\endgroup\$
4
  • \$\begingroup\$ It should not matter so long as your are consistent. Just use the same one as the rendering technology you are using to avoid confusion. \$\endgroup\$ Feb 14, 2013 at 19:18
  • \$\begingroup\$ @ClassicThunder I think that for example it matters for gravitation. I mean when a body is dropping, box2d will decrease its Y and on the screen it would go up in that case, if it uses cartesian system. \$\endgroup\$ Feb 14, 2013 at 19:21
  • 2
    \$\begingroup\$ "I mean when a body is dropping, Box2D will decrease its Y" You can specify the direction of gravity and so long as you are consistent it works. I use a gravity value of (0, 98.1) for my game because the top left is 0,0 and higher values of y are towards the bottom of the screen. \$\endgroup\$ Feb 14, 2013 at 19:32
  • \$\begingroup\$ @ClassicThunder So that's a good news, I can use screen coordinates in Box2D. If you want create an answer describing it and I will accept it. \$\endgroup\$ Feb 14, 2013 at 19:34

2 Answers 2

3
\$\begingroup\$

According to a post I located on the Box2D forums here, it uses your renderer's coordinate system, with some coefficient relating world space units to renderer units.

The testbed for Box2D supposedly uses OpenGL, in which Y+ is up, X+ is right, and Z+ is projecting out from the monitor's surface.

Also, an article I found here mentions the SCREEN_TO_WORLD and WORLD_TO_SCREEN global parameters, and provides an implementation of a Camera class to overcome the challenges of the somewhat-poor intentionally-separated implementation of this in Box2D. Even if you're already past this point, it may provide further insight into what you're trying to accomplish.

Sorry if this isn't really a true answer, but I hope I've at least pointed you in the right direction.

\$\endgroup\$
1
  • \$\begingroup\$ so it seems like it is cartesian system and values can be negative. So it's not really render system unless you use opengl/directx. Thank you for the links. \$\endgroup\$ Feb 14, 2013 at 18:58
2
\$\begingroup\$

Note, that there is nothing like "left - right orientation" in mathematics. When you have vector spaces, everything works perfectly without having to define, what is left and what is right. It depends only on how you draw it (e.g. gravity vector (0, -1) and Y going "up" is equivalent to gravity vector (0, 1) a Y going "down").

\$\endgroup\$

You must log in to answer this question.

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