Interaction

Interaction

Chi Chung Ko (National University of Singapore, Singapore) and Chang Dong Cheng (CCS Automation PTE LTD, Singapore)
Copyright: © 2009 |Pages: 29
DOI: 10.4018/978-1-59904-789-8.ch008
OnDemand PDF Download:
$37.50

Abstract

In Chapter VII, we discussed how animation can be applied in Java 3D to increase the visual impact of a virtual 3D world and illustrate the dynamic of the various 3D objects to the user (Tate, Moreland, & Bourne, 2001). In this chapter, we will continue this process to make the virtual 3D universe even more interesting and appealing by adding the ability for the user to interact with the 3D objects being rendered. In Java 3D, both animation and interaction can be accomplished through the use of the behavior class. Having discussed how this class helps to carry out animation in the last chapter, we will now concentrate on the mechanism of using behavior class to achieve interaction. Technically, the behavior class is an abstract class with mechanisms for the scene graph to be changed. Being an extension of the leaf class, it can also be a part of a normal scene. In particular, it may be a leaf node in the scene graph and can be placed in the same way as geometry is placed. For instance, in an application where it is necessary to render and control a rotating cube, the rotation behavior for the animation and interaction can be placed under the same transform group as the geometry object for rendering the cube. The main objective of adding a behavior object in a scene graph is of course to change the scene graph in response to a stimulus in the form of, say, pressing a key, moving a mouse, colliding objects, or a combination of these and other events. The change in the virtual 3D world may consist of translating or rotating objects, removing some objects, changing the attributes of others, or any other desirable outcomes in the specific application.
Chapter Preview
Top

Behavior Class

In Java 3D, all behavior must be based on extending the behavior base class. Specifically, to create an animation or interaction behavior, this base class must first be appropriately extended before it is added to the appropriate position in the scene graph for changing the associated visual objects.

The object that a behavior will act upon is called the object of change. It is through this object that the behavior will be able to change the virtual world. Specifically, the following shows the general code development procedure for creating a custom behavior class.

  • 1.

    Create the relevant constructors with references to the object of change. Any behavior created will need a reference to an object of change so that the system will know the 3D objects that will be affected by the behavior.

  • 2.

    Specify the initial wakeup criteria using the initialization() method. The system will invoke this method when the scene graph containing the behavior class becomes live. It sets the initial conditions or triggers under which the behavior should be executed.

  • 3.

    Decode the trigger condition using the processStimulus() method, and act upon this appropriately. In other words, we need to determine the condition or event, be it a key stroke, mouse click, mouse movement, or other relevant events, being activated and then carry out appropriate processing.

The processStimulus() method will be invoked during runtime by the system when the appropriate trigger conditions have occurred. Initially, the trigger conditions set in the initialization() method will be used. Subsequently, the trigger conditions may be changed in the processStimulus() method itself after it has been invoked.

Note that the calling of processStimulus() depends on the stimulus and many events may be encoded as a single trigger condition. For example, since different mouse actions such as clicking or moving are taken as a single WakeupOnAWTEvent, processStimulus() must carry out some appropriate decoding to find out the specific user input, say, right click or left click. After this, relevant changes to the object of change can be made, resulting in changes in the objects in the virtual 3D world.

With valid stimulus, the invocation of processStimulus() will be invoked by the system between the rendering of adjacent frames. Since the rendering of complicated 3D objects may be compute and system intensive, careful consideration must be taken to ensure that the processing will not result in a substantial reduction of the frame rate or animation speed.

The code fragment in Figure 1 gives an example where a custom behavior class is created for moving a cube upwards when a mouse button is clicked. The example includes the three basic steps outlined in the previous code development procedure.

Complete Chapter List

Search this Book:
Reset
Table of Contents
Preface
Chi Chung Ko
Chapter 1
Chi Chung Ko, Chang Dong Cheng
Web-based virtual reality is fast becoming an important application and technological tools in the next generation of games and simulation as well... Sample PDF
Virtual Reality and Java 3D
$37.50
Chapter 2
Java 3D Overview  (pages 18-31)
Chi Chung Ko, Chang Dong Cheng
In the last chapter, a brief introduction on the creation of 3D content through the use of Java 3D and other programming methodologies for virtual... Sample PDF
Java 3D Overview
$37.50
Chapter 3
Geometry Objects  (pages 32-74)
Chi Chung Ko, Chang Dong Cheng
To create 3D graphics, we have to build graphics or visual objects and position them appropriately in a virtual scene. In general, there are three... Sample PDF
Geometry Objects
$37.50
Chapter 4
Appearance Objects  (pages 75-96)
Chi Chung Ko, Chang Dong Cheng
In the last chapter, the creation of the skeletons or shapes of 3D objects has been discussed through the use of geometry objects in Java 3D. In... Sample PDF
Appearance Objects
$37.50
Chapter 5
Textures  (pages 97-113)
Chi Chung Ko, Chang Dong Cheng
Although extensive use of basic attributes such as color and material will be able to make an object realistic to the human user, it will be time... Sample PDF
Textures
$37.50
Chapter 6
Chi Chung Ko, Chang Dong Cheng
How the properties of virtual 3D objects can be specified and defined has been discussed in earlier chapters. However, how a certain virtual object... Sample PDF
Lighting, Fog, and Background
$37.50
Chapter 7
Animation Objects  (pages 132-158)
Chi Chung Ko, Chang Dong Cheng
We have discussed important Java 3D objects that are basically static in the last few chapters. Starting from this chapter, we will be looking at... Sample PDF
Animation Objects
$37.50
Chapter 8
Interaction  (pages 159-187)
Chi Chung Ko, Chang Dong Cheng
In Chapter VII, we discussed how animation can be applied in Java 3D to increase the visual impact of a virtual 3D world and illustrate the dynamic... Sample PDF
Interaction
$37.50
Chapter 9
Picking  (pages 188-216)
Chi Chung Ko, Chang Dong Cheng
The last two chapters have discussed how animation and interaction can be created in Java 3D to increase visual impact, to show object dynamics and... Sample PDF
Picking
$37.50
Chapter 10
Chi Chung Ko, Chang Dong Cheng
One of the most useful and important advantages of 3D graphics rendering and applications is that there is the possibility for the user to navigate... Sample PDF
Navigation, Input Devices, and Collision
$37.50
Chapter 11
Multiple Views  (pages 238-263)
Chi Chung Ko, Chang Dong Cheng
Our discussions in previous chapters have centered on the creation and interaction of visual objects in a virtual 3D world. The objects and scenes... Sample PDF
Multiple Views
$37.50
Chapter 12
Audio  (pages 264-275)
Chi Chung Ko, Chang Dong Cheng
Of all the human perceptions, two of the most important ones are perhaps vision and sound, for which we have developed highly specialized sensors... Sample PDF
Audio
$37.50
Chapter 13
Chi Chung Ko, Chang Dong Cheng
In this final chapter, we will describe the use of Java 3D as a visualization technology in the development of a Web-based 3D real time oscilloscope... Sample PDF
A Web-Based 3D Real Time Oscilloscope Experiment
$37.50
Appendix A: Downloading Software
Appendix B: Running the Rotating Cube Program
Appendix C: ViewManager
Appendix D: Main Applet for Web-Based 3D Experiment
Appendix E: Scene Graph Implementation for Web-Based 3D Experiment
Appendix F: Knob Class for Web-Based 3D Experiment
Appendix G: Navigation and Collision Detection for Web-Based 3D Experiment
Appendix H: Picking for Web-Based 3D Experiment
Appendix I: Program Summary and Screen Capture
About the Authors