📄 behaviors.html
字号:
object's scheduling region. If the ViewPlatform object's activationvolume does not intersect with a behavior's scheduling region,Java 3Dcan safely ignore that behavior's wakeup criteria.</p><p>In essence, the Java 3D scheduler performs the followingchecks:</p><ul> <li>Find all Behavior objects with scheduling regions that intersectthe active ViewPlatform object's activation volume.</li></ul><ul> <li>For each Behavior object within the ViewPlatform's activationvolume, if that behavior's WakeupCondition is <code>true</code>,schedule that Behavior object for execution.</li></ul><p>Java 3D's behavior scheduler executes those Behavior objectsthathavebeen scheduled by calling the behavior's <code>processStimulus</code>method.</p><h2>Interpolator Behaviors</h2><p>This section describes Java 3D's predefined <a href="../Interpolator.html">Interpolator</a> behaviors.They are called <em>interpolators</em>because they smoothly interpolate between the two extreme values thatan interpolator can produce. Interpolators perform simple behavioralacts, yet they provide broad functionality.</p><p>The Java 3D API provides interpolators for a number offunctions:manipulating transforms within a TransformGroup, modifying the valuesof a Switch node, and modifying Material attributes such as color andtransparency.</p><p>These predefined Interpolator behaviors share the same mechanism forspecifying and later for converting a temporal value into an alphavalue. Interpolators consist of two portions: a generic portion thatall interpolators share and a domain-specific portion.</p><p>The generic portion maps time in milliseconds onto a value in therange[0.0, 1.0] inclusive. The domain-specific portion maps an alpha valuein the range [0.0, 1.0] onto a value appropriate to the predefinedbehavior's range of outputs. An alpha value of 0.0 generates aninterpolator's minimum value, an alpha value of 1.0 generates aninterpolator's maximum value, and an alpha value somewhere in betweengenerates a value proportionally in between the minimum and maximumvalues.</p><h3>Mapping Time to Alpha</h3><p>Several parameters control the mapping of time onto an alpha value(seethe javadoc for the <a href="../Alpha.html">Alpha</a> object for adescription of the API).That mapping is deterministic as long as its parameters do not change.Thus, two different interpolators with the same parameters willgenerate the same alpha value given the same time value. This meansthat two interpolators that do not communicate can still preciselycoordinate their activities, even if they reside in different threadsor even different processors-as long as those processors haveconsistent clocks.</p><p><a href="#Figure_1">Figure1</a>shows the components of an interpolator's time-to-alpha mapping. Timeis represented on the horizontal axis. Alpha is represented on thevertical axis. As we move from left to right, we see the alpha valuestart at 0.0, rise to 1.0, and then decline back to 0.0 on theright-hand side.</p><p>On the left-hand side, the trigger time defineswhen this interpolator's waveform begins in milliseconds. The regiondirectly to the right of the trigger time, labeled Phase Delay, definesa time period where the waveform does not change. During phase delaysalpha is either 0 or 1, depending on which region it precedes.</p><p>Phase delays provide an important means for offsetting multipleinterpolators from one another, especially where the interpolators haveall the same parameters. The next four regions, labeled <b>α</b>increasing, <b>α</b> at 1, <b>α</b> decreasing, and<b>α</b> at 0, all specify durations forthe corresponding valuesof alpha.</p><p>Interpolators have a loop count that determines how many times torepeat the sequence of alpha increasing, alpha at 1, alpha decreasing,and alpha at 0; they also have associated mode flags that enable eitherthe increasing or decreasing portions, or both, of the waveform.</p><p><a name="Figure_1"></a><img style="width: 500px; height: 141px;" alt="Time-to-Alpha Mapping" title="Time-to-Alpha Mapping" src="Behaviors1.gif"></p><p></p><ul> <font size="-1"><b><i>Figure 1</i> – An Interpolator's GenericTime-to-Alpha Mapping Sequence</b></font></ul><p>Developers can use the loop count in conjunction with the mode flags togenerate various kinds of actions. Specifying a loop count of 1 andenabling the mode flag for only the alpha-increasing and alpha-at-1portion of the waveform, we would get the waveform shown in <a href="#Figure_2">Figure2</a>.</p><p><a name="Figure_2"></a><img style="width: 241px; height: 100px;" alt="Alpha Increasing" title="Alpha Increasing" src="Behaviors2.gif"></p><p></p><ul> <font size="-1"><b><i>Figure 2</i> – An Interpolator Set to a LoopCount of 1 with Mode Flags Set to EnableOnly the Alpha-Increasing and Alpha-at-1 Portion of the Waveform</b></font></ul><p>In <a href="#Figure_2">Figure2</a>,the alpha value is 0 before the combination of trigger time plus thephase delay duration. The alpha value changes from 0 to 1 over aspecified interval of time, and thereafter the alpha value remains 1(subject to the reprogramming of the interpolator's parameters). Apossible use of a single alpha-increasing value might be to combine itwith a rotation interpolator to program a door opening.</p><p>Similarly, by specifying a loop count of 1 anda mode flag that enables only the alpha-decreasing and alpha-at-0portion of the waveform, we would get the waveform shown in <a href="#Figure_3">Figure3</a>.</p><p>In <a href="#Figure_3">Figure3</a>,the alpha value is 1 before the combination of trigger time plus thephase delay duration. The alpha value changes from 1 to 0 over aspecified interval; thereafter the alpha value remains 0 (subject tothe reprogramming of the interpolator's parameters). A possible use ofa single <b>α</b>-decreasing value might be to combine it with arotationinterpolator to program a door closing.</p><p><a name="Figure_3"></a><img style="width: 241px; height: 88px;" alt="Alpha Decreasing" title="Alpha Decreasing" src="Behaviors3.gif"></p><p></p><ul> <font size="-1"><b><i>Figure 3</i> – An Interpolator Set to a LoopCount of 1 with Mode Flags Set to EnableOnly the Alpha-Decreasing and Alpha-at-0 Portion of the Waveform</b></font></ul><p>We can combine both of the above waveforms by specifying a loop countof 1 and setting the mode flag to enable both the alpha-increasing andalpha-at-1 portion of the waveform as well as the alpha-decreasing andalpha-at-0 portion of the waveform. This combination would result inthe waveform shown in <a href="#Figure_4">Figure4</a>.</p><p><a name="Figure_4"></a><img style="width: 241px; height: 100px;" alt="Alpha Increasing & Decreasing" title="Alpha Increasing & Decreasing" src="Behaviors4.gif"></p><p></p><ul> <font size="-1"><b><i>Figure 4</i> – An Interpolator Set to a LoopCount of 1 with Mode FlagsSet to Enable All Portions of the Waveform</b></font></ul><p>In <a href="#Figure_4">Figure4</a>,the alpha value is 0 before the combination of trigger time plus thephase delay duration. The alpha value changes from 0 to 1 over aspecified period of time, remains at 1 for another specified period oftime, then changes from 1 to 0 over a third specified period of time;thereafter the alpha value remains 0 (subject to the reprogramming ofthe interpolator's parameters). A possible use of an alpha-increasingvalue followed by an alpha-decreasing value might be to combine it witha rotation interpolator to program a door swinging open and thenclosing.</p><p>By increasing the loop count, we can getrepetitive behavior, such as a door swinging open and closed somenumber of times. At the extreme, we can specify a loop count of -1(representing infinity).</p><p>We can construct looped versions of the waveforms shown in <a href="#Figure_2">Figure2</a>, <a href="#Figure_3">Figure3</a>, and <a href="#Figure_4">Figure4</a>. <a href="#Figure_5">Figure5</a> shows a looping interpolator with mode flags set to enableonly the alpha-increasing and alpha-at-1 portion of the waveform.</p><p><a name="Figure_5"></a><img style="width: 500px; height: 99px;" alt="Alpha Increasing Infinite Loop" title="Alpha Increasing Infinite Loop" src="Behaviors5.gif"></p><p></p><ul> <font size="-1"><b><i>Figure 5</i> – An Interpolator Set to LoopInfinitely and Mode Flags Set to EnableOnly the Alpha-Increasing and Alpha-at-1 Portion of the Waveform</b></font></ul><p>In <a href="#Figure_5">Figure5</a>, alpha goes from 0 to 1 over a fixed duration of time, staysat 1 for another fixed duration of time, and then repeats.</p><p>Similarly, <a href="#Figure_6">Figure6</a> shows a looping interpolator with mode flags set to enableonly the alpha-decreasing and alpha-at-0 portion of the waveform.</p><p><a name="Figure_6"></a><img style="width: 500px; height: 97px;" alt="Alpha Decreasing Infinite Loop" title="Alpha Decreasing Infinite Loop" src="Behaviors6.gif"></p><p></p><ul> <font size="-1"><b><i>Figure 6</i> – An Interpolator Set to LoopInfinitely and Mode Flags Set to EnableOnly the Alpha-Decreasing and Alpha-at-0 Portion of the Waveform</b></font></ul><p>Finally, <a href="#Figure_7">Figure7</a> shows a looping interpolator with both the increasing anddecreasing portions of the waveform enabled.</p><p>In all three cases shown by <a href="#Figure_5">Figure5</a>, <a href="#Figure_6">Figure6</a>, and <a href="#Figure_7">Figure7</a>, we can compute the exact value of alpha at any point in time.</p><p><a name="Figure_7"></a><img style="width: 500px; height: 99px;" alt="Alpha Increasing & Decreasing Infinite Loop" title="Alpha Increasing & Decreasing Infinite Loop" src="Behaviors7.gif"></p><p></p><ul> <font size="-1"><b><i>Figure 7</i> – An Interpolator Set to LoopInfinitely and Mode Flags Setto Enable All Portions of the Waveform</b></font></ul><p>Java 3D's preprogrammed behaviors permit other behaviors to changetheir parameters. When such a change occurs, the alpha value changes tomatch the state of the newly parameterized interpolator.</p><h3>Acceleration of Alpha</h3><p>Commonly, developers want alpha to change slowly at first and thentospeed up until the change in alpha reaches some appropriate rate. Thisis analogous to accelerating your car up to the speed limit-it does notstart off immediately at the speed limit. Developers specify this"ease-in, ease-out" behavior through two additional parameters, the <code>increasingAlphaRampDuration</code>and the <code>decreasing-AlphaRampDuration</code>.</p><p>Each of these parameters specifies a period within the increasing ordecreasing alpha duration region during which the "change in alpha" isaccelerated (until it reaches its maximum per-unit-of-time step size)and then symmetrically decelerated. <a href="#Figure_8">Figure8</a> shows three general examples of how the <code>increasingAlphaRampDuration</code>method can be used to modify the alpha waveform. A value of 0 for theincreasing ramp duration implies that <b>α</b>is not accelerated; it changes at a constant rate. A value of 0.5 orgreater (clamped to 0.5) for this increasing ramp duration implies thatthe change in <b>α</b> is accelerated during the first half of theperiod andthen decelerated during the second half of the period. For a value of <em>n</em>that is less than 0.5, alpha is accelerated for duration <em>n</em>,held constant for duration (1.0 - 2<em>n</em>), then decelerated forduration <em>n</em> of the period.</p><p><a name="Figure_8"></a><img style="width: 500px; height: 354px;" alt="Alpha acceleration" title="Alpha acceleration" src="Behaviors8.gif"></p><p></p><ul> <font size="-1"><b><i>Figure 8</i> – How an Alpha-Increasing WaveformChanges with VariousValues of increasing-AlphaRampDuration</b></font></ul></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -