From 2ac675ae100f612a422d0be53043f579dbd272b3 Mon Sep 17 00:00:00 2001 From: Brendan Zabarauskas Date: Sun, 13 Oct 2013 06:54:24 +1100 Subject: [PATCH] Fix slerp --- AUTHORS | 1 + src/cgmath/quaternion.rs | 12 ++++++------ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/AUTHORS b/AUTHORS index e834dec..3fa559d 100644 --- a/AUTHORS +++ b/AUTHORS @@ -11,6 +11,7 @@ Erick Tryzelaar Luqman Aden Maik Klein Mikko Perttunen +Tomasz Stachowiak With thanks to: diff --git a/src/cgmath/quaternion.rs b/src/cgmath/quaternion.rs index 8de82ff..29cc10f 100644 --- a/src/cgmath/quaternion.rs +++ b/src/cgmath/quaternion.rs @@ -252,14 +252,14 @@ impl Quat { // stay within the domain of acos() let robust_dot = dot.clamp(&-one::(), &one::()); - let theta: Rad = acos(robust_dot.clone()); // the angle between the quaternions - let theta: Rad = theta.mul_s(amount); // the fraction of theta specified by `amount` + let theta: Rad = acos(robust_dot.clone()); - let q = other.sub_q(&self.mul_s(robust_dot)) - .normalize(); + let scale1 = sin(theta.mul_s(one::() - amount)); + let scale2 = sin(theta.mul_s(amount)); - self.mul_s(cos(theta.clone())) - .add_q(&q.mul_s(sin(theta))) + self.mul_s(scale1) + .add_q(&other.mul_s(scale2)) + .mul_s(sin(theta).recip()) } } }