5.3. The Components of Physically Simulated Bodies

In order to construct physically simulated agents, you'll need to be familiar with the components of physically simulated bodies. There are three main components used in physical simulations:

5.3.1. The Link Class

The Link class is the basic building block of physically simulated objects. A link is simply a rigid body with a particular shape. Once a Link is created and associated with a shape, it can be attached to other links via Joint objects, covered in the section The Joint Class and its Subclasses (Section 5.3.2) or brought into the physical simulation by being associated with a MultiBody, as discussed in the section on using MultiBody objects (Section 5.3.3). Link objects by themselves will not appear in the simulated world unless (directly or indirectly) associated with a MultiBody object. A Link object that is not associated with a MultiBody is known as an "orphaned" Link.

5.3.2. The Joint Class and its Subclasses

As mentioned in the previous section (Section 5.3.3), Links are joined together using Joint objects.

There are several types of joints available—see each class' documentation for more details:

5.3.3. The MultiBody class

A MultiBody is a single logical physically simulated agent, whether it is made up of a single Link, or multiple Links joined together with Joint objects. Links and Joints have no physical presence in the world, unless they are associated with MultiBody objects. Therefore, after creating a structure using Links and Joints, you must create a MultiBody object for the structure before it appears in the world.

As mentioned above, a MultiBody may contain only a single Link object. More commonly, however, it contains a series of Links connected by Joint objects. Consider a body, for example: it is made up of parts (arms, legs, torso, head), but they are all part of a single logical unit, namely the body. The Link objects are joined together using subclasses of the class Joint.

Keeping these logical units together under a single MultiBody allows the user to move or rotate the entire logical structure, as opposed to moving or rotating individual links. Imagine that suddenly your arm was moved across the room without the rest of your body —in all likelihood, this would not make you very happy. This is what it's like for the underlying physics engine to move a single link—confusing and painful things can happen. By encompassing a set of connected Links within a MultiBody, the user has more logical control over the object.

To create a MultiBody, you'll first need to construct a network of Link and Joint objects (or possibly just a single Link object). Once you've created your Links, you'll need to pick one to be the root link. The root link will be permanently associated with the MultiBody. All other Links attached to it, both directly and indirectly, will also be part of the MultiBody (though they may become dissociated from it later if the relevant Joints are broken). Once a networks of Links is associated with a MultiBody, the Links will appear in the simulated world.

Any Link that is attached (via a Joint) to a Link in a MultiBody will become part of the MultiBody, unless the new link is also associated with a MultiBody. In the event that Links from two distinct MultiBodies are joined, then the MultiBodies will remain distinct and all of the links will remain part of their respective bodies.