X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FModel%2Fmodelmgr.cxx;h=46ed240f4c8d2f17c7e3d17a4e099bc8d484ad0c;hb=e600cd3d000723b7b7fd4557ad72cfe971daf423;hp=0310274bd612c38cf55dbb38ff08a17e0dd9ac26;hpb=6110139197f594f7703cb52235f1de63feb68745;p=flightgear.git diff --git a/src/Model/modelmgr.cxx b/src/Model/modelmgr.cxx index 0310274bd..46ed240f4 100644 --- a/src/Model/modelmgr.cxx +++ b/src/Model/modelmgr.cxx @@ -18,8 +18,6 @@ #include #include -#include - #include #include #include @@ -71,13 +69,14 @@ FGModelMgr::add_model (SGPropertyNode * node) SG_LOG(SG_AIRCRAFT, SG_INFO, "Adding model " << node->getStringValue("name", "[unnamed]")); - const char *path = node->getStringValue("path", "Models/Geometry/glider.ac"); + const char *model_path = node->getStringValue("path", "Models/Geometry/glider.ac"); osg::Node *object; try { - object = SGModelLib::loadDeferredModel(path, globals->get_props()); + std::string fullPath = simgear::SGModelLib::findDataFile(model_path); + object = SGModelLib::loadDeferredModel(fullPath, globals->get_props()); } catch (const sg_throwable& t) { - SG_LOG(SG_AIRCRAFT, SG_ALERT, "Error loading " << path << ":\n " + SG_LOG(SG_AIRCRAFT, SG_ALERT, "Error loading " << model_path << ":\n " << t.getFormattedMessage() << t.getOrigin()); return; } @@ -88,27 +87,25 @@ FGModelMgr::add_model (SGPropertyNode * node) instance->node = node; model->init( object ); - - // Set position and orientation either - // indirectly through property refs - // or directly with static values. + double lon = node->getDoubleValue("longitude-deg"), + lat = node->getDoubleValue("latitude-deg"), + elevFt = node->getDoubleValue("elevation-ft"); + + model->setPosition(SGGeod::fromDegFt(lon, lat, elevFt)); +// Set position and orientation either +// indirectly through property refs +// or directly with static values. SGPropertyNode * child = node->getChild("longitude-deg-prop"); if (child != 0) instance->lon_deg_node = fgGetNode(child->getStringValue(), true); - else - model->setLongitudeDeg(node->getDoubleValue("longitude-deg")); child = node->getChild("latitude-deg-prop"); if (child != 0) instance->lat_deg_node = fgGetNode(child->getStringValue(), true); - else - model->setLatitudeDeg(node->getDoubleValue("latitude-deg")); child = node->getChild("elevation-ft-prop"); if (child != 0) instance->elev_ft_node = fgGetNode(child->getStringValue(), true); - else - model->setElevationFt(node->getDoubleValue("elevation-ft")); child = node->getChild("roll-deg-prop"); if (child != 0) @@ -150,7 +147,7 @@ namespace { double testNan(double val) throw (sg_range_exception) { - if (osg::isNaN(val)) + if (SGMisc::isNaN(val)) throw sg_range_exception("value is nan"); return val; } @@ -160,18 +157,19 @@ struct UpdateFunctor : public std::unary_function void operator()(FGModelMgr::Instance* instance) const { SGModelPlacement* model = instance->model; - double lon, lat, elev, roll, pitch, heading; - lon = lat = elev = roll = pitch = heading = 0.0; - + double roll, pitch, heading; + roll = pitch = heading = 0.0; + SGGeod pos = model->getPosition(); + try { // Optionally set position from properties if (instance->lon_deg_node != 0) - lon = testNan(instance->lon_deg_node->getDoubleValue()); + pos.setLongitudeDeg(testNan(instance->lon_deg_node->getDoubleValue())); if (instance->lat_deg_node != 0) - lat = testNan(instance->lat_deg_node->getDoubleValue()); + pos.setLatitudeDeg(testNan(instance->lat_deg_node->getDoubleValue())); if (instance->elev_ft_node != 0) - elev = testNan(instance->elev_ft_node->getDoubleValue()); - + pos.setElevationFt(testNan(instance->elev_ft_node->getDoubleValue())); + // Optionally set orientation from properties if (instance->roll_deg_node != 0) roll = testNan(instance->roll_deg_node->getDoubleValue()); @@ -186,14 +184,8 @@ struct UpdateFunctor : public std::unary_function << " has invalid values"); return; } - // Optionally set position from properties - if (instance->lon_deg_node != 0) - model->setLongitudeDeg(lon); - if (instance->lat_deg_node != 0) - model->setLatitudeDeg(lat); - if (instance->elev_ft_node != 0) - model->setElevationFt(elev); + model->setPosition(pos); // Optionally set orientation from properties if (instance->roll_deg_node != 0) model->setRollDeg(roll);