Game Development Reference
In-Depth Information
three times throughout this topic in functions such as glutInitDisplayMode() ,
glutClear() , and our DebugDrawer class.
Tip
Bitmasks are used by Bullet for these operations because performing comparis-
ons on them is absurdly fast and they use a minimal amount of data. With po-
tentially thousands of comparisons to perform per simulation step, this is a very
worthwhile optimization that has been built into Bullet.
Because the two values for group and mask are shorts , we have 2 bytes, or 16 bits,
to work with. But, Bullet reserves one of these bits for internal usage, which gives
us access to the remaining 15, however this should be more than enough groups for
most situations.
The last thing to consider is that if we want two objects to collide with one another,
then both of their masks must include the group of the opposing object. For example,
if we want the players to collide with power-ups, we can set the player's mask to do
so; but power-ups must also be flagged to collide with player's, or else the collisions
will not occur. Remember this when attempting to use this feature in the future, be-
cause it is an easy thing to forget.
Note
The BasicDemo application is becoming cluttered, so we have created a specific
application to test collision filtering named CollisionFilteringDemo . Using
this object, instead of BasicDemo , required a handful of changes to our main()
function.
To implement collision filtering, we simply pass the two aforementioned shorts into
our call to the addRigidBody() function. This merely requires a change in the
parameters and the function calls of CreateGameObject() . Because it is so trivial,
we won't show the whole source code here, but we will make a couple of relevant
points:
Search WWH ::




Custom Search