X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FInstrumentation%2Fkr_87.cxx;h=6683f8f935b563f3d784eb6991051836cba7fa23;hb=5cad5aa7da2476ca8323a61f81dea59676dca085;hp=5466ac8cf568fcfa1fcdc5ad20961318a9a9e167;hpb=161fb0c770fe7842a729b0143f895992e5fca4b9;p=flightgear.git diff --git a/src/Instrumentation/kr_87.cxx b/src/Instrumentation/kr_87.cxx index 5466ac8cf..6683f8f93 100644 --- a/src/Instrumentation/kr_87.cxx +++ b/src/Instrumentation/kr_87.cxx @@ -16,7 +16,7 @@ // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software -// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // // $Id$ @@ -29,6 +29,8 @@ #include #include +#include +#include #include #include @@ -36,7 +38,7 @@ #include "kr_87.hxx" #include -SG_USING_STD(string); +using std::string; static int play_count = 0; static time_t last_time = 0; @@ -244,14 +246,12 @@ void FGKR_87::unbind () { // Update the various nav values based on position and valid tuned in navs void FGKR_87::update( double dt_sec ) { - double acft_lon = lon_node->getDoubleValue() * SGD_DEGREES_TO_RADIANS; - double acft_lat = lat_node->getDoubleValue() * SGD_DEGREES_TO_RADIANS; - double acft_elev = alt_node->getDoubleValue() * SG_FEET_TO_METER; + SGGeod acft = SGGeod::fromDegFt(lon_node->getDoubleValue(), + lat_node->getDoubleValue(), + alt_node->getDoubleValue()); need_update = false; - Point3D aircraft = sgGeodToCart( Point3D( acft_lon, acft_lat, acft_elev ) ); - Point3D station; double az1, az2, s; // On timeout, scan again @@ -361,20 +361,17 @@ void FGKR_87::update( double dt_sec ) { if ( valid ) { // cout << "adf is valid" << endl; // staightline distance - station = Point3D( x, y, z ); - dist = aircraft.distance3D( station ); + // What a hack, dist is a class local variable + dist = sqrt(distSqr(SGVec3d::fromGeod(acft), xyz)); // wgs84 heading - geo_inverse_wgs_84( acft_elev, - acft_lat * SGD_RADIANS_TO_DEGREES, - acft_lon * SGD_RADIANS_TO_DEGREES, - stn_lat, stn_lon, + geo_inverse_wgs_84( acft, SGGeod::fromDeg(stn_lon, stn_lat), &az1, &az2, &s ); heading = az1; // cout << " heading = " << heading // << " dist = " << dist << endl; - effective_range = kludgeRange(stn_elev, acft_elev, range); + effective_range = kludgeRange(stn_elev, acft.getElevationFt(), range); if ( dist < effective_range * SG_NM_TO_METER ) { inrange = true; } else if ( dist < 2 * effective_range * SG_NM_TO_METER ) { @@ -497,10 +494,9 @@ void FGKR_87::update( double dt_sec ) { // Update current nav/adf radio stations based on current postition void FGKR_87::search() { - double acft_lon = lon_node->getDoubleValue() * SGD_DEGREES_TO_RADIANS; - double acft_lat = lat_node->getDoubleValue() * SGD_DEGREES_TO_RADIANS; - double acft_elev = alt_node->getDoubleValue() * SG_FEET_TO_METER; - + SGGeod pos = SGGeod::fromDegFt(lon_node->getDoubleValue(), + lat_node->getDoubleValue(), alt_node->getDoubleValue()); + // FIXME: the panel should handle this static string last_ident = ""; @@ -511,9 +507,8 @@ void FGKR_87::search() { // ADF. //////////////////////////////////////////////////////////////////////// - FGNavRecord *adf - = globals->get_navlist()->findByFreq( freq, acft_lon, acft_lat, - acft_elev ); + + FGNavRecord *adf = globals->get_navlist()->findByFreq( freq, pos); if ( adf != NULL ) { char sfreq[128]; snprintf( sfreq, 10, "%d", freq ); @@ -529,10 +524,8 @@ void FGKR_87::search() { stn_lat = adf->get_lat(); stn_elev = adf->get_elev_ft(); range = adf->get_range(); - effective_range = kludgeRange(stn_elev, acft_elev, range); - x = adf->get_x(); - y = adf->get_y(); - z = adf->get_z(); + effective_range = kludgeRange(stn_elev, pos.getElevationM(), range); + xyz = adf->cart(); if ( globals->get_soundmgr()->exists( "adf-ident" ) ) { globals->get_soundmgr()->remove( "adf-ident" );