From: Thomas Geymayer Date: Wed, 1 May 2013 22:47:24 +0000 (+0200) Subject: Allow adding a contition to locked-track animation X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=2af78a38740840a7be9c7fbfe244de88d8e3de8c;p=simgear.git Allow adding a contition to locked-track animation --- diff --git a/simgear/misc/sg_path.cxx b/simgear/misc/sg_path.cxx index 2b4536a0..7db261da 100644 --- a/simgear/misc/sg_path.cxx +++ b/simgear/misc/sg_path.cxx @@ -425,7 +425,7 @@ bool SGPath::isAbsolute() const bool SGPath::isNull() const { - return path.empty() || (path == ""); + return path.empty(); } std::string SGPath::str_native() const diff --git a/simgear/nasal/cppbind/detail/to_nasal_helper.cxx b/simgear/nasal/cppbind/detail/to_nasal_helper.cxx index d3dd584f..8e6e22b6 100644 --- a/simgear/nasal/cppbind/detail/to_nasal_helper.cxx +++ b/simgear/nasal/cppbind/detail/to_nasal_helper.cxx @@ -31,7 +31,7 @@ namespace nasal naRef to_nasal_helper(naContext c, const std::string& str) { naRef ret = naNewString(c); - naStr_fromdata(ret, str.c_str(), str.size()); + naStr_fromdata(ret, str.c_str(), static_cast(str.size())); return ret; } diff --git a/simgear/scene/model/SGTrackToAnimation.cxx b/simgear/scene/model/SGTrackToAnimation.cxx index 38a79b7d..d80e0b78 100644 --- a/simgear/scene/model/SGTrackToAnimation.cxx +++ b/simgear/scene/model/SGTrackToAnimation.cxx @@ -85,7 +85,12 @@ class FindGroupVisitor: if( !_group ) _group = &group; else - SG_LOG(SG_IO, SG_WARN, "FindGroupVisitor: name not unique"); + SG_LOG + ( + SG_IO, + SG_WARN, + "FindGroupVisitor: name not unique '" << _name << "'" + ); } protected: @@ -122,7 +127,14 @@ class SGTrackToAnimation::UpdateCallback: _slave_tf(slave_tf), _root_length(0), _slave_length(0), - _root_initial_angle(0) + _root_initial_angle(0), + _condition(anim->getCondition()), + _root_disabled_value( + anim->readOffsetValue("disabled-rotation-deg") + ), + _slave_disabled_value( + anim->readOffsetValue("slave-disabled-rotation-deg") + ) { setName("SGTrackToAnimation::UpdateCallback"); @@ -228,32 +240,49 @@ class SGTrackToAnimation::UpdateCallback: ).preMult(_target_center), dir = target_pos - _node_center; - double offset = -_root_initial_angle; - if( _root_length > 0 ) + double root_angle, + slave_angle; + + if( !_condition || _condition->test() ) { - double dist = dir.length(), - slave_angle = -_slave_initial_angle; - if( dist < _root_length + _slave_length ) - { - offset += angleFromSSS(_root_length, dist, _slave_length); + root_angle = -_root_initial_angle; + slave_angle = -_slave_initial_angle; - if( _slave_tf ) - slave_angle += angleFromSSS(_root_length, _slave_length, dist) - - SGMiscd::pi(); + if( _root_length > 0 ) + { + double dist = dir.length(); + if( dist < _root_length + _slave_length ) + { + root_angle += angleFromSSS(_root_length, dist, _slave_length); + + if( _slave_tf ) + slave_angle += angleFromSSS(_root_length, _slave_length, dist) + - SGMiscd::pi(); + } } - if( _slave_tf ) - _slave_tf->setAngleRad(slave_angle); - } + // Ensure direction is perpendicular to lock axis + float proj = _lock_axis * dir; + if( proj != 0.0 ) + dir -= _lock_axis * proj; - // Ensure direction is perpendicular to lock axis - float proj = _lock_axis * dir; - if( proj != 0.0 ) - dir -= _lock_axis * proj; + float x = dir * _track_axis, + y = dir * _up_axis; + root_angle += std::atan2(y, x); + } + else + { + root_angle = _root_disabled_value + ? SGMiscd::deg2rad(_root_disabled_value->getValue()) + : 0; + slave_angle = _slave_disabled_value + ? SGMiscd::deg2rad(_slave_disabled_value->getValue()) + : 0; + } - float x = dir * _track_axis, - y = dir * _up_axis; - tf->setAngleRad( std::atan2(y, x) + offset ); + tf->setAngleRad( root_angle ); + if( _slave_tf ) + _slave_tf->setAngleRad(slave_angle); traverse(node, nv); } @@ -273,6 +302,10 @@ class SGTrackToAnimation::UpdateCallback: _slave_length, _root_initial_angle, _slave_initial_angle; + + SGSharedPtr _condition; + SGExpressiond_ref _root_disabled_value, + _slave_disabled_value; }; //------------------------------------------------------------------------------ diff --git a/simgear/scene/model/animation.cxx b/simgear/scene/model/animation.cxx index 180b1851..649cc108 100644 --- a/simgear/scene/model/animation.cxx +++ b/simgear/scene/model/animation.cxx @@ -567,6 +567,30 @@ void SGAnimation::readRotationCenterAndAxis( SGVec3d& center, center = readVec3("center", "-m", center); } +//------------------------------------------------------------------------------ +SGExpressiond* SGAnimation::readOffsetValue(const char* tag_name) const +{ + const SGPropertyNode* node = _configNode->getChild(tag_name); + if( !node ) + return 0; + + SGExpressiond_ref expression; + if( !node->nChildren() ) + expression = new SGConstExpression(node->getDoubleValue()); + else + expression = SGReadDoubleExpression(_modelRoot, node->getChild(0)); + + if( !expression ) + return 0; + + expression = expression->simplify(); + + if( expression->isConst() && expression->getValue() == 0 ) + return 0; + + return expression.release(); +} + void SGAnimation::removeMode(osg::Node& node, osg::StateAttribute::GLMode mode) { diff --git a/simgear/scene/model/animation.hxx b/simgear/scene/model/animation.hxx index 5afc8c19..8cf0b020 100644 --- a/simgear/scene/model/animation.hxx +++ b/simgear/scene/model/animation.hxx @@ -73,6 +73,8 @@ protected: const SGVec3d& def = SGVec3d::zeros() ) const; void readRotationCenterAndAxis(SGVec3d& center, SGVec3d& axis) const; + SGExpressiond* readOffsetValue(const char* tag_name) const; + void removeMode(osg::Node& node, osg::StateAttribute::GLMode mode); void removeAttribute(osg::Node& node, osg::StateAttribute::Type type); void removeTextureMode(osg::Node& node, unsigned unit, diff --git a/simgear/structure/SGExpression.hxx b/simgear/structure/SGExpression.hxx index c5ef8761..193dbbca 100644 --- a/simgear/structure/SGExpression.hxx +++ b/simgear/structure/SGExpression.hxx @@ -900,6 +900,11 @@ typedef SGExpression SGExpressionf; typedef SGExpression SGExpressiond; typedef SGExpression SGExpressionb; +typedef SGSharedPtr SGExpressioni_ref; +typedef SGSharedPtr SGExpressionf_ref; +typedef SGSharedPtr SGExpressiond_ref; +typedef SGSharedPtr SGExpressionb_ref; + /** * Global function to make an expression out of properties.