Docsity
Docsity

Prepare-se para as provas
Prepare-se para as provas

Estude fácil! Tem muito documento disponível na Docsity


Ganhe pontos para baixar
Ganhe pontos para baixar

Ganhe pontos ajudando outros esrudantes ou compre um plano Premium


Guias e Dicas
Guias e Dicas


Tutorial Java3D Capitulo 5 - Animação, Notas de estudo de Análise de Sistemas de Engenharia

Tutorial Java3D - Animação Permission to use, copy, modify, and distribute this documentation for NON-COMMERCIAL purposes and without fee is hereby granted provided that this copyright notice appears in all copies.

Tipologia: Notas de estudo

Antes de 2010

Compartilhado em 10/04/2010

alessandro-borges-10
alessandro-borges-10 🇧🇷

3

(2)

12 documentos

1 / 43

Toggle sidebar

Esta página não é visível na pré-visualização

Não perca as partes importantes!

bg1
Tutorial version 1.5 (Java 3D API v 1.1.2)
Getting Started with
the Java 3D API
Chapter 5
Animation
Dennis J Bouvier
K Computing
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b

Pré-visualização parcial do texto

Baixe Tutorial Java3D Capitulo 5 - Animação e outras Notas de estudo em PDF para Análise de Sistemas de Engenharia, somente na Docsity!

Tutorial version 1.5 (Java 3D API v 1.1.2)

Getting Started with

the Java 3D

API

Chapter 5

Animation

Dennis J Bouvier

K Computing

The Java 3D Tutorial

© 1999 Sun Microsystems, Inc. 2550 Garcia Avenue, Mountain View, California 94043-1100 U.S.A All Rights Reserved.

The information contained in this document is subject to change without notice.

SUN MICROSYSTEMS PROVIDES THIS MATERIAL "AS IS" AND MAKES NO WARRANTY OF ANY KIND, EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. SUN MICROSYSTEMS SHALL NOT BE LIABLE FOR ERRORS CONTAINED HEREIN OR FOR INCIDENTAL OR CONSEQUENTIAL DAMAGES (INCLUDING LOST PROFITS IN CONNECTION WITH THE FURNISHING, PERFORMANCE OR USE OF THIS MATERIAL, WHETHER BASED ON WARRANTY, CONTRACT, OR OTHER LEGAL THEORY).

THIS DOCUMENT COULD INCLUDE TECHNICAL INACCURACIES OR TYPOGRAPHICAL ERRORS. CHANGES ARE PERIODICALLY MADE TO THE INFORMATION HEREIN; THESE CHANGES WILL BE INCORPORATED IN NEW EDITIONS OF THE PUBLICATION. SUN MICROSYSTEMS, INC. MAY MAKE IMPROVEMENTS AND/OR CHANGES IN THE PRODUCT(S) AND/OR PROGRAM(S) DESCRIBED IN THIS PUBLICATION AT ANY TIME.

Some states do not allow the exclusion of implied warranties or the limitations or exclusion of liability for incidental or consequential damages, so the above limitations and exclusion may not apply to you. This warranty gives you specific legal rights, and you also may have other rights which vary from state to state.

Permission to use, copy, modify, and distribute this documentation for NON-COMMERCIAL purposes and without fee is hereby granted provided that this copyright notice appears in all copies.

This documentation was prepared for Sun Microsystems by K Computing (530 Showers Drive, Suite 7-225, Mountain View, CA 94040, 770-982-7881, www.kcomputing.com). For further information about course development or course delivery, please contact either Sun Microsystems or K Computing.

Java, JavaScript, Java 3D, HotJava, Sun, Sun Microsystems, and the Sun logo are trademarks or registered trademarks of Sun Microsystems, Inc. All other product names mentioned herein are the trademarks of their respective owners.

The Java 3D Tutorial 5-ii

The Java 3D Tutorial 5-iii This document is one part of a tutorial on using the Java 3D API. You should be familiar with Java 3D API basics to fully appreciate the material presented in this Chapter. Additional chapters and the full preface to this material are presented in the Module 0 document available at: http://java.sun.com/products/javamedia/3d/collateral

Cover Image

