track-to animation: fix "short" and "long" tracking.

This commit is contained in:
Thomas Geymayer 2013-11-10 11:14:50 +01:00
parent 508a5c5f66
commit 9f89737986

View File

@ -106,13 +106,17 @@ class FindGroupVisitor:
*/ */
double angleFromSSS(double side1, double side2, double opposite) double angleFromSSS(double side1, double side2, double opposite)
{ {
return std::acos double c = ( SGMiscd::pow<2>(side1)
( + SGMiscd::pow<2>(side2)
( SGMiscd::pow<2>(side1) - SGMiscd::pow<2>(opposite)
+ SGMiscd::pow<2>(side2) ) / (2 * side1 * side2);
- SGMiscd::pow<2>(opposite)
) / (2 * side1 * side2) if( c <= -1 )
); return M_PI;
else if( c >= 1 )
return 0;
else
return std::acos(c);
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
@ -270,8 +274,10 @@ class SGTrackToAnimation::UpdateCallback:
root_angle += angleFromSSS(_root_length, dist, _slave_length); root_angle += angleFromSSS(_root_length, dist, _slave_length);
if( _slave_tf ) if( _slave_tf )
{
slave_angle += angleFromSSS(_root_length, _slave_length, dist) slave_angle += angleFromSSS(_root_length, _slave_length, dist)
- SGMiscd::pi(); - SGMiscd::pi();
}
if( _slave_dof >= 2 ) if( _slave_dof >= 2 )
slave_target_dist = _slave_length; slave_target_dist = _slave_length;
} }
@ -282,7 +288,7 @@ class SGTrackToAnimation::UpdateCallback:
// to rotate the objects to reach the target. // to rotate the objects to reach the target.
osg::Vec3 root_dir = target_pos - _node_center; osg::Vec3 root_dir = target_pos - _node_center;
root_dir.normalize(); root_dir.normalize();
osg::Vec3 slave_pos = root_dir * _root_length; osg::Vec3 slave_pos = _node_center + root_dir * _root_length;
slave_target_dist = (target_pos - slave_pos).length(); slave_target_dist = (target_pos - slave_pos).length();
} }