]> git.mxchange.org Git - flightgear.git/blobdiff - src/FDM/YASim/YASim.cxx
MSVC (warning) fixes.
[flightgear.git] / src / FDM / YASim / YASim.cxx
index 730d57e12d5a587df8c8468a881a650860331c3a..d6c2236b4e5485eb50be3a08cbe6f020085e05b6 100644 (file)
@@ -2,13 +2,11 @@
 #include <simgear/debug/logstream.hxx>
 #include <simgear/math/sg_geodesy.hxx>
 #include <simgear/misc/sg_path.hxx>
-#include <simgear/scene/model/location.hxx>
 #include <simgear/scene/model/placement.hxx>
 #include <simgear/xml/easyxml.hxx>
 
 #include <Main/globals.hxx>
 #include <Main/fg_props.hxx>
-#include <Model/acmodel.hxx>
 
 #include "FGFDM.hpp"
 #include "Atmosphere.hpp"
@@ -18,6 +16,9 @@
 #include "Integrator.hpp"
 #include "Glue.hpp"
 #include "Gear.hpp"
+#include "Hook.hpp"
+#include "Launchbar.hpp"
+#include "FGGround.hpp"
 #include "PropEngine.hpp"
 #include "PistonEngine.hpp"
 
@@ -45,6 +46,7 @@ YASim::YASim(double dt)
 
     _dt = dt;
 
+    _fdm->getAirplane()->getModel()->setGroundCallback( new FGGround(this) );
     _fdm->getAirplane()->getModel()->getIntegrator()->setInterval(_dt);
 }
 
@@ -187,12 +189,32 @@ void YASim::update(double dt)
         return;
     }
 
+    // ground.  Calculate a cartesian coordinate for the ground under
+    // us, find the (geodetic) up vector normal to the ground, then
+    // use that to find the final (radius) term of the plane equation.
+    float v[3] = { get_uBody()*FT2M, get_vBody()*FT2M, get_wBody()*FT2M };
+    float lat = get_Latitude(); float lon = get_Longitude();
+    double xyz[3];
+    sgGeodToCart(lat, lon, 0.0, xyz);
+    // build the environment cache.
+    float vr = _fdm->getVehicleRadius();
+    vr += 2.0*dt*Math::mag3(v);
+    prepare_ground_cache_m( 0.0, xyz, vr );
+
+    // Track time increments.
+    FGGround* gr
+      = (FGGround*)_fdm->getAirplane()->getModel()->getGroundCallback();
+
     int i;
     for(i=0; i<iterations; i++) {
+        gr->setTimeOffset(iterations*_dt);
         copyToYASim(false);
         _fdm->iterate(_dt);
         copyFromYASim();
     }
+
+    // Reset the time increment.
+    gr->setTimeOffset(0.0);
 }
 
 void YASim::copyToYASim(bool copyState)
@@ -211,10 +233,6 @@ void YASim::copyToYASim(bool copyState)
     wind[1] = get_V_east_airmass() * FT2M * -1.0;
     wind[2] = get_V_down_airmass() * FT2M * -1.0;
 
-    // Get ground elevation from the FGinterface's FGlocation data
-    double ground = getACModel()->get3DModel()->getSGLocation()->get_cur_elev_m();
-    // cout << "YASIM: ground = " << ground << endl;
-
     float pressure = fgGetFloat("/environment/pressure-inhg") * INHG2PA;
     float temp = fgGetFloat("/environment/temperature-degc") + 273.15;
     float dens = fgGetFloat("/environment/density-slugft3") 
@@ -281,19 +299,16 @@ void YASim::copyToYASim(bool copyState)
     Math::tmul33(xyz2ned, wind, wind);
     model->setWind(wind);
 
-    // ground.  Calculate a cartesian coordinate for the ground under
-    // us, find the (geodetic) up vector normal to the ground, then
-    // use that to find the final (radius) term of the plane equation.
-    double xyz[3], gplane[3]; float up[3];
-    sgGeodToCart(lat, lon, ground, xyz);
-    Glue::geodUp(lat, lon, up); // FIXME, needless reverse computation...
-    int i;
-    for(i=0; i<3; i++) gplane[i] = up[i];
-    double rad = gplane[0]*xyz[0] + gplane[1]*xyz[1] + gplane[2]*xyz[2];
-    model->setGroundPlane(gplane, rad);
-
     // air
     model->setAir(pressure, temp, dens);
+
+    // Query a ground plane for each gear/hook/launchbar and
+    // write that value into the corresponding class.
+    _fdm->getAirplane()->getModel()->updateGround(&s);
+
+    Launchbar* l = model->getLaunchbar();
+    if (l)
+        l->setLaunchCmd(0.0<fgGetFloat("/controls/gear/catapult-launch-cmd"));
 }
 
 // All the settables:
@@ -446,27 +461,15 @@ void YASim::copyFromYASim()
        node->setFloatValue("compression-norm", g->getCompressFraction());
     }
 
-    for(i=0; i<model->numThrusters(); i++) {
-        SGPropertyNode * node = fgGetNode("engines/engine", i, true);
-        Thruster* t = model->getThruster(i);
-
-       node->setBoolValue("running", t->isRunning());
-       node->setBoolValue("cranking", t->isCranking());
-
-        float tmp[3];
-        t->getThrust(tmp);
-       node->setDoubleValue("prop-thrust", Math::mag3(tmp) * KG2LBS / 9.8);
-
-        PropEngine* pe = t->getPropEngine();
-        if(pe) {
-           node->setDoubleValue("rpm", pe->getOmega() * RAD2RPM);
-
-            pe->getTorque(tmp);
-            float power = Math::mag3(tmp) * pe->getOmega();
-            float maxPower = pe->getPistonEngine()->getMaxPower();
+    Hook* h = airplane->getHook();
+    if(h) {
+       SGPropertyNode * node = fgGetNode("gear/tailhook", 0, true);
+       node->setFloatValue("position-norm", h->getCompressFraction());
+    }
 
-           node->setDoubleValue("max-hp", maxPower * W2HP);
-           node->setDoubleValue("power-pct", 100 * power/maxPower);
-        }
+    Launchbar* l = airplane->getLaunchbar();
+    if(l) {
+       SGPropertyNode * node = fgGetNode("gear/launchbar", 0, true);
+       node->setFloatValue("position-norm", l->getCompressFraction());
     }
 }