]> git.mxchange.org Git - flightgear.git/blobdiff - src/AIModel/AIBase.cxx
Remove unused variables
[flightgear.git] / src / AIModel / AIBase.cxx
index 28944390218b3edc59e51ae9b4447671bba3bdd5..391cc577b04d4ba3974cb487492ecfa5c1294108 100644 (file)
 #  include <config.h>
 #endif
 
-
 #include <simgear/compiler.h>
 
 #include STL_STRING
 
 #include <osg/ref_ptr>
 #include <osg/Node>
+#include <osgDB/FileUtils>
 
 #include <simgear/math/point3d.hxx>
 #include <simgear/math/polar3d.hxx>
 #include <simgear/math/sg_geodesy.hxx>
 #include <simgear/misc/sg_path.hxx>
 #include <simgear/scene/model/location.hxx>
-#include <simgear/scene/model/model.hxx>
+#include <simgear/scene/model/modellib.hxx>
 #include <simgear/scene/util/SGNodeMasks.hxx>
 #include <simgear/debug/logstream.hxx>
 #include <simgear/props/props.hxx>
 #include <Scripting/NasalSys.hxx>
 
 #include "AIBase.hxx"
+#include "AIModelData.hxx"
 #include "AIManager.hxx"
 
 const double FGAIBase::e = 2.71828183;
 const double FGAIBase::lbs_to_slugs = 0.031080950172;   //conversion factor
 
+using namespace simgear;
 
 FGAIBase::FGAIBase(object_type ot) :
     props( NULL ),
@@ -138,6 +140,7 @@ void FGAIBase::update(double dt) {
 void FGAIBase::Transform() {
 
     if (!invisible) {
+        aip.setVisible(true);
         aip.setPosition(pos);
 
         if (no_roll)
@@ -146,43 +149,49 @@ void FGAIBase::Transform() {
             aip.setOrientation(roll, pitch, hdg);
 
         aip.update();
+    } else {
+        aip.setVisible(false);
+        aip.update();
     }
 
 }
 
 bool FGAIBase::init(bool search_in_AI_path) {
+    osg::ref_ptr<osgDB::ReaderWriter::Options> opt=
+        new osgDB::ReaderWriter::Options(*osgDB::Registry::instance()->getOptions());
+
+    if(search_in_AI_path)
+    {
+        SGPath ai_path(globals->get_fg_root());
+        ai_path.append("AI");
+        opt->getDatabasePathList().push_front(ai_path.str());
+    }
 
-    if (!model_path.empty()) {
-
-        if ( search_in_AI_path
-                && (model_path.substr(model_path.size() - 4, 4) == ".xml")) {
-            SGPath ai_path("AI");
-            ai_path.append(model_path);
-            try {
-                model = load3DModel( globals->get_fg_root(), ai_path.str(), props,
-                        globals->get_sim_time_sec() );
-            } catch (const sg_exception &e) {
-                model = NULL;
-            }
-        } else
-            model = NULL;
-
-        if (!model.get()) {
-            try {
-                model = load3DModel( globals->get_fg_root(), model_path, props,
-                        globals->get_sim_time_sec() );
-            } catch (const sg_exception &e) {
-                model = NULL;
-            }
-        }
+    string f = osgDB::findDataFile(model_path, opt.get());
 
-    }
+    if(f.empty())
+        f="Models/Geometry/glider.ac";
 
-    if (model.get()) {
+    model = load3DModel(f, props);
+
+    if (model.valid()) {
+        model->setNodeMask(model->getNodeMask() & ~SG_NODEMASK_TERRAIN_BIT);
         aip.init( model.get() );
         aip.setVisible(true);
         invisible = false;
         globals->get_scenery()->get_scene_graph()->addChild(aip.getSceneGraph());
+
+    } else if (!model_path.empty()) {
+        SG_LOG(SG_INPUT, SG_WARN, "AIBase: Could not load model " << model_path);
+    }
+
+    setDie(false);
+    return true;
+}
+
+void FGAIBase::initModel(osg::Node *node)
+{
+    if (model.valid()) {
         fgSetString("/ai/models/model-added", props->getPath());
 
     } else if (!model_path.empty()) {
@@ -191,18 +200,12 @@ bool FGAIBase::init(bool search_in_AI_path) {
 
     props->setStringValue("submodels/path", _path.c_str());
     setDie(false);
-    return true;
 }
 
 
-osg::Node* FGAIBase::load3DModel(const string& fg_root,
-                      const string &path,
-                      SGPropertyNode *prop_root,
-                      double sim_time_sec)
+osg::Node* FGAIBase::load3DModel(const string &path, SGPropertyNode *prop_root)
 {
-  model = sgLoad3DModel(fg_root, path, prop_root, sim_time_sec, 0,
-                        new FGNasalModelData(prop_root));
-  model->setNodeMask(model->getNodeMask() & ~SG_NODEMASK_TERRAIN_BIT);
+  model = SGModelLib::loadPagedModel(path, prop_root, new FGAIModelData(this, prop_root));
   return model.get();
 }
 
@@ -435,15 +438,7 @@ SGVec3d FGAIBase::getCartPosAt(const SGVec3d& _off) const {
 }
 
 SGVec3d FGAIBase::getCartPos() const {
-    // Transform that one to the horizontal local coordinate system.
-    SGQuatd hlTrans = SGQuatd::fromLonLat(pos);
-
-    // and postrotate the orientation of the AIModel wrt the horizontal
-    // local frame
-    hlTrans *= SGQuatd::fromYawPitchRollDeg(hdg, pitch, roll);
-
     SGVec3d cartPos = SGVec3d::fromGeod(pos);
-
     return cartPos;
 }
 
@@ -470,6 +465,12 @@ void FGAIBase::_setLatitude ( double latitude )  {
     pos.setLatitudeDeg(latitude);
 }
 
+void FGAIBase::_setUserPos(){
+    userpos.setLatitudeDeg(manager->get_user_latitude());
+    userpos.setLongitudeDeg(manager->get_user_longitude());
+    userpos.setElevationM(manager->get_user_altitude() * SG_FEET_TO_METER);
+}
+
 void FGAIBase::_setSubID( int s ) {
     _subID = s;
 }
@@ -586,6 +587,18 @@ double FGAIBase::_getHeading() const {
     return hdg;
 }
 
+double  FGAIBase::_getXOffset() const {
+    return _x_offset;
+}
+
+double  FGAIBase::_getYOffset() const {
+    return _y_offset;
+}
+
+double  FGAIBase::_getZOffset() const {
+    return _z_offset;
+}
+
 const char* FGAIBase::_getPath() const {
     return model_path.c_str();
 }
@@ -606,7 +619,6 @@ const char* FGAIBase::_getSubmodel() const {
     return _submodel.c_str();
 }
 
-
 void FGAIBase::CalculateMach() {
     // Calculate rho at altitude, using standard atmosphere
     // For the temperature T and the pressure p,