Game Development Reference
In-Depth Information
enum CollisionGroups {
COLGROUP_NONE = 0,
COLGROUP_STATIC = 1 << 0,
COLGROUP_BOX = 1 << 1,
COLGROUP_SPHERE = 1 << 2
};
This enum , found in BulletOpenGLApplication.h , defines the possible collision
groups for our object. Each represents a different group and is represented by a
value of 1, but bit shifted left by gradually increasing values of 2, 4, 8, 16, and so on.
This is a simple pattern to ensure that each value consumes a unique bit. The same
enum that defines the values for the groups is also used to determine each new ob-
ject's collision mask. To set more than one group for an object's collision mask, we
use the bitwise-or operator, as follows:
COLGROUP_BOX | COLGROUP_STATIC
Passing this value as the object's mask makes it collide with any object flagged for
either of these groups.
Defining linear and angular freedom
It's becoming increasingly common these days to see the games that are visually 3D,
but all gameplay and physics occurs in only two dimensions. These types of games
are typically referred to as 2.5D games . These are either attempts to bring a classic
2D game back to life with modern 3D graphics, or a way to keep the simplicity of 2D
gameplay, but give them more life and believability through advanced graphics. To
achieve this, physics objects must only be able to move in the X and Y axes, and
only able to rotate around the Z axis.
Restrictions of this kind can be applied to any rigid body object in Bullet by setting
the linear or angular factor of a rigid body. Simply call the setLinearFactor() or
setAngularFactor() functions on any rigid body, passing in a btVector3 that
specifies which axes are allowed, and which are not. For instance, to restrict the
movement of an object to behave as if it was a 2.5D game, we would call:
Search WWH ::




Custom Search