]> git.mxchange.org Git - flightgear.git/blobdiff - src/Model/model.cxx
Make sure that all elapsed time gets passed to update when a subsystem
[flightgear.git] / src / Model / model.cxx
index b32d054ee9c20ae103ba45633db5cc5daa5fddde..00773806e5d0ff90359812115550497734126954 100644 (file)
@@ -11,6 +11,7 @@
 
 #include <plib/sg.h>
 #include <plib/ssg.h>
+#include <plib/ul.h>
 
 #include <simgear/compiler.h>
 #include <simgear/debug/logstream.hxx>
@@ -179,7 +180,7 @@ make_animation (ssgBranch * model,
                 SGPropertyNode_ptr node)
 {
   Animation * animation = 0;
-  const char * type = node->getStringValue("type");
+  const char * type = node->getStringValue("type", "none");
   if (!strcmp("none", type)) {
     animation = new NullAnimation(node);
   } else if (!strcmp("range", type)) {
@@ -253,7 +254,7 @@ fgLoad3DModel (const string &path)
                                 // Load the 3D aircraft object itself
   SGPath xmlpath;
   SGPath modelpath = path;
-  if ( path[ 0 ] == '/' || path[ 0 ] == '\\' || ( isalpha( path[ 0 ] ) && path[ 1 ] == ':' ) ) {
+  if ( ulIsAbsolutePathName( path.c_str() ) ) {
     xmlpath = modelpath;
   }
   else {
@@ -283,8 +284,8 @@ fgLoad3DModel (const string &path)
   }
 
                                 // Set up the alignment node
-  ssgTransform * align = new ssgTransform;
-  align->addKid(model);
+  ssgTransform * alignmainmodel = new ssgTransform;
+  alignmainmodel->addKid(model);
   sgMat4 res_matrix;
   make_offsets_matrix(&res_matrix,
                       props.getFloatValue("/offsets/heading-deg", 0.0),
@@ -293,11 +294,21 @@ fgLoad3DModel (const string &path)
                       props.getFloatValue("/offsets/x-m", 0.0),
                       props.getFloatValue("/offsets/y-m", 0.0),
                       props.getFloatValue("/offsets/z-m", 0.0));
-  align->setTransform(res_matrix);
+  alignmainmodel->setTransform(res_matrix);
+
+                                // Load panels
+  unsigned int i;
+  vector<SGPropertyNode_ptr> panel_nodes = props.getChildren("panel");
+  for (i = 0; i < panel_nodes.size(); i++) {
+    SG_LOG(SG_INPUT, SG_DEBUG, "Loading a panel");
+    FGPanelNode * panel = new FGPanelNode(panel_nodes[i]);
+    if (panel_nodes[i]->hasValue("name"))
+        panel->setName((char *)panel_nodes[i]->getStringValue("name"));
+    model->addKid(panel);
+  }
 
                                 // Load animations
   vector<SGPropertyNode_ptr> animation_nodes = props.getChildren("animation");
-  unsigned int i;
   for (i = 0; i < animation_nodes.size(); i++) {
     const char * name = animation_nodes[i]->getStringValue("name", 0);
     vector<SGPropertyNode_ptr> name_nodes =
@@ -305,14 +316,6 @@ fgLoad3DModel (const string &path)
     make_animation(model, name, name_nodes, animation_nodes[i]);
   }
 
-                                // Load panels
-  vector<SGPropertyNode_ptr> panel_nodes = props.getChildren("panel");
-  for (i = 0; i < panel_nodes.size(); i++) {
-    printf("Reading a panel in model.cxx\n");
-    FGPanelNode * panel = new FGPanelNode(panel_nodes[i]);
-    model->addKid(panel);
-  }
-
                                 // Load sub-models
   vector<SGPropertyNode_ptr> model_nodes = props.getChildren("model");
   for (i = 0; i < model_nodes.size(); i++) {
@@ -333,7 +336,7 @@ fgLoad3DModel (const string &path)
     model->addKid(align);
   }
 
-  return model;
+  return alignmainmodel;
 }
 
 
@@ -507,10 +510,9 @@ TimedAnimation::update ()
     float sim_time_sec = globals->get_sim_time_sec();
     if ((sim_time_sec - _last_time_sec) >= _duration_sec) {
         _last_time_sec = sim_time_sec;
+        _step++;
         if (_step >= getBranch()->getNumKids())
             _step = 0;
-        else
-            _step++;
         ((ssgSelector *)getBranch())->selectStep(_step);
     }
 }
@@ -551,7 +553,7 @@ void
 RotateAnimation::update ()
 {
   if (_table == 0) {
-    _position_deg = (_prop->getDoubleValue() + _offset_deg) * _factor;
+   _position_deg = _prop->getDoubleValue() * _factor + _offset_deg;
    if (_has_min && _position_deg < _min_deg)
      _position_deg = _min_deg;
    if (_has_max && _position_deg > _max_deg)