From ff593b1faf68003d27ecd7c909a8f56d727d778e Mon Sep 17 00:00:00 2001 From: Squareys Date: Sat, 10 Oct 2015 16:22:24 +0200 Subject: [PATCH] Math: Cleanup ScLERP implementation. - Use explicit conversion to `T` - Use `std::` for `acos, cos, sin` to avoid use of double only functions - Do not mutate variables in math code to avoid confusion Signed-off-by: Squareys --- src/Magnum/Math/DualQuaternion.h | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/Magnum/Math/DualQuaternion.h b/src/Magnum/Math/DualQuaternion.h index 3f8f10674..d9218d71e 100644 --- a/src/Magnum/Math/DualQuaternion.h +++ b/src/Magnum/Math/DualQuaternion.h @@ -66,20 +66,20 @@ template inline DualQuaternion sclerp(const DualQuaternion& from, const T dotResult = dot(from.real().vector(), to.real().vector()); - /* Multiplying with -1.0f ensures shortest path when dot < 0. */ + /* Multiplying with -1 ensures shortest path when dot < 0 */ /* diff = \hat d = p^*q */ - const DualQuaternion diff = from.quaternionConjugated()*((dotResult < .0) ? -to : to); + const DualQuaternion diff = from.quaternionConjugated()*((dotResult < T(0)) ? -to : to); /* angle = t \hat a_D */ - const T angle = acos(diff.real().scalar())*t; + const T angle = std::acos(diff.real().scalar())*t; /* precompute sin/cos for manifold use */ - const T sinAngle = sin(angle); - const T cosAngle = cos(angle); + const T sinAngle = std::sin(angle); + const T cosAngle = std::cos(angle); /* merely a shortcut */ const Vector3& m = diff.real().vector(); /* invr = \frac 1 {|l_V|} */ - const T invr = 1/m.length(); + const T invr = m.lengthInverted(); /* direction = \hat {\boldsymbol n} = \hat l_V \frac 1 {|l_V|} */ const Vector3 direction = m*invr; @@ -88,14 +88,14 @@ template inline DualQuaternion sclerp(const DualQuaternion& from, const Vector3 v = direction*sinAngle; /* pitch = \frac {\hat a_D} 2 = m_S \frac 1 {|l_V|} */ - T pitch = -diff.dual().scalar()*invr; + const T pitch = -diff.dual().scalar()*invr; /* moment = \hat {\boldsymbol n}_D */ const Vector3 moment = (diff.dual().vector() - (direction*(pitch*diff.real().scalar())))*invr; - pitch *= t; + const T pitchT = pitch*t; /* Vector of dual part of q_{ScLERP} */ - const Vector3 v2 = moment*sinAngle + direction*(pitch*cosAngle); + const Vector3 v2 = moment*sinAngle + direction*(pitchT*cosAngle); - return from*DualQuaternion{Quaternion{v, cosAngle}, Quaternion{v2, -pitch*sinAngle}}; + return from*DualQuaternion{Quaternion{v, cosAngle}, Quaternion{v2, -pitchT*sinAngle}}; } /**