Download presentation
Presentation is loading. Please wait.
1
Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 1 Chapter 11 Animation F To understand the concept and methods of animation F To understand and create Alpha objects F To apply various interpolators to creating animations F To create morphing with Morph nodes and behaviors F To use LOD behaviors F To use billboard behaviors
2
Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 2 Animation F Generate sequences of graphics renderings that vary with time F An effect of live motions F Producing frames, the intermediate results of the changing process, is often the main objective F To produce the animated graphics effects, the rendered scene must change dynamically with time F The changes may involve different attributes of the scene such as geometry, transformation, position, color, and transparency
3
Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 3 Behavior F The Interpolator subclasses of Behavior encapsulate common animation actions F The Alpha class represents a function ot time that can be used to drive the interpolator.
4
Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 4 Alpha F A function of time –usually periodic F Has a range from 0.0 to 1.0
5
Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 5 Alpha Parameters F Times in milliseconds F loopCount - number of cycles (Default -1) –Use -1 to repeat forever F startTime (system start time) F triggerTime (0) F phaseDelayDuration(0) F isPaused (false), pause time (0) F alphaAtZeroDuration (0) F alphaAtOneDuration (0) F increasingAlphaDuration (1000) F decreasingAlphaDuration (0) F increasingAlphaRampDuration (0) –acceleration interval F decreasingAlphaRampDuration (0) –deceleration interval
6
Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 6 Alpha Constructors public Alpha() public Alpha( int loopCount, long increasingAlphaRampDuration) public Alpha( int loopCount, long triggerTime, long phaseDuration, long increasingAlphaRampDuration, long alphaAtOneDuration) public Alpha( int loopCount, long triggerTime, long phaseDuration, long increasingAlphaRampDuration, long alphaAtOneDuration, long decreasingAlphaRampDuration, long alphaAtZeroDuration)
7
Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 7 TestAlpha.java F Plots the alpha waveform for different sets of parameters F To get the value of alpha –at current time public float value() –at a specified time public float value(long atTime)
8
Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 8 Interpolator F Interpolator is an abstract subclass of Behavior –It has a number of predefined subclasses containing typical behaviors needed for animation u For example, Color, Switch, Transparency, Transform F The idea is to set two values for a particular attribute and interpolate values in between as a function of time F Alpha object is used to trigger the changes
9
Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 9 Interpolator F Specify endpoints F Interpolate intermediate points –Assign an Alpha object to the Interpolator
10
Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 10 Interpolator Classes
11
Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 11 ColorInterpolator F Interpolate between two colors for a Material Alpha alpha = new Alpha(); Material mat = new Material(); ColorInterpolator ci = new ColorInterpolator( alpha, mat, red, green); ci.setSchedulingBounds( bounds);
12
Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 12 TransparencyInterpolator F Interpolate between two transparency values for a particular TransparencyAttributes object TransparencyInterpolator( Alpha a, TransparencyAttributes target); TransparencyInterpolator( Alpha a, TransparencyAttributes target, float t1, float t2);
13
Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 13 TransforInterpolator F Applied to a TransformGroup F Maintains a Transform3D object to represent the operation F Has several subclasses –RotationInterpolator –ScaleInterpolator –PositionInterpolator
14
Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 14 PathInterpolator F Two positions aren't always enough to specify a sequence of position changes F PathInterpolator allows you to specify a sequence of control points or key frames F Linearly interpolate the intermediate values between each pair of adjacent points F The timing of the interpolation related to the alpha values is controlled by a sequence of numbers called knots F Subclasses for interpolating positions and rotations
15
Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 15 PathInterpolator Point3f [] positions = { new Point3f(0,0,0), new Point3f(1,1,0), new Point3f(2,0,0)}; float [] knots = {0f,.3f, 1f}; PositionPathInterpolator interpolator = new PositionPathInterpolator( alpha, target, axis, knots, positions);
16
Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 16 Pendulum.java F Adds a pendulum to the clock from chapter 10 –pendulum consists of a cylinder and a sphere F Uses a RotationInterpolator to control the pendulum –Axis of rotation is y-axis by default –Add a Transform3D object to make it rotate about the z-axis (rotate by /2 about x-axis)
17
Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 17 A Pendulum
18
Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 18 Morphing F Animation technique that smoothly transforms one object to another –Not limited to affine transformations
19
Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 19 Morph Class F Morph is a leaf node class –Contains one appearance bundle –Has an array of geometries –An associated array of weights is also defined F Typically the weights are modified by a Behavior object to achieve the animation.
20
Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 20 Weighted Sum of Geometries F The geometry of the Morph object is defined by the weighted sum of the geometries in the array
21
Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 21 Morphing.java F Four GeometryArray objects –Two vertical tubes of different lengths u createGeometry1 –Two sections of a torus with different lengths u createGeometry2 F MorphingBehavior class sets weight based on alpha values
22
Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 22 MorphingBehavior.java F WakeupCondition is 10 elapsed frames F Three sub-intervals for alpha values –[0, 1/3], [1/3, 2/3], [2/3, 1] –In each subinterval, interpolate between two adjacent geometries
23
Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 23 Morphing.java Scene Graph
24
Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 24 LOD F LOD = Level-Of-Detail F Useful for reducing the computational cost of rendering complex shapes –A visual object closer to the viewer will be larger and show more details than the same object viewed from a distance –Can render a distant object with less resolution and detail without significantly affecting the quality
25
Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 25 LOD class F An abstract subclass of Behavior F DistanceLOD is a concrete subclass of LOD F LOD object contains a list of switch nodes –Child of each switch node is selected based on distance to the viewer F LOD also contains an array of distances that determine when to change from one level of detail to the next
26
Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 26 TestLOD.java F Switch node with 4 children which are spheres with different numbers of divisions –First three are texture mapped with textures of different resolutions –Fourth sphere is a solid color
27
Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 27 LOD Example
28
Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 28 Billboard F Operates on a TransformGroup whose children will always be aligned to face the viewer –Two modes: ROTATE_ABOUT_POINT, ROTATE_ABOUT_AXIS F Useful for –Text labels –Simulating complex 3D scene with a 2D object such as an image
29
Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 29 TestBillboard.java
30
Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 30 AxesBillboard.java F Like Axes class except each Text3D object is attached to a TransformGroup controlled by a Billboard object F Billboard objects are set to ROTATE_ABOUT_POINT mode
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.