I'm worried about this Caution box from the Box2d manual:

Box2D is tuned for MKS units. Keep the size of moving objects roughly between 0.1 and 10 meters. You'll need to use some scaling system when you render your environment and actors. The Box2D testbed does this by using an OpenGL viewport transform. DO NOT USE PIXELS.

I don't want to use OpenGL since I know nothing about it. I'm using SFML to render my game.

  • \$\begingroup\$ Are you trying to scale elements based on the screen size? \$\endgroup\$ – TomTsagk Dec 4 '19 at 17:15
  • \$\begingroup\$ i guess... im pretty newbie about that. Please help. Give advice. \$\endgroup\$ – 0x00004 Dec 4 '19 at 17:17
  • \$\begingroup\$ I'm trying to help, but if you don't know what the issue is, then I can't provide a solution. I'm not familiar with Box2D, but if its using OpenGL to position elements, and you don't want to use that, then I'd advice to use another tool that is using pixels instead. \$\endgroup\$ – TomTsagk Dec 4 '19 at 17:18
  • \$\begingroup\$ Box2d has a framework called "TesBed" that uses openGl viewport transform as scaling system. But i can use any other system in my app im sure of it. \$\endgroup\$ – 0x00004 Dec 4 '19 at 17:21
  • \$\begingroup\$ What are you trying to do? What do you need simulated? Can your objects fit in the [0.1..10.0] range? \$\endgroup\$ – Vaillancourt Dec 4 '19 at 17:22

This caution box is telling you to not base your physics simulation on pixels. The pixels your game will be able to show will not be the same across all device, and is not a reliable measure to have your game consistent.

What it suggests is that you use "real world" sized objects in your simulation, and use your rendering engine to display the simulation. You really want to separate the two concerns and think in "real world" objects rather than in "pixels" (these become smaller each year that goes by).

In their examples, they use the concept of OpenGL's viewport, which is used to control what is rendered on the window.

In your case, might want to look into SFML's View. I have not worked with SFML a lot, but this is basically a wrapper of OpenGL's viewport concept.

So for example, you'll simulate your car with real dimensions (say 1.8m x 4.6m), you'll stick a sprite which has that scale to it, but you'll ask SFML to render a parking lot of 200 x 200 units (where units are 'meters' in your game). It'll scale the view appropriately so that it fits in your render window.

| improve this answer | |
  • \$\begingroup\$ Thanks for explaining that.What is that thing other people use then? They just multiply meters * pixels. I can do the same? \$\endgroup\$ – 0x00004 Dec 4 '19 at 18:04
  • \$\begingroup\$ You could do that if you used another kind of rendering system. If you use SFML, don't do that, SFML has the feature coded for you in the view I describe above. \$\endgroup\$ – Vaillancourt Dec 4 '19 at 18:09
  • \$\begingroup\$ So okay. After i set up the viewport i can just use meters in box2 code and pixels in sfml code simple as that? \$\endgroup\$ – 0x00004 Dec 4 '19 at 18:12
  • \$\begingroup\$ Yeah, I guess you can do that. The core thing is, really, keep your simulation in MKS, and convert the positions in pixels once you're at the rendering stage. \$\endgroup\$ – Vaillancourt Dec 4 '19 at 18:14
  • \$\begingroup\$ Wait so i have to do it manually when at rendering stage? Like pos * SCALEFACTOR? \$\endgroup\$ – 0x00004 Dec 4 '19 at 18:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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