Difference between revisions of "Interpolation/Linear/Vectors"
< Interpolation | Linear
Jump to navigation
Jump to search
Line 1: | Line 1: | ||
{{LSL_Function | {{LSL_Function | ||
|mode=user | |mode=user | ||
|func= | |func=pLin | ||
|p1_type=list|p1_name=v | |p1_type=list|p1_name=v | ||
|p2_type=float|p2_name=t | |p2_type=float|p2_name=t | ||
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=<lsl>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( | if(Index < 0) return 0; | ||
if(Index > --Length) return Length; | |||
if( | return Index; | ||
} | } | ||
// Released into public domain. By Nexii Malthus.</lsl> | // Released into public domain. By Nexii Malthus.</lsl> |
Revision as of 12:04, 16 September 2011
LSL Portal | Functions | Events | Types | Operators | Constants | Flow Control | Script Library | Categorized Library | Tutorials |
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 | |||
• integer | Loop |
Specification
<lsl>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.</lsl>
Examples
<lsl></lsl>