diff --git a/src/Cockpit/navcom.cxx b/src/Cockpit/navcom.cxx index a7a62cc09..e621ddbf2 100644 --- a/src/Cockpit/navcom.cxx +++ b/src/Cockpit/navcom.cxx @@ -323,12 +323,33 @@ FGNavCom::update(double dt) if ( nav_has_gs ) { station = Point3D( nav_gs_x, nav_gs_y, nav_gs_z ); nav_gs_dist = aircraft.distance3D( station ); + // wgs84 heading to glide slope + geo_inverse_wgs_84( elev, + lat * SGD_RADIANS_TO_DEGREES, + lon * SGD_RADIANS_TO_DEGREES, + nav_gslat, nav_gslon, + &az1, &az2, &s ); + double r = az1 - nav_radial; + while ( r > 180.0 ) { r -= 360.0;} + while ( r < -180.0 ) { r += 360.0;} + if ( r >= -90.0 && r <= 90.0 ) { + nav_gs_dist_signed = nav_gs_dist; + } else { + nav_gs_dist_signed = -nav_gs_dist; + } + /* cout << "Target Radial = " << nav_radial + << " Bearing = " << az1 + << " dist (signed) = " << nav_gs_dist_signed + << endl; */ + } else { nav_gs_dist = 0.0; } - // wgs84 heading - geo_inverse_wgs_84( elev, lat * SGD_RADIANS_TO_DEGREES, lon * SGD_RADIANS_TO_DEGREES, + // wgs84 heading to localizer + geo_inverse_wgs_84( elev, + lat * SGD_RADIANS_TO_DEGREES, + lon * SGD_RADIANS_TO_DEGREES, nav_loclat, nav_loclon, &az1, &az2, &s ); // cout << "az1 = " << az1 << " magvar = " << nav_magvar << endl; diff --git a/src/Cockpit/navcom.hxx b/src/Cockpit/navcom.hxx index b01330ee4..33a01dcf5 100644 --- a/src/Cockpit/navcom.hxx +++ b/src/Cockpit/navcom.hxx @@ -103,6 +103,7 @@ class FGNavCom : public FGSubsystem double nav_gs_y; double nav_gs_z; double nav_gs_dist; + double nav_gs_dist_signed; SGTimeStamp prev_time; SGTimeStamp curr_time; double nav_elev; @@ -208,6 +209,7 @@ public: inline double get_nav_gslon() const { return nav_gslon; } inline double get_nav_gslat() const { return nav_gslat; } inline double get_nav_gs_dist() const { return nav_gs_dist; } + inline double get_nav_gs_dist_signed() const { return nav_gs_dist_signed; } inline double get_nav_elev() const { return nav_elev; } inline double get_nav_heading() const { return nav_heading; } inline double get_nav_radial() const { return nav_radial; } diff --git a/src/Network/native_gui.cxx b/src/Network/native_gui.cxx index 46ee30bdc..30261b140 100644 --- a/src/Network/native_gui.cxx +++ b/src/Network/native_gui.cxx @@ -154,8 +154,9 @@ void FGProps2NetGUI( FGNetGUI *net ) { if ( current_radiostack->get_navcom1()->get_nav_loc() ) { // is an ILS - net->dist_nm = current_radiostack->get_navcom1()->get_nav_gs_dist() - * SG_METER_TO_NM; + net->dist_nm + = current_radiostack->get_navcom1()->get_nav_gs_dist_signed() + * SG_METER_TO_NM; } else { // is a VOR net->dist_nm = current_radiostack->get_navcom1()->get_nav_loc_dist()