Flylib.com

Books Software

 
 
 

The Articulated Figure Application


Pros and Cons of Keyframe Animation

The advantage of using multiple models is they can be designed and created outside of Java 3D with software specific to the task (I used Poser). Model creation can be carried out independently of game development, perhaps assigned to someone skilled in 3D modeling. An animation sequence is a combination of poses, which you can mix and match. For example, the poses needed in a fighting game will be different from those in a sports game.

Several Java 3D loaders support keyframe animation. For example, the NWN loader (http://nwn-j3d. sourceforge .net/loader.about.php) defines animations as frames sequences which refer to the Never Winter Night models. Playing an animation consists of calling the loader's playAnimation( ) method with the name of the animation sequence. You'll find a list of all the keyframe animation loaders in Chapter 14.

A major drawback is the potential size of each model and the number of models required to cover all the necessary positions . I chose the simplest figure (size 20 KB) and a small number of poses (13), coming to 260 KB, which must be loaded at startup. These numbers could become unmanageable with larger models and more poses, but that depends on the application. One means of reducing the memory requirements is to share poses between the sprites (by using Java 3D SharedGroup nodes), which would be useful for groups of similar sprites, such as soldiers. This would require changes to the implementation detailed in this chapter.


Chapter 20. An Articulated , Moveable Figure

This chapter describes the implementation of an articulated figure (sprite), composed of moveable and rotatable limbs , which can be instructed to walk, run, and jump around a checkerboard floor.

This work is based on the first part of a student project carried out for me by Thana Konglikhit in 2003-2004.


Chapter 19 was concerned with sprite animation but used the keyframe animation of multiple models. Advantages of figure articulation over keyframes include the increase in control over the figure and the reduction in memory requirements since only one model is being manipulated.

A disadvantage of articulation is the model will probably be a Java 3D creature of cylinders , spheres, and blocks, which must be "dressed" in some way. This will usually necessitate the loading of 3D models, which may bring back the problem of excessive memory usage.

Another issue is the increased complexity of the control code, which requires some mechanism for coordinating the movement of numerous transformGroup s; for instance, a single step forward will affect many joints, and the exact changes needed aren't obvious. I utilize forward kinematics in this chapter.

There are several ways of extending the basic articulation technique, including the use of mesh deformation, morphing, and skinning, which I briefly mention at the end.


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 .