From: Thomas Geymayer Date: Sun, 5 Jan 2014 18:38:03 +0000 (+0100) Subject: Fix track-to animation basic tracking without slave object X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=2335796a28dffe7392e14b43049e2192424d535c;p=simgear.git Fix track-to animation basic tracking without slave object --- diff --git a/simgear/scene/model/SGTrackToAnimation.cxx b/simgear/scene/model/SGTrackToAnimation.cxx index d77879c2..d74034db 100644 --- a/simgear/scene/model/SGTrackToAnimation.cxx +++ b/simgear/scene/model/SGTrackToAnimation.cxx @@ -206,9 +206,7 @@ class SGTrackToAnimation::UpdateCallback: virtual void operator()(osg::Node* node, osg::NodeVisitor* nv) { - if( _root_length <= 0 ) - // TODO prevent invalid animation from being added? - return; + // TODO prevent invalid animation from being added? SGRotateTransform* tf = static_cast(node); @@ -266,37 +264,41 @@ class SGTrackToAnimation::UpdateCallback: y = dir * _up_axis; root_angle += std::atan2(y, x); - // Handle scissor/ik rotation - double dist = dir.length(), - slave_target_dist = 0; - if( dist < _root_length + _slave_length ) + if( _root_length > 0 ) { - root_angle += angleFromSSS(_root_length, dist, _slave_length); - - if( _slave_tf ) + // Handle scissor/ik rotation + double dist = dir.length(), + slave_target_dist = 0; + if( dist < _root_length + _slave_length ) { - slave_angle += angleFromSSS(_root_length, _slave_length, dist) - - SGMiscd::pi(); + root_angle += angleFromSSS(_root_length, dist, _slave_length); + + if( _slave_tf ) + { + slave_angle += angleFromSSS(_root_length, _slave_length, dist) + - SGMiscd::pi(); + } + if( _slave_dof >= 2 ) + slave_target_dist = _slave_length; + } + else if( _slave_dof >= 2 ) + { + // If the distance is too large we need to manually calculate the + // distance of the slave to the target, as it is not possible + // anymore to rotate the objects to reach the target. + osg::Vec3 root_dir = target_pos - _node_center; + root_dir.normalize(); + osg::Vec3 slave_pos = _node_center + root_dir * _root_length; + slave_target_dist = (target_pos - slave_pos).length(); } - if( _slave_dof >= 2 ) - slave_target_dist = _slave_length; - } - else if( _slave_dof >= 2 ) - { - // If the distance is too large we need to manually calculate the - // distance of the slave to the target, as it is not possible anymore - // to rotate the objects to reach the target. - osg::Vec3 root_dir = target_pos - _node_center; - root_dir.normalize(); - osg::Vec3 slave_pos = _node_center + root_dir * _root_length; - slave_target_dist = (target_pos - slave_pos).length(); - } - if( slave_target_dist > 0 ) - // Calculate angle to rotate "out of the plane" to point towards the - // target object. - slave_angle2 = std::asin((_lock_axis * lock_proj) / slave_target_dist) - - _slave_initial_angle2; + if( slave_target_dist > 0 ) + // Calculate angle to rotate "out of the plane" to point towards the + // target object. + slave_angle2 = std::asin( (_lock_axis * lock_proj) + / slave_target_dist ) + - _slave_initial_angle2; + } } else {