Difference between revisions of "Slerp"

From Second Life Wiki
Jump to navigation Jump to search
m (LSL Slerp moved to Slerp)
Line 6: Line 6:
</dl>
</dl>


<pre>
<lsl>rotation slerp( rotation a, rotation b, float f ) {
rotation slerp( rotation a, rotation b, float f ) {
     float angleBetween = llAngleBetween(a, b);
     float angleBetween = llAngleBetween(a, b);
     if ( angleBetween > PI )
     if ( angleBetween > PI )
         angleBetween = angleBetween - TWO_PI;
         angleBetween = angleBetween - TWO_PI;
     return a*llAxisAngle2Rot(llRot2Axis(b/a)*a, angleBetween*f);
     return a*llAxisAngle2Rot(llRot2Axis(b/a)*a, angleBetween*f);
}//Written by Francis Chung, Taken from http://forums.secondlife.com/showthread.php?p=536622
}//Written by Francis Chung, Taken from http://forums.secondlife.com/showthread.php?p=536622</lsl>
</pre>

Revision as of 15:55, 8 February 2008

"Wikipedia logo"Slerp

Slerp is shorthand for spherical linear interpolation, introduced by Ken Shoemake in the context of quaternion interpolation for the purpose of animating 3D rotation. It refers to constant speed motion along a unit radius great circle arc, given the ends and an interpolation parameter between 0 and 1.

<lsl>rotation slerp( rotation a, rotation b, float f ) {

   float angleBetween = llAngleBetween(a, b);
   if ( angleBetween > PI )
       angleBetween = angleBetween - TWO_PI;
   return a*llAxisAngle2Rot(llRot2Axis(b/a)*a, angleBetween*f);

}//Written by Francis Chung, Taken from http://forums.secondlife.com/showthread.php?p=536622</lsl>