© Prof. Dr. H. Gläser, Graphische Datenverarbeitung Benutzer Interaktion Benutzer Interaktion...

34
© Prof. Dr. H. Gläser, Graphische Datenverarbeitung enutzer Interaktion nutzer Interaktion (interaction): virtuelle Welt reagiert auf Benutzer Eingaben Animation virtuelle Welt verändert sich im Laufe der Zeit irekte Auswirkungen von Benutzer Eingaben llboard Verhalten) Stimulus Änderung bewirkt

Transcript of © Prof. Dr. H. Gläser, Graphische Datenverarbeitung Benutzer Interaktion Benutzer Interaktion...

Page 1: © Prof. Dr. H. Gläser, Graphische Datenverarbeitung Benutzer Interaktion Benutzer Interaktion (interaction): die virtuelle Welt reagiert auf Benutzer Eingaben.

© Prof. Dr. H. Gläser, Graphische Datenverarbeitung

Benutzer Interaktion

Benutzer Interaktion (interaction):

die virtuelle Welt reagiert auf Benutzer Eingaben

Animation

die virtuelle Welt verändert sich im Laufe der ZeitIndirekte Auswirkungen von Benutzer Eingaben (billboard Verhalten)

Stimulus Änderungbewirkt

Page 2: © Prof. Dr. H. Gläser, Graphische Datenverarbeitung Benutzer Interaktion Benutzer Interaktion (interaction): die virtuelle Welt reagiert auf Benutzer Eingaben.

© Prof. Dr. H. Gläser, Graphische Datenverarbeitung

Benutzer Interaktion

Module2: Interaction and Animation Chapter 4. Interaction

The Java 3D Tutorial 4-2

4.1.1 Applications of BehaviorSince a behavior is a link between a stimulus and an action, considering all the combinations of possiblestimuli and possible actions is to consider the many applications of Behavior objects. The following tablesurveys the realm of possibilities with Behavior, listing possible stimuli down the left column and possiblechanges across the top.

The table does not list all possible applications of Behavior, only the simple ones (one stimulus results inone change). Some combinations of stimulus and change only make sense in a specific setting; these arelisted as 'application specific'. Furthermore, combinations of stimuli and combinations of actions arepossible.

Table 4-1 Applications of Behavior Categorized by Stimulus and Object of Change

object of change

stimulus(reason for

change)

TransformGroup(visual objects changeorientation or location)

Geometry(visual objects change

shape or color)

Scene Graph(adding, removing, or

switching objects)

View(change viewing

location or direction)

user interaction application specific application specific navigation

collisionsvisual objects

change orientationor location

visual objectschange appearance

in collision

visual objectsdisappear in

collision

View changes withcollision

time animation animation animation animation

View location billboard level of detail(LOD)

application specific application specific

In Table 4-1 some of the possible behaviors are spelled out. For example, collision actions are described.Others, such as billboard or level of detail (LOD) behaviors, may not be familiar to you. Below are somequick explanations.

The chart does not include all applications of Behavior; combinations of stimuli and/or changes are notshown. Picking is also implemented using behaviors but is not listed in the table. Although listed in Table4-1 and implemented in Java 3D API, collision detection is not addressed in this tutorial.

Natural things, such as trees, take a tremendous amount of geometry to accurately represent all of thebranches, leaves and bark structure. One alternative is to use a textured polygon instead of the geometry.This technique is sometime referred to as the billboard approach. This is especially true when a behavior isused to automatically orient the textured polygon orthogonal to the viewer such that only the front texturedface is viewed. This orienting behavior is called billboard behavior.

The billboard approach is effective when the object to be represented by the texture is distant so that theindividual parts of the visual object represented by the texture would not easily be distinguished. For thetree example, if the viewer is so distant that branches are hardly distinguishable, it is hardly worth thememory and computation requirements to represent each leaf of the tree. This technique is recommendedfor any application requiring visually complex objects in a distance. However, if the viewer were able to

Nicht im Tutorial:Feststellen von Kollisionen

Page 3: © Prof. Dr. H. Gläser, Graphische Datenverarbeitung Benutzer Interaktion Benutzer Interaktion (interaction): die virtuelle Welt reagiert auf Benutzer Eingaben.

© Prof. Dr. H. Gläser, Graphische Datenverarbeitung

Benutzer Interaktion

(billboard = Reklametafel)sehr detaillierte Geometrien werden zu Texturen vereinfacht.Behavior sorgt dafür, daß die Tafel unabhängig vom Sichtwinkelimmer senkrecht zum Beobachter steht

Reklametafel Verhalten

LOD Verhalten

Je näher der Betrachter den Dingen kommt, desto detailliertevisual object Geometrien werden verwendet. Behavior schaltet automatischzwischen den unterschiedlichen Detaillierungsgraden (level ofdetail - LOD) um

Page 4: © Prof. Dr. H. Gläser, Graphische Datenverarbeitung Benutzer Interaktion Benutzer Interaktion (interaction): die virtuelle Welt reagiert auf Benutzer Eingaben.

© Prof. Dr. H. Gläser, Graphische Datenverarbeitung

