Game Development Reference
Next, we'll explore how Bullet lets us build custom collision shapes through the use of
Continue from here using the Chapter7.2_ConvexHulls project files.
Much like our OpenGL code, we provide the vertex points from which to build the ob-
ject and Bullet takes care of the hard work for us; in fact Bullet makes it even easier
than that, because we don't need to define indices or provide them in a specific order
of rotation. Bullet will always try to create the simplest convex shape it can from the
given set of points (also known as a point cloud or vertex cloud in this context). It
is important for the objects to be convex because it is orders of magnitude is easier
to calculate collisions with convex shapes (those without any internal dips or caves in
the shape) than with concave shapes (those with caves in its surface).
A convex hull is defined by the btConvexHullShape class. We must perform a little
programming gymnastics to create our convex hull, by generating an array of five
btVector3 s, and passing the memory address of the first point's x coordinate into
our convex hull. This may seem confusing at first, but it's straightforward once we ap-
preciate the importance of contiguous memory.
A btVector3 consists of four floats: x, y, z, and an unused buffer float. Why is there
an unused variable in this object? Because CPUs are very efficient while working in
powers of 2, and since a float is 4 bytes large, that makes an entire btVector3 ob-
ject 16 bytes large. Throwing in an unused float like this is a good way to force the
compiled code to make these objects 16 bytes large. This is yet another one of those
low-level optimizations to be found in Bullet. In addition, an array of btVector3 s are
contiguous in memory (by definition) such that they follow one another sequentially by