]> git.mxchange.org Git - simgear.git/commitdiff
Allow adding a contition to locked-track animation
authorThomas Geymayer <tomgey@gmail.com>
Wed, 1 May 2013 22:47:24 +0000 (00:47 +0200)
committerThomas Geymayer <tomgey@gmail.com>
Wed, 1 May 2013 22:47:51 +0000 (00:47 +0200)
simgear/misc/sg_path.cxx
simgear/nasal/cppbind/detail/to_nasal_helper.cxx
simgear/scene/model/SGTrackToAnimation.cxx
simgear/scene/model/animation.cxx
simgear/scene/model/animation.hxx
simgear/structure/SGExpression.hxx

index 2b4536a0d7f3ea226fc718085b3f06fac1285cba..7db261da67e6314cb56119ad2218f7a267b91080 100644 (file)
@@ -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
index d3dd584f156f92af32ee2b1d76974429f72a41c6..8e6e22b639a74d5b1a3fb46188b78e3526d95618 100644 (file)
@@ -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<int>(str.size()));
     return ret;
   }
 
index 38a79b7d73d7a455c13ba685ffd11d2e9bbdd4bf..d80e0b7863daa9c28f8f58bfa25adc1d7ab9dfb8 100644 (file)
@@ -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<SGCondition const>      _condition;
+    SGExpressiond_ref   _root_disabled_value,
+                        _slave_disabled_value;
 };
 
 //------------------------------------------------------------------------------
index 180b1851f6586c0ab66f93fb06177bfd18712625..649cc108b960b0bdba52a475cbc8e5a33fa24637 100644 (file)
@@ -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<double>(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)
 {
index 5afc8c1972d4a56c8338ffdf91022b625e9671fd..8cf0b0205a07206824de521c73d98d25e1e3967c 100644 (file)
@@ -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,
index c5ef8761ffbbca2e3773128fabb42fd89491c163..193dbbca86a86e4173fa5b61a35a8f0c57194a70 100644 (file)
@@ -900,6 +900,11 @@ typedef SGExpression<float> SGExpressionf;
 typedef SGExpression<double> SGExpressiond;
 typedef SGExpression<bool> SGExpressionb;
 
+typedef SGSharedPtr<SGExpressioni> SGExpressioni_ref;
+typedef SGSharedPtr<SGExpressionf> SGExpressionf_ref;
+typedef SGSharedPtr<SGExpressiond> SGExpressiond_ref;
+typedef SGSharedPtr<SGExpressionb> SGExpressionb_ref;
+
 /**
  * Global function to make an expression out of properties.