]> git.mxchange.org Git - flightgear.git/commitdiff
Added Tony's function to set position on a glide slope.
authorcurt <curt>
Wed, 20 Feb 2002 16:56:44 +0000 (16:56 +0000)
committercurt <curt>
Wed, 20 Feb 2002 16:56:44 +0000 (16:56 +0000)
src/Main/fg_init.cxx
src/Main/fg_init.hxx

index 32754320ab6b378e60823cfdc8e6db4444622c8f..f12755289841ef145dc185eaa9099abaf3b577fe 100644 (file)
@@ -467,6 +467,33 @@ bool fgSetPosFromAirportIDandHdg( const string& id, double tgt_hdg ) {
     return true;
 }
 
+void fgSetPosFromGlideSlope(void) {
+    double gs = fgGetDouble("/velocities/glideslope");
+    double od = fgGetDouble("/sim/startup/offset-distance");
+    double alt = fgGetDouble("/position/altitude-ft");
+    
+    //if glideslope and offset-distance are set and altitude is
+    //not, calculate the initial altitude
+    if( fabs(gs) > 0.01 && fabs(od) > 0.1 && alt < -9990 ) {
+       od *= SG_NM_TO_METER * SG_METER_TO_FEET;
+       alt = fabs(od*tan(gs));
+       fgSetDouble("/position/altitude-ft",alt);
+       fgSetBool("/sim/startup/onground", false);
+       SG_LOG(SG_GENERAL,SG_INFO, "Calculated altitude as: " << alt  << " ft");
+    } else if( fabs(gs) > 0.01 && alt > 0 && fabs(od) < 0.1) {
+       od  = alt/tan(gs);
+       od *= -1*SG_FEET_TO_METER * SG_METER_TO_NM;
+       fgSetDouble("/sim/startup/offset-distance",od);
+       SG_LOG(SG_GENERAL,SG_INFO, "Calculated offset distance as: " 
+                                      << od  << " nm");
+    } else if( fabs(gs) > 0.01 ) {
+       SG_LOG(SG_GENERAL,SG_ALERT, "Glideslope given but not altitude" 
+                                 << " or offset-distance.  Resetting"
+                                 << " glideslope to zero" );
+        fgSetDouble("/velocities/glideslope",0);                                 
+    }                             
+                                     
+}                      
 
 // General house keeping initializations
 bool fgInitGeneral( void ) {
index 23350450e5afb65ee1d4c74ac0c9d91b0ccd9ae5..6ed654e7cb774a5716a7f97f39ff6d7bd172e30b 100644 (file)
@@ -80,6 +80,10 @@ bool fgSetPosFromAirportID( const string& id );
 // Set position and heading given an airport id and heading (degrees)
 bool fgSetPosFromAirportIDandHdg( const string& id, double tgt_hdg );
 
+//find altitude given glideslope and offset distance or offset distance
+//given glideslope and altitude
+void fgSetPosFromGlideSlope(void);
+
 // Initialize various time dependent systems (lighting, sun position, etc.)
 // returns a new instance of the SGTime class
 SGTime *fgInitTime();