5

What is the proper way to debug draw Bullet physics in libGDX so that I may see the btCollisionObjects that I am setting up?

So far I have the below, but it doesn't appear that the btCollisionObjects are appearing.

public void render(float delta) {

    debugDrawer.begin(cam);
    collisionWorld.debugDrawWorld();
    debugDrawer.end();
    modelBatch.begin(cam);
    ...
    modelBatch.end();
}

@Override
public void show() {
    Bullet.init();
    ...         
    collisionConfig = new btDefaultCollisionConfiguration();
    dispatcher = new btCollisionDispatcher(collisionConfig);
    broadphase = new btDbvtBroadphase();
    collisionWorld = new btCollisionWorld(dispatcher, broadphase, collisionConfig);
    debugDrawer = new DebugDrawer();
    collisionWorld.setDebugDrawer(debugDrawer);
    debugDrawer.setDebugMode(btIDebugDraw.DebugDrawModes.DBG_MAX_DEBUG_DRAW_MODE);
}
chue x
  • 18,573
  • 7
  • 56
  • 70
AWippler
  • 417
  • 3
  • 9
  • 16
  • Can you try to get the debug drawing stuff out of the modelbatch begin/end? Also please note that the DebugDrawer has a serious problem with memory. I think it has a memory leak. – noone May 22 '14 at 06:21
  • I have updated the code to reflect the changes I made. Still do not see the objects. – AWippler May 22 '14 at 06:27
  • The `DebugDrawer` is the one from the tests? And it does implement some of the callbacks? – noone May 22 '14 at 06:41
  • If all this is okay, I assume it has something to do with the camera you supply. Set a breakpoint in your DebugDrawer callbacks and see whether they aren't called at all, or if they just get drawn offscreen. – noone May 22 '14 at 06:45

2 Answers2

5

Hopefully this will still help you 3 months after the fact, because your snippets definitely helped me! ;)

I put your code snippets into my app, and was able to get debug drawing working fine.

For the record, I'm using a dynamicsWorld instead, but swapped out code and it works.

dynamicsWorld = new btDiscreteDynamicsWorld(dispatcher, broadphase, constraintSolver, collisionConfig);

The one thing I would suggest is swapping when you draw the models and when you draw the debug. If you put the debug second, it will get drawn last, and thus on top of the models. Otherwise you will experience the debug draw being covered up by the models. Try this instead:

public void render(float delta) {

    modelBatch.begin(cam);
    ...
    modelBatch.end();

    debugDrawer.begin(cam);
    collisionWorld.debugDrawWorld();
    debugDrawer.end();
}
AWippler
  • 417
  • 3
  • 9
  • 16
CenterOrbit
  • 6,446
  • 1
  • 28
  • 34
0

Adding the collision objects into collision world helped me. Besides I could hardly find documentation for this. I wonder where AWippler found the debugging code for bullet3D wrapper for libgdx. Anyone else having trouble can try this.

@Override
public void show() {
    Bullet.init();
    ...         
    collisionConfig = new btDefaultCollisionConfiguration();
    dispatcher = new btCollisionDispatcher(collisionConfig);
    broadphase = new btDbvtBroadphase();
    collisionWorld = new btCollisionWorld(dispatcher, broadphase, collisionConfig);
    for (Ball b : gameWorld.balls) {
        collisionWorld.addCollisionObject(b.getBallObject());
    }
    for (Brick b : gameWorld.bricks) {
        collisionWorld.addCollisionObject(b.getBrickObject());
    }
    debugDrawer = new DebugDrawer();
    collisionWorld.setDebugDrawer(debugDrawer);
    debugDrawer.setDebugMode(btIDebugDraw.DebugDrawModes.DBG_MAX_DEBUG_DRAW_MODE);
}
Anutrix
  • 145
  • 1
  • 9