Game Development Reference
In-Depth Information
Compound shapes
Bullet also allows us to build another type of customized physics object by combining
multiple child shapes together into a parent compound shape.
Note
Continue from here using the Chapter7.3_CompoundShapes project files.
Compound shapes are treated much the same way as any other shape, except its
constituent pieces are stuck together by a set of very rigid constraints (much like the
constraints we explored in Chapter 5 , Raycasting and Constraints ). We'll use com-
pound shapes to create a dumbbell, a pair of spheres connected via a connecting rod.
Tip
Note that the child shapes do not need to touch one another for the compound
shape feature to work. The child shapes could be separated by great distances
and still behave as if they were tightly coupled.
The class in question is the btCompoundShape class. The member function ad-
dChildShape() , attaches the given child shape into the compound shape at the giv-
en transform. Therefore a simple compound shape can be built as follows:
// create two shapes for the rod and the load
btCollisionShape* pRod = new
btBoxShape(btVector3(1.5f, 0.2f, 0.2f));
btCollisionShape* pLoad = new
btSphereShape(0.5f);
// create a transform we'll use to set each
object's positionbtTransform trans;
trans.setIdentity();
// create our compound shape
btCompoundShape* pCompound = new
Search WWH ::




Custom Search