Fix to Quat::slerp so that it interpolates along the shortest path.

This commit is contained in:
Robert Osfield 2002-06-25 20:36:17 +00:00
parent cbeeeefdab
commit 3765631cd7

View File

@ -151,9 +151,17 @@ void Quat::slerp( const float t, const Quat& from, const Quat& to )
{ {
const double epsilon = 0.00001; const double epsilon = 0.00001;
double omega, cosomega, sinomega, scale_from, scale_to ; double omega, cosomega, sinomega, scale_from, scale_to ;
// this is a dot product osg::Quat quatTo(to);
cosomega = from.asVec4() * to.asVec4() ; // 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 ) if( (1.0 - cosomega) > epsilon )
{ {
@ -175,7 +183,8 @@ void Quat::slerp( const float t, const Quat& from, const Quat& to )
} }
// use Vec4 arithmetic // 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 // so that we get a Vec4
} }