Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DebugDrawing in libGDX

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);
}
like image 788
AWippler Avatar asked May 22 '14 05:05

AWippler


People also ask

How do you make a libGDX game?

Create your first libGDX game. React to user input. Show different screens in your game. Use OpenGL to draw your game. Use images in your game. Add music and sound effects. Cross-platform code.

Why use libGDX?

Well Proven libGDX is a well proven and reliable framework with a sound base and documentation. Furthermore, there are plenty of gamesbuilt on top of libGDX, many of which are open source. Active Community Get great support from a very welcoming communityof game and application developers or take a look at our extensive third-party ecosystem.

What are the best resources to learn libGDX?

After you have created your very first libGDX project, we highly recommend our A Simple Game and Extending the Simple Game pages. If you’re completely new to game dev and have never developed a game before, this (even more straight-forward) tutorial by tann is also worth a look as an alternative.

What's new at libGDX Jam 2022?

libGDX Jam June 2022 June 1, 2022 With our 21st collaboration, the libGDX Jam continues the time honoured tradition of making awesome games using the best framework out there. We encourage ca... libGDX 1.11.0 May 11, 2022 We are proud to present a new major release of libGDX: version 1.11.0! libGDX Jam March 2022 February 28, 2022


1 Answers

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();
}
like image 192
CenterOrbit Avatar answered Sep 30 '22 15:09

CenterOrbit