Difference between revisions of "Interpolation/Linear/Vectors"

From Second Life Wiki
Jump to: navigation, search
(Created page with "{{LSL_Function |mode=user |func=vLin |p1_type=list|p1_name=v |p2_type=float|p2_name=t |p3_type=integer|p3_name=Loop |return_type=vector |return_value=returns the interpolation of…")
 
Line 25: Line 25:
 
   t-=f;
 
   t-=f;
 
   return v1*(1-t) + v2*t;
 
   return v1*(1-t) + v2*t;
}</lsl>
+
}
 +
// Released into public domain. By Nexii Malthus.</lsl>
 
|examples=<lsl></lsl>
 
|examples=<lsl></lsl>
 
|cat1=Examples
 
|cat1=Examples
 
}}
 
}}

Revision as of 03:36, 14 September 2011

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>