Difference between revisions of "Interpolation/Linear/Vectors"

From Second Life Wiki
Jump to: navigation, search
m (<lsl> tag to <source>)
 
Line 9: Line 9:
 
|func_desc=
 
|func_desc=
 
Linearly interpolates between two vector points in a list of vectors that define a path.
 
Linearly interpolates between two vector points in a list of vectors that define a path.
|spec=<lsl>vector pLin(list v, float t, integer Loop) {
+
|spec=<source lang="lsl2">vector pLin(list v, float t, integer Loop) {
 
     integer l = llGetListLength(v); t *= l-1;
 
     integer l = llGetListLength(v); t *= l-1;
 
     integer f = llFloor(t); t -= f;
 
     integer f = llFloor(t); t -= f;
Line 20: Line 20:
 
     return Index;
 
     return Index;
 
}
 
}
// Released into public domain. By Nexii Malthus.</lsl>
+
// Released into public domain. By Nexii Malthus.</source>
|examples=<lsl></lsl>
+
|examples=<source lang="lsl2"></source>
 
|cat1=Examples
 
|cat1=Examples
 
}}
 
}}

Latest revision as of 15:06, 24 January 2015

Summary

Function: vector pLin( list v, float t, integer Loop );

Linearly interpolates between two vector points in a list of vectors that define a path.
Returns a vector

• list v
• float t Ranges between [0, 1]
• integer Loop Whether the list is a curved line or loops into a closed shape.

Specification

vector pLin(list v, float t, integer Loop) {
    integer l = llGetListLength(v); t *= l-1;
    integer f = llFloor(t); t -= f;
    return llList2Vector(v,pIndex(f,l,Loop))*(1-t) + llList2Vector(v,pIndex(f+1,l,Loop))*t;
}
integer pIndex( integer Index, integer Length, integer Loop) {
    if(Loop) return Index % Length;
    if(Index < 0) return 0;
    if(Index > --Length) return Length;
    return Index;
}
// Released into public domain. By Nexii Malthus.

Examples