]> git.mxchange.org Git - flightgear.git/commitdiff
Use an SGGeod inside FGAIFlightPlan::Waypoint.
authorJames Turner <zakalawe@mac.com>
Mon, 8 Oct 2012 14:52:06 +0000 (15:52 +0100)
committerJames Turner <zakalawe@mac.com>
Mon, 8 Oct 2012 14:52:06 +0000 (15:52 +0100)
This allows incremental refactoring to move away from discrete lat/lon use in favour of SGGeod.

src/AIModel/AIFlightPlan.cxx
src/AIModel/AIFlightPlan.hxx

index f8f7c57636f3ec39f3de1265df69c719021480ef..1ec20e1881935e65dec9a4ef61566c11c15e423e 100644 (file)
@@ -46,9 +46,6 @@
 using std::cerr;
 
 FGAIWaypoint::FGAIWaypoint() {
-  latitude    = 0;
-  longitude   = 0;
-  altitude    = 0;
   speed       = 0;
   crossat     = 0;
   finished    = 0;
@@ -68,7 +65,37 @@ bool FGAIWaypoint::contains(string target) {
         return true;
 }
 
-FGAIFlightPlan::FGAIFlightPlan() 
+double FGAIWaypoint::getLatitude()
+{
+  return pos.getLatitudeDeg();
+}
+
+double FGAIWaypoint::getLongitude()
+{
+  return pos.getLongitudeDeg();
+}
+
+double FGAIWaypoint::getAltitude()
+{
+  return pos.getElevationFt();
+}
+
+void FGAIWaypoint::setLatitude(double lat)
+{
+  pos.setLatitudeDeg(lat);
+}
+
+void FGAIWaypoint::setLongitude(double lon)
+{
+  pos.setLongitudeDeg(lon);
+}
+
+void FGAIWaypoint::setAltitude(double alt)
+{
+  pos.setElevationFt(alt);
+}
+
+FGAIFlightPlan::FGAIFlightPlan()
 {
     sid             = 0;
     repeat          = false;
@@ -345,8 +372,7 @@ void FGAIFlightPlan::eraseLastWaypoint()
 
 // gives distance in feet from a position to a waypoint
 double FGAIFlightPlan::getDistanceToGo(double lat, double lon, FGAIWaypoint* wp) const{
-  return SGGeodesy::distanceM(SGGeod::fromDeg(lon, lat), 
-      SGGeod::fromDeg(wp->getLongitude(), wp->getLatitude()));
+  return SGGeodesy::distanceM(SGGeod::fromDeg(lon, lat), wp->getPos());
 }
 
 // sets distance in feet from a lead point to the current waypoint
@@ -394,14 +420,15 @@ void FGAIFlightPlan::setLeadDistance(double distance_ft){
 }
 
 
-double FGAIFlightPlan::getBearing(FGAIWaypoint* first, FGAIWaypoint* second) const{
-  return getBearing(first->getLatitude(), first->getLongitude(), second);
+double FGAIFlightPlan::getBearing(FGAIWaypoint* first, FGAIWaypoint* second) const
+{
+  return SGGeodesy::courseDeg(first->getPos(), second->getPos());
 }
 
 
-double FGAIFlightPlan::getBearing(double lat, double lon, FGAIWaypoint* wp) const{
-  return SGGeodesy::courseDeg(SGGeod::fromDeg(lon, lat), 
-      SGGeod::fromDeg(wp->getLongitude(), wp->getLatitude()));
+double FGAIFlightPlan::getBearing(double lat, double lon, FGAIWaypoint* wp) const
+{
+  return SGGeodesy::courseDeg(SGGeod::fromDeg(lon, lat), wp->getPos());
 }
 
 void FGAIFlightPlan::deleteWaypoints()
@@ -423,10 +450,7 @@ void FGAIFlightPlan::resetWaypoints()
       wpt_vector_iterator i = waypoints.end();
       i--;
       wpt->setName        ( (*i)->getName()       );
-      wpt->setLatitude    ( (*i)->getLatitude()   );
-      wpt->setLongitude   ( (*i)->getLongitude()  );
-      wpt->setAltitude    ( (*i)->getAltitude()   );
-      wpt->setSpeed       ( (*i)->getSpeed()      );
+      wpt->setPos         ( (*i)->getPos()        );
       wpt->setCrossat     ( (*i)->getCrossat()    );
       wpt->setGear_down   ( (*i)->getGear_down()  );
       wpt->setFlaps_down  ( (*i)->getFlaps_down() );
index e5e4bb10db4090f3b77f281d429954de4101ec4b..c32d88345cdf0bba5a7abc04ebbd2ffd77868e0a 100644 (file)
 #include <simgear/compiler.h>
 #include <vector>
 #include <string>
-
+#include <simgear/math/SGMath.hxx>
 
 class FGTaxiRoute;
 class FGRunway;
 class FGAIAircraft;
 class FGAirport;
-class SGGeod;
 
 class FGAIWaypoint {
 private:
    std::string name;
-   double latitude;
-   double longitude;
-   double altitude;
+   SGGeod pos;
    double speed;
    double crossat;
    bool finished;
@@ -51,9 +48,10 @@ public:
     FGAIWaypoint();
     ~FGAIWaypoint() {};
     void setName        (std::string nam) { name        = nam; };
-    void setLatitude    (double lat) { latitude    = lat; };
-    void setLongitude   (double lon) { longitude   = lon; };
-    void setAltitude    (double alt) { altitude    = alt; };
+    void setLatitude    (double lat);
+    void setLongitude   (double lon);
+    void setAltitude    (double alt);
+    void setPos         (const SGGeod& aPos) { pos = aPos; }
     void setSpeed       (double spd) { speed       = spd; };
     void setCrossat     (double val) { crossat     = val; };
     void setFinished    (bool   fin) { finished    = fin; };
@@ -68,9 +66,10 @@ public:
     bool contains(std::string name);
 
     std::string getName  () { return name;        };
-    double getLatitude   () { return latitude;    };
-    double getLongitude  () { return longitude;   };
-    double getAltitude   () { return altitude;    };
+    const SGGeod& getPos () { return pos;         };
+    double getLatitude   ();
+    double getLongitude  ();
+    double getAltitude   ();
     double getSpeed      () { return speed;       };
 
     double getCrossat    () { return crossat;     };