translating or rotating objects, removing some objects, changing the attributes of others,
or any other desirable outcomes in the specific application.
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.
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.
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.
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.
Search WWH ::