Actions and interactions
- 13.1 Spatial transforms
- 13.2 Object picking
- 13.3 Behaviors
- 13.4 Summary
System action and user interaction in a 3D application can take many forms. Actions
are automatic manipulations of an object or the view by the system, such as turning
an object in a preview or blinking the eyes on an avatar to make it seem more lifelike.
Actions are also called animations, where objects in the scene appear to move of their
own volition. With actions the user is a passive observer; there is no two-way dialogue
between the system and the user as in interaction. With interaction the user's involvement
is usually direct and explicit, such as in-scene mouseover feedback and object
dragging. Actions and interactions can occur in the 3D scene as well as outside of it,
in the 2D area surrounding the 3D display in the application's window frame. With
Java 3D the focus is on in-scene activities, which is the subject of this chapter. Associations
between Java 3D and out-of-scene interaction will be covered in chapter 14.
This chapter and the next roughly divide Java 3D actions and interactions into
spatial transformations, object picking, and behaviors. Spatial transformations are the
basis for all geometric manipulation of objects and views in the virtual world; object
picking identifies what the user is pointing to in the scene; and, behaviors, as embodied
by the Behavior class, are the basis for Java 3D event handling, especially collision
and change detection.
All of these capabilities play (or should play) major roles in UI work. Unfortunately,
picking and colliding in particular are rather poorly documented and loosely
defined in the API specification. This, together with the fact that source code is not
included with Java 3D means that a lot of the details about these areas can be obtained
only through a process of trial and error. Rather than ignore these important UI capabilities
or to only treat them lightly, I've chosen to dig into the details, so be warned.
Any details covered here about these subjects could easily change with future releases
of Java 3D.
13. 1 SPATIAL TRANSFORMS
Any time the system slides an object in the scene or rotates one, either as a result of a
programmed action or a user interaction, a TransformGroup group node is likely to
be involved. This node, together with its associate, the Transform3D class, is at the
heart of all geometric manipulation in Java 3D. Being a group node, it can have child
nodes; but its distinction among group nodes is that any change to its Transform3D
component object influences the geometry of its child nodes, as a group. For example,
specifying a 10-meter shift in a TransformGroup node would cause its child
objects, as a group, to move 10 meters relative to the node. If the node's parent was
itself a TransformGroup node with a 10-meter translation in the same direction, then
the net result on the child objects would be a 20-meter translation— the combination
of the two translations.
Although the framework in the next part of the book uses spatial transforms
extensively, it does so in a manner that does not lend itself to nice, clean code samples.
The details of why this is so will be left for the discussions in part 4 about the frame-work.
For now, code fragments at the end of this section will illustrate how to use
TransformGroup and Transform3D in some practical UI situations. If you are curious
and can't wait until the next part, spatial transformation in the form of generalized
actuation and actuators can be found in the j3dui.control.actuatorspackage
in the framework.
13.1.1 Local coordinates
Another way of looking at a TransformGroup node is that each one defines a local 3D
coordinate system inside the virtual world space, and its child nodes live within this
local space. As the local space is moved, rotated, and stretched by the host node's
transform, so too are the child nodes. The implication of nesting transform groups in
the scene graph is that their coordinate systems become nested. For example, causing
a transform node that is high up in the scene graph to perform a rotation has the
effect of rotating the local space of its children and, correspondingly, that of any
lower-level nodes. Any visible leaf node descendants in these nested coordinate systems,
high or low, will also appear to rotate. This is shown in figure 13. 1 where three
north-pointing arrow shapes are placed under three different groups, each with a different
local coordinate space. The bottommost shape receives the combined effects of
the 90-degree rotations from its parent and grandparent TransformGroup nodes,
with a combined rotation of 180 degrees as seen by the user.
New on the Java Boutique:
New Review:
Time Management Made Easy with the Quartz Enterprise Job Scheduler
Why not just use the Java timer API? This open source scheduling
API boasts simplicity, ease-of-integration, a well-rounded feature
set, and it's free!
New Applet:
Reverse Complement
Reverse Complement is a simple applet that converts DNA or RNA
sequences into three useful formats.
Elsewhere on internet.com:
WebDeveloper Java
Lots of Java information on webdeveloper.com
WDVL Java
Thorough Java resource at the Web Developer's Virtual Library.
ScriptSearch Java
Hundreds of free Java code files to download.
jGuru: Your View of the Java Universe
Customizable portal with online training, FAQs, regular news updates, and tutorials.
|