From: curt Date: Wed, 20 Feb 2002 16:56:44 +0000 (+0000) Subject: Added Tony's function to set position on a glide slope. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=1ea557f2491971848f6e9c237f69b4c19f9822b6;p=flightgear.git Added Tony's function to set position on a glide slope. --- diff --git a/src/Main/fg_init.cxx b/src/Main/fg_init.cxx index 32754320a..f12755289 100644 --- a/src/Main/fg_init.cxx +++ b/src/Main/fg_init.cxx @@ -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 ) { diff --git a/src/Main/fg_init.hxx b/src/Main/fg_init.hxx index 23350450e..6ed654e7c 100644 --- a/src/Main/fg_init.hxx +++ b/src/Main/fg_init.hxx @@ -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();