Game Development Reference
In-Depth Information
Note
Continue from here using the Chapter4.1_HandlingMultipleObjects pro-
ject files.
Designing our objects
We would like to create simple objects of various shapes such as boxes, spheres,
and cylinders, and do so without having to repeat tasks such as creating the motion
state, the rigid body, the rigid body construction info, and so on. Essentially, the only
data that should be unique between any two objects are:
• The mass
• The shape
• The color
• The initial position and rotation
Because of this, it should be possible to create new objects using only these four
parameters, while we automatically build the rest from that information. Hence, the
constructor for our new GameObject class looks as follows:
GameObject(btCollisionShape* pShape, float
mass, const btVector3 &color, const btVector3
&initialPosition = btVector3(0,0,0), const
btQuaternion &initialRotation = btQuaternion());
GameObject is a new class that stores important personal data, such as the Bullet
object components, and its own color. It also gives us a few helper functions to ac-
cess this data if we need (and we will). The majority of the work happens in the con-
structor, requiring us to specify the object's mass, color, shape, and initial transform
(in the form of a vector for position and a quaternion for rotation).
Most of the code should be straightforward, with the exception of local inertia. This
value is normally referred to as the moment of inertia in most physics circles. It es-
sentially boils down to the object's resistance to change in angular velocity around
each axis of rotation. The classic example of this is a pole carried by a tight rope
Search WWH ::




Custom Search