interpolation/Linear/Vectors

From Second Life Wiki
< Interpolation‎ | Linear
Revision as of 02:36, 14 September 2011 by Nexii Malthus (talk | contribs)
Jump to navigation Jump to 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;

} // Released into public domain. By Nexii Malthus.</lsl>

Examples

<lsl></lsl>