The cover image represents the key frame animation possible using a Morph object and the appropriate behavior. Section 5.5 presents an example program utilizing a Morph object, an Alpha object, and a

  • Chapter Table of Contents
  • Animation.............................................................................................................................................5-
    • 5.1 Animations................................................................................................................................5-
    • 5.2 Interpolators and Alpha Object Provide Time-based Animations.................................................5-
      • 5.2.1 Alpha.................................................................................................................................5-
      • 5.2.2 Using Interpolator and Alpha Objects.................................................................................5-
      • 5.2.3 Example Using Alpha and RotationInterpolator ..................................................................5-
      • 5.2.4 Alpha API .........................................................................................................................5-
      • 5.2.5 Interpolator Behavior Classes...........................................................................................5-
      • 5.2.6 Core Interpolator API ......................................................................................................5-
      • 5.2.7 Path Interpolator Classes..................................................................................................5-
    • 5.3 Billboard Class........................................................................................................................5-
      • 5.3.1 Using a Billboard Object..................................................................................................5-
      • 5.3.2 Example Billboard Program .............................................................................................5-
      • 5.3.3 Billboard API ..................................................................................................................5-
    • 5.4 Level of Detail (LOD) Animations ...........................................................................................5-
      • 5.4.1 Using a DistanceLOD Object ...........................................................................................5-
      • 5.4.2 Example Usage of DistanceLOD......................................................................................5-
      • 5.4.3 DistanceLOD API............................................................................................................5-
      • 5.4.4 LOD (Level of Detail) API...............................................................................................5-
    • 5.5 Morph .....................................................................................................................................5-
      • 5.5.1 Using a Morph Object......................................................................................................5-
      • 5.5.2 Example Morph Application: Walking..............................................................................5-
      • 5.5.3 Morph API ......................................................................................................................5-
    • 5.6 Chapter Summary....................................................................................................................5-
    • 5.7 Self Test..................................................................................................................................5-
  • Figure 5-1 Some Classes used in Java 3D Animations............................................................................5- List of Figures
  • Figure 5-2 Phases of the Alpha Waveform.............................................................................................5-
  • Figure 5-3 Some Basic Waveforms Easily Made with an Alpha Object. .................................................5-
  • Figure 5-4 Recipe for Using an Interpolator and Alpha Objects for Animation........................................5-
  • Figure 5-5 Scene Rendered at 4:30 by the ClockApp Example Program. ................................................5-
  • Figure 5-6 Smoothing of the Waveform Produced by Alpha...................................................................5-
  • Figure 5-7 Four Scenes Rendered by AlphaApp Showing the Effect of IncreasingAlphaRampDuration. .5-
  • Figure 5-8 Java 3D Core and Utility (shaded boxes) Interpolator Classes Hierarchy. ............................5-
  • Figure 5-9 Two Scenes from InterpolatorApp Showing Various Interpolators.......................................5-
    • NodeComponent Object...............................................................................................................5- Figure 5-10 Partial Scene Graph Diagram of a ColorInterpolator Object and its Target Material
  • Figure 5-11The Relationship Between Knots and Alpha Value for a 2D Position Example. ..................5-
  • Figure 5-12 Recipe for Using a Path Interpolator Object......................................................................5-
    • of the Color Cube. The Red Dots Show the Knots Positions of the Example Application..............5- Figure 5-13A Scene Rendered by RotPosPathApp Showing the Interpolation of the Rotation and Position
  • Figure 5-14 Recipe for Using a Billboard Object to Provide Animation. ...............................................5-
  • Figure 5-15 Diagram of Scene Graph Using a Billboard Object as Created in Code Fragment 5-3. .......5-
  • Figure 5-16 Image of BillboardApp with all 2D 'Trees' Facing the Viewer............................................5-
  • Figure 5-17 Recipe for Using a DistanceLOD Object to Provide Animation. ........................................5-
  • Figure 5-18 Partial Scene Graph Diagram for DistanceLODApp Example Program.............................5-
  • Figure 5-19 Two Scenes Rendered from DistanceLODApp..................................................................5-
  • Figure 5-20 Recipe for Using a Morph Object. ....................................................................................5-
  • Figure 5-21 Key Frame Images from MorphApp with the Trace of One Vertex. ...................................5-
    • Classes (not all are good).............................................................................................................5- Figure 5-22 A Scene Rendered from Morph3App Showing the Animations of Three Alternative Behavior
  • Code Fragment 5-1 Using a RotationInterpolator and Alpha to Spin a Clock (from ClockApp)...............5- List of Code Fragments
  • Code Fragment 5-2 An Excerpt from the CreateSceneGraph Method of RotPosPathApp.java...............5-
  • Code Fragment 5-3 Except From the createSceneGraph Method of BillboardApp.java. ........................5-
  • Code Fragment 5-4 Excerpt from createSceneGraph Method in DistanceLODApp. ..............................5-
  • Code Fragment 5-5 MorphBehavior Class from MorphApp. ................................................................5-
  • Code Fragment 5-6 An Excerpt from the createSceneGraph Method of MorphApp. .............................5-
  • Table 5-1 Summary of Core Interpolator Classes.................................................................................5- List of Tables
  • Alpha Constructor Summary .................................................................................................................5- List of Reference Blocks
  • Alpha Method Summary (partial list) ....................................................................................................5-
  • Interpolator Method Summary (partial list)..........................................................................................5-
  • ColorInterpolator Constructor Summary..............................................................................................5-
  • ColorInterpolator Method Summary (partial list) .................................................................................5-
  • PositionInterpolator Constructor Summary ..........................................................................................5-
  • PositionInterpolator Method Summary (partial list)..............................................................................5-
  • RotationInterpolator Constructor Summary .........................................................................................5-
  • RotationInterpolator Method Summary (partial list).............................................................................5-
  • ScaleInterpolator Constructor Summary ..............................................................................................5-
  • ScaleInterpolator Method Summary.....................................................................................................5-
  • SwitchValueInterpolator Constructor Summary ...................................................................................5-
  • SwitchValueInterpolator Method Summary (partial list) ......................................................................5-
  • Switch Constructor Summary..............................................................................................................5-
  • Switch Method Summary (partial list) .................................................................................................5-
  • Switch Capability Summary................................................................................................................5-
  • TransparencyInterpolator Constructor Summary..................................................................................5-
  • TransparencyInterpolator Method Summary ........................................................................................5-
  • PathInterpolator ..................................................................................................................................5-
  • PathInterpolator Method Summary (partial list) ...................................................................................5-
  • RotPosPathInterpolator Constructor Summary ....................................................................................5-
  • RotPosPathInterpolator Method Summary...........................................................................................5-
  • Billboard Constructor Summary ..........................................................................................................5-
  • Billboard Method Summary (partial list) .............................................................................................5-
  • DistanceLOD Constructor Summary ...................................................................................................5-
  • DistanceLOD Method Summary..........................................................................................................5-
  • LOD Constructor Summary ................................................................................................................5-
  • LOD Method Summary.......................................................................................................................5-
  • Morph Constructor Summary..............................................................................................................5-
  • Morph Method Summary (partial list) .................................................................................................5-
  • Morph Capabilities Summary..............................................................................................................5-
  • Preface to Chapter

