1 chapter 10 behavior and interaction to understand dynamic behaviors in graphics to understand...

26
1 Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearso n Education, Inc. All rights reserved. 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

Post on 21-Dec-2015

214 views

Category:

Documents


0 download

TRANSCRIPT

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

1Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved.

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

Page 2: 1 Chapter 10 Behavior and Interaction  To understand dynamic behaviors in graphics  To understand Java 3D Behavior and WakeupCondition classes  To apply

2Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved.

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

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

3Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved.

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

Page 4: 1 Chapter 10 Behavior and Interaction  To understand dynamic behaviors in graphics  To understand Java 3D Behavior and WakeupCondition classes  To apply

4Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved.

Behavior Execution Cycles

Page 5: 1 Chapter 10 Behavior and Interaction  To understand dynamic behaviors in graphics  To understand Java 3D Behavior and WakeupCondition classes  To apply

5Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved.

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.

Page 6: 1 Chapter 10 Behavior and Interaction  To understand dynamic behaviors in graphics  To understand Java 3D Behavior and WakeupCondition classes  To apply

6Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved.

Behavior Classes Behavior

– abstract

– extends Leaf

Two methodsvoid initialize()

void processStimulus ( Enumeration wakeupCriteria)

Page 7: 1 Chapter 10 Behavior and Interaction  To understand dynamic behaviors in graphics  To understand Java 3D Behavior and WakeupCondition classes  To apply

7Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved.

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

Page 8: 1 Chapter 10 Behavior and Interaction  To understand dynamic behaviors in graphics  To understand Java 3D Behavior and WakeupCondition classes  To apply

8Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved.

Wakeup Condition

Page 9: 1 Chapter 10 Behavior and Interaction  To understand dynamic behaviors in graphics  To understand Java 3D Behavior and WakeupCondition classes  To apply

9Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved.

Combining Wakeup Criteria

Subclasses of WakeupConditionWakeupAnd(WakeupCriterion[] criteria)WakeupOr(WakeupCriterion[] criteria)WakeupOrOfAnds(WakeupAnd[] criteriaAnds)WakeupAndOfOrs(WakeupOr[] criteriaOrs)

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

10Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved.

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);

Page 11: 1 Chapter 10 Behavior and Interaction  To understand dynamic behaviors in graphics  To understand Java 3D Behavior and WakeupCondition classes  To apply

11Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved.

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)

Page 12: 1 Chapter 10 Behavior and Interaction  To understand dynamic behaviors in graphics  To understand Java 3D Behavior and WakeupCondition classes  To apply

12Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved.

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.

Page 13: 1 Chapter 10 Behavior and Interaction  To understand dynamic behaviors in graphics  To understand Java 3D Behavior and WakeupCondition classes  To apply

13Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved.

Example: Clock.java

Page 14: 1 Chapter 10 Behavior and Interaction  To understand dynamic behaviors in graphics  To understand Java 3D Behavior and WakeupCondition classes  To apply

14Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved.

Classes for Interaction

Page 15: 1 Chapter 10 Behavior and Interaction  To understand dynamic behaviors in graphics  To understand Java 3D Behavior and WakeupCondition classes  To apply

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

Page 16: 1 Chapter 10 Behavior and Interaction  To understand dynamic behaviors in graphics  To understand Java 3D Behavior and WakeupCondition classes  To apply

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

Page 17: 1 Chapter 10 Behavior and Interaction  To understand dynamic behaviors in graphics  To understand Java 3D Behavior and WakeupCondition classes  To apply

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

Page 18: 1 Chapter 10 Behavior and Interaction  To understand dynamic behaviors in graphics  To understand Java 3D Behavior and WakeupCondition classes  To apply

11/12/08

Using Keys for Interaction

KeyNavigationBehavior operates on a TransformGroup

Similar constructors to the mouse behavior

Page 19: 1 Chapter 10 Behavior and Interaction  To understand dynamic behaviors in graphics  To understand Java 3D Behavior and WakeupCondition classes  To apply

19Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved.

KeyNavigatorBehavior

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

Page 20: 1 Chapter 10 Behavior and Interaction  To understand dynamic behaviors in graphics  To understand Java 3D Behavior and WakeupCondition classes  To apply

20Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved.

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)

Page 21: 1 Chapter 10 Behavior and Interaction  To understand dynamic behaviors in graphics  To understand Java 3D Behavior and WakeupCondition classes  To apply

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

Page 22: 1 Chapter 10 Behavior and Interaction  To understand dynamic behaviors in graphics  To understand Java 3D Behavior and WakeupCondition classes  To apply

22Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved.

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);

Page 23: 1 Chapter 10 Behavior and Interaction  To understand dynamic behaviors in graphics  To understand Java 3D Behavior and WakeupCondition classes  To apply

11/12/08

TestPickBehavior

Behaviors are applied to the BranchGroup containing the objects

Behaviors need reference to the canvas and the scheduling bounds

Page 24: 1 Chapter 10 Behavior and Interaction  To understand dynamic behaviors in graphics  To understand Java 3D Behavior and WakeupCondition classes  To apply

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

Page 25: 1 Chapter 10 Behavior and Interaction  To understand dynamic behaviors in graphics  To understand Java 3D Behavior and WakeupCondition classes  To apply

25Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved.

DataViewer.java

Page 26: 1 Chapter 10 Behavior and Interaction  To understand dynamic behaviors in graphics  To understand Java 3D Behavior and WakeupCondition classes  To apply

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 pointsPickIntersection inter = results[i].getIntersection(0);Point3d pt = inter.getClosestVertexCoordinates();int[] ind = inter.getPrimitiveCoordinateIndices();