Game Development Reference
In-Depth Information
btCompoundShape();
// add the rod
pCompound->addChildShape(trans, pRod);
trans.setOrigin(btVector3(-1.75f, 0.0f, 0.0f));
// add the top load
pCompound->addChildShape(trans, pLoad);
trans.setIdentity();
// add the bottom load
trans.setOrigin(btVector3(1.75f, 0.0f, 0.0f));
pCompound->addChildShape(trans, pLoad);
// create a game object using the compound shape
CreateGameObject(pCompound, 2.0f,
btVector3(0.8,0.4,0.1), btVector3(-4, 10.0f,
0.0f));
Bullet lets us create yet another complex physics object with only a handful of
instructions. But, yet again, we have the problem of rendering this shape. We
can use the compound shape's member functions getNumChildShapes() ,
getChildTransform() , and getChildShape() to iterate through the child
shapes, but remember that our DrawShape() command only accepts a single
shape to draw at a time, and if we push our compound shape into a game object
and render it, it would not draw anything, because the parent itself is not one of the
supported types.
What we must do is to call the DrawShape() function recursively for each child as
follows:
case COMPOUND_SHAPE_PROXYTYPE:
{
// get the shape
const btCompoundShape* pCompound =
static_cast<const btCompoundShape*>(pShape);
// iterate through the children
for (int i = 0; i <
pCompound->getNumChildShapes(); ++i) {
// get the transform of the sub-shape
btTransform thisTransform =
Search WWH ::




Custom Search