]> git.mxchange.org Git - flightgear.git/blobdiff - src/ATCDCL/approach.cxx
Merge branch 'torsten/metar'
[flightgear.git] / src / ATCDCL / approach.cxx
index 44784abf1e5b45c52db3bf70cea496b4fdbb661a..e1ff8226e212b2000314f790ee1efba05ff3cb6e 100644 (file)
 #  include <config.h>
 #endif
 
+#include <iostream>
+
 #include "approach.hxx"
 #include "transmission.hxx"
 #include "transmissionlist.hxx"
 #include "ATCDialog.hxx"
 
 #include <Airports/runways.hxx>
+#include <Airports/simple.hxx>
+
 #include <simgear/constants.h>
-#include <simgear/math/polar3d.hxx>
 #include <simgear/misc/sg_path.hxx>
 
 #include <Environment/environment_mgr.hxx>
@@ -38,6 +41,9 @@
 
 #include <GUI/gui.h>
 
+using std::cout;
+using std::endl;
+
 //Constructor
 FGApproach::FGApproach(){
   comm1_node = fgGetNode("/instrumentation/comm[0]/frequencies/selected-mhz", true);
@@ -402,19 +408,19 @@ double FGApproach::angle_diff_deg( const double &a1, const double &a2) {
 void FGApproach::calc_wp( const int &i ) {
        
        int j;
-       double course, d, cd, a1;
+       double course, d, cd, a1, az2;
        
        int wpn = planes[i].wpn;
        // waypoint 0: Threshold of active runway
-       calc_gc_course_dist(Point3D(lon*SGD_DEGREES_TO_RADIANS, lat*SGD_DEGREES_TO_RADIANS, 0.0),
-                           Point3D(active_rw_lon*SGD_DEGREES_TO_RADIANS,active_rw_lat*SGD_DEGREES_TO_RADIANS, 0.0 ),
-                           &course, &d);
+  SGGeod activeRunway(SGGeod::fromDeg(active_rw_lon, active_rw_lat));
+  SGGeodesy::inverse(_geod, activeRunway, course, az2, d);
+  
        double d1 = active_rw_hdg+180.0;
        if ( d1 > 360.0 ) d1 -=360.0;
-       calc_cd_head_dist(360.0-course*SGD_RADIANS_TO_DEGREES, d/SG_NM_TO_METER, 
+       calc_cd_head_dist(360.0-course, d/SG_NM_TO_METER, 
                          d1, active_rw_len/SG_NM_TO_METER/2.0, 
                          &planes[i].wpts[wpn][0], &planes[i].wpts[wpn][1]);
-       planes[i].wpts[wpn][2] = elev;
+       planes[i].wpts[wpn][2] = _geod.getElevationM();
        planes[i].wpts[wpn][4] = 0.0;
        planes[i].wpts[wpn][5] = 0.0;
        wpn += 1;
@@ -501,7 +507,7 @@ void FGApproach::calc_wp( const int &i ) {
        // ====================
        // vertical navigation
        // ====================
-       double alt = elev+3000.0;
+       double alt = _geod.getElevationM()+3000.0;
        planes[i].wpts[1][2] = round_alt( true, alt );
        for ( j=2; j<wpn-1; ++j ) {
                double dalt = planes[i].alt - planes[i].wpts[j-1][2];
@@ -554,26 +560,15 @@ double FGApproach::round_alt( const bool hl, double alt ) {
 void FGApproach::get_active_runway() {
        //cout << "Entering FGApproach::get_active_runway()\n";
 
-  FGEnvironment stationweather =
-      ((FGEnvironmentMgr *)globals->get_subsystem("environment"))
-        ->getEnvironment(lat, lon, elev);
-
-  double hdg = stationweather.get_wind_from_heading_deg();
-  
-  FGRunway runway;
-  if ( globals->get_runways()->search( ident, int(hdg), &runway) ) {
-    active_runway = runway._rwy_no;
-    active_rw_hdg = runway._heading;
-    active_rw_lon = runway._lon;
-    active_rw_lat = runway._lat;
-    active_rw_len = runway._length;
-    //cout << "Active runway is: " << active_runway << "  heading = " 
-    // << active_rw_hdg 
-    // << " lon = " << active_rw_lon 
-    // << " lat = " << active_rw_lat <<endl;
-  }
-  else cout << "FGRunways search failed\n";
+  const FGAirport* apt = fgFindAirportID(ident);
+  assert(apt);
+  FGRunway* runway = apt->getActiveRunwayForUsage();
 
+  active_runway = runway->ident();
+  active_rw_hdg = runway->headingDeg();
+  active_rw_lon = runway->longitude();
+  active_rw_lat = runway->latitude();
+  active_rw_len = runway->lengthFt();
 }
 
 // ========================================================================
@@ -591,15 +586,11 @@ void FGApproach::update_plane_dat() {
     planes[i].hdg = hdg_node->getDoubleValue();
     planes[i].spd = speed_node->getDoubleValue();
 
-    /*Point3D aircraft = sgGeodToCart( Point3D(planes[i].lon*SGD_DEGREES_TO_RADIANS, 
-                                            planes[i].lat*SGD_DEGREES_TO_RADIANS, 
-                                            planes[i].alt*SG_FEET_TO_METER) );*/
-    double course, distance;
-    calc_gc_course_dist(Point3D(lon*SGD_DEGREES_TO_RADIANS, lat*SGD_DEGREES_TO_RADIANS, 0.0),
-                       Point3D(planes[i].lon*SGD_DEGREES_TO_RADIANS,planes[i].lat*SGD_DEGREES_TO_RADIANS, 0.0 ),
-                       &course, &distance);
-    planes[i].dist = distance/SG_NM_TO_METER;
-    planes[i].brg  = 360.0-course*SGD_RADIANS_TO_DEGREES;
+    double course, distance, az2;
+    SGGeod plane(SGGeod::fromDeg(planes[1].lon, active_rw_lat));
+    SGGeodesy::inverse(_geod, plane, course, az2, distance);
+    planes[i].dist = distance * SG_METER_TO_NM;
+    planes[i].brg  = 360.0-course;
 
     //cout << "Plane Id: " << planes[i].ident << "  Distance to " << ident 
     // << " is " << planes[i].dist << " miles   " << "Bearing " << planes[i].brg << endl;