Game Development Reference
In-Depth Information
m_dynamicsWorld->debugDrawWorld();
}
This method obviously doesn
t do any of the rendering. Part of the BaseGame-
Physics class is a member that does the heavy lifting. Bullet lets you inherit from
one of their base classes and implement your own draw routines.
A physics system can
'
'
t know or care how you render your visible geometry. It could
be a text display, and it wouldn ' t know any different except for all the extra CPU
time it would get! You simply can
t debug physics problems looking at raw data, so
the easiest debugging technique for physics problems is to draw physics data as visi-
ble geometry. Collision hulls show up as wireframes around your objects. Contact
points and normals are drawn as lines, and forces can be drawn as lines of different
lengths in the direction of the force. Bullet provides an easy way for you to do this.
You simply inherit from the btIDebugDraw class, overload a few methods, and
you
'
'
ll see everything you need to debug physics:
class BulletDebugDrawer : public btIDebugDraw
{
public:
// btIDebugDraw interface
virtual void
drawLine(const btVector3& from,
const btVector3& to,
const btVector3& color);
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;
};
Pretty simple. You just overload the provided methods to render on-screen, and
there
s an incredible amount of useful stuff you can do
with this data, including histories, averages, and statistics of all sorts. But for this
example, you just draw on-screen in the simplest manner possible.
The code for drawLine() is in the GameCode4 source code in Dev\Source\GCC4\
Physics\PhysicsDebugDrawer.cpp.
'
s your debug info! There
'
Search WWH ::




Custom Search