[−][src]Function minterpolate::quasi_spherical_linear_interpolate
pub fn quasi_spherical_linear_interpolate<T>(
input: f32,
inputs: &[f32],
outputs: &[T],
normalize: bool
) -> T where
T: InterpolationPrimitive + Clone,
Do quasi spherical linear interpolation.
This should only ever be used on quaternions, it will produce incorrect results for other data types. This will produce a result that compared to real spherical linear interpolation has an error around 10^-4, but runs much faster because it does no trigonometry or sqrt calls.
Algorithm was created by Jonathan Blow: Hacking Quaternions
f(d) = d <= 0.5 => lerp(p0, p1, y'(d))
f(d) = d > 0.5 => lerp(p0, p1, 1 - y'(1 - d))
y'(d) = 2 * k * d^2 - 3 * k * d + k + 1
k = worst_case_slope * (1 - attenuation * dot(p0, p1))^2
d = (t - t0) / (t1 - t0)
p0 = output at left keyframe
p1 = output at right keyframe
t0 = input at left keyframe
t1 = input at right keyframe
Parameters:
input
: the input value to the functioninputs
: list of discrete input values for each keyframeoutputs
: list of output values to interpolate between, for spherical linear interpolation this should be the same size asinputs
normalize
: if true, normalize the interpolated value before returning it