Fix slerp

This commit is contained in:
Brendan Zabarauskas 2013-10-13 06:54:24 +11:00
parent cae2839a3b
commit 2ac675ae10
2 changed files with 7 additions and 6 deletions

View file

@ -11,6 +11,7 @@ Erick Tryzelaar
Luqman Aden Luqman Aden
Maik Klein Maik Klein
Mikko Perttunen Mikko Perttunen
Tomasz Stachowiak
With thanks to: With thanks to:

View file

@ -252,14 +252,14 @@ impl<S: Float> Quat<S> {
// stay within the domain of acos() // stay within the domain of acos()
let robust_dot = dot.clamp(&-one::<S>(), &one::<S>()); let robust_dot = dot.clamp(&-one::<S>(), &one::<S>());
let theta: Rad<S> = acos(robust_dot.clone()); // the angle between the quaternions let theta: Rad<S> = acos(robust_dot.clone());
let theta: Rad<S> = theta.mul_s(amount); // the fraction of theta specified by `amount`
let q = other.sub_q(&self.mul_s(robust_dot)) let scale1 = sin(theta.mul_s(one::<S>() - amount));
.normalize(); let scale2 = sin(theta.mul_s(amount));
self.mul_s(cos(theta.clone())) self.mul_s(scale1)
.add_q(&q.mul_s(sin(theta))) .add_q(&other.mul_s(scale2))
.mul_s(sin(theta).recip())
} }
} }
} }