Difference between revisions of "Nlerp"
Jump to navigation
Jump to search
Frionil Fang (talk | contribs) (considerably faster than slerp, can be neat for a visual effect since it isn't constant speed, AND is a valid use for rotation addition) |
Frionil Fang (talk | contribs) m (Multiplication by reciprocal is b) |
||
Line 8: | Line 8: | ||
float ti = 1-t; | float ti = 1-t; | ||
rotation r = <a.x*ti, a.y*ti, a.z*ti, a.s*ti>+<b.x*t, b.y*t, b.z*t, b.s*t>; | rotation r = <a.x*ti, a.y*ti, a.z*ti, a.s*ti>+<b.x*t, b.y*t, b.z*t, b.s*t>; | ||
float m = llSqrt(r.x*r.x+r.y*r.y+r.z*r.z+r.s*r.s); // normalize | float m = 1/llSqrt(r.x*r.x+r.y*r.y+r.z*r.z+r.s*r.s); // normalize | ||
return <r.x | return <r.x*m, r.y*m, r.z*m, r.s*m>; | ||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
See also: [[Slerp]] | See also: [[Slerp]] |
Latest revision as of 06:30, 29 March 2024
Nlerp is shorthand for normalized linear interpolation. It is a faster, less mathematically accurate alternative to spherical interpolation for the purpose of animating 3D rotation. It travels the "least twisting" path between the two rotations, but does not move at a constant speed; it will accelerate and decelerate at the start and end, which may be interesting for a visual effect.
The following nlerp algorithm uses a and b for ends and t for the interpolation parameter.
t is in the range [0, 1].
rotation nlerp(rotation a, rotation b, float t) {
float ti = 1-t;
rotation r = <a.x*ti, a.y*ti, a.z*ti, a.s*ti>+<b.x*t, b.y*t, b.z*t, b.s*t>;
float m = 1/llSqrt(r.x*r.x+r.y*r.y+r.z*r.z+r.s*r.s); // normalize
return <r.x*m, r.y*m, r.z*m, r.s*m>;
}
See also: Slerp