Fix to Quat::slerp so that it interpolates along the shortest path.
This commit is contained in:
parent
cbeeeefdab
commit
3765631cd7
@ -152,9 +152,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 ;
|
||||||
|
|
||||||
|
osg::Quat quatTo(to);
|
||||||
// this is a dot product
|
// this is a dot product
|
||||||
|
|
||||||
cosomega = from.asVec4() * to.asVec4();
|
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 )
|
||||||
{
|
{
|
||||||
omega= acos(cosomega) ; // 0 <= omega <= Pi (see man acos)
|
omega= acos(cosomega) ; // 0 <= omega <= Pi (see man acos)
|
||||||
@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user