]> git.mxchange.org Git - flightgear.git/commitdiff
Made it possible to add and remove models programmatically, as
authordavid <david>
Mon, 30 Dec 2002 15:44:11 +0000 (15:44 +0000)
committerdavid <david>
Mon, 30 Dec 2002 15:44:11 +0000 (15:44 +0000)
requested by Leon Otte.

src/Model/modelmgr.cxx
src/Model/modelmgr.hxx

index f3f7cc8e4f83468743796b888063a759354fa6f0..3507cc4f6e36839709acc9d87fc1dd246e51173b 100644 (file)
@@ -83,7 +83,7 @@ FGModelMgr::init ()
     globals->get_scenery()->get_scene_graph()->addKid(model->getSceneGraph());
 
                                // Save this instance for updating
-    _instances.push_back(instance);
+    add_instance(instance);
   }
 }
 
@@ -124,6 +124,19 @@ FGModelMgr::update (double dt)
   }
 }
 
+void
+FGModelMgr::add_instance (Instance * instance)
+{
+    _instances.push_back(instance);
+}
+
+void
+FGModelMgr::remove_instance (Instance * instance)
+{
+    _instances.erase(find(_instances.begin(), _instances.end(), instance));
+    delete instance;
+}
+
 void
 FGModelMgr::draw ()
 {
index d0b7841cd7410007b5a4bb3b34bc74ff7a61bd19..87ee0fe76977b36e4870c96feeae991bed655dba 100644 (file)
@@ -30,18 +30,20 @@ class FGModelPlacement;
 class FGModelMgr : public FGSubsystem
 {
 public:
-  FGModelMgr ();
-  virtual ~FGModelMgr ();
-
-  virtual void init ();
-  virtual void bind ();
-  virtual void unbind ();
-  virtual void update (double dt);
-
-  virtual void draw ();
-
-private:
 
+  /**
+   * A dynamically-placed model using properties.
+   *
+   * The model manager uses the property nodes to update the model's
+   * position and orientation; any of the property node pointers may
+   * be set to zero to avoid update.  Normally, a caller should
+   * load the model by instantiating FGModelPlacement with the path
+   * to the model or its XML wrapper, then assign any relevant
+   * property node pointers.
+   *
+   * @see FGModelPlacement
+   * @see FGModelMgr#add_instance
+   */
   struct Instance
   {
     Instance ();
@@ -55,6 +57,38 @@ private:
     SGPropertyNode * heading_deg_node;
   };
 
+  FGModelMgr ();
+  virtual ~FGModelMgr ();
+
+  virtual void init ();
+  virtual void bind ();
+  virtual void unbind ();
+  virtual void update (double dt);
+
+  /**
+   * Add an instance of a dynamic model to the manager.
+   *
+   * NOTE: pointer ownership is transferred to the model manager!
+   *
+   * The caller is responsible for setting up the Instance structure
+   * as required.  The model manager will continuously update the
+   * location and orientation of the model based on the current
+   * values of the properties.
+   */
+  virtual void add_instance (Instance * instance);
+
+
+  /**
+   * Remove an instance of a dynamic model from the manager.
+   *
+   * NOTE: the manager will delete the instance as well.
+   */
+  virtual void remove_instance (Instance * instance);
+
+  virtual void draw ();
+
+private:
+
   vector<Instance *> _instances;
 
   ssgSelector * _selector;