2

I have been fiddling around with bullet for a bit and I now want to draw debug. I have an opengl world with working bullet physics and everything.

What I have tried is this: I have created a class GLDebugDrawer like this:

#include "LinearMath/btIDebugDraw.h"

class GLDebugDrawer : public btIDebugDraw
{
   int m_debugMode;

public:

   GLDebugDrawer();
   virtual ~GLDebugDrawer();

   virtual void   drawLine(const btVector3& from, const btVector3& to, const btVector3& fromColor, const btVector3& toColor);

   virtual void   drawLine(const btVector3& from, const btVector3& to, const btVector3& color);

   virtual void   drawSphere(const btVector3& p, btScalar radius, const btVector3& color);

   virtual void   drawTriangle(const btVector3& a, const btVector3& b, const btVector3& c, const btVector3& color, btScalar alpha);

   virtual void   drawContactPoint(const btVector3& PointOnB, const btVector3& normalOnB, btScalar distance, int lifeTime, const btVector3& color);

   virtual void   reportErrorWarning(const char* warningString);

   virtual void   draw3dText(const btVector3& location, const char* textString);

   virtual void   setDebugMode(int debugMode);

   virtual int      getDebugMode() const { return m_debugMode; }

};

Then in the game I include this header and create a instance of it.

Where I initialize the bt world, I set the debug draw type like this:

debugDraw->DBG_DrawWireframe; // this breaks when I run the app
debugDraw->setDebugMode(btIDebugDraw::DBG_DrawWireframe); // so does this
debugDraw->setDebugMode(1); // this doesn't

I then set the debug to the bullet world like this:

bt_dynamicsWorld->setDebugDrawer(debugDraw);

And finally, I render the debug draw after I render the bullet bodies like this:

bt_dynamicsWorld->debugDrawWorld();

There must be something that I am missing as I am not getting any wireframes or anything when running.

genpfault
  • 51,148
  • 11
  • 85
  • 139
bogdan.css
  • 355
  • 6
  • 17
  • I know this is an old message, but it popped up to the top when I searched. Did you happen to actually implement any of those methods in your GLDebugDrawer class? – Jamie May 31 '16 at 13:28

2 Answers2

1

There is a simple set of code available at http://sio2interactive.forumotion.net/t599-enabling-bullet-debug-draw-code-included which should be relatively straightforward to use to modify your code, looks like you may need to change bt_dynamicsWorld->setDebugDrawer(debugDraw); to bt_dynamicsWorld->setDebugDrawer(&debugDraw); (not sure though as don't know how you have your framework setup.

GMasucci
  • 2,834
  • 22
  • 42
  • 1
    hey there. Thanks for the reply. I have looked at that article and followed it, but I am still not getting anything through. If I do `bt_dynamicsWorld->setDebugDrawer(&debugDraw);` I get this: `cannot convert argument 1 from 'GLDebugDrawer **' to 'btIDebugDraw *'`. – bogdan.css Nov 14 '13 at 15:59
0

First you have to pass a reference of your instantiated class to the setDebugDrawer function like this:

GLDebugDrawer MyDrawer;
...
bt_dynamicsWorld->setDebugDrawer(&MyDrawer);

Second, and equally as important, you must define the virtual functions laid out in your GLDebugDrawer class so that when bullet calls one of these functions to draw debugging information your debug drawer can actually draw something to the screen.

KKlouzal
  • 732
  • 9
  • 32