Java Reference
In-Depth Information
collIsIon events
Sudden changes to how objects should be rendered in a 3D world will most likely be nec-
essary when two objects collide with each other. The detection of collisions and how they
can be handled are therefore important issues in Java 3D.
However, since these issues are complicated, we will not discuss the topic in detail in
this chapter. Instead, for the sake of completeness, a summary of the important classes and
methods that can be used for handling collisions are presented in Figures 16, 17, and 18.
Specifically, the setting of wakeup events for detecting when a specific object has collided
with other objects, when it no longer collide with any other objects, and when it moves
while in collision are summarized in the respective figures. A detailed example on the use
of these wakeup events will be presented later.
elapsed tIme and frame events
For handling situations where objects are evolving or changing as a function of time and in
animation, the use of classes that provide wakeup triggers after a certain number of frames
or milliseconds have passed may be very useful.
Figure 19 gives a summary of the usage of the WakeupOnElapsedFrames and Wake-
upOnElapsedTime classes for such applications. Note that the wakeup criterion may be
passive or non-passive. If the latter is selected, the rendering of the various objects will
proceed to be carried out continuously. Also, the execution of behaviors and rendering will
not be synchronized in general, except for the case when a frame count of 0 is specified.
In this situation, the relevant behavior will be invoked every frame, and changes to the
objects being rendered will take effect in the same rendering frame.
A simple example on the use of WakeupOnElapsedFrames is given in Figure 20. The
wakeup criteria for the program correspond to that of pressing the mouse or when 100
frames have passed. When triggers for these events are received and the processStimulus
method is invoked, a relevant system message will be printed.
Figure 21 gives the code segment and result from using WakeupOnElapsedTime to
render a clock that ticks at the same rate as the system clock. The methods for the drawing
of the clock frame and its three hands are not shown. Essentially, two arrays are used to
store vertices that can be used to draw the clock and its hands corresponding to specified
time using appropriate methods. Note, however, that for the position for the hands to be
varied, the Shape3D capability has to be changed to ALLOW_GEOMETRY_WRITE.
As specified in the initial wake up criterion, the clock is started by the pressing of a
key. When this happens, the processStimulus method retrieves the system time, invokes
the relevant methods to render the clock hands according to the system time, which is in
24-hour format, and then sets the new wake up criterion to that for a time lapsed of 1000
Search WWH ::

Custom Search