From 3765631cd7bda540fdc03bf6716bb457ad83f4e0 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 25 Jun 2002 20:36:17 +0000 Subject: [PATCH] Fix to Quat::slerp so that it interpolates along the shortest path. --- src/osg/Quat.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/osg/Quat.cpp b/src/osg/Quat.cpp index f17d5c31e..ddafb2e48 100644 --- a/src/osg/Quat.cpp +++ b/src/osg/Quat.cpp @@ -151,9 +151,17 @@ void Quat::slerp( const float t, const Quat& from, const Quat& to ) { const double epsilon = 0.00001; double omega, cosomega, sinomega, scale_from, scale_to ; - - // this is a dot product - cosomega = from.asVec4() * to.asVec4() ; + + osg::Quat quatTo(to); + // this is a dot product + + cosomega = from.asVec4() * to.asVec4(); + + if ( cosomega <0.0 ) + { + cosomega = -cosomega; + quatTo.set(-to._fv); + } if( (1.0 - cosomega) > epsilon ) { @@ -175,7 +183,8 @@ void Quat::slerp( const float t, const Quat& from, const Quat& to ) } // use Vec4 arithmetic - _fv = (from._fv*scale_from) + (to._fv*scale_to); + _fv = (from._fv*scale_from) + (quatTo._fv*scale_to); + // so that we get a Vec4 }