< Zurück | Inhalt | Weiter >

12.4 Using a cubic−spline interpolator

Java 3D includes a class to perform cubic−spline interpolation of position, rotation, and scale between key frames. The class uses the Kochanek−Bartels (K−B) algorithm to allow smooth interpolation between key frames (knots), which specify pose and interpolation information. Unlike linear interpolation, which suffers from potential discontinuities at control points (knots), K−B interpolation, while guaranteeing that the path passes through all the control points, varies the path smoothly. Instead of a piece of taut string strung between control points, the analogy is closer to a springy rod that passes through each point.


The K−B algorithm is fairly complex, and a discussion of the mathematics behind the algorithm is beyond the scope of this practical book. There are a number of very good online resources that describe the algorithm in detail. In addition, because the Interpolator class that implements the algorithm is in the Java 3D utils package, all the source code is available for inspection.


The good news is that the algorithm is extremely flexible and allows very fine control over the interpolated path. Each key frame, along with all the pose information (position, rotation, scale), also defines the following three parameters:


Tension (–1 to +1)

Continuity (–1 to +1)

Bias (–1 to +1)


As with most terms in this book, a picture is worth a thousand words, so see figures 12.5, 12.6, and 12.7, which illustrate the K−B parameters.

image


Figure 12.5 The effect of varying the tension parameter at a key frame on a 2D K−B spline curve


image


Figure 12.6 The effect of varying the continuity parameter at a key frame on a 2D K−B spline curve

image


Figure 12.7 The effect of varying the bias parameter at a key frame on a 2D K−B spline curve


 

Tension parameter
Continuity
Bias
12.4.2 Creating the LOD behavior
12.4.3 Reading spline key frames from disk
From Utils.java in the org.selman.java3d.book package
12.4.4 Creating the texture−mapped sky backdrop
From SplineInterpolatorTest.java
12.4.5 Controlling the extent of the audio for the helicopters
From Helicopter.java