⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 behaviors.html

📁 JAVA多媒体开发类库说明
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head>  <meta content="text/html; charset=ISO-8859-1" http-equiv="content-type">  <title>Java 3D API - Behaviors and Interpolators</title></head><body><h2>Behaviors and Interpolators</h2><p><a href="../Behavior.html">Behavior</a> nodes provide the means foranimating objects, processing keyboard and mouse inputs, reacting tomovement, and enabling and processing pick events. Behavior nodescontain Java code and state variables. A Behavior node's Java code caninteract with Java objects, change node values within a Java&nbsp;3Dscenegraph, change the behavior's internal state-in general, perform anycomputation it wishes.</p><p>Simple behaviors can add surprisingly interesting effects to a scenegraph. For example, one can animate a rigid object by using a Behaviornode to repetitively modify the TransformGroup node that points to theobject one wishes to animate. Alternatively, a Behavior node can trackthe current position of a mouse and modify portions of the scene graphin response.</p><h2>Behavior Object</h2><p>A Behavior leaf node object contains a scheduling region and twomethods: an <code>initialize</code> method called once when thebehavior becomes "live" and a <code>processStimulus</code>method called whenever appropriate by the Java&nbsp;3D behaviorscheduler.The Behavior object also contains the state information needed by its <code>initialize</code>and <code>processStimulus</code> methods.</p><p>The <em>scheduling region</em> defines a spatial volume that servesto enable the scheduling of Behavior nodes. A Behavior node is <em>active</em>(can receive stimuli) whenever an active ViewPlatform's activationvolume intersects a Behavior object's scheduling region. Only activebehaviors can receive stimuli.</p><p>The <em>scheduling interval</em> defines apartial order of execution for behaviors that wake up in response tothe same wakeup condition (that is, those behaviors that are processedat the same "time"). Given a set of behaviors whose wakeup conditionsare satisfied at the same time, the behavior scheduler will execute allbehaviors in a lower scheduling interval before executing any behaviorin a higher scheduling interval. Within a scheduling interval,behaviors can be executed in any order, or in parallel. Note that thispartial ordering is only guaranteed for those behaviors that wake up atthe same time in response to the same wakeup condition, for example,the set of behaviors that wake up every frame in response to aWakeupOnElapsedFrames(0) wakeup condition.</p><p>The <code>processStimulus</code> method receives and processes abehavior's ongoing messages. The Java&nbsp;3D behavior schedulerinvokes aBehavior node's <code>processStimulus</code>method when an active ViewPlatform's activation volume intersects aBehavior object's scheduling region and all of that behavior's wakeupcriteria are satisfied. The <code>processStimulus</code> methodperforms its computations and actions (possibly including theregistration of state change information that could cause Java&nbsp;3Dtowake other Behavior objects), establishes its next wakeup condition,and finally exits.</p><p>A typical behavior will modify one or more nodes or node componentsinthe scene graph. These modifications can happen in parallel withrendering. In general, applications cannot count on behavior executionbeing synchronized with rendering. There are two exceptions to thisgeneral rule:</p><ul>  <li>All modifications to scene graph objects (not including geometryby-reference or texture by-reference) made from the <code>processStimulus</code>method of a single behavior instance are guaranteed to take effect inthe same rendering frame</li></ul><ul>  <li>All modifications to scene graph objects (not including geometryby-reference or texture by-reference) made from the <code>processStimulus</code>methods of the set of behaviors that wake up in response to aWakeupOnElapsedFrames(0) wakeup condition are guaranteed to take effectin the same rendering frame.</li></ul><p>Note that modifications to geometry by-reference or textureby-reference are not guaranteed to show up in the same frame as otherscene graph changes.</p><h3>Code Structure</h3><p>When the Java&nbsp;3D behavior scheduler invokes a Behavior object's<code>processStimulus</code>method, that method may perform any computation it wishes. Usually, itwill change its internal state and specify its new wakeup conditions.Most probably, it will manipulate scene graph elements. However, thebehavior code can change only those aspects of a scene graph elementpermitted by the capabilities associated with that scene graph element.A scene graph's capabilities restrict behavioral manipulation to thosemanipulations explicitly allowed.</p><p>The application must provide the Behavior object with references tothose scene graph elements that the Behavior object will manipulate.The application provides those references as arguments to thebehavior's constructor when it creates the Behavior object.Alternatively, the Behavior object itself can obtain access to therelevant scene graph elements either when Java&nbsp;3D invokes its <code>initialize</code>method or each time Java&nbsp;3D invokes its <code>processStimulus</code>method.</p><p>Behavior methods have a very rigid structure. Java&nbsp;3D assumesthattheyalways run to completion (if needed, they can spawn threads). Eachmethod's basic structure consists of the following:</p><ul>  <li>Code to decode and extract references from the WakeupConditionenumeration that caused the object's awakening.</li></ul><ul>  <li>Code to perform the manipulations associated with theWakeupCondition.</li></ul><ul>  <li>Code to establish this behavior's new WakeupCondition.</li></ul><ul>  <li>A path to Exit (so that execution returns to the Java&nbsp;3Dbehaviorscheduler).</li></ul><h3>WakeupCondition Object</h3><p>A <a href="../WakeupCondition.html">WakeupCondition</a> object isanabstract class specialized to fourteendifferent WakeupCriterion objects and to four combining objectscontaining multiple WakeupCriterion objects.</p><p>A Behavior node provides the Java&nbsp;3D behavior scheduler with aWakeupCondition object. When that object's WakeupCondition has beensatisfied, the behavior scheduler hands that same WakeupCondition backto the Behavior via an enumeration.</p><p></p><h3>WakeupCriterion Object</h3><p>Java&nbsp;3D provides a rich set of wakeup criteria that Behaviorobjectscan use in specifying a complex WakeupCondition. These wakeup criteriacan cause Java&nbsp;3D's behavior scheduler to invoke a behavior's <code>processStimulus</code>method whenever</p><ul>  <li>The center of an active ViewPlatform enters a specified region.</li></ul><ul>  <li>The center of an active ViewPlatform exits a specified region.</li></ul><ul>  <li>A behavior is activated.</li></ul><ul>  <li>A behavior is deactivated.</li></ul><ul>  <li>A specified TransformGroup node's transform changes.</li></ul><ul>  <li>Collision is detected between a specified Shape3D node's Geometryobject and any other object.</li></ul><ul>  <li>Movement occurs between a specified Shape3D node's Geometryobject and any other object with which it collides.</li></ul><ul>  <li>A specified Shape3D node's Geometry object no longer collideswith any other object.</li></ul><ul>  <li>A specified Behavior object posts a specific event.</li></ul><ul>  <li>A specified AWT event occurs.</li></ul><ul>  <li>A specified time interval elapses.</li></ul><ul>  <li>A specified number of frames have been drawn.</li></ul><ul>  <li>The center of a specified Sensor enters a specified region.</li></ul><ul>  <li>The center of a specified Sensor exits a specified region.</li></ul><p>A Behavior object constructs a <a href="../WakeupCriterion.html">WakeupCriterion</a>by constructing theappropriate criterion object. The Behavior object must provide theappropriate arguments (usually a reference to some scene graph objectand possibly a region of interest). Thus, to specify aWakeupOnViewPlatformEntry, a behavior would specify the region thatwill cause the behavior to execute if an active ViewPlatform enters it.</p><h3>Composing WakeupCriterionObjects</h3><p>A Behavior object can combine multiple WakeupCriterion objects intoamore powerful, composite WakeupCondition. Java&nbsp;3D behaviorsconstruct acomposite WakeupCondition in one of the following ways:</p><ul>  <li><a href="../WakeupAnd.html">WakeupAnd</a>: An array ofWakeupCriterion objects ANDed together.</li></ul><pre>            WakeupCriterion &amp;&amp; WakeupCriterion &amp;&amp; ...<br></pre><ul>  <li><a href="../WakeupOr.html">WakeupOr</a>: An array ofWakeupCriterion objects ORed together.</li></ul><pre>            WakeupCriterion || WakeupCriterion || ...<br></pre><ul>  <li><a href="../WakeupAndOfOrs.html">WakeupAndOfOrs</a>: An array ofWakeupOr WakeupCondition objects thatare then ANDed together.</li></ul><pre>            WakeupOr &amp;&amp; WakeupOr &amp;&amp; ...<br></pre><ul>  <li><a href="../WakeupOrOfAnds.html">WakeupOrOfAnds</a>: An array ofWakeupAnd WakeupCondition objectsthat are then ORed together.</li></ul><pre>            WakeupAnd || WakeupAnd || ...<br></pre><h2>Composing Behaviors</h2><p>Behavior objects can condition themselves to awaken only whensignaledby another Behavior node. The <a href="../WakeupOnBehaviorPost.html">WakeupOnBehaviorPost</a>WakeupCriteriontakes as arguments a reference to a Behavior node and an integer. Thesetwo arguments allow a behavior to limit its wakeup criterion to aspecific post by a specific behavior.</p><p>The WakeupOnBehaviorPost WakeupCriterion permits behaviors to chaintheir computations, allowing parenthetical computations-one behavioropens a door and the second closes the same door, or one behaviorhighlights an object and the second unhighlights the same object.</p><p></p><h2>Scheduling</h2><p>As a virtual universe grows large, Java&nbsp;3D must carefullyhusbanditsresources to ensure adequate performance. In a 10,000-object virtualuniverse with 400 or so Behavior nodes, a naive implementation of Java3D could easily end up consuming the majority of its compute cycles inexecuting the behaviors associated with the 400 Behavior objects beforeit draws a frame. In such a situation, the frame rate could easily dropto unacceptable levels.</p><p>Behavior objects are usually associated with geometric objects inthevirtual universe. In our example of 400 Behavior objects scatteredthroughout a 10,000-object virtual universe, only a few of theseassociated geometric objects would be visible at a given time. Asizable fraction of the Behavior nodes-those associated with nonvisibleobjects-need not be executed. Only those relatively few Behaviorobjects that are associated with visible objects must be executed.</p><p>Java&nbsp;3D mitigates the problem of a large number of Behaviornodes inahigh-population virtual universe through execution culling-choosing toinvoke only those behaviors that have high relevance.</p><p>Java&nbsp;3D requires each behavior to have a <em>scheduling region</em>and to post a wakeup condition. Together a behavior's scheduling regionand wakeup condition provide Java&nbsp;3D's behavior scheduler withsufficient domain knowledge to selectively prune behavior invocationsand invoke only those behaviors that absolutely need to be executed.</p><p></p><h2>How Java&nbsp;3D PerformsExecution Culling</h2><p>Java&nbsp;3D finds all scheduling regions associated with Behaviornodesandconstructs a scheduling/volume tree. It also creates an AND/OR treecontaining all the Behavior node wakeup criteria. These two datastructures provide the domain knowledge Java&nbsp;3D needs to pruneunneededbehavior execution (to perform "execution triage").</p><p>Java&nbsp;3D must track a behavior's wakeup conditions only if anactiveViewPlatform object's activation volume intersects with that Behavior

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -