Class Diagrams for Mover3D


The Articulated Figure Application

The Mover3D application demonstrates the articulated figure approach.

The lefthand picture in Figure 20-1 shows the figure's initial stance and the righthand one is the position 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

Figure 20-1. Initial position and after limb movement


The commands are typed into a text field at the bottom of the application window and processed when Enter is pressed. All the commands are carried out as a group, causing a single reorientation of the figure.

The first four commands specify forward (f in the command line above) 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 the head stays facing forward.

Pressing Enter again repeats the commands, though when a limb reaches its predefined maximum positive or negative rotation, operations that would rotate it beyond these limits are ignored. Figure 20-2 shows the result of executing the command line from Figure 20-1 a few more times. Several of the limbs have reached their rotational limits, including the upper-right leg and the upper-left arm.

The right arm passes through the right leg because Mover3D does not employ collision avoidance to prevent limbs from intersecting.


Aside from commands that influence individual limbs, several affect the entire figure, moving it over the floor and rotating it around the y-axis. These commands can

Figure 20-2. Repeated limb movements


be typed into the text field or entered by pressing arrow keys on the keyboard. Figure 20-3 displays the outcome of the text field commands:

     f, f, c, c, f, f

Figure 20-3. Figure movement


This sequence causes the figure to move from its starting position at (0,0) on the floor, forward 0.6 units (2 x 0.3), 45 degrees to its right (two 22.5 degree turns), and forward another 0.6 units.

The move increment and rotation angle are hardwired into the code. An advantage of 22.5 degrees is that four turns total 90 degrees, and 16 turns bring the figure back to its original orientation.

Figure 20-4 is a view of the scene after repeating the f, f, c, c, f, f commands three times.

Figure 20-4. Repeated figure movement


The figure can move up and down (i.e., it can float), but it can't be lowered below floor level. Rotations are limited to clockwise and counterclockwise around the vertical, with no support for turns about the x- or z-axes. This means, for example, that the figure cannot lie on its back on the floor. The main reason for these restrictions was to reduce the complexity of the implementation.

As with the limb operations, all figure commands entered into the text field update the figure at once after Enter is pressed. The operations are carried out in the order specified by reading the input sequence from left to right. Figures 20-3 and 20-4 show that the entire figure moves and rotates as a single unit.

Figure 20-5 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.

Building the Figure

The figure is created by connecting together instances of the Limb class. The shape of a limb is specified using a LatheShape3D object (introduced in Chapter 17), and its appearance is derived from a texture.

As the limbs are connected, they form a parent/child hierarchy. Each limb can be given an initial orientation relative to its parent limb, and it can be rotated around its x-, y-, and z-axes at runtime. A limb may be invisible, which enables it to be used as a connector between other limbs without being rendered. For example, invisible limbs are used to connect the arms to the torso.

Figure 20-5. Reset limbs


Though the aim is to make a limbed, human figure, the Limb class is sufficiently general to be used to build most kinds of articulated shapes.



Killer Game Programming in Java
Killer Game Programming in Java
ISBN: 0596007302
EAN: 2147483647
Year: 2006
Pages: 340

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net