< Zurück | Inhalt | Weiter >

12.2 The Alpha class

java.lang.Object

|

+−−javax.media.j3d.Alpha


A good understanding of the Alpha class is key to using all the Interpolator behaviors. The Alpha class defines a function that converts the current time (in milliseconds) to a value between 0 and 1 (alpha value). The alpha value can then be used by the Interpolator to produce the desired interpolation between specified end states.


For example, a PositionInterpolator might be used to move an object between position (0,0,0) and (0,0,5) in 10 seconds. To achieve the desired result, an Alpha object must be created that returns 0 at 0 seconds and 1 at 10 seconds. The PositionInterpolator can then use the Alpha object to create the desired z coordinate (table 12.1).


Table 12.1 Coordinate calculation using Alpha


Time (seconds)

Alpha

Z Coordinate

0

0

0 * 5 = 0

5

0.5

0.5 * 5 = 2.5

10

1

1 * 5 = 5

The Alpha class uses a parameterized function to convert time values to alpha values between 0 and 1.


Figure 12.1 illustrates the basic shape of the functions that can be created using the Alpha class. Nine parameters can be used to create a customized Alpha function are listed there.


image


Figure 12.1 The phases of the Alpha class: triggerTime (1), phase delay (2), increasing alpha (3), increasing alpha ramp (4), at one (5), decreasing alpha (6), decreasing alpha ramp (7), at zero (8), and loopCount (9)


The increasing alpha phase (3) is composed of three potential sections, as is the decreasing alpha phase (6). The values of increasing alpha ramp (4) and decreasing alpha ramp (7) define symmetrical acceleration and deceleration of the Alpha value at the beginning and end of the phase. These quadratic sections help to smooth the transition from 0 to 1 (increasing alpha) or 1 to 0 (decreasing alpha). Note that the Alpha value varies linearly between the quadratic sections. The loopCount parameter (9) allows Alpha functions to be repeated (a fixed number of times or infinitely) by joining Alpha functions end to end.

Run the AlphaTest example and interactively modify the nine parameters to get a good feel for how to parameterize an Alpha object for your application (figure 12.2).


image


Figure 12.2 The AlphaTest example allows an Alpha object to be parameterized interactively and plots the resulting Alpha function



 

NOTE
From the file Values.xls from the CustomAlphaTest example
12.2.2 Summary