]> git.mxchange.org Git - flightgear.git/blobdiff - src/ATC/ATCutils.cxx
Mathias Fröhlich:
[flightgear.git] / src / ATC / ATCutils.cxx
index f5decf766499407b1041ee06e470162307b3b401..14442917e408620d1d5ba7da8125be16b950b7ca 100644 (file)
@@ -253,7 +253,7 @@ Point3D dclUpdatePosition(Point3D pos, double heading, double angle, double dist
 
 // Get a heading in degrees from one lat/lon to another.
 // This function assumes the world is spherical.  If geodetic accuracy is required use the functions is sg_geodesy instead!
-// Warning - at the moment we are not checking for identical points - currently it returns 90 in this instance.
+// Warning - at the moment we are not checking for identical points - currently it returns 0 in this instance.
 double GetHeadingFromTo(Point3D A, Point3D B) {
        double latA = A.lat() * DCL_DEGREES_TO_RADIANS;
        double lonA = A.lon() * DCL_DEGREES_TO_RADIANS;
@@ -261,24 +261,8 @@ double GetHeadingFromTo(Point3D A, Point3D B) {
        double lonB = B.lon() * DCL_DEGREES_TO_RADIANS;
        double xdist = sin(lonB - lonA) * (double)SG_EQUATORIAL_RADIUS_M * cos((latA+latB)/2.0);
        double ydist = sin(latB - latA) * (double)SG_EQUATORIAL_RADIUS_M;
-       
-       if(xdist >= 0) {
-               if(ydist > 0) {
-                       return(atan(xdist/ydist) * DCL_RADIANS_TO_DEGREES);
-               } else if (ydist == 0) {
-                       return(90.0);
-               } else {
-                       return(180.0 - atan(xdist/fabs(ydist)) * DCL_RADIANS_TO_DEGREES);
-               }
-       } else {
-               if(ydist > 0) {
-                       return(360.0 - atan(fabs(xdist)/ydist) * DCL_RADIANS_TO_DEGREES);
-               } else if (ydist == 0) {
-                       return(270.0);
-               } else {
-                       return(180.0 + atan(xdist/ydist) * DCL_RADIANS_TO_DEGREES);
-               }
-       }
+       double heading = atan2(xdist, ydist) * DCL_RADIANS_TO_DEGREES;
+       return heading < 0.0 ? heading + 360 : heading;
 }
 
 // Given a heading (in degrees), bound it from 0 -> 360
@@ -308,27 +292,27 @@ double GetAngleDiff_deg( const double &a1, const double &a2) {
 // in fg_init.cxx, and are just here temporarily until some rationalisation occurs.
 // find basic airport location info from airport database
 bool dclFindAirportID( const string& id, FGAirport *a ) {
-    FGAirport result;
+    const FGAirport* result;
 
     if ( id.length() ) {
         SG_LOG( SG_GENERAL, SG_INFO, "Searching for airport code = " << id );
 
-        result = globals->get_airports()->search( id );
-        if ( result.id.empty() ) {
-            SG_LOG( SG_GENERAL, SG_ALERT,
-                    "Failed to find " << id << " in basic.dat.gz" );
+        result = globals->get_airports()->search(id);
+        if ( result == NULL ) {
+            SG_LOG( SG_GENERAL, SG_WARN,
+                    "Failed to find " << id << " in apt.dat.gz" );
             return false;
         }
     } else {
         return false;
     }
 
-    *a = result;
+    *a = *result;
 
     SG_LOG( SG_GENERAL, SG_INFO,
             "Position for " << id << " is ("
-            << a->longitude << ", "
-            << a->latitude << ")" );
+            << a->getLongitude() << ", "
+            << a->getLatitude() << ")" );
 
     return true;
 }
@@ -342,7 +326,7 @@ double dclGetAirportElev( const string& id ) {
             "Finding elevation for airport: " << id );
 
     if ( dclFindAirportID( id, &a ) ) {
-        return a.elevation * SG_FEET_TO_METER;
+        return a.getElevation() * SG_FEET_TO_METER;
     } else {
         return -9999.0;
     }
@@ -357,7 +341,7 @@ Point3D dclGetAirportPos( const string& id ) {
             "Finding position for airport: " << id );
 
     if ( dclFindAirportID( id, &a ) ) {
-        return Point3D(a.longitude, a.latitude, a.elevation);
+        return Point3D(a.getLongitude(), a.getLatitude(), a.getElevation());
     } else {
         return Point3D(0.0, 0.0, -9999.0);
     }
@@ -367,8 +351,8 @@ Point3D dclGetAirportPos( const string& id ) {
 // Given a Point3D (lon/lat/elev) and an FGRunway struct, determine if the point lies on the runway
 bool OnRunway(Point3D pt, const FGRunway& rwy) {
        FGATCAlignedProjection ortho;
-       Point3D centre(rwy.lon, rwy.lat, 0.0);  // We don't need the elev
-       ortho.Init(centre, rwy.heading);
+       Point3D centre(rwy._lon, rwy._lat, 0.0);        // We don't need the elev
+       ortho.Init(centre, rwy._heading);
        
        Point3D xyc = ortho.ConvertToLocal(centre);
        Point3D xyp = ortho.ConvertToLocal(pt);
@@ -376,8 +360,8 @@ bool OnRunway(Point3D pt, const FGRunway& rwy) {
        //cout << "Length offset = " << fabs(xyp.y() - xyc.y()) << '\n';
        //cout << "Width offset = " << fabs(xyp.x() - xyc.x()) << '\n';
        
-       if((fabs(xyp.y() - xyc.y()) < ((rwy.length/2.0) + 5.0)) 
-               && (fabs(xyp.x() - xyc.x()) < (rwy.width/2.0))) {
+       if((fabs(xyp.y() - xyc.y()) < ((rwy._length/2.0) + 5.0)) 
+               && (fabs(xyp.x() - xyc.x()) < (rwy._width/2.0))) {
                return(true);
        }