]> git.mxchange.org Git - flightgear.git/blobdiff - src/Model/modelmgr.cxx
I have added Aaron Wilson's virtual 3d runway projection to the HUD.
[flightgear.git] / src / Model / modelmgr.cxx
index 4ed1c6bbbdde00f149ca50f0b8d54552ab1c721d..4175f65bf9de7bd0275bbe635ea6882c51fe9421 100644 (file)
@@ -3,9 +3,26 @@
 //
 // This file is in the Public Domain, and comes with no warranty.
 
-#include "modelmgr.hxx"
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
+#include <simgear/compiler.h>
+
+#include <vector>
+
+#include <plib/ssg.h>
+
+#include <simgear/scene/model/placement.hxx>
+#include <simgear/scene/model/model.hxx>
 
 #include <Main/fg_props.hxx>
+#include <Scenery/scenery.hxx>
+
+
+#include "modelmgr.hxx"
+
+SG_USING_STD(vector);
 
 
 FGModelMgr::FGModelMgr ()
@@ -15,8 +32,8 @@ FGModelMgr::FGModelMgr ()
 
 FGModelMgr::~FGModelMgr ()
 {
-  for (int i = 0; i < _instances.size(); i++) {
-    globals->get_models_branch()
+  for (unsigned int i = 0; i < _instances.size(); i++) {
+    globals->get_scenery()->get_models_branch()
       ->removeKid(_instances[i]->model->getSceneGraph());
     delete _instances[i];
   }
@@ -25,16 +42,22 @@ FGModelMgr::~FGModelMgr ()
 void
 FGModelMgr::init ()
 {
-  vector<SGPropertyNode *> model_nodes =
+  vector<SGPropertyNode_ptr> model_nodes =
     fgGetNode("/models", true)->getChildren("model");
-  for (int i = 0; i < model_nodes.size(); i++) {
+  for (unsigned int i = 0; i < model_nodes.size(); i++) {
     SGPropertyNode * node = model_nodes[i];
     SG_LOG(SG_GENERAL, SG_INFO,
           "Adding model " << node->getStringValue("name", "[unnamed]"));
     Instance * instance = new Instance;
-    FG3DModel * model = new FG3DModel;
+    SGModelPlacement *model = new SGModelPlacement;
     instance->model = model;
-    model->init(node->getStringValue("path", "Models/Geometry/glider.ac"));
+    ssgBranch *object
+        = sgLoad3DModel( globals->get_fg_root(),
+                         node->getStringValue("path",
+                                              "Models/Geometry/glider.ac"),
+                         globals->get_props(),
+                         globals->get_sim_time_sec() );
+    model->init( object );
 
                                // Set position and orientation either
                                // indirectly through property refs
@@ -76,10 +99,10 @@ FGModelMgr::init ()
       model->setHeadingDeg(node->getDoubleValue("heading-deg"));
 
                                // Add this model to the global scene graph
-    globals->get_scene_graph()->addKid(model->getSceneGraph());
+    globals->get_scenery()->get_scene_graph()->addKid(model->getSceneGraph());
 
                                // Save this instance for updating
-    _instances.push_back(instance);
+    add_instance(instance);
   }
 }
 
@@ -94,11 +117,11 @@ FGModelMgr::unbind ()
 }
 
 void
-FGModelMgr::update (int dt)
+FGModelMgr::update (double dt)
 {
-  for (int i = 0; i < _instances.size(); i++) {
+  for (unsigned int i = 0; i < _instances.size(); i++) {
     Instance * instance = _instances[i];
-    FG3DModel * model = instance->model;
+    SGModelPlacement * model = instance->model;
 
                                // Optionally set position from properties
     if (instance->lon_deg_node != 0)
@@ -116,10 +139,29 @@ FGModelMgr::update (int dt)
     if (instance->heading_deg_node != 0)
       model->setHeadingDeg(instance->heading_deg_node->getDoubleValue());
 
-    instance->model->update(dt);
+    instance->model->update( globals->get_scenery()->get_center() );
   }
 }
 
+void
+FGModelMgr::add_instance (Instance * instance)
+{
+    _instances.push_back(instance);
+}
+
+void
+FGModelMgr::remove_instance (Instance * instance)
+{
+    vector<Instance *>::iterator it;
+    for (it = _instances.begin(); it != _instances.end(); it++) {
+        if (*it == instance) {
+            _instances.erase(it);
+            delete instance;
+            return;
+        }
+    }
+}
+
 void
 FGModelMgr::draw ()
 {