in the direction of the positive y axis. After this movement, the trigger is reset in line 34.
Thus, subsequent mouse clicks will move the cube up by the same amount every time.
Note that the code segment in Figure 1 includes two import statements for the behavior
class. Specifically, java.awt.event.* is for mouse interaction, while java.util.Enumeration
is for the purpose of decoding the wake up conditions.
Having created a desirable behavior for moving an object in Figure 1, Figure 2 shows
how this can be incorporated into the main code segment for the creation of the Java 3D
virtual world. The created scene graph is also shown. As depicted, before adding the ap-
propriate behavior, a TransformGroup, which is at a level above the cube to be rotated, is
first created which will serve as the target of the behavior subsequently.
Next, an instance of the behavior class is added to the scene graph. Note that if the
scene graph is not live, the behavior will not be initialized. Lastly, scheduling bounds are
provided for the behavior. This behavior will only be active for the receiving of stimulus
when its scheduling bounds intersect the activation volume of a ViewPlatform. We will
discuss this in more detail in the next section.
setSchedulingBounds from javax.media.j3d.Behavior is a method that allows the bound-
ing region of a behavior to be specified. If this region intersects with the region of the
ViewPlatform as illustrated in Figure 3, this behavior will be able to receive user and event
stimulus and will be able to render changes in the virtual 3D world.
Conceptually, as illustrated, the view region is a region that can be seen by the user
and corresponds to the user view, while the behavior region is a region where something
interesting may be going on. However, the user can only see what is happening in his or
her view and if this happens not to contain the region where interesting behavior is going
on, the user will still not be able to see the latter.
Technically, the ViewingPlatform is a property of the universe in Java3D, with a default
region centered at the origin and an activation radius of 62. On the other hand, the bounding
region for a behavior can be specified under the BoundingSphere class, and has a default
center at the origin and a radius of one. Thus, the default bounding sphere will intersect
the normal ViewingTransform, and the behavior will be visible. However, if the latter is
changed to those values given in Figure 4 (which show the normal declaration formats of
ViewingPlatform and bounding sphere), there will be no interaction and the behavior will
not be visible.
Search WWH ::