Interpolation
LSL Portal | Functions | Events | Types | Operators | Constants | Flow Control | Script Library | Categorized Library | Tutorials |
Changes/ 1.0-1.1 - Added rotation types
<lsl> //===================================================// // Interpolation Library 1.1 // // "May 7 2008", "19:16:20 GMT-0" // // Copyright (C) 2008, Nexii Malthus (cc-by) // // http://creativecommons.org/licenses/by/3.0/ // //===================================================//
float fLin(float v0, float v1,float t){
return v0*(1-t) + v1*t;}
float fCos(float v0,float v1,float t){
float F = (1 - llCos(t*PI))/2; return v0*(1-F)+v1*F;}
float fCub(float v0,float v1,float v2,float v3,float t){
float P = (v3-v2)-(v0-v1);float Q = (v0-v1)-P;float R = v2-v0;float S = v1; return P*llPow(t,3) + Q*llPow(t,2) + R*t + S;}
vector vLin(vector v0, vector v1,float t){
return v0*(1-t) + v1*t;}
vector vCos(vector v0,vector v1,float t){
float F = (1 - llCos(t*PI))/2; return v0*(1-F)+v1*F;}
vector vCub(vector v0,vector v1,vector v2,vector v3,float t){
vector P = (v3-v2)-(v0-v1);vector Q = (v0-v1)-P;vector R = v2-v0;vector S = v1; return P*llPow(t,3) + Q*llPow(t,2) + R*t + S;}
rotation rLin(rotation r0,rotation r1,float t){
// Spherical-Linear Interpolation float ang = llAngleBetween(r0, r1); if( ang > PI) ang -= TWO_PI; return r0 * llAxisAngle2Rot( llRot2Axis(r1/r0)*r0, ang*t);}
rotation rCos(rotation r0,rotation r1,float t){
// Spherical-Cosine Interpolation float f = (1 - llCos(t*PI))/2; float ang = llAngleBetween(r0, r1); if( ang > PI) ang -= TWO_PI; return r0 * llAxisAngle2Rot( llRot2Axis(r1/r0)*r0, ang*f);}
rotation rCub(rotation r0,rotation r1,rotation r2,rotation r3,float t){
// Spherical-Cubic Interpolation // r0 = Start, r1 = End, r2 and r3 affect path of curve! return rLin( rLin(r0,r1,t), rLin(r2,r3,t), 2*t*(1-t) );}
default{state_entry(){}}
</lsl>