gs = globals->get_gslist()->findByFreq(nav_freq, lon, lat, elev);
}
-
if ( loc != NULL ) {
nav_id = loc->get_ident();
+ // cout << "localizer = " << nav_id << endl;
nav_valid = true;
if ( last_nav_id != nav_id || last_nav_vor ) {
nav_trans_ident = loc->get_trans_ident();
}
} else if ( nav != NULL ) {
nav_id = nav->get_ident();
+ // cout << "nav = " << nav_id << endl;
nav_valid = true;
if ( last_nav_id != nav_id || !last_nav_vor ) {
last_nav_id = nav_id;
{
FGNavRecord *nav = NULL;
Point3D station;
- double d2;
- double min_dist = 999999999.0;
-
- // prime the pump with info from stations[0]
- if ( stations.size() > 0 ) {
- nav = stations[0];
- station = Point3D( nav->get_x(), nav->get_y(), nav->get_z());
- min_dist = aircraft.distance3Dsquared( station );
- }
+ double dist;
+ double min_dist = FG_NAV_MAX_RANGE * SG_NM_TO_METER;
- // check if any of the remaining stations are closer
- for ( unsigned int i = 1; i < stations.size(); ++i ) {
+ // find the closest station within a sensible range (FG_NAV_MAX_RANGE)
+ for ( unsigned int i = 0; i < stations.size(); ++i ) {
// cout << "testing " << current->get_ident() << endl;
station = Point3D( stations[i]->get_x(),
stations[i]->get_y(),
stations[i]->get_z() );
- d2 = aircraft.distance3Dsquared( station );
+ dist = aircraft.distance3D( station );
// cout << " dist = " << sqrt(d)
// << " range = " << current->get_range() * SG_NM_TO_METER
// << endl;
- if ( d2 < min_dist ) {
- min_dist = d2;
+ if ( dist < min_dist ) {
+ min_dist = dist;
nav = stations[i];
}
}
SG_USING_STD(istream);
-#define FG_NAV_DEFAULT_RANGE 50
-#define FG_LOC_DEFAULT_RANGE 18
-#define FG_DME_DEFAULT_RANGE 50
+#define FG_NAV_DEFAULT_RANGE 50 // nm
+#define FG_LOC_DEFAULT_RANGE 18 // nm
+#define FG_DME_DEFAULT_RANGE 50 // nm
+#define FG_NAV_MAX_RANGE 300 // nm
class FGNavRecord {