Interpolation/Linear/Vectors

From Second Life Wiki
< Interpolation‎ | Linear
Revision as of 03:35, 14 September 2011 by Nexii Malthus (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Summary

Function: vector vLin( 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){

 float l = llGetListLength(v); t *= l-1;
 float f = (float)llFloor(t);
 integer i1 = 0; integer i2 = 0;
 if(Loop){ i1 = (integer)(f-llFloor(f/l)*l);
       ++f;i2 = (integer)(f-llFloor(f/l)*l);
 } else {
   if(  f > l-1 ) i1 = (integer)l-1;
   else if(  f >= 0 ) i1 = (integer)f;
   if(f+1 > l-1 ) i2 = (integer)l-1;
   else if(f+1 >= 0 ) i2 = (integer)f+1;
 }
 vector v1 = llList2Vector(v, i1);
 vector v2 = llList2Vector(v, i2);
 t-=f;
 return v1*(1-t) + v2*t;

}</lsl>

Examples

<lsl></lsl>