As far as I know, the unit in Box2D is meters. When I use Box2D in Processing with JBox2D, I set the "world size" as the window size specified in the setup().

Now I'm wondering if there is any function that scales down the world. For example, how can I simulate the throw of tennis ball within a room, without using a window of only 5 x 5 pixels?

Additionally, is there any good documentation like the Java API?

  • 3
    \$\begingroup\$ How you render the world and how your physics simulate the world are entirely different. You don't need nor want each unit in the physics simulation to represent a single pixel. \$\endgroup\$ – Sean Middleditch Nov 5 '13 at 2:17

To expand on Sean's comment, you should create a separate class or set of classes to connect your physics world with your rendering.

I'm not entirely familiar with Processing, but usually it'd be something like this:

class Box2DObject{
    final float PHYSICS_SCALE = 100.0;
    b2Body body;
    Image image;
    Box2DObject(b2Body ibody, Image iimage){
        body = ibody;
        image = iimage;

    void update(){
        image.x = body.GetPosition().x * PHYSICS_SCALE;
        image.y = body.GetPosition().y * PHYSICS_SCALE;

update() is called every rendering update on each Box2DObject, after calling box2d's world.step() method. The hard work is done by the PHYSICS_SCALE constant defined at the top of the class. This effectively sets a ratio of 1 meter to be 100 pixels (in this case). This means that a tennis ball with a box2d diameter of 67mm, would have a display size of 6.7 pixels. Increasing/decreasing the PHYSICS_SCALE constant increases/decreases the display size.

As far as API documentation goes, most ports I have seen are largely similar to the original C++ library. The C++ API documentation can be found online at http://www.learn-cocos2d.com/api-ref/1.0/Box2D/html/index.html or in the C++ distribution which can be downloaded here https://code.google.com/p/box2d/downloads/list.

I hope this helps.


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.