Benutzer InteraktionModule2: Interaction and Animation Chapter 4. Interaction

The Java 3D Tutorial 4-4

Behavior

Billboard

Interpolator

LOD

DistanceLOD

ColorInterpolator

RotPosPathScaleInterpolator

MouseBehavior

MouseRotate

MouseZoom

MouseTranslate

KeyNavigatorBehavior

PickRotateBehavior

PickZoomBehavior

PickTranslateBehaviorPickMouseBehavior

Figure 4-1 Hierarchy of Subclasses of Behavior

4.2.1 Writing a Behavior ClassThis section explains how to write a custom behavior class. You know from Section 4.1 that there arebehavior classes you can use without writing a class. However, in seeing how to create a Behavior classyou learn how behaviors work. So even if you only plan to use a behavior class, you might want to readthis section. Also, the class written in this section is used in the next section. (If you don't plan to write aBehavior class you can skip this section for now.)

Mechanics of BehaviorsA custom behavior class implements the initialization and processStimulus methods from the abstractBehavior class. Of course, the custom behavior class also has at least one constructor and may have othermethods as well.

Most behaviors will act on a scene graph object to affect the behavior. In Table 4-1, the object a behavioracts upon is refered to as the object of change. It is through this object, or objects, that the behavioraffects the virtual world. While it is possible to have a behavior that does not have an object of change,most do.

The behavior needs a reference to its object(s) of change to be able to make the behavioral changes. Theconstructor can be used to set the reference to the object of change. If it does not, another method in thecustom behavior class must store this information. In either case, the reference is made at the time thescene graph is being constructed, which is the first computation of the behavior.

Die Klasse Behavior

Interaktion

Animation

Page 5: © Prof. Dr. H. Gläser, Graphische Datenverarbeitung Benutzer Interaktion Benutzer Interaktion (interaction): die virtuelle Welt reagiert auf Benutzer Eingaben.

© Prof. Dr. H. Gläser, Graphische Datenverarbeitung

Benutzer Interaktion

-> drei Methoden implementieren:initializeprocessStimulusKonstruktor

Verhaltensklassen selbst programmieren

behavior ist abstrakte Klasse

- stellt Referenz zum „object of change“ her

- aufgerufen wenn „live“- Anfangstrigger Ereignis(WakeupCondition Objekt)spezifizieren Methode: wakeupOn(<WakeupCondition Objekt> )

- aufgerufen wenn Trigger Ereignis, - Ereignis „entschlüsseln“,- „object of change“ ändern- Trigger erneut setzen !!

Page 6: © Prof. Dr. H. Gläser, Graphische Datenverarbeitung Benutzer Interaktion Benutzer Interaktion (interaction): die virtuelle Welt reagiert auf Benutzer Eingaben.

© Prof. Dr. H. Gläser, Graphische Datenverarbeitung

Benutzer Interaktion

import java.awt.event.*; import java.util.Enumeration;

class SimpleBehavior extends Behavior{

private TransformGroup targetTG; private Transform3D rotation = new Transform3D(); private double angle = 0.0;

SimpleBehavior(TransformGroup targetTG){ this.targetTG = targetTG; }

void initialize(){ this.wakeupOn(new WakeupOnAWTEvent(KeyEvent.KEY_PRESSED)); } void processStimulus(Enumeration criteria){ angle = angle + 0.1; rotation.rotY(angle); targetTG.setTransform(rotation); this.wakeupOn(new WakeupOnAWTEvent(KeyEvent.KEY_PRESSED)); }

}

Page 7: © Prof. Dr. H. Gläser, Graphische Datenverarbeitung Benutzer Interaktion Benutzer Interaktion (interaction): die virtuelle Welt reagiert auf Benutzer Eingaben.

© Prof. Dr. H. Gläser, Graphische Datenverarbeitung

Benutzer Interaktion

Ausführungsbegrenzung (execution culling)

Nur wenn sich activation volume der ViewPlatform undscheduling bonds des Behavior schneiden, wird das Verhaltenausgeführt

Einfügen des Verhaltens Objekts in den Szene Graphen

vrgl. folgendes Programmfragment

Page 8: © Prof. Dr. H. Gläser, Graphische Datenverarbeitung Benutzer Interaktion Benutzer Interaktion (interaction): die virtuelle Welt reagiert auf Benutzer Eingaben.

© Prof. Dr. H. Gläser, Graphische Datenverarbeitung

Benutzer Interaktion

BranchGroup createSceneGraph() { BranchGroup objRoot = new BranchGroup();

TransformGroup objRotate = new TransformGroup(); objRotate.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); objRoot.addChild(objRotate); objRotate.addChild(new ColorCube(0.4));

SimpleBehavior myRotationBehavior = new SimpleBehavior(objRotate); myRotationBehavior.setSchedulingBounds(new BoundingSphere()); objRoot.addChild(myRotationBehavior);

objRoot.compile();

return objRoot; }

objRotate Objekt wird erst im Behavior eine rotierende TransformGroup !

