|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--javax.media.j3d.SceneGraphObject | +--javax.media.j3d.Node | +--javax.media.j3d.Leaf | +--javax.media.j3d.Behavior
Behavior is an abstract class that contains the framework for all
behavioral components in Java 3D. It contains a scheduling region
and two methods: An initialization
method, called once
when the behavior becomes "live," and a processStimulus
method called whenever
appropriate by the Java 3D behavior scheduler. The Behavior object
also contains the state information needed by its
initialize
* and processStimulus
methods.
The scheduling region defines a spatial volume that serves to enable the scheduling of Behavior nodes. A Behavior node is active (can receive stimuli) whenever a ViewPlatform's activation volume intersects a Behavior object's scheduling region. Only active behaviors can receive stimuli.
The initialize
method allows a Behavior object to initialize
its internal state and specify its initial wakeup condition(s). Java 3D
invokes a behavior's initialize code when the behavior's containing
BranchGroup node is added to the virtual universe. Java 3D does not
invoke the initialize method in a new thread.
Thus, for Java 3D to regain control, the initialize method must not execute an
infinite loop; it must return. Furthermore, a wakeup condition must be set or
else the behavior's processStimulus method is never executed.
The processStimulus
method receives and processes a behavior's
ongoing messages. The Java 3D behavior scheduler invokes a Behavior node's
processStimulus method when a ViewPlatform's activation volume intersects a
Behavior object's scheduling region and all of that behavior's wakeup criteria
are satisfied. The processStimulus method performs its computations and actions
(possibly including the registration of state change information that could cause
Java 3D to wake other Behavior objects), establishes its next wakeup condition,
and finally exits.
Code Structure
When the Java 3D behavior scheduler invokes a Behavior object's processStimulus method, that method may perform any computation it wishes. Usually, it will change its internal state and specify its new wakeup conditions. Most probably, it will manipulate scene graph elements. However, the behavior code can only change those aspects of a scene graph element permitted by the capabilities associated with that scene graph element. A scene graph's capabilities restrict behavioral manipulation to those manipulations explicitly allowed.
The application must provide the Behavior object with references to those scene graph elements that the Behavior object will manipulate. The application provides those references as arguments to the behavior's constructor when it creates the Behavior object. Alternatively, the Behavior object itself can obtain access to the relevant scene graph elements either when Java 3D invokes its initialize method or each time Java 3D invokes its processStimulus method.
Behavior methods have a very rigid structure. Java 3D assumes that they always run to completion (if needed, they can spawn threads). Each method's basic structure consists of the following:
WakeupCondition Object
A WakeupCondition object is an abstract class specialized to fourteen different WakeupCriterion objects and to four combining objects containing multiple WakeupCriterion objects. A Behavior node provides the Java 3D behavior scheduler with a WakeupCondition object. When that object's WakeupCondition has been satisfied, the behavior scheduler hands that same WakeupCondition back to the Behavior via an enumeration.
WakeupCriterion Object
Java 3D provides a rich set of wakeup criteria that Behavior objects can use in specifying a complex WakeupCondition. These wakeup criteria can cause Java 3D's behavior scheduler to invoke a behavior's processStimulus method whenever
WakeupCondition
Fields inherited from class javax.media.j3d.Node |
ALLOW_AUTO_COMPUTE_BOUNDS_READ,
ALLOW_AUTO_COMPUTE_BOUNDS_WRITE,
ALLOW_BOUNDS_READ,
ALLOW_BOUNDS_WRITE,
ALLOW_COLLIDABLE_READ,
ALLOW_COLLIDABLE_WRITE,
ALLOW_LOCAL_TO_VWORLD_READ,
ALLOW_PICKABLE_READ,
ALLOW_PICKABLE_WRITE,
ENABLE_COLLISION_REPORTING,
ENABLE_PICK_REPORTING |
Constructor Summary | |
Behavior()
Constructs a Behavior node with default parameters. |
Method Summary | |
boolean |
getEnable()
Retrieves the state of the Behavior enable flag. |
BoundingLeaf |
getSchedulingBoundingLeaf()
Retrieves the Behavior node's scheduling bounding leaf. |
Bounds |
getSchedulingBounds()
Retrieves the Behavior node's scheduling bounds. |
protected View |
getView()
Returns the primary view associated with this behavior. |
abstract void |
initialize()
Initialize this behavior. |
void |
postId(int postId)
Post the specified Id. |
abstract void |
processStimulus(java.util.Enumeration criteria)
Process a stimulus meant for this behavior. |
void |
setEnable(boolean state)
Enables or disables this Behavior. |
void |
setSchedulingBoundingLeaf(BoundingLeaf region)
Set the Behavior's scheduling region to the specified bounding leaf. |
void |
setSchedulingBounds(Bounds region)
Set the Behavior's scheduling region to the specified bounds. |
void |
updateNodeReferences(NodeReferenceTable referenceTable)
Callback used to allow a node to check if any scene graph objects referenced by that node have been duplicated via a call to cloneTree . |
protected void |
wakeupOn(WakeupCondition criteria)
Defines this behavior's wakeup criteria. |
Methods inherited from class javax.media.j3d.Node |
cloneNode,
cloneTree,
cloneTree,
cloneTree,
cloneTree,
cloneTree,
cloneTree,
duplicateNode,
getBounds,
getBoundsAutoCompute,
getCollidable,
getLocalToVworld,
getLocalToVworld,
getParent,
getPickable,
setBounds,
setBoundsAutoCompute,
setCollidable,
setPickable |
Methods inherited from class javax.media.j3d.SceneGraphObject |
clearCapability,
duplicateSceneGraphObject,
getCapability,
getUserData,
isCompiled,
isLive,
setCapability,
setUserData |
Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
Constructor Detail |
public Behavior()
Method Detail |
public abstract void initialize()
public abstract void processStimulus(java.util.Enumeration criteria)
criteria
- an enumeration of triggered wakeup criteria for this
behaviorpublic void setSchedulingBounds(Bounds region)
region
- the bounds that contains the Behavior's new scheduling
regionpublic Bounds getSchedulingBounds()
public void setSchedulingBoundingLeaf(BoundingLeaf region)
region
- the bounding leaf node used to specify the Behavior
node's new scheduling regionpublic BoundingLeaf getSchedulingBoundingLeaf()
protected void wakeupOn(WakeupCondition criteria)
criteria
- the wakeup criteria for this behaviorpublic void postId(int postId)
postId
- the Id being postedpublic void setEnable(boolean state)
state
- true or false to enable or disable this Behaviorpublic boolean getEnable()
protected View getView()
public void updateNodeReferences(NodeReferenceTable referenceTable)
cloneTree
.
This method is called by cloneTree
after all nodes in
the sub-graph have been duplicated. The cloned Leaf node's method
will be called and the Leaf node can then look up any object references
by using the getNewObjectReference
method found in the
NodeReferenceTable
object. If a match is found, a
reference to the corresponding object in the newly cloned sub-graph
is returned. If no corresponding reference is found, either a
DanglingReferenceException is thrown or a reference to the original
object is returned depending on the value of the
allowDanglingReferences
parameter passed in the
cloneTree
call.
NOTE: Applications should not call this method directly. It should only be called by the cloneTree method.
referenceTable
- a NodeReferenceTableObject that contains the
getNewObjectReference
method needed to search for
new object instances.NodeReferenceTable
,
Node.cloneTree()
,
DanglingReferenceException
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |