]> git.mxchange.org Git - flightgear.git/blobdiff - src/Autopilot/route_mgr.cxx
AircraftModel hacking for package support.
[flightgear.git] / src / Autopilot / route_mgr.cxx
index fa9e588a289d4a3ee27690bf2dbc38067439d274..0ef6e72c207da6bfe5be57da8c21c95ed3329016 100644 (file)
@@ -51,6 +51,8 @@
 #include "Navaids/positioned.hxx"
 #include <Navaids/waypoint.hxx>
 #include <Navaids/procedure.hxx>
+#include <Navaids/routePath.hxx>
+
 #include "Airports/airport.hxx"
 #include "Airports/runways.hxx"
 #include <GUI/new_gui.hxx>
@@ -482,11 +484,13 @@ void FGRouteMgr::update( double dt )
     return;
   }
   
-  double courseDeg;
-  double distanceM;
-  boost::tie(courseDeg, distanceM) = leg->waypoint()->courseAndDistanceFrom(currentPos);
-  
-// update wp0 / wp1 / wp-last
+  // use RoutePath to compute location of active WP
+  RoutePath path(_plan);
+  SGGeod wpPos = path.positionForIndex(_plan->currentIndex());
+  double courseDeg, az2, distanceM;
+  SGGeodesy::inverse(currentPos, wpPos, courseDeg, az2, distanceM);
+
+  // update wp0 / wp1 / wp-last
   wp0->setDoubleValue("dist", distanceM * SG_METER_TO_NM);
   wp0->setDoubleValue("true-bearing-deg", courseDeg);
   courseDeg -= magvar->getDoubleValue(); // expose magnetic bearing
@@ -507,8 +511,9 @@ void FGRouteMgr::update( double dt )
   
   FlightPlan::Leg* nextLeg = _plan->nextLeg();
   if (nextLeg) {
-    boost::tie(courseDeg, distanceM) = nextLeg->waypoint()->courseAndDistanceFrom(currentPos);
-     
+    wpPos = path.positionForIndex(_plan->currentIndex() + 1);
+    SGGeodesy::inverse(currentPos, wpPos, courseDeg, az2, distanceM);
+
     wp1->setDoubleValue("dist", distanceM * SG_METER_TO_NM);
     wp1->setDoubleValue("true-bearing-deg", courseDeg);
     courseDeg -= magvar->getDoubleValue(); // expose magnetic bearing
@@ -741,7 +746,7 @@ bool FGRouteMgr::activate()
     return false;
   }
  
-  _plan->setCurrentIndex(0);
+  _plan->activate();
   active->setBoolValue(true);
   SG_LOG(SG_AUTOPILOT, SG_INFO, "route-manager, activate route ok");
   return true;