Game Development Reference
In-Depth Information
Note
Notice the special case to avoid picking static objects, such as our ground plane.
When we gave our ground plane a mass of zero, Bullet automatically set the stat-
ic flag for us, allowing us to check for it at a later date.
Before we can destroy the picked rigid body we need to know what GameObject
that corresponds to. We will have to search through our list of game objects, com-
paring their rigid bodies with the picked one, until we find it. Then, and only then, is
it safe to destroy it.
Check the DestroyGameObject() function in the chapter's source code for details
of this process. This function searches through our list of objects hunting down
GameObject that corresponds to the given btRigidBody . It is then called during
the Keyboard() function, whenever we detect that the user pressed the D key.
Tip
Note that the mouse coordinates, x and y , are also passed into functions such
as Keyboard() . This greatly simplifies our input handling, preventing us from
having to store the current mouse data locally.
Launch the application, hover the mouse cursor over an object, and press D on the
keyboard. Any objects beneath the cursor should now be instantly destroyed (with
the exception of the ground plane). The following are the screenshots before and
after destruction of the box on the left:
Search WWH ::




Custom Search