Game Development Reference
In-Depth Information
Rendering soft bodies
Our base application doesn't know anything about soft bodies (nor should it), so we
will need to extend the RenderScene() function to handle our soft body rendering
code. We make use of btSoftBodyHelpers again, which contains a function that
will help us render our soft body through the very same rendering code that we use
to draw the debug lines on the screen. This will require us to add one more function
override in our debug drawer to render triangles in addition to lines.
Because our soft body is not built from GameObject , we need to handle its render-
ing a little differently than before. We can obtain and iterate through any soft bodies
in our scene by calling the getSoftBodyArray() function on our world object and
then use our debug drawer to render each of its triangles:
// check the list of our world's soft bodies
for (int i=0; i<
m_pSoftBodyWorld->getSoftBodyArray().size();
i++) {
// get the body
btSoftBody* pBody =
(btSoftBody*)m_pSoftBodyWorld->getSoftBodyArray()[i];
// is it possible to render?
if (m_pSoftBodyWorld->getDebugDrawer() &&
!(m_pSoftBodyWorld->getDebugDrawer()->getDebugMode()
& (btIDebugDraw::DBG_DrawWireframe))) {
// draw it
btSoftBodyHelpers::Draw(pBody,
m_pSoftBodyWorld->getDebugDrawer(),
m_pSoftBodyWorld->getDrawFlags());
}
}
Launching our application now, we should observe a sphere fall, collide with the
ground, and deform. We can also launch boxes with the right-mouse button to de-
form it even more. The following screenshot shows our soft body falling from the sky
and deforming under its own weight:
Search WWH ::




Custom Search