# Chapter 20.   An Articulated, Moveable Figure

```
```

This chapter describes the implementation of an articulated figure, composed of rotatable limbs, which can be moved around a checkboard floor in a similar manner to the 3D sprites in Chapters 18 and 19.

This work is based on the first part of Thana Konglikhit's student project.

The left-hand image shows the figure in its initial stance, the next is the figure after the following commands have been processed:

```
urLeg f 40, lrLeg f -40, ulArm f 20, llArm f 20, chest t 10, head t -10

```

The first four commands specify forward (f) rotations of the limbs representing the upper part of the right leg (urLeg), the lower right leg (lrLeg), the upper left arm (ulArm), and the lower part of the left arm (llArm). The chest and head are turned (t) left and right respectively, so that the head stays facing forward.

All the operations are carried out as a group, causing a single re-orientation of the figure.

Pressing <enter> repeats the commands, although when a limb reaches its predefined maximum or minimum rotation, operations which would rotate it beyond these limits are ignored. The screen shot on the right shows the result of executing the commands several times.

Note that the right arm passes through the right leg; The Mover3D application does not employ collision avoidance to prevent limbs intersecting.

The user can move the entire figure about the floor by typing commands into the text field or by pressing arrow keys on the keyboard. The left-hand image below displays the outcome of the commands:

```f, f, c, c, f, f

```

The commands cause the figure to move from its starting position at (0,0) on the floor: forward 0.6 units, 22.5 degrees to its right, and forward another 0.6 units. The right-hand image is a view of the scene after repeating these commands three times. Sixteen repetitions will cause the figure to return to its starting position at (0,0).

These commands are reminiscent of the turtle geometry constructs found in languages like Logo.

As with the limb operations, all movements entered into the textfield update the figure at once. The operations are carried out in the order specified by reading the input sequence left-to-right.

A close look at the pictures above shows that its limbs are unaffected by the movement: the entire figure is moved and rotated as a single 'unit'.

The screen shot on the right illustrates the result of pressing the "reset" button in the GUI: the figure's limbs are rotated back to their starting position, but the figure remains at its current position and orientation on the floor.

## Other features:

• the articulated figure is created by connecting instances of our Limb class and its subclasses. These classes are sufficiently general to build most kinds of articulated shape;
• each limb can be given an initial orientation relative to its 'parent' limb, and can be rotated around its x-, y-, and z-axes at run time. The rotation ranges can be pre-set;
• the shape of a limb is described using a LatheShape3D object (see Chapter 17) which allows a typical limb shape to be specified with just a few coordinates;
• a limb's cross-sectional shape can be modified by using subclasses of LatheShape3D when defining the limb;
• the appearance of a limb is derived from a texture, and reflects light;
• a limb may be invisible, which enables it to be used as a connector between other limbs without being rendered;
• the command language for limbs allows each limb to be individually rotated;
• the command language for the figure permits the figure to be moved around the board, rotated around the y-axis, and lifted into the air. The figure cannot be lowered below the floor or rotated around its x- or z- axes. This means, for example, that it is not possible to make the figure lie on its back on the floor.

```
```

## Downloads

Navigation:

Dr. Andrew Davison
E-mail: ad@fivedots.coe.psu.ac.th
Back to my home page