Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Chapter 10 Behavior and Interaction  To understand dynamic behaviors in graphics  To understand Java 3D Behavior and WakeupCondition classes  To apply.

Similar presentations


Presentation on theme: "1 Chapter 10 Behavior and Interaction  To understand dynamic behaviors in graphics  To understand Java 3D Behavior and WakeupCondition classes  To apply."— Presentation transcript:

1 1 Chapter 10 Behavior and Interaction  To understand dynamic behaviors in graphics  To understand Java 3D Behavior and WakeupCondition classes  To apply Behavior nodes in scene graphs  To use mouse behaviors  To use key navigator behaviors  To use view platform behaviors  To combine picking and behaviors

2 2 Dynamic 3D Scenes  3D graphics is not limited to static content  There are two common types of dynamic change in a scene –Interaction allows the user to control the changes –Animation generates changes under the control of the program

3 3 Behavior  Java3D uses behavior to facilitate dynamics in a scene graph  Behavior is a leaf node –Defines actions to be taken when the behavior is activated (waked-up)‏ –Behavior is triggered by wakeup conditions  For interactions, triggers are user generated  For animation, triggers are time-based

4 4 Behavior Execution Cycles

5 5 Behavior  During the initialization of the Behavior object, it sets a WakeupCondition object.  When the wakeup condition occurs, it will awaken the Behavior by calling its processStimulus.  After executing the custom code in processStimulus, a wakeup condition can be set again by calling the wakeupOn method.  The process will then repeat indefinitely.

6 6 Behavior Classes  Behavior –abstract –extends Leaf  Two methods void initialize()‏ void processStimulus ( Enumeration wakeupCriteria)‏

7 7 WakeupCondition  Serve as signals to trigger different behaviors under different circumstances  WakeupCriterion –Many subclasses for different kinds of triggers  time, AWT events, collisions, transform changes, …  Subclasses that are used to create combinations of conditions

8 8 Wakeup Condition

9 9 Combining Wakeup Criteria  Subclasses of WakeupCondition WakeupAnd(WakeupCriterion[] criteria)‏ WakeupOr(WakeupCriterion[] criteria)‏ WakeupOrOfAnds(WakeupAnd[] criteriaAnds)‏ WakeupAndOfOrs(WakeupOr[] criteriaOrs)‏

10 10 Combining Wakeup Criteria WakeupCriterion[] criteria1 = {new WakeupOnElapsedTime(10000)}; WakeupCriterion[] criteria2 = {new WakeupOnElapsedFrames(5), new WakeupOnCollisionEntry(node)}; WakeupAnd[] ands = {new WakeupAnd( criteria1), new WakeupAnd(criteria2)}; WakeupOrOfAnds condition = new WakeupOrOfAnds( ands);

11 11 Scheduling Bounds  Each Behavior has a scheduling bounds  Behavior is active only if the scheduling bounds intersects the view platform  Set scheduling bounds with setSchedulingBounds( Bounds bounds)‏ setSchedulingBoundingLeaf( BoundingLeaf bounds)‏

12 12 Implement Custom Behavior  Define a subclass of Behavior class and override the initialize and processStimulus methods.  Set the appropriate wakeup condition in the initialize method. If necessary set the wakeup condition again in processStimulus.  Create an instance of the custom Behavior class and add it to the scene graph as a leaf.  Set the influence bound for the behavior object.

13 13 Example: Clock.java

14 14 Classes for Interaction

15 11/12/08 Mouse Behavior  Mouse behavior classes –Operate on a TransformGroup –Triggered by WakeUpOnAWTEvent  Three classes for rotation, translation and zoom  Constructors take –TransformGroup –Component –TransformGroup and Component

16 11/12/08 Mouse Behaviors  MouseRotate: drag the mouse with the left button down.  MouseTranslate: drag the mouse with the right button down.  MouseZoom: drag the mouse with the middle button down –Drag left button down while holding the Alt key if there is no middle mouse button

17 11/12/08 MoveGlobe.java  Contains a texture-mapped sphere and a set of coordinate axes  Three behaviors for rotation, translation and zoom –All applied to the TransformGroup above the sphere –Axes don't change  Notice the event handling is all hidden inside the Behavior objects

18 11/12/08 Using Keys for Interaction  KeyNavigationBehavior operates on a TransformGroup  Similar constructors to the mouse behavior

19 19 KeyNavigatorBehavior , : Rotate left/right , : Translate forward/backward  Alt-, Alt- : Translate left/right  PgUp, PgDn: Rotate up/down  Alt-PgUp, Alt-PgDn: Translate up/down  -: Reduce back clip distance  +: Reset back clip distance  =: Reset

20 20 View Platform Behavior  OrbitBehavior allows user to interact with the view platform using the mouse –One class supports rotation, translation and zoom –Behavior is applied to the TransformGroup of the view platform  Constructors –OrbitBehavior() –OrbitBehavior(Canvas3D cv) –OrbitBehavior(Canvas3D cv, int flags)

21 11/12/08 MoveView.java  Similar to MoveGlobe except the view platform is moved rather than the globe itself –Direction of apparent motion is reversed –Axes move too

22 22 Picking and Mouse Behavior  PickMouseBehavior has three subclasses –PickRotateBehavior –PickTranslateBehavior –PickZoomBehavior  Changes apply only to picked object  Constructor PickRotateBehavior rotator = new PickRotateBehavior(cv, root, bounds); root.addChild(rotator);

23 11/12/08 TestPickBehavior  Behaviors are applied to the BranchGroup containing the objects  Behaviors need reference to the canvas and the scheduling bounds

24 11/12/08 Data Visualization  The possibility of interacting with a 3D scene provides a powerful tool for studying 3D data sets –Reorienting the scene gives different views of the data  Improves perception of 3D nature of the data –Ability to select subsets of the data allows refinment of the view

25 25 DataViewer.java

26 11/12/08 Using Pick Intersections  Use PickCanvas to pick based on mouse coordinates  All data points are in same 3D object as vertices –need to find the intersection with the pick volume to select individual points PickIntersection inter = results[i].getIntersection(0); Point3d pt = inter.getClosestVertexCoordinates(); int[] ind = inter.getPrimitiveCoordinateIndices();


Download ppt "1 Chapter 10 Behavior and Interaction  To understand dynamic behaviors in graphics  To understand Java 3D Behavior and WakeupCondition classes  To apply."

Similar presentations


Ads by Google