Tutorial version 1.6 (Java 3D API v 1.2)
Getting Started with
the Java 3D™ API
Chapter 4
Interaction
BG
TG
View Platform
View Canvas3D Screen3D
Physical Body Physical Environment S
TG
S
TG
S
TG
S
TG
S
TG
S
TG
TG
BG
B
Dennis J BouvierModule2: Interaction and Animation Chapter 4. Interaction
The Java 3D Tutorial
© 2000-2001 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.
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.Module 2: Interaction and Animation Chapter 4. Interaction
The Java 3D Tutorial 4-i
Table of Contents
Chapter 4:
INTERACTION ......................................................................................................................................................4-1
4.1 BEHAVIOR: THE BASE FOR INTERACTION AND ANIMATION............................................................................4-1
4.1.1 Applications of Behavior......................................................................................................................4-2
4.1.2 Overview of Behavior Classes..............................................................................................................4-3
4.2 BEHAVIOR BASICS .........................................................................................................................................4-3
4.2.1 Writing a Behavior Class .....................................................................................................................4-4
4.2.2 Using a Behavior Class........................................................................................................................4-7
4.2.3 Behavior Class API............................................................................................................................4-10
4.3 WAKEUP CONDITIONS: HOW BEHAVIORS ARE TRIGGERED..........................................................................4-12
4.3.1 WakeupCondition...............................................................................................................................4-13
4.3.2 WakeupCriterion ................................................................................................................................4-13
4.3.3 Specific WakeupCriterion Classes .....................................................................................................4-14
4.3.4 WakeupCondition Composition..........................................................................................................4-24
4.4 BEHAVIOR UTILITY CLASSES FOR KEYBOARD NAVIGATION ........................................................................4-25
4.4.1 Simple KeyNavigatorBehavior Example Program.............................................................................4-26
4.4.2 KeyNavigatorBehavior and KeyNavigator Classes ...........................................................................4-28
4.5 UTILITY CLASSES FOR MOUSE INTERACTION...............................................................................................4-29
4.5.1 Using the Mouse Behavior Classes....................................................................................................4-29
4.5.2 Mouse Behavior Foundation..............................................................................................................4-31
4.5.3 Specific Mouse Behavior Classes.......................................................................................................4-32
4.5.4 Mouse Navigation ..............................................................................................................................4-35
4.6 PICKING .......................................................................................................................................................4-36
4.6.1 Using Picking Utility Classes.............................................................................................................4-38
4.6.2 Java 3D API Core Picking Classes....................................................................................................4-40
4.6.3 General Picking Package Classes......................................................................................................4-50
4.6.4 Specific Picking Behavior Classes .....................................................................................................4-53
4.7 CHAPTER SUMMARY....................................................................................................................................4-56
4.8 SELF TEST....................................................................................................................................................4-56Module2: Interaction and Animation Chapter 4. Interaction
The Java 3D Tutorial 4-ii
List of Figures
Figure 4-1 Hierarchy of Subclasses of Behavior ...................................................................................... 4-4
Figure 4-2 Recipe for Writing a Custom Behavior Class ......................................................................... 4-5
Figure 4-3 Recipe for Using a Behavior Class.......................................................................................... 4-8
Figure 4-4 Scene Graph Diagram of the Content Branch Graph Created in SimpleBehaviorApp.java... 4-8
Figure 4-5 An Alternative Scene Graph Placement for the Behavior Object in SimpleBehaviorApp... 4-10
Figure 4-6 API Class Hierarchy for Behavior......................................................................................... 4-11
Figure 4-7 The Java 3D API Class Hierarchy for WakeupCondition and Related Classes.................... 4-13
Figure 4-8 The Basic View Branch Graph Showing the View Platform Transform.............................. 4-26
Figure 4-9Recipe for Using the KeyNavigatorBehavior Utility Class ................................................... 4-27
Figure 4-10 Recipe for Using Mouse Behavior Classes ......................................................................... 4-30
Figure 4-11 Projection of PickRay in the Virtual World....................................................................... 4-36
Figure 4-12 Scene Graph Diagram for a Cube Composed of Discrete Shape3D Plane Objects. ........... 4-37
Figure 4-13 Recipe for Using Mouse Picking Utility Classes ................................................................ 4-39
Figure 4-14 PickShape Hierarchy ........................................................................................................... 4-41
Figure 4-15 Parameters of PickCone pick shapes................................................................................... 4-44
Figure 4-16 Parameters of PickCylinder pick shapes ............................................................................. 4-46
List of Tables
Table 4-1 Applications of Behavior Categorized by Stimulus and Object of Change ............................ 4-2
Table 4-2 The 14 Specific WakeupCriterion Classes ............................................................................. 4-14
Table 4-3 KeyNavigatorBehavior Movements ....................................................................................... 4-28
Table 4-4 Summary of Specific MouseBehavior Classes....................................................................... 4-29
Table 4-5 Selection of PickShape ........................................................................................................... 4-41
List of Code Fragments
Code Fragment 4-1 SimpleBehavior Class in SimpleBehaviorApp.java.................................................. 4-6
Code Fragment 4-2 CreateSceneGraph Method in SimpleBehaviorApp.java.......................................... 4-8
Code Fragment 4-3 Outline of OpenBehavior Class, an Example of Coordinated Behavior Classes.... 4-17
Code Fragment 4-4 Code using OpenBehavior and CloseBehavior, Coordinated Behavior Classes .... 4-17
Code Fragment 4-5 Using the KeyNavigatorBehavior Class (part 1) .................................................... 4-27
Code Fragment 4-6 Using the KeyNavigatorBehavior Class (part 2) .................................................... 4-28
Code Fragment 4-7 Using the MouseRotate Utility Class...................................................................... 4-30
Code Fragment 4-8 Using Mouse Behavior Classes for Interactive Navigation of th
đang được dịch, vui lòng đợi..