X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FModel%2Fmodelmgr.cxx;h=72d257368421b74b0041f3bd3aeb1ffa985c4bb9;hb=575b3ac98c2aad3fd80375cdfbe49c9180b8788e;hp=680230897cec7562978e3dd94abb9750212412cc;hpb=f3eafe1007d356f9c37985828d3968ae6a162e32;p=flightgear.git diff --git a/src/Model/modelmgr.cxx b/src/Model/modelmgr.cxx index 680230897..72d257368 100644 --- a/src/Model/modelmgr.cxx +++ b/src/Model/modelmgr.cxx @@ -6,9 +6,12 @@ #include #include
+#include -#include "modelmgr.hxx" #include "model.hxx" +#include "placement.hxx" + +#include "modelmgr.hxx" FGModelMgr::FGModelMgr () @@ -18,8 +21,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]; } @@ -30,14 +33,20 @@ FGModelMgr::init () { vector 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; + FGModelPlacement *model = new FGModelPlacement; instance->model = model; - model->init(node->getStringValue("path", "Models/Geometry/glider.ac")); + ssgBranch *object + = fgLoad3DModel( 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 @@ -79,10 +88,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); } } @@ -97,11 +106,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; + FGModelPlacement * model = instance->model; // Optionally set position from properties if (instance->lon_deg_node != 0) @@ -119,10 +128,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::iterator it; + for (it = _instances.begin(); it != _instances.end(); it++) { + if (*it == instance) { + _instances.erase(it); + delete instance; + return; + } + } +} + void FGModelMgr::draw () {