RenderWare V2.1

Previous Page Index Next Page


Hierarchical Modeling in RenderWare
Constructing Hierarchical Models in Scripts
Traversing Clump Hierarchies
Finding a Particular Clump In a Hierarchy

Hierarchical Modeling


Hierarchical modeling is the process of building models that preserve the hierarchical structure of objects and allow the position and orientation of an object in the hierarchy to be specified relative to its parent.

Hierarchical Modeling in RenderWare

RenderWare’s hierarchical modeling support provides the ability to explicitly model articulation or "joints" connecting objects.

A clump may have a parent and zero or more children.

Each clump has its own independent, local coordinate system. A clump has three associated matrices: a modeling transformation matrix, a joint (or articulation) transformation matrix, and a local transformation matrix (LTM)

The modeling and joint transformations of a child clump together specify the mapping from its the local coordinate system to that of the parent clump. The joint transformation specifies the rotation of the child clump about its local origin; clumps are therefore always "hinged" about their local origin (the joint is always at the origin of the child clump). The modeling transformation specifies where the origin of the child clump is with respect to the origin of the parent clump.

Typically, the geometry being added to a clump is positioned with respect to that clump’s origin by applying translation, rotation or scaling to the current transformation matrix.

The local transformation matrix (LTM) of a clump maps from the local coordinate system of the clump to the world coordinate system of the scene to which it belongs. It may be calculated by initialization to the identity matrix followed by an ascent from that clump to the root of its hierarchy with post transformation first by the joint and then the modeling transformation at each level. Note that a clump’s local transformation is computed by RenderWare and can be retrieved by RwGetClumpLTM(). It cannot (and need not) be set directly by the application programmer.

Constructing Hierarchical Models in Scripts

This section gives a simple example of building a hierarchical model in a RenderWare script (.rwx) file. The example is equally applicable to RenderWare’s "Object Builder" API functions.

The following is an example of a script defining a simple hierarchical model forming part of a robot’s body:


ModelBegin
ClumpBegin
Color 1.0 0.0 0.0
Surface 0.5 0.5 0.5


Block 0.6 0.8 0.3

Translate 0.3 0.4 0.15
ClumpBegin
Color 1.0 1.0 1.0

Translate 0.1 -0.4 0.0
Block 0.2 0.8 0.2
ClumpEnd
ClumpEnd
ModelEnd

The top-level ClumpBegin ... ClumpEnd block defines a clump representing the central section of a robot’s body. One arm of the robot is then modeled by a child of this clump.

The Translate keyword applies a translation to the current transformation matrix (CTM).

When the definition of the child clump is begun (with ClumpBegin), the modeling matrix for the child clump is set to the CTM. The first Translate keyword positions the child clump in relation to its parent; the child’s local origin is displaced by [0.3 0.4 0.15] from that of the parent.

Before adding the second block corresponding to the child clump, a translation is applied to the CTM. This specifies the position of the block relative to the origin of the clump.

The rotation of the arm about the "shoulder joint" requires only one additional line in the script: RotateJointTM. This keyword should be inserted immediately before the ClumpBegin ... ClumpEnd defining the child clump. The command specifies the direction of the axis of rotation about the joint (in the child‘s local space) and the angle of rotation in degrees:


RotateJointTM 1.0 0.0 0.0 30

The above rotates the arm about the X axis of the child’s local space by 30 degrees.

Traversing Clump Hierarchies

There are two ways of traversing clump hierarchies:

1 Starting from any clump in a clump hierarchy, every other clump in that hierarchy may be visited with clump access functions such as RwGetClumpParent(), RwGetNextClump() and RwGetFirstChildClump().

2 All clumps in a hierarchy may be iterated over by the API function RwForAllClumpsInHierarchy() and its variants . This family of functions is convenient in situations when the same operation is to be applied to each clump in a hierarchy.

Finding a Particular Clump In a Hierarchy

There are two main techniques for finding a particular clump:

1 RenderWare allows an integer tag to be attached to each clump. A clump’s tag can be set by the API function RwSetClumpTag() or the script keyword Tag and retrieved by the API function RwGetClumpTag(). Tags are convenient for marking parts of a hierarchical model for identification and manipulation by an application program. A tagged clump may be found with RwFindTaggedClump().

2 The second, more general technique involves RwFindClump()or one of its variants. These functions apply a Boolean (predicate) call-back function to each clump in a hierarchy in turn until the call-back function returns non-zero. Iteration is then terminated. The clump passed as the argument to the call-back function is returned.