cur_fdm_state->unbind();
AptId = a.id.c_str(); /// NHV fix wrong case crash
- fgSetString("/sim/presets/airport-id", AptId.c_str() );
- // fgSetDouble("/position/altitude-ft", -9999.0 );
- // fgSetPosFromAirportID( AptId );
- fgSetPosFromAirportIDandHdg( AptId,
- cur_fdm_state->get_Psi() *
- SGD_RADIANS_TO_DEGREES);
- fgSetTowerPosFromAirportID( AptId,
- cur_fdm_state->get_Psi() *
- SGD_RADIANS_TO_DEGREES);
+ fgSetString("/sim/presets/airport-id", AptId.c_str() );
+ fgSetDouble("/sim/presets/longitude-deg", -9999.0 );
+ fgSetDouble("/sim/presets/latitude-deg", -9999.0 );
+ fgInitPosition();
+
// BusyCursor(0);
fgReInitSubsystems();
double visibility_meters =
- fgGetDouble("/environment/visibility-m");
+ fgGetDouble("/environment/visibility-m");
global_tile_mgr.update( longitude->getDoubleValue(),
- latitude->getDoubleValue(),visibility_meters );
+ latitude->getDoubleValue(),
+ visibility_meters );
// BusyCursor(1);
} else {
AptId += " not in database.";
// Preset lon/lat given an airport id
-bool fgSetPosFromAirportID( const string& id ) {
+static bool fgSetPosFromAirportID( const string& id ) {
FGAirport a;
// double lon, lat;
// Set current tower position lon/lat given an airport id
-bool fgSetTowerPosFromAirportID( const string& id, double hdg ) {
+static bool fgSetTowerPosFromAirportID( const string& id, double hdg ) {
FGAirport a;
// tower height hard coded for now...
float towerheight=50.0f;
// Set current_options lon/lat given an airport id and heading (degrees)
-bool fgSetPosFromAirportIDandHdg( const string& id, double tgt_hdg ) {
+static bool fgSetPosFromAirportIDandHdg( const string& id, double tgt_hdg ) {
FGRunway r;
FGRunway found_r;
double found_dir = 0.0;
}
-void fgSetPosFromGlideSlope() {
+static void fgSetDistOrAltFromGlideSlope() {
double gs = fgGetDouble("/sim/presets/glideslope");
double od = fgGetDouble("/sim/presets/offset-distance");
double alt = fgGetDouble("/sim/presets/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 ) {
+ // set altitude from glideslope and offset-distance
od *= SG_NM_TO_METER * SG_METER_TO_FEET;
alt = fabs(od*tan(gs));
- fgSetDouble("/sim/presets/altitude-ft",alt);
+ fgSetDouble("/sim/presets/altitude-ft", alt);
fgSetBool("/sim/presets/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) {
+ // set offset-distance from glideslope and altitude
od = alt/tan(gs);
od *= -1*SG_FEET_TO_METER * SG_METER_TO_NM;
- fgSetDouble("/sim/presets/offset-distance",od);
+ fgSetDouble("/sim/presets/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." );
SG_LOG( SG_GENERAL, SG_ALERT, "Resetting glideslope to zero" );
- fgSetDouble("/sim/presets/glideslope",0);
+ fgSetDouble("/sim/presets/glideslope", 0);
}
}
+// Set the initial position based on presets (or defaults)
+bool fgInitPosition() {
+ // Calculate offset-distance or altitude relative to glide slope
+ // if either was not specified.
+ fgSetDistOrAltFromGlideSlope();
+
+ // If we have an explicit, in-range lon/lat, don't change it, just use it.
+ // If not, check for an airport-id and use that.
+ // If not, default to the middle of the KSFO field.
+ // The default values for lon/lat are deliberately out of range
+ // so that the airport-id can take effect; valid lon/lat will
+ // override airport-id, however.
+ double lon_deg = fgGetDouble("/sim/presets/longitude-deg");
+ double lat_deg = fgGetDouble("/sim/presets/latitude-deg");
+ if ( lon_deg >= -180.0 && lon_deg <= 180.0
+ && lat_deg >= -90.0 && lat_deg <= 90.0 )
+ {
+ // valid lon/lat specified, use it.
+ } else {
+ string apt = fgGetString("/sim/presets/airport-id");
+ double hdg = fgGetDouble("/sim/presets/heading-deg");
+ if ( !apt.empty() ) {
+ // An airport id is requested, set position from that.
+ fgSetPosFromAirportIDandHdg( apt, hdg );
+
+ // set tower position (a little off the heading for single
+ // runway airports)
+ fgSetTowerPosFromAirportID( apt, hdg );
+ } else {
+ // No lon/lat specified, no airport specified, default to
+ // middle of KSFO field.
+ fgSetDouble("/sim/presets/longitude-deg", -122.374843);
+ fgSetDouble("/sim/presets/latitude-deg", 37.619002);
+ }
+ }
+
+ fgSetDouble( "/position/longitude-deg",
+ fgGetDouble("/sim/presets/longitude-deg") );
+ fgSetDouble( "/position/latitude-deg",
+ fgGetDouble("/sim/presets/latitude-deg") );
+ fgSetDouble( "/orientation/heading-deg",
+ fgGetDouble("/sim/presets/heading-deg") );
+
+ return true;
+}
+
+
// General house keeping initializations
-bool fgInitGeneral( void ) {
+bool fgInitGeneral() {
string root;
#if defined(FX) && defined(XMESA)
// find basic airport location info from airport database
bool fgFindAirportID( const string& id, FGAirport *a );
-// Set pos given an airport id
-bool fgSetPosFromAirportID( const string& id );
-
-// Set tower position given an airport id
-bool fgSetTowerPosFromAirportID( const string& id, double hdg );
-
-// 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);
+// Set the initial position based on presets (or defaults)
+bool fgInitPosition();
// Initialize various time dependent systems (lighting, sun position, etc.)
// returns a new instance of the SGTime class
# endif
#endif
- // Set position relative to glide slope if requested
- fgSetPosFromGlideSlope();
-
- // If we have an explicit, in-range lon/lat, use it.
- // If not, check for an airport-id and use that.
- // If not, default to the middle of the KSFO field.
- // The default values for lon/lat are deliberately out of range
- // so that the airport-id can take effect; valid lon/lat will
- // override airport-id, however.
- double lon_deg = fgGetDouble("/position/longitude-deg");
- double lat_deg = fgGetDouble("/position/latitude-deg");
- if (lon_deg < -180 || lon_deg > 180 || lat_deg < -90 || lat_deg > 90) {
- if ( fgGetString("/sim/presets/airport-id")[0] != '\0' ) {
- fgSetPosFromAirportIDandHdg( fgGetString("/sim/presets/airport-id"),
- fgGetDouble("/sim/presets/heading-deg") );
- // set tower position (a little off the heading for single
- // runway airports)
- fgSetTowerPosFromAirportID( fgGetString("/sim/presets/airport-id"),
- fgGetDouble("/sim/presets/heading-deg") );
- } else {
- // Default to middle of KSFO field
- fgSetDouble("/sim/presets/longitude-deg", -122.374843);
- fgSetDouble("/sim/presets/latitude-deg", 37.619002);
- }
- }
+ // based on the requested presets, calculate the true starting
+ // lon, lat
+ fgInitPosition();
SGTime *t = fgInitTime();
globals->set_time_params( t );