]> git.mxchange.org Git - flightgear.git/blobdiff - src/AIModel/AIBase.cxx
add <load>/<unload> support to AI models, including aircraft models. For
[flightgear.git] / src / AIModel / AIBase.cxx
index 3750d695f133f9fb5bffb8a5ae357c2ee1d9e204..d7eda2d56fe17a4a7d93c249a8d76909bed96869 100644 (file)
@@ -15,7 +15,7 @@
 //
 // You should have received a copy of the GNU General Public License
 // along with this program; if not, write to the Free Software
-// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
 
 #ifdef HAVE_CONFIG_H
@@ -39,6 +39,7 @@
 
 #include <Main/globals.hxx>
 #include <Scenery/scenery.hxx>
+#include <Scripting/NasalSys.hxx>
 
 
 #include "AIBase.hxx"
@@ -64,7 +65,6 @@ FGAIBase::FGAIBase(object_type ot)
     invisible = true;
     no_roll = true;
     life = 900;
-    index = 0;
     delete_me = false;
 }
 
@@ -74,10 +74,13 @@ FGAIBase::~FGAIBase() {
         globals->get_scenery()->unregister_placement_transform(aip.getTransform());
         globals->get_scenery()->get_scene_graph()->removeKid(aip.getSceneGraph());
     }
-    SGPropertyNode *root = globals->get_props()->getNode("ai/models", true);
-    root->removeChild(getTypeString(), index);
+    if (props) {
+      SGPropertyNode* parent = props->getParent();
+      if (parent)
+        parent->removeChild(props->getName(), props->getIndex(), false);
+    }
     delete fp;
-    fp = NULL;
+    fp = 0;
 }
 
 
@@ -119,11 +122,6 @@ void FGAIBase::Transform() {
 
 bool FGAIBase::init() {
 
-   SGPropertyNode *root = globals->get_props()->getNode("ai/models", true);
-
-   index = manager->getNum(_otype) - 1;
-   props = root->getNode(getTypeString(), index, true);
-
    if (!model_path.empty()) {
      try {
        model = load3DModel( globals->get_fg_root(), model_path, props,
@@ -165,7 +163,8 @@ ssgBranch * FGAIBase::load3DModel(const string& fg_root,
       model = sgLoad3DModel(fg_root,
                            path,
                            prop_root,
-                           sim_time_sec);
+                           sim_time_sec, 0,
+                           new FGNasalModelData);
       manager->setModel(path, model);
     }
   
@@ -332,35 +331,23 @@ double FGAIBase::UpdateRadar(FGAIManager* manager)
    return range_ft2;
 }
 
-Point3D
-FGAIBase::getCartPosAt(const Point3D& off) const
+SGVec3d
+FGAIBase::getCartPosAt(const SGVec3d& _off) const
 {
-  // The offset converted to the usual body fixed coordinate system.
-  sgdVec3 sgdOff;
-  sgdSetVec3(sgdOff, -off.x(), off.z(), -off.y());
-
   // Transform that one to the horizontal local coordinate system.
-  sgdMat4 hlTrans;
-  sgdMakeRotMat4(hlTrans, hdg, pitch, roll);
-  sgdXformPnt3(sgdOff, hlTrans);
-
-  // Now transform to the wgs84 earth centeres system.
-  Point3D pos2(pos.lon()* SGD_DEGREES_TO_RADIANS,
-               pos.lat() * SGD_DEGREES_TO_RADIANS,
-               pos.elev());
-  Point3D cartPos3D = sgGeodToCart(pos2);
-  sgdMat4 ecTrans;
-  sgdMakeCoordMat4(ecTrans, cartPos3D.x(), cartPos3D.y(), cartPos3D.z(),
-                   pos.lon(), 0, - 90 - pos.lat());
-  sgdXformPnt3(sgdOff, ecTrans);
-
-  return Point3D(sgdOff[0], sgdOff[1], sgdOff[2]);
-}
+  SGQuatd hlTrans = SGQuatd::fromLonLatDeg(pos.lon(), pos.lat());
+  // and postrotate the orientation of the AIModel wrt the horizontal
+  // local frame
+  hlTrans *= SGQuatd::fromYawPitchRollDeg(hdg, pitch, roll);
 
-Point3D
-FGAIBase::getGeocPosAt(const Point3D& off) const
-{
-  return sgCartToGeod(getCartPosAt(off));
+  // The offset converted to the usual body fixed coordinate system
+  // rotated to the earth fiexed coordinates axis
+  SGVec3d off = hlTrans.backTransform(_off);
+
+  // Add the position offset of the AIModel to gain the earth centered position
+  SGVec3d cartPos = SGGeod::fromDegFt(pos.lon(), pos.lat(), pos.elev());
+
+  return cartPos + off;
 }
 
 /*