Difference between revisions of "Interpolation/Target"

From Second Life Wiki
Jump to navigation Jump to search
(Created page with "{{LSL Header|Interpolation}} {{RightToc|clear:right;}} == Target == {|cellspacing="0" cellpadding="3" border="1" style="border: 1px solid #aaaaaa; margin: 1em 1em 1em 0pt; …")
 
(Page not needed anymore.)
 
Line 1: Line 1:
{{LSL Header|[[Interpolation]]}}
{{RightToc|clear:right;}}


== Target ==
{|cellspacing="0" cellpadding="3" border="1" style="border: 1px solid #aaaaaa; margin: 1em 1em 1em 0pt; background-color: #ffffff; border-collapse: collapse" width="80%"
!style="color: #000000; background-color: #aaaaff;" height="20px"|
===Float Target===
|-
|
Steps float 'Now' closer using float 'Vel' towards 'Target' while clamping between 'Min' and 'Max'. Useful for games, simulations and vehicles. For example keeping realtime track of linear and angular acceleration and velocity of a vehicle.
<lsl>
float fTarget(float Now, float Target, float Min, float Max, float Vel) {
    if(llFabs(Target-Now) < Vel) return Target;
    if(Now < Target) Now += Vel; else Now -= Vel;
    if(Now < Min) Now = Min; else if(Now > Max) Now = Max;
    return Now;
}
</lsl>
{|cellspacing="0" cellpadding="3" border="1" style="border: 1px solid #aaaaaa; margin: 1em 1em 1em 0pt; background-color: #ffffff; border-collapse: collapse" width="80%"
|
{|cellspacing="0" cellpadding="6" border="1" style="border: 1px solid #aaaaaa; margin: 1em 1em 1em 0pt; background-color: #e0e0ff; border-collapse: collapse"
!style="background-color: #d0d0ee" | Input
!style="background-color: #d0d0ee" | Description
|-
| float Now
| 'Now' current value
|-
| float Target
| move 'Now' towards 'Target'
|-
| float Min
| Clamp output at minimum
|-
| float Max
| Clamp output at maximum
|-
| float Vel
| Move 'Now' towards 'Target' at 'Vel' (Velocity)
|-
!style="background-color: #d0d0ee" | Output
!style="background-color: #d0d0ee" | Description
|-
| return float fTarget
| Returns clamped output of a single step of 'Now' towards 'Target' using 'Vel'
|}
| Graph goes here, k.
|}
<div style="float:right;font-size: 80%;">
Released to Public Domain. By Nexii Malthus</div>
|}

Latest revision as of 04:35, 14 September 2011