Difference between revisions of "Slerp"

From Second Life Wiki
Jump to navigation Jump to search
Line 2: Line 2:
<dl><dd>
<dl><dd>
<div id="box">
<div id="box">
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.
'''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.
</div>
</div>
</dl>
</dl>


<lsl>rotation slerp( rotation a, rotation b, float f ) {
The following slerp algorithm uses '''a''' and '''b''' for ends and '''t''' for the interpolation parameter.<br>
    float angleBetween = llAngleBetween(a, b);
To continue the rotation past the ends use a value for '''t''' outside the range '''[0, 1]'''.
    if ( angleBetween > PI )
 
        angleBetween = angleBetween - TWO_PI;
<lsl>rotation slerp( rotation a, rotation b, float t ) {
    return a*llAxisAngle2Rot(llRot2Axis(b/a)*a, angleBetween*f);
  float angle = llRot2Angle(b /= a);
}//Written by Francis Chung, Taken from http://forums.secondlife.com/showthread.php?p=536622</lsl>
  if (angle > PI)
      angle -= TWO_PI;
  return llAxisAngle2Rot( llRot2Axis(b), t * angle) * a;
}//Written collectively, Taken from http://forums.secondlife.com/showthread.php?p=536622</lsl>

Revision as of 23:32, 15 March 2009

"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.

The following slerp algorithm uses a and b for ends and t for the interpolation parameter.
To continue the rotation past the ends use a value for t outside the range [0, 1].

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

  float angle = llRot2Angle(b /= a);
  if (angle > PI)
     angle -= TWO_PI;
  return llAxisAngle2Rot( llRot2Axis(b), t * angle) * a;

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