Another set of animation classes animates visual objects in response to view changes. This set of classes includes the billboard and Level of Detail (LOD) behaviors which are driven not by the passage of time, but on the position or orientation of the view. Classes for both of these behaviors are provided in the Java 3D core and presented in Sections 5.3 and 5.4, respectively. Figure 5-1 shows the high level class hierarchy for animation classes.

Behavior

Billboard

Interpolator

LOD

DistanceLOD

ColorInterpolator

RotPosPathScaleInterpolator

Figure 5-1 Some Classes used in Java 3D Animations

Section 5.5 presents the Morph class. The Morph class is used in both animation or interpolator applications.

5.2 Interpolators and Alpha Object Provide Time-based Animations^3

An Alpha object produces a value between zero and one, inclusive, depending on the time and the parameters of the Alpha object. Interpolators are customized behavior objects that use an Alpha object to provide animations of visual objects. Interpolator actions include changing the location, orientation, size, color, or transparency of a visual object. All interpolator behaviors could be implemented by creating a custom behavior class; however, using an interpolator makes creating these animations much easier. Interpolator classes exist for other actions, including some combinations of these actions. The RotationInterpolator class is used in an example program in Section 5.2.3.

5.2.1 Alpha

An alpha object produces a value, called the alpha value, between 0.0 and 1.0, inclusive. The alpha value changes over time as specified by the parameters of the alpha object. For specific parameter values at any particular time, there is only one alpha value the alpha object will produce. Plotting the alpha value over time shows the waveform that the alpha object produces.

The alpha object waveform has four phases: increasing alpha, alpha at one, decreasing alpha, and alpha at zero. The collection of all four phases is one cycle of the alpha waveform. These four phases correspond with four parameters of the Alpha object. The duration of the four phases is specified by an integer value expressing the duration in milliseconds of time. Figure 5-2 shows the four phases of the alpha waveform.

All alpha timings are relative to the start time for the Alpha object. The start time for all Alpha object is taken from the system start time. Consequently, Alpha objects created at different times will have the same

(^3) Section 1.9 introduced the RotationInterpolator and Alpha classes. You may want to read that section

first. Also, the Java 3D API Specification covers Alpha in detail.

start time. As a result, all interpolator objects, even those based on different Alpha objects, are synchronized.

Alpha objects can have their waveforms begin at different times. The beginning of an alpha object's first waveform cycle may be delayed by either or both of two other parameters: TriggerTime and PhaseDelayDuration. The TriggerTime parameter specifies a time after the StartTime to begin operation of the Alpha object. For a time specified by the PhaseDelayDuration parameter after the TriggerTime, the first cycle of the waveform begins^4. Figure 5-2 shows the StartTime, TriggerTime and PhaseDelayDuration.

An alpha waveform may cycle once, repeat a specific number of times, or cycle continuously. The number of cycles is specified by the loopCount parameter. When the loopCount is positive, it specifies the number of cycles. A loopCount of –1 specifies continuous looping. When the alpha waveform cycles more than once, only the four cycles repeat. The phase delay is not repeated.

4 Phases of Alpha Waveform

  1. increasingAlphaDuration
  2. alphaAtOneDuration
  3. decreasingAlphaDuration
  4. alphaAtZeroDuration

duration of one cycle duration of second cycle

alpha value

program start time trigger time phase delay

time

Figure 5-2 Phases of the Alpha Waveform.

An alpha waveform does not always use all four phases. An alpha waveform can be formed from one, two, three, or four phases of the Alpha waveform. Figure 5-3 shows waveforms created using one, two, or three phases of the Alpha waveform. Six of the 15 possible phase combinations are shown in the figure.

(^4) Either startTime or phaseDelayDuration can be used for the same purpose. It is a rare application that requires the

use of both parameters.

In this application, the target object is a TransformGroup object. The ALLOW_TRANSFORM_WRITE capability is required for the TransformGroup target object. Some other interpolators act upon different target objects. For example, the target of a ColorInterpolator object is a Material object. An interpolator object sets the value of its target object based on the alpha value and values that the interpolator object holds.

The interpolator defines the end points of the animation. In the case of the RotationInterpolator, the object specifies the start and end angles of rotation. The alpha controls the animation with respect to the timing and how the interpolator will move from one defined point to the other by the specification of the phases of the alpha waveform.

This application uses the default RotationInterpolator settings of a start angle of zero and an end angle of 2 Π (one complete rotation). The default axis of rotation is the y-axis. The alpha object is set to continuously rotate (loopCount = -1) with a period of one minute (60,000 milliseconds). The combination of these two objects will cause the visual object to rotate one full rotation every minute. The cycle continuously and immediately repeats. The result looks like the clock is continuously spinning, not that the clock spins once and starts over.

Code Fragment 5-1 shows the createSceneGraph method from ClockApp.java. This code fragment is annotated with the steps from the recipe of Figure 5-4.

  1. public BranchGroup createSceneGraph() {
  2. // Create the root of the branch graph
  3. BranchGroup objRoot = new BranchGroup();
  4. // create target TransformGroup with Capabilities

6. å TransformGroup objSpin = new TransformGroup();

  1. objSpin.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
  2. // create Alpha that continuously rotates with a period of 1 minute

10. ç Alpha alpha = new Alpha (-1, 60000);

  1. // create interpolator object; by default: full rotation about y-axis

13. é RotationInterpolator rotInt = new RotationInterpolator(alpha, objSpin);

14. è rotInt.setSchedulingBounds(new BoundingSphere());

  1. //assemble scene graph

17. ê objRoot.addChild(objSpin);

  1. objSpin.addChild(new Clock());
  2. objRoot.addChild(rotInt);
  3. // Let Java 3D perform optimizations on this scene graph.
  4. objRoot.compile();
  5. return objRoot; 25.} // end of CreateSceneGraph method of ClockApp

