Game Development Reference
In-Depth Information
Debug rendering
Observing a problem visually is usually the easiest first step in diagnosing it. So it is
helpful for a physics engine to provide a means to draw debug information onto the
screen whether it's the edges of objects, the points of collision, the depth of penet-
ration, or more. Bullet provides a very simple interface for us to render this kind of
debugging data onto our scene, which we will implement in this section.
Continue from here using the Chapter4.2_DebugDrawer project files.
Building the debug drawer
To create our own debug drawer, we will inherit from btIDebugDraw , an interface
class for debug rendering. This object must override essential functions such as
drawLine() or drawContactPoint() . There are a few functions such as re-
portErrorWarning() and draw3dText() that we're not interested in, but are
pure virtual, and requires us to at least define them. Since we won't need them, we
will leave them empty.
Here is a snippet of one of the functions defined in DebugDrawer , which draws a
colored line between the two given points:
void DebugDrawer::drawLine(const btVector3
&from,const btVector3 &to, const btVector3
// draws a simple line of pixels between
// use the GL_LINES primitive to draw lines
glColor3f(color.getX(), color.getY(),
glVertex3f(from.getX(), from.getY(),
Search WWH ::

Custom Search