Page 9: © Prof. Dr. H. Gläser, Graphische Datenverarbeitung Benutzer Interaktion Benutzer Interaktion (interaction): die virtuelle Welt reagiert auf Benutzer Eingaben.

© Prof. Dr. H. Gläser, Graphische Datenverarbeitung

Benutzer Interaktion

Module2: Interaction and Animation Chapter 4. Interaction

The Java 3D Tutorial 4-8

1. prepare the scene graph (by adding a TransformGroup or other necessary objects)2. insert behavior object in the scene graph, referencing the object of change3. specify a scheduling bounds (or SchedulingBoundingLeaf)4. set write (and read) capabilities for the target object (as appropriate)

Figure 4-3 Recipe for Using a Behavior Class

The following code fragment, Code Fragment 4-2, is annotated with the step numbers from the recipe.This code fragment is an except from the SimpleBehaviorApp example program found in theexamples/Interaction directory. In this same application the SimpleBehavior class, found in CodeFragment 4-2, is defined. Code Fragment 4-2 continues where Code Fragment 4-1 ended and the linenumbers are sequential for the two code fragments.

37. public BranchGroup createSceneGraph() {38. // Create the root of the branch graph39. BranchGroup objRoot = new BranchGroup();40.41. TransformGroup objRotate = new TransformGroup();42. objRotate.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);43. Œ44. objRoot.addChild(objRotate);45. objRotate.addChild(new ColorCube(0.4));46.47. SimpleBehavior myRotationBehavior = new SimpleBehavior(objRotate);48. Ž myRotationBehavior.setSchedulingBounds(new BoundingSphere());49. objRoot.addChild(myRotationBehavior);50.51. // Let Java 3D perform optimizations on this scene graph.52. objRoot.compile();53.54. return objRoot;55. } // end of CreateSceneGraph method of SimpleBehaviorApp

Code Fragment 4-2 CreateSceneGraph Method in SimpleBehaviorApp.java

Very little code is needed to complete the program started in Code Fragment 4-1 and 4-2. The completeprogram, SimpleBehaviorApp, is found in the examples/Interaction directory. Thecomplete application renders a ColorCube object in a static scene until a keyboard key is pressed. Inresponse to any key press, the ColorCube rotates 0.1 radians (about 6 ). Figure 4-4 shows the scene graphdiagram for the content branch graph of this application.

BG

TGB

ColorCube

objRoot

objRotate

myRotationBehavior

Figure 4-4 Scene Graph Diagram of the Content Branch Graph Created in SimpleBehaviorApp.java.Welches Problem könnte mit dieser „Aufhängung“ desBehavior Objekts auftreten, wenn nicht rotiert sonderntranslatiert wird ?

Page 10: © Prof. Dr. H. Gläser, Graphische Datenverarbeitung Benutzer Interaktion Benutzer Interaktion (interaction): die virtuelle Welt reagiert auf Benutzer Eingaben.

© Prof. Dr. H. Gläser, Graphische Datenverarbeitung

Benutzer Interaktion

Bounds Objekt des Behavior Objektsscheduling Bereich

activation volume der ViewPlatform

Solange sich activation volume und scheduling Bereich schneiden,ist das Verhalten aktiv

Page 11: © Prof. Dr. H. Gläser, Graphische Datenverarbeitung Benutzer Interaktion Benutzer Interaktion (interaction): die virtuelle Welt reagiert auf Benutzer Eingaben.

© Prof. Dr. H. Gläser, Graphische Datenverarbeitung

Benutzer Interaktion

Bounds Objekt des Behavior Objektsscheduling Bereich

activation volume der ViewPlatform

Würfel wird immer noch bewegt, selbst wenn er gar nicht mehr gesehen wird

Page 12: © Prof. Dr. H. Gläser, Graphische Datenverarbeitung Benutzer Interaktion Benutzer Interaktion (interaction): die virtuelle Welt reagiert auf Benutzer Eingaben.

© Prof. Dr. H. Gläser, Graphische Datenverarbeitung

Benutzer Interaktion

Bounds Objekt des Behavior Objektsscheduling Bereich

activation volume der ViewPlatform

Würfel kann nicht mehr bewegt werden, obwohl der Benutzer ihnsehen kann

Page 13: © Prof. Dr. H. Gläser, Graphische Datenverarbeitung Benutzer Interaktion Benutzer Interaktion (interaction): die virtuelle Welt reagiert auf Benutzer Eingaben.

© Prof. Dr. H. Gläser, Graphische Datenverarbeitung

Benutzer Interaktion

1. Lösung:

Module2: Interaction and Animation Chapter 4. Interaction

The Java 3D Tutorial 4-10

solution uses a BoundingLeaf object for the scheduling bounds. Consult Section 3.7 or the Java 3D APISpecification for information on the BoundingLeaf class.

BG

TG B

ColorCube

objRoot

objRotatemyRotationBehavior

Figure 4-5 An Alternative Scene Graph Placement for the Behavior Object in SimpleBehaviorApp.

Behavior Class Design Recommendations

The mechanics of writing a custom behavior are simple. However, you should be aware that a poorlywritten behavior can degrade rendering performance3. While there are other considerations in writing abehavior, two things to avoid are: memory burn and unnecessary trigger conditions.

'Memory burn' is the term for unnecessarily creating objects in Java. Excessive memory burn will causegarbage collections. Occasional pauses in rendering is typical of memory burn since during the garbagecollection, the rendering will stop45.

Behavior class methods are often responsible for creating memory burn problems. For example, in CodeFragment 4-1 the processStimulus uses a 'new' in the invocation of wakeupOn (line 24). This causes anew object to be created each time the method is invoked. That object becomes garbage each time thebehavior is triggered.

Potential memory burn problems are normally easy to identify and avoid. Look for any use of 'new' in thecode to find the source of memory burn problems. Whenever possible, replace the use of the new with codethat reuses an object.

Later, in Section 4.3,the classes and methods used in setting the trigger conditions for a behavior object arediscussed. In that section, you will see it is possible to set a trigger condition that will wake a behaviorevery frame of the rendering. If there is nothing for the behavior to do, this is an unnecessary waste ofprocessor power invoking the behavior's processStimulus method. Not to say that there isn't a good reasonto trigger a behavior on every frame, just make sure you have the reason.

4.2.3 Behavior Class APIThis section presents the detail of the Behavior class API. Figure 4-6 shows the Java 3D API classhierarchy including the Behavior class. As an abstract class, Behavior must be extended before a behavior

3 The amount of performance degradation depends heavily on the execution environment. If you plan to distributeyour applications, consider users with software rendering environments.4 How often and how regular the pause depends on the execution environment.5 You can diagnose a memory burn problem by invoking the Java virtual machine with the - verbose:gc commandline option. If memory burn is the cause for rendering pauses, then the garbage collection report produced to theconsole will coinside with the pauses.

2. Lösung: Einsatz von BoundingLeaf

void setSchedulingBoundingLeaf(BoundingLeaf bl)

Page 14: © Prof. Dr. H. Gläser, Graphische Datenverarbeitung Benutzer Interaktion Benutzer Interaktion (interaction): die virtuelle Welt reagiert auf Benutzer Eingaben.

© Prof. Dr. H. Gläser, Graphische Datenverarbeitung

Benutzer Interaktion

Performanz Fallen

„Memory Burn“:Unnötiges Erzeugen von Objekten.Bsp.: in processStimulus die Verwendung von new.Garbage Collector vernichtet alte Objekte -> Zeichnen wirdunterbrochenObjekte nach Möglichkeit wiederverwenden.

Unnötige Trigger AufrufeEs gibt eine Methode, die den Trigger bei jedem Neuzeichnendes Bilds (rendering) aufruft. Dies ist oft nicht nötig.

Page 15: © Prof. Dr. H. Gläser, Graphische Datenverarbeitung Benutzer Interaktion Benutzer Interaktion (interaction): die virtuelle Welt reagiert auf Benutzer Eingaben.

© Prof. Dr. H. Gläser, Graphische Datenverarbeitung

Benutzer Interaktion

Weitere Methoden von Behavior

void postId(int postId) WakeupOnBehaviorPost

Verkettet Behavior

void setEnable(boolean state) Möglichkeit Behavior aufinaktiv zu setzen, auch wenn eseigentlich aktiv ist

View getView() Es kann viele View Objekte geben, diedas Verhalten aktivieren. Aber esgibt einen primary View (der erste,der mit einer live Platform verknüpftwird). An diesem richtet sich das Verhalten(z.B. billboard) aus.getView liefert den primary View

Page 16: © Prof. Dr. H. Gläser, Graphische Datenverarbeitung Benutzer Interaktion Benutzer Interaktion (interaction): die virtuelle Welt reagiert auf Benutzer Eingaben.

© Prof. Dr. H. Gläser, Graphische Datenverarbeitung

Benutzer Interaktion

Aufwach Bedingungen

Module2: Interaction and Animation Chapter 4. Interaction

The Java 3D Tutorial 4-13

allow the composition of multiple wakeup conditions in a single wakeup condition. Figure 4-7 shows theclass hierarchy for these classes.

java.lang.Object

javax.media.j3d.WakeupCondition

WakeupOr

WakeupAnd

WakeupAndOfOrs

WakeupOrOfAnds

WakeupCriterion

WakeupOnActivationWakeupOnAWTEventWakeupOnBehaviorPostWakeupOnCollisionEntryWakeupOnCollisionExitWakeupOnCollisionMovementWakeupOnDeactivationWakeupOnElapsedFramesWakeupOnElapsedTimeWakeupOnSensorEntryWakeupOnSensorExitWakeupOnTransformChangeWakeupOnViewPlatformEntryWakeupOnViewPlatformExit

Figure 4-7 The Java 3D API Class Hierarchy for WakeupCondition and Related Classes.

A behavior object's wakeup condition can be specified as one of the specific wakeup criterion or as acombination of criteria using the wakeup composition classes. The following sections describeWakeupCondition and its descendant classes.

4.3.1 WakeupConditionThe WakeupCondition class provides two methods. The first method, allElements, returns the enumerationlist of all wakeup criterion for the WakeupCondition object. The other method, triggeredElements,enumerates which of the wakeup criterion has caused the behavior to be triggered. This method may beuseful in the processStimulus method of a Behavior object.

WakeupCondition Method Summary

The WakeupCondition abstract class is the base for all wakeup classes. It provides the following two methods.

Enumeration allElements()Returns an enumeration of all WakeupCriterion objects in this Condition.

Enumeration triggeredElements()Returns an enumeration of all triggered WakeupCriterion objects in this Condition.

4.3.2 WakeupCriterion

WakeupCriterion is an abstract method for the 14 specific wakeup criterion classes. WakeupConditionprovides only one method: hasTriggered. You probably don't need to use this method as thetriggeredElements method of WakeupCondition performs this operation for you.

Page 17: © Prof. Dr. H. Gläser, Graphische Datenverarbeitung Benutzer Interaktion Benutzer Interaktion (interaction): die virtuelle Welt reagiert auf Benutzer Eingaben.

© Prof. Dr. H. Gläser, Graphische Datenverarbeitung

Benutzer Interaktion

Triggermechanismus eines Verhaltens

Behavior Objekt

WakeupCondition Objekt:

WakeupOnAWTEvent

processStimulus Methode wird ausgelöst

KeyEvent.KEY_PRESSED

„Trigger“

„Trigger“

Page 18: © Prof. Dr. H. Gläser, Graphische Datenverarbeitung Benutzer Interaktion Benutzer Interaktion (interaction): die virtuelle Welt reagiert auf Benutzer Eingaben.

© Prof. Dr. H. Gläser, Graphische Datenverarbeitung

Benutzer Interaktion

Triggermechanismus zwischen verschiedenen Verhalten(Wache auf bei „Post“ vom Behavior)

WakeupCondition Objekt:

WakeupOnBehaviorPost

postID(1)

Behavior Objekt B

Behavior Objekt A

processStimulus Methode wird ausgelöst

„Trigger“

Page 19: © Prof. Dr. H. Gläser, Graphische Datenverarbeitung Benutzer Interaktion Benutzer Interaktion (interaction): die virtuelle Welt reagiert auf Benutzer Eingaben.

© Prof. Dr. H. Gläser, Graphische Datenverarbeitung

Benutzer Interaktion

Beispiel

Tastendruck: -> Tür öffnet sichErneueter Tastendruck: -> Tür schließt sich

Page 20: © Prof. Dr. H. Gläser, Graphische Datenverarbeitung Benutzer Interaktion Benutzer Interaktion (interaction): die virtuelle Welt reagiert auf Benutzer Eingaben.

© Prof. Dr. H. Gläser, Graphische Datenverarbeitung

Benutzer Interaktion

class OpenBehavior extends Behavior{ private TransformGroup targetTG; private WakeupCriterion pairPostCondition; private WakeupCriterion AWTEventCondition; OpenBehavior(TransformGroup targetTG){ this.targetTG = targetTG; AWTEventCondition = new WakeupOnAWTEvent(KeyEvent.KEY_PRESSED); } public void setBehaviorObjectPartner(Behavior behaviorObject){ pairPostCondition = new WakeupOnBehaviorPost(behaviorObject, 1); } public void initialize(){ this.wakeupOn(AWTEventCondition); } public void processStimulus(Enumeration criteria){ if (AWTEventCondition.hasTriggered()){ // make door open -- code excluded this.wakeupOn(pairPostCondition); postId(1); } else { this.wakeupOn(AWTEventCondition); } } }

Dekodieren:Wer hat getriggert:Taste oder anderes Behavior

Triggern des anderenBehavior

CloseBehavior hat analogenCode (auch mit postID = 1 !)

Page 21: © Prof. Dr. H. Gläser, Graphische Datenverarbeitung Benutzer Interaktion Benutzer Interaktion (interaction): die virtuelle Welt reagiert auf Benutzer Eingaben.

© Prof. Dr. H. Gläser, Graphische Datenverarbeitung

Benutzer Interaktion

TransformGroup doorTG = new TransformGroup(); OpenBehavior openObject = new OpenBehavior(doorTG); CloseBehavior closeObject = new CloseBehavior(doorTG);

openObject.setBehaviorObjectPartner(closeObject); closeObject.setBehaviorObjectPartner(openObject);

// Setze scheduling bounds für behavior Objekte -- code excluded

Innerhalb einer Methode, die den Szene Graph zusammenbaut:

Page 22: © Prof. Dr. H. Gläser, Graphische Datenverarbeitung Benutzer Interaktion Benutzer Interaktion (interaction): die virtuelle Welt reagiert auf Benutzer Eingaben.

© Prof. Dr. H. Gläser, Graphische Datenverarbeitung

Benutzer Interaktion

Kollisionsdetektion

- weites Thema

WakeupOnCollisionEntry

WakeupOnCollisionMovement

WakeupOnCollisionExit

Wenn 2 Objekte kollidieren

Wenn 2 Objekte sich während der Kollision bewegenWenn 2 Objekte die Kollision beenden

- Kollision kann so schnell sein, dass kein Trigger ausgelöst wird

- Für ein Objekt kann zu einer Zeit nur eine Kollision behandelt werden

WakeupOnCollision*( BoundsNodeScreneGraphPath

[, int]USE_BOUNDSUSE_GEOMETRY

)

[, int]

Page 23: © Prof. Dr. H. Gläser, Graphische Datenverarbeitung Benutzer Interaktion Benutzer Interaktion (interaction): die virtuelle Welt reagiert auf Benutzer Eingaben.

© Prof. Dr. H. Gläser, Graphische Datenverarbeitung

Benutzer Interaktion

Weiteres Aufwachen

WakeupOnDeactivation()

WakeupOnElapsedFrames(int frameCount)

WakeupOnElapsedTime(long milliseconds)

activation volume und scheduling boundsohne Schnitt

WakeupOnSensorEntry / Exit(Bounds ...) Sensor ist ein beliebigesEingabegerät außer Tastatur und Maus

WakeupOnTransformChange(TransformGroup ...) Hier kann auch Verhaltenmit einem Utility Verhaltenkoordiniert werden

WakeupOnViewPlatformEntry / Exit(Bounds ...)

Page 24: © Prof. Dr. H. Gläser, Graphische Datenverarbeitung Benutzer Interaktion Benutzer Interaktion (interaction): die virtuelle Welt reagiert auf Benutzer Eingaben.

© Prof. Dr. H. Gläser, Graphische Datenverarbeitung

Benutzer Interaktion

Kombination von Aufwachbedingungen

Module2: Interaction and Animation Chapter 4. Interaction

The Java 3D Tutorial 4-13

allow the composition of multiple wakeup conditions in a single wakeup condition. Figure 4-7 shows theclass hierarchy for these classes.

java.lang.Object

javax.media.j3d.WakeupCondition

WakeupOr

WakeupAnd

WakeupAndOfOrs

WakeupOrOfAnds

WakeupCriterion

WakeupOnActivationWakeupOnAWTEventWakeupOnBehaviorPostWakeupOnCollisionEntryWakeupOnCollisionExitWakeupOnCollisionMovementWakeupOnDeactivationWakeupOnElapsedFramesWakeupOnElapsedTimeWakeupOnSensorEntryWakeupOnSensorExitWakeupOnTransformChangeWakeupOnViewPlatformEntryWakeupOnViewPlatformExit

Figure 4-7 The Java 3D API Class Hierarchy for WakeupCondition and Related Classes.

A behavior object's wakeup condition can be specified as one of the specific wakeup criterion or as acombination of criteria using the wakeup composition classes. The following sections describeWakeupCondition and its descendant classes.

4.3.1 WakeupConditionThe WakeupCondition class provides two methods. The first method, allElements, returns the enumerationlist of all wakeup criterion for the WakeupCondition object. The other method, triggeredElements,enumerates which of the wakeup criterion has caused the behavior to be triggered. This method may beuseful in the processStimulus method of a Behavior object.

WakeupCondition Method Summary

The WakeupCondition abstract class is the base for all wakeup classes. It provides the following two methods.

Enumeration allElements()Returns an enumeration of all WakeupCriterion objects in this Condition.

Enumeration triggeredElements()Returns an enumeration of all triggered WakeupCriterion objects in this Condition.

4.3.2 WakeupCriterion

WakeupCriterion is an abstract method for the 14 specific wakeup criterion classes. WakeupConditionprovides only one method: hasTriggered. You probably don't need to use this method as thetriggeredElements method of WakeupCondition performs this operation for you.

WakeupOn*

Page 25: © Prof. Dr. H. Gläser, Graphische Datenverarbeitung Benutzer Interaktion Benutzer Interaktion (interaction): die virtuelle Welt reagiert auf Benutzer Eingaben.

© Prof. Dr. H. Gläser, Graphische Datenverarbeitung

Benutzer Interaktion

Module2: Interaction and Animation Chapter 4. Interaction

The Java 3D Tutorial 4-26

BG

TG ViewPlatform Transform

View Platform

View Canvas3D Screen3D

Physical Body Physical Environment

contentbranch graph

Figure 4-8 The Basic View Branch Graph Showing the View Platform Transform

How to Navigate in a SimpleUniverseYou might be thinking that needing access to the view platform transform group object means abandoningthe SimpleUniverse utility. However, the SimpleUniverse, and related classes, provide a combination ofmethod to retrieve the ViewPlatformTransform object. Therefore, you can have your SimpleUniverse andnavigate in it too!

Specifically, the following line of code retrieves the ViewPlatformTransform from a SimpleUniverse object,su.

TransformGroup vpt = su.getViewingPlatform().getViewPlatformTransform();

4.4.1 Simple KeyNavigatorBehavior Example ProgramIt is easy to use the KeyNavigatorBehavior utility class in a Java 3D program. This section demonstratesusing the class in the KeyNavigatorApp example program found in the examples/Interactionsubdirectory. In this program you can see that the steps involved in using the KeyNavigatorBehavior classare essentially identical to those of using any behavior class (as discussed in section 4.2.2 on page 4-7).The steps for using KeyNavigatorBehavior are summarized in Figure 4-9.

1. create a KeyNavigatorBehavior object, setting the transform group 2. add the KeyNavigatorBehavior object to the scene graph 3. provide a bounds (or BoundingLeaf) for the KeyNavigatorBehavior objectFigure 4-9Recipe for Using the KeyNavigatorBehavior Utility Class

Der Beobachter wird durch die Virtuelle Welt bewegt

Behavior

Bewegen der View Platform

Wie kommt manbeim SimpleUniversean die Transform Groupder View Platform ?

Frage:

Page 26: © Prof. Dr. H. Gläser, Graphische Datenverarbeitung Benutzer Interaktion Benutzer Interaktion (interaction): die virtuelle Welt reagiert auf Benutzer Eingaben.

© Prof. Dr. H. Gläser, Graphische Datenverarbeitung

Benutzer Interaktion

Bewegen der View Platform

ViewingPlatform vp = su.getViewingPlatform;TransformGroup vpt = vp.getViewPlatformTransform();

Mit dieser TransformGroup kann der Beobachter rotiert undverschoben werden

su ist ein SimpleUniverse Objekt

Page 27: © Prof. Dr. H. Gläser, Graphische Datenverarbeitung Benutzer Interaktion Benutzer Interaktion (interaction): die virtuelle Welt reagiert auf Benutzer Eingaben.

© Prof. Dr. H. Gläser, Graphische Datenverarbeitung

Benutzer Interaktion

AWTEventTastendruck

Verhaltens Utility Klassen für die Tastatur Navigation

processStimulus(...)

abstrakte KlasseBehavior

implementiert

KeyNavigatorBehavior

KeyNavigator

bedient sich

Konstruktur nimmt (nur) TransformGroup entgegen

(wird vom Programmierernicht beeinflußt)

wertet aus

Page 28: © Prof. Dr. H. Gläser, Graphische Datenverarbeitung Benutzer Interaktion Benutzer Interaktion (interaction): die virtuelle Welt reagiert auf Benutzer Eingaben.

© Prof. Dr. H. Gläser, Graphische Datenverarbeitung

Benutzer Interaktion

Verhalten des KeyNavigatorBehavior

Module2: Interaction and Animation Chapter 4. Interaction

The Java 3D Tutorial 4-28

26. public KeyNavigatorApp() {27. setLayout(new BorderLayout());28. Canvas3D canvas3D = new Canvas3D(null);29. add("Center", canvas3D);30.31. // SimpleUniverse is a Convenience Utility class32. SimpleUniverse simpleU = new SimpleUniverse(canvas3D);33.34. BranchGroup scene = createSceneGraph(simpleU);35.36. simpleU.addBranchGraph(scene);37. } // end of KeyNavigatorApp (constructor)

Code Fragment 4-6 Using the KeyNavigatorBehavior Class (part 2)

How to make Universal Application of a BehaviorAs with any behavior object, the KeyNavigtorBehavior object is only active when its scheduling boundsintersects the activation volume of a ViewPlatform. This can be particularly limiting for a navigationbehavior, where the behavior should always be on. Chapter 3 discusses a solution to this problem using aBoundingLeaf. Refer to the BoundingLeaf section of Chapter 3 for more information.

4.4.2 KeyNavigatorBehavior and KeyNavigator ClassesThe keyboard navigation utility is implemented as two classes. At run time there are two objects. The firstobject is the KeyNavigatorBehavior object, the second is a KeyNavigator object. The second class is notdocumented here since neither the programmer nor the user need to know that the second class or objectexists.

The KeyNavigatorBehavior object performs all the typical functions of a behavior class, except that it callson the KeyNavigator object to perform the processStimulus function. The KeyNavigator class takes theAWTEvent and processes it down to the individual key stroke level. Table 4-3 shows the effect of theindividual key strokes. KeyNavigator implements motion with acceleration.

Table 4-3 KeyNavigatorBehavior Movements

Key movement Alt-key movement

ß rotate left lateral translate left

à rotate right lateral translate right

á move forward

â move backward

PgUp rotate up translation up

PgDn rotate down translation down

+ restore back clip distance(and return to the origin)

- reduce back clip distance

= return to center of universe

Page 29: © Prof. Dr. H. Gläser, Graphische Datenverarbeitung Benutzer Interaktion Benutzer Interaktion (interaction): die virtuelle Welt reagiert auf Benutzer Eingaben.

© Prof. Dr. H. Gläser, Graphische Datenverarbeitung

Benutzer Interaktion

Verhaltens Utility Klassen für die Maus Navigation

abstrakte Klasse MouseBehavior

MouseRotate MouseTranslate MouseZoom

implementieren

zu benutzensetTransformGroup(TransformGroup ...)

MouseBehaviorCallback Interface

zu implementieren:transformChanged(int type, Transform3D ...)

BenutzerMouseBehaviorKlassedie transformChanged Methode dieser Klasse wird aufgerufen,

wenn die MouseTranslate Klassen aktiviert werden

type = MOUSE_ROTATE,...

setupCallback(MouseBehaviorCallback ...)

Page 30: © Prof. Dr. H. Gläser, Graphische Datenverarbeitung Benutzer Interaktion Benutzer Interaktion (interaction): die virtuelle Welt reagiert auf Benutzer Eingaben.

© Prof. Dr. H. Gläser, Graphische Datenverarbeitung

Benutzer Interaktion

Customizing der Maus Navigation

Möglichkeit A: Implementieren einer eigenen MouseBehavior Klasse(Extension von MouseBehavior)

Möglichkeit B: Ableiten von MouseBehavior*, Überschreiben vontransformChanged

Möglichkeit C: Registrieren bei einer MouseBehavior* Klasse,implementieren vom Interface MouseBehaviorInterfaced.h. der Methode transformChanged

Page 31: © Prof. Dr. H. Gläser, Graphische Datenverarbeitung Benutzer Interaktion Benutzer Interaktion (interaction): die virtuelle Welt reagiert auf Benutzer Eingaben.

© Prof. Dr. H. Gläser, Graphische Datenverarbeitung

Benutzer Interaktion

„Anklicken“ oder PickingModule2: Interaction and Animation Chapter 4. Interaction

The Java 3D Tutorial 4-36

image plate

visualobject

mouse pointer pick ray

Figure 4-11 Projection of PickRay in the Virtual World

In some cases the interaction is not directly with the selected object, but with an object along the scenegraph path to the object. For example, in picking a ColorCube object for rotation, the ColorCube object isnot manipulated; the TransformGroup object above the ColorCube in the scene graph path to theColorCube is. On the other hand, if the pick operation selects a visual object for which a color change isintended, then the visual object selected is indeed required.

The determination of the object for further processing is not always easy. If a cubic visual object that is tobe rotated is composed of six individual Shape3D objects arranged by six TransformGroup objects, as inthe scene graph diagram of Figure 4-12, it is not the TransformGroup object above the intersectedShape3D object that needs to be modified. The 'cube' is rotated by manipulation of the TransformGroupobject that is the child of the BranchGroup object in the scene graph. For this reason, the result of somepicking operations is to return the scene graph path for further processing.

BG

S

TG

S

TG

S

TG

S

TG

S

TG

S

TG

TG

Figure 4-12 Scene Graph Diagram for a Cube Composed of Discrete Shape3D Plane Objects.

Intersection testing is computationally expensive. Therefore, picking is computationally expensive and ismore expensive with increasing complexity of the scene. The Java 3D API provides a number of ways thata programmer can limit the amount of computation done in picking. One important way is through thecapabilities and attributes of scene graph nodes. Whether or not a scene graph node is pickable is set withthe setPickable() method of the class. A node with setPickable() set to false is not

Das naheste Objekt wird selektiert (oder eine Liste mit geschnittenen Objekten wird geliefert)

Der scene graph des selektierten Objekts wird zurückgeliefert(um z.B. den Knoten auszusuchen ,der geändert werden soll, z.B.TransformGroup für Rotieren)

Page 32: © Prof. Dr. H. Gläser, Graphische Datenverarbeitung Benutzer Interaktion Benutzer Interaktion (interaction): die virtuelle Welt reagiert auf Benutzer Eingaben.

© Prof. Dr. H. Gläser, Graphische Datenverarbeitung

Benutzer Interaktion

Performanz Aspekte des Picking

Schnittpunktsberechnung ist aufwendig

Node Methode setPickable(boolean pickable)-wirkt auch auf alle Kinder

ENABLE_PICK_REPORTING capability eines Node Objekts:dieser Node wird im zurückgelieferten scene graph path aufjeden Fall aufgeführt. -Sonst nur, wenn er zur eindeutigen Identifizierung des pathbenötigt wird.

Im Konstruktor: USE_BOUNDS, oder USE_GEOMETRY

Page 33: © Prof. Dr. H. Gläser, Graphische Datenverarbeitung Benutzer Interaktion Benutzer Interaktion (interaction): die virtuelle Welt reagiert auf Benutzer Eingaben.

© Prof. Dr. H. Gläser, Graphische Datenverarbeitung

Benutzer Interaktion

Beschränkung des pick testing auf den Teil des scene graph, derin Frage kommt:in pick utility Klassen kann eine Wurzel eines Untergraphenangegeben werden, der nur untersucht wird. Er sollte möglichstausschließlich pickable Objekte enthalten.

PickRotateBehavior behavior = new PickRotateBehavior(root, canvas, bounds); root.addChild(behavior);

Pick Utility KlassenWo die Maus sich bewegt

Page 34: © Prof. Dr. H. Gläser, Graphische Datenverarbeitung Benutzer Interaktion Benutzer Interaktion (interaction): die virtuelle Welt reagiert auf Benutzer Eingaben.

© Prof. Dr. H. Gläser, Graphische Datenverarbeitung

Benutzer Interaktion

Bei picks geht‘s noch weiter: noch nicht gemacht: S.46 bis 58