Game Development Reference
In-Depth Information
Chapter 7. Collision Shapes
So far we've only built box collision shapes, but Bullet offers much more variety
than this. In this chapter, we'll explore some more built-in collision shapes to bring
more variety into our scene. We will initially cover some more built-in shapes such
as spheres and cylinders, and then explore how to build unique, customized shapes
through convex hulls and compound shapes.
Spheres and cylinders
The btSphereShape and btCylinderShape are the two collision shapes that
could not be more simple; they define a sphere and cylinder, respectively.
Note
Continue from here using the Chapter7.1_SpheresAndCylinders project
files.
We already know how to create btBoxShape , and building these new built-in shapes
is not much different. Note that nothing about the way we handle rigid bodies or mo-
tion states changes when we start working with different collision shapes. This is one
of the big advantages of the Bullet's modular object system. These new shapes can
be instantiated in the creation of a new GameObject as follows:
CreateGameObject( new btSphereShape(1.0f ), 1.0,
btVector3(0.7f, 0.7f, 0.0f), btVector3(-5.0,
10.0f, 0.0f));
CreateGameObject( new
btCylinderShape(btVector3(1,1,1 )), 1.0,
btVector3(0.0f, 0.7f, 0.0f), btVector3(-2,
10.0f, 0.0f));
Simple, right? Unfortunately, we now face a more significant challenge: how to render
these new objects? We could just render them like boxes, but this won't be ideal. We'll
Search WWH ::




Custom Search