]> git.mxchange.org Git - flightgear.git/commitdiff
Allow a "threshold" value to determine which localizers to snap to the
authorcurt <curt>
Fri, 28 May 2004 20:57:05 +0000 (20:57 +0000)
committercurt <curt>
Fri, 28 May 2004 20:57:05 +0000 (20:57 +0000)
runway heading or not.

src/Main/fg_init.cxx
src/Navaids/navdb.cxx
src/Navaids/navdb.hxx

index a9c583d7a037386c437cb6bea67594dbcea6c2c8..43f699fd650194562bf10db6bebb44586a68f7d9 100644 (file)
@@ -1062,12 +1062,15 @@ fgInitNav ()
                 "Problems loading one or more navigational database" );
     }
 
-    if ( fgGetBool("/sim/navdb/auto-align-localizers", true) ) {
+    if ( fgGetBool("/sim/navdb/localizers/auto-align", true) ) {
         // align all the localizers with their corresponding runways
         // since data sources are good for cockpit navigation
         // purposes, but not always to the error tolerances needed to
         // exactly place these items.
-        fgNavDBAlignLOCwithRunway( runways, loclist );
+        double threshold
+            = fgGetDouble( "/sim/navdb/localizers/auto-align-threshold-deg",
+                           5.0 );
+        fgNavDBAlignLOCwithRunway( runways, loclist, threshold );
     }
 
     SG_LOG(SG_GENERAL, SG_INFO, "  Fixes");
index f267911200b3ab852554dc7c6d25d0667c530dc2..92253f357eb7f63381f91430d3a1049581f915da 100644 (file)
@@ -121,8 +121,9 @@ bool fgNavDBInit( FGNavList *navlist, FGNavList *loclist, FGNavList *gslist,
 // Given a localizer record and it's corresponding runway record,
 // adjust the localizer position so it is in perfect alignment with
 // the runway.
-static void update_loc_position( FGNavRecord *loc, FGRunway *rwy ) {
-
+static void update_loc_position( FGNavRecord *loc, FGRunway *rwy,
+                                 double threshold )
+{
     double hdg = rwy->heading;
     hdg += 180.0;
     if ( hdg > 360.0 ) {
@@ -155,12 +156,23 @@ static void update_loc_position( FGNavRecord *loc, FGRunway *rwy ) {
                         &az1, &az2, &dist_m );
     // cout << "Distance moved = " << dist_m << endl;
 
-    loc->set_lat( nloc_lat );
-    loc->set_lon( nloc_lon );
-    loc->set_multiuse( rwy->heading );
-
     // cout << "orig heading = " << loc->get_multiuse() << endl;
     // cout << "new heading = " << rwy->heading << endl;
+
+    double hdg_diff = loc->get_multiuse() - rwy->heading;
+
+    // clamp to [-180.0 ... 180.0]
+    if ( hdg_diff < -180.0 ) {
+        hdg_diff += 360.0;
+    } else if ( hdg_diff > 180.0 ) {
+        hdg_diff -= 360.0;
+    }
+
+    if ( fabs(hdg_diff) <= threshold ) {
+        loc->set_lat( nloc_lat );
+        loc->set_lon( nloc_lon );
+        loc->set_multiuse( rwy->heading );
+    }
 }
 
 
@@ -169,7 +181,8 @@ static void update_loc_position( FGNavRecord *loc, FGRunway *rwy ) {
 // it then "moves" the localizer and updates it's heading so it
 // *perfectly* aligns with the runway, but is still the same distance
 // from the runway threshold.
-void fgNavDBAlignLOCwithRunway( FGRunwayList *runways, FGNavList *loclist ) {
+void fgNavDBAlignLOCwithRunway( FGRunwayList *runways, FGNavList *loclist,
+                                double threshold ) {
     nav_map_type navmap = loclist->get_navaids();
 
     nav_map_iterator freq = navmap.begin();
@@ -186,7 +199,7 @@ void fgNavDBAlignLOCwithRunway( FGRunwayList *runways, FGNavList *loclist ) {
 
             FGRunway r;
             if ( runways->search(id, rwy, &r) ) {
-                update_loc_position( (*loc), &r );
+                update_loc_position( (*loc), &r, threshold );
             }
             ++loc;
         }
index 36f1bdc42447cc7a9a558777f25bdb4b5c7710ee..5f0c39ff9496a5d4c70f773a75d0fc45912d0759 100644 (file)
@@ -50,7 +50,8 @@ bool fgNavDBInit( FGNavList *navlist, FGNavList *loclist, FGNavList *gslist,
 // it then "moves" the localizer and updates it's heading so it
 // *perfectly* aligns with the runway, but is still the same distance
 // from the runway threshold.
-void fgNavDBAlignLOCwithRunway( FGRunwayList *runways, FGNavList *loclist );
+void fgNavDBAlignLOCwithRunway( FGRunwayList *runways, FGNavList *loclist,
+                                double threshold );
 
 
 #endif // _FG_NAVDB_HXX