Code Fragment 5-1 Using a RotationInterpolator and Alpha to Spin a Clock (from ClockApp).

Figure 5-5 is of a scene rendered by ClockApp at 4:30. The clock face is oblique to the viewer since the entire clock face is rotating.

Figure 5-5 Scene Rendered at 4:30 by the ClockApp Example Program.

The ClockApp program shows a simple application of the RotationInterpolator. The Clock object, defined in Clock.java available in the examples/Animation subdirectory, shows a more advanced application of the RotationInterpolator object. The clock object in the program uses one RotationInterpolator object to animate each hand of the clock^8. However, only one alpha object is used in the clock. It is not necessary to use one Alpha object to coordinate the hands; as noted above, all Alpha objects are synchronized on the program start time. However, sharing one Alpha object saves system memory.

Some of the potentially interesting features of the Clock Class are:

  • the setting of the start and end angles for the hands,
  • the setting of the axes of rotation, and
  • the setting of the polygonal culling for the various components of the clock.

The source code for the clock is in Clock.java, also available in the examples/Animation subdirectory. The study of the Clock class is left to the reader.

Smoothing of the Alpha Waveform

In addition to the duration of the four phases, the programmer can specify a ramp duration for the increasing alpha and decreasing alpha phases. During the ramp duration, the alpha value changes gradually. In the case of motion interpolators, it will appear as though the visual object is accelerating and decelerating in a more natural, real world, manner.

The ramp duration value is used for both the beginning and ending portions of the phase and therefore the ramp duration is limited to half of the duration of the phase. Figure 5-6 shows an Alpha waveform with both IncreasingAlphaRampDuration and a DecreasingAlphaRampDuration. Note that the alpha value changes linearly between the two ramp periods.

(^8) Since the clock has front and back facing hands, there are four hands and four RotationInterpolator objects.

5.2.4 Alpha API

The API of the Alpha class is straightforward. Four constructors cover the most common alpha applications. A plethora of methods, listed in the next reference block, make easy work of customizing an Alpha object to fit any application.

Alpha Constructor Summary

extends: Object

The alpha class converts a time value into an alpha value (a value in the range 0 to 1, inclusive). The Alpha object is effectively a function of time that generates values in the range [0,1]. A common use of the Alpha provides alpha values for Interpolator behaviors. The characteristics of the Alpha object are determined by user-definable parameters. Refer to Figure 5-2, Figure 5-6, and the text accompanying these figures for more information.

Alpha() Constructs an Alpha object with mode = INCREASING_ENABLE, loopCount = -1, increasingAlphaDuration = 1000, all other parameters = 0, except StartTime. StartTime is set as the start time of the program.

Alpha(int loopCount, long increasingAlphaDuration) This constructor takes only the loopCount and increasingAlphaDuration as parameters, sets the mode to INCREASING_ENABLE and assigns 0 to all of the other parameters (except StartTime).

Alpha(int loopCount, long triggerTime, long phaseDelayDuration, long increasingAlphaDuration, long increasingAlphaRampDuration, long alphaAtOneDuration) Constructs a new Alpha object and sets the mode to INCREASING_ENABLE.

Alpha(int loopCount, int mode, long triggerTime, long phaseDelayDuration, long increasingAlphaDuration, long increasingAlphaRampDuration, long alphaAtOneDuration, long decreasingAlphaDuration, long decreasingAlphaRampDuration, long alphaAtZeroDuration) This constructor takes all of the Alpha user-definable parameters.

Alpha Method Summary (partial list)

Refer to Figure 5-2, Figure 5-6, and the text accompanying these figures for more information. Each of the set- methods has a matching parameterless get-method which returns the a value of the type that corresponds to the parameter of the set-method.

boolean finished() Query to test if this alpha object has finished all its activity.

void setAlphaAtOneDuration(long alphaAtOneDuration) Set this alpha's alphaAtOneDuration to the specified value.

void setAlphaAtZeroDuration(long alphaAtZeroDuration) Set this alpha's alphaAtZeroDuration to the specified value.

void setDecreasingAlphaDuration(long decreasingAlphaDuration) Set this alpha's decreasingAlphaDuration to the specified value.

void setDecreasingAlphaRampDuration(long decreasingAlphaRampDuration) Set this alpha's decreasingAlphaRampDuration to the specified value.

void setIncreasingAlphaDuration(long increasingAlphaDuration) Set this alpha's increasingAlphaDuration to the specified value.

void setIncreasingAlphaRampDuration(long increasingAlphaRampDuration) Set this alpha's increasingAlphaRampDuration to the specified value.

void setLoopCount(int loopCount) Set this alpha's loopCount to the specified value.

void setMode(int mode) Set this alpha's mode to that specified in the argument. This can be set to INCREASING_ENABLE, DECREASING_ENABLE, or the OR-ed value of the two. DECREASING_ENABLE - Specifies that phases 3 and 4 are used INCREASING_ENABLE - Specifies that phases 1 and 2 are used.

void setPhaseDelayDuration(long phaseDelayDuration) Set this alpha's phaseDelayDuration to that specified in the argument.

void setStartTime(long startTime) Sets this alpha's startTime to that specified in the argument; startTime sets the base (or zero) for all relative time computations; the default value for startTime is the system start time.

void setTriggerTime(long triggerTime) Set this alpha's triggerTime to that specified in the argument.

float value() This function returns a value between 0.0 and 1.0 inclusive, based on the current time and the time-to-alpha parameters established for this alpha.

float value(long atTime) This function returns a value between 0.0 and 1.0 inclusive, based on the specified time and the time-to-alpha parameters established for this alpha.

Table 5-1 Summary of Core Interpolator Classes

Interpolator class used to target object type page

ColorInterpolator (^) change the diffuse color of an

object(s)

Material 5-

PathInterpolator^10 abstract class TransformGroup 5-

PositionInterpolator (^) change the position of an

object(s)

TransformGroup 5-

RotationInterpolator (^) change the rotation

(orientation) of an object(s)

TransformGroup 5-

ScaleInterpolator (^) change the size of an object(s) TransformGroup 5-

SwitchValueInterpolator (^) choose one of (switch) among

a collection of objects

Switch 5-

TransparencyInterpolator (^) change the transparency of an

object(s)

TransparencyAttributes 5-

An example program, InterpolatorApp.java, demonstrates six non-abstract interpolator classes of Table 5-1. In this program, each interpolator object is driven by a single Alpha object. Figure 5-9 shows two scenes rendered by InterpolatorApp. Changes in position, rotation, scale, color, transparency, and visual object (top to bottom) are made by PositionInterpolator, RotationInterpolator, ScaleInterpolator, ColorInterpolator, TransparencyInterpolator, and SwitchValueInterpolator objects, respectively. The complete source code for InterpolatorApp is available in the examples/Animation subdirectory of the examples distribution.

Position

Rotation

Scale

Color

Transparency

SwitchValue

Figure 5-9 Two Scenes from InterpolatorApp Showing Various Interpolators.

(^10) The PathInterpolator class is an abstract class and does not have a target object, but each of the known extensions

of this interpolator have a TransformGroup target object. See Section 5.2.7 for more information.

Interpolator Programming Pitfalls

Interpolator objects are derived from, and closely related to, behavior objects. Consequently, using interpolator objects give rise to the same programming pitfalls as using behavior objects (see Programming Pitfalls of Using Behavior Objects on page 4-9). In addition to these, there are general Interpolator programming pitfalls, and specific pitfalls for some interpolator classes. Two general pitfalls are listed here while the interpolator class specific ones are listed with the appropriate class' reference blocks in the next section.

One potential interpolator programming pitfall is not realizing that interpolator objects clobber the value of its target objects. You might think that the TransformGroup target of a RotationInterpolator can be used to translate the visual object in addition to the rotation provided by the interpolator. This is not true. The transform set in the target TransformGroup object is re-written on each frame the Alpha object is active. This also means that two interpolators can not have the same target object^11.

Another general interpolator pitfall is not setting the appropriate capability for the target object. Failing to do so will result in a runtime error.

5.2.6 Core Interpolator API

As an abstract class, Interpolator is only used when creating a new subclass. The Interpolator class provides only one method for users of Interpolator subclasses. Methods useful in writing subclasses are not listed here. The majority of the information needed for writing a subclass of interpolator can be gleaned from Chapter 4.

Interpolator Method Summary (partial list)

extends: Behavior known subclasses: ColorInterpolator, PathInterpolator, PositionInterpolator, RotationInterpolator, ScaleInterpolator, SwitchValueInterpolator, TCBSplinePathInterpolator, TransparencyInterpolator

The Interpolation behavior is an abstract class that provides the building blocks used by its various interpolation specializations.

void setAlpha(Alpha alpha) Set this interpolator's alpha to the alpha object specified.

ColorInterpolator

A ColorInterpolator object has a Material object as its target. This interpolator changes the diffuse color component of the target material. This makes the ColorInterpolator both powerful and limited. The power comes from the ability of having more than one visual object share the same Material object. So, one ColorInterpolator with one Material target can affect more than one visual object. The limitation is that visual objects with a Material NodeComponent are only visible when lit.

The majority of the potential programming pitfalls are the result of the complexity of shaded (lit) scenes. Lighting is sufficiently complex that it is the subject of an entire chapter, Chapter 6. For example, the color of a shaded visual object is the combination of specular, diffuse, and ambient components. The ColorInterpolator only changes one of three components, the diffuse color, so in certain situations it is

(^11) There is nothing preventing this, but only one of the interpolator objects will affect the target with the effect of the

others being overwritten.

ColorInterpolator Method Summary (partial list)

The get-methods do not follow the convention of other interpolators. They are listed here.

void setEndColor(Color3f color) Sets the endColor for this interpolator. matching get-method: void getEndColor(Color3f color)

void setStartColor(Color3f color) Sets the startColor for this interpolator. matching get-method: void getStartColor(Color3f color)

void setTarget(Material target) Sets the target material component object for this interpolator. matching get-method: Material getTarget()

PositionInterpolator

The PositionInterpolator varies the position of a visual object(s) along an axis. The specification of the end points of interpolation is made with two floating point values and an axis of translation. The default axis of translation is the x-axis.

PositionInterpolator Constructor Summary

extends: Interpolator

This class defines a behavior that modifies the translational component of its target TransformGroup by linearly interpolating between a pair of specified positions (using the value generated by the specified Alpha object). The interpolated position is used to generate a translation transform along the local X-axis (or the specified axis of translation) of this interpolator.

PositionInterpolator(Alpha alpha, TransformGroup target) Constructs a trivial position interpolator with a specified target, with the default axis of translation (X), a startPosition of 0.0f, and an endPosition of 1.0f.

PositionInterpolator(Alpha alpha, TransformGroup target, Transform3D axisOfTranslation, float startPosition, float endPosition) Constructs a new position interpolator that varies the target TransformGroup's translational component (startPosition and endPosition) along the specified axis of translation.

PositionInterpolator Method Summary (partial list)

Each of the set-methods has a matching parameterless get-method which returns a value of the type corresponding to the parameter of the set-method.

void setAxisOfTranslation(Transform3D axisOfTranslation) Sets the axis of translation for this interpolator.

void setEndPosition(float position) Sets the endPosition for this interpolator.

void setStartPosition(float position) Sets the startPosition for this interpolator.

void setTarget(TransformGroup target) Sets the target for this interpolator.

RotationInterpolator

The RotationInterpolator varies the rotational orientation of a visual object(s) about an axis. The specification of the end points of interpolation is made with two floating point angle values and an axis of rotation. The default axis of rotation is the positive y-axis.

RotationInterpolator Constructor Summary

extends: Interpolator

This class defines a behavior that modifies the rotational component of its target TransformGroup by linearly interpolating between a pair of specified angles (using the value generated by the specified Alpha object). The interpolated angle is used to generate a rotation transform about the local Y-axis of this interpolator, or the specified axis of rotation.

RotationInterpolator(Alpha alpha, TransformGroup target) Constructs a trivial rotation interpolator with a specified target, the default axis of rotation is used (+Y), a minimum angle of 0.0f, and a maximum angle of 2*pi radians.

RotationInterpolator(Alpha alpha, TransformGroup target, Transform3D axisOfRotation, float minimumAngle, float maximumAngle) Constructs a new rotation interpolator that varies the target transform node's rotational component.