< Zurück | Inhalt | Weiter >


The bias parameter enables you to apportion tension at a key frame to each curve segment either side of the key frame. In this way the path is skewed about the key frame, with the segment on one side of the key frame slacker than the segment on the other side.

12.4.1 The SplineInterpolatorTest example

SplineInterpolatorTest is one of the most ambitious examples of the book. When I thought of animating an object using a spline curve, I thought of tracking a camera along a spline curve and rendering the results. My initial idea was to model an architectural or city fly−over, and the example grew from there.

SplineInterpolatorTest creates a virtual model of the city of Boston. The example loads a predefined spline curve from a file and takes the viewer on a virtual flight around the city (figures 12.8, 12.9, and 12.10).


Figure 12.8 A frame from the SplineInterpolatorTest example. Take a virtual fly−over of Boston city center


Figure 12.9 When viewed from afar, the SplineInterpolatorTest dynamically switches to a low−resolution image of the whole of the city. One of the orbiting helicopters is visible in the frame


Figure 12.10 Looking up at one of the helicopters orbiting the city

The virtual city is composed of the following elements:

A square with a high−resolution satellite image of the city texture mapped onto it.

A larger square with a lower resolution satellite image applied.

A large blue square to act as a base for the model and supply a consistent horizon.

A cloudy sky backdrop texture mapped onto a Background Sphere.

Some randomly created texture mapped buildings (Boxes).

Three helicopters each flying a spline curve loaded from a file. The geometry for the helicopters is also loaded from a file.

Sound support. Each helicopter has an attached PointSound source. The 3D sound engine generates 3D spatial sound from the three sound sources.

The rendered results are very pleasing, and the smoothness of the spline based animation gives a nice impression of movement and acceleration through the generated world. The satellite images were downloaded from the Microsoft Terraserver satellite image database. Terraserver is very useful in that different resolution images (i.e., from 32 meters per pixel down to 1 meter per pixel) can be easily downloaded. It allows a LOD behavior to be used, so that a high−resolution image appears when the viewer is close to the city and a lower resolution image appears when the viewer is far above the city. Both texture images are 256 × 256 pixels in size, and hence should be supported by hardware renderers.

To support the functionality required for the example, a base class was created for defining the behaviors, geometry, and appearance for the objects in the world. For an application of this complexity, the approach taken in most example code, which is to throw everything in the Applet class, was clearly not going to work. What was required was an OO design that empowered the objects within the world with the abilities they required. These abilities include:

Create geometry.

Load geometry from a disk file.

Assign a texture image.

Assign a sound.

Assign a spline path and Alpha object to animate the object.

Load a spline path from a disk file.

These chores are handled by the ComplexObject class, which allows the main code of the application to deal with the objects themselves, and not with TransformGroups, sounds, appearances, and the like. This keeps the reusable functionality low in the class hierarchy and puts the application−specific details in super classes and the main Applet class itself.

The code for the example is obviously too long to be shown in full, so some interesting highlights will be discussed. The source code for ComplexObject is in the org.selman.java3d.book package.