1 // fg_init.cxx -- Flight Gear top level initialization routines
3 // Written by Curtis Olson, started August 1997.
5 // Copyright (C) 1997 Curtis L. Olson - curt@infoplane.com
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 // General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
29 // For BC 5.01 this must be included before OpenGL includes.
30 #ifdef FG_MATH_EXCEPTION_CLASH
35 #include <simgear/xgl/xgl.h>
40 // work around a stdc++ lib bug in some versions of linux, but doesn't
41 // seem to hurt to have this here for all versions of Linux.
43 # define _G_NO_EXTERN_TEMPLATES
46 #include <simgear/compiler.h>
50 #include <simgear/constants.h>
51 #include <simgear/debug/logstream.hxx>
52 #include <simgear/math/fg_geodesy.hxx>
53 #include <simgear/math/point3d.hxx>
54 #include <simgear/math/polar3d.hxx>
55 #include <simgear/misc/fgpath.hxx>
56 #include <simgear/timing/sg_time.hxx>
58 #include <Aircraft/aircraft.hxx>
59 #include <Airports/runways.hxx>
60 #include <Airports/simple.hxx>
61 #include <Autopilot/auto_gui.hxx>
62 #include <Autopilot/newauto.hxx>
63 #include <Cockpit/cockpit.hxx>
64 #include <Cockpit/radiostack.hxx>
65 #include <Cockpit/panel.hxx>
66 #include <Cockpit/sp_panel.hxx>
67 #include <FDM/Balloon.h>
68 #include <FDM/External.hxx>
69 #include <FDM/JSBSim.hxx>
70 #include <FDM/LaRCsim.hxx>
71 #include <FDM/MagicCarpet.hxx>
72 #include <Include/general.hxx>
73 #include <Joystick/joystick.hxx>
74 #include <Objects/matlib.hxx>
75 #include <Navaids/fixlist.hxx>
76 #include <Navaids/ilslist.hxx>
77 #include <Navaids/navlist.hxx>
78 #include <Scenery/scenery.hxx>
79 #include <Scenery/tilemgr.hxx>
80 #include <Time/event.hxx>
81 #include <Time/light.hxx>
82 #include <Time/sunpos.hxx>
83 #include <Time/moonpos.hxx>
84 #include <Time/tmp.hxx>
86 #ifndef FG_OLD_WEATHER
87 # include <WeatherCM/FGLocalWeatherDatabase.h>
89 # include <Weather/weather.hxx>
92 #include "fg_init.hxx"
94 #include "globals.hxx"
95 #include "options.hxx"
99 #if defined(FX) && defined(XMESA)
100 #include <GL/xmesa.h>
103 FG_USING_STD(string);
105 extern const char *default_root;
108 // Read in configuration (file and command line)
109 bool fgInitConfig ( int argc, char **argv ) {
110 // Attempt to locate and parse a config file
111 // First check fg_root
112 FGPath config( current_options.get_fg_root() );
113 config.append( "system.fgfsrc" );
114 current_options.parse_config_file( config.str() );
116 // Next check home directory
117 char* envp = ::getenv( "HOME" );
118 if ( envp != NULL ) {
120 config.append( ".fgfsrc" );
121 current_options.parse_config_file( config.str() );
124 // Parse remaining command line options
125 // These will override anything specified in a config file
126 if ( current_options.parse_command_line(argc, argv) !=
127 fgOPTIONS::FG_OPTIONS_OK )
129 // Something must have gone horribly wrong with the command
130 // line parsing or maybe the user just requested help ... :-)
131 current_options.usage();
132 FG_LOG( FG_GENERAL, FG_ALERT, "\nExiting ...");
140 // Set current_options lon/lat given an airport id
141 bool fgSetPosFromAirportID( const string& id ) {
146 // set initial position from airport id
148 FGPath path( current_options.get_fg_root() );
149 path.append( "Airports" );
150 path.append( "simple.mk4" );
151 FGAirports airports( path.c_str() );
153 FG_LOG( FG_GENERAL, FG_INFO,
154 "Attempting to set starting position from airport code "
157 // FGPath inpath( current_options.get_fg_root() );
158 // inpath.append( "Airports" );
159 // inpath.append( "apt_simple" );
160 // airports.load( inpath.c_str() );
162 // FGPath outpath( current_options.get_fg_root() );
163 // outpath.append( "Airports" );
164 // outpath.append( "simple.gdbm" );
165 // airports.dump_gdbm( outpath.c_str() );
167 if ( ! airports.search( id, &a ) ) {
168 FG_LOG( FG_GENERAL, FG_ALERT,
169 "Failed to find " << id << " in database." );
172 current_options.set_lon( a.longitude );
173 current_options.set_lat( a.latitude );
179 FG_LOG( FG_GENERAL, FG_INFO,
180 "Position for " << id << " is ("
181 << a.longitude << ", "
182 << a.latitude << ")" );
188 // Set current_options lon/lat given an airport id and heading (degrees)
189 bool fgSetPosFromAirportIDandHdg( const string& id, double tgt_hdg ) {
195 // set initial position from runway and heading
197 FGPath path( current_options.get_fg_root() );
198 path.append( "Airports" );
199 path.append( "runways.mk4" );
200 FGRunways runways( path.c_str() );
202 FG_LOG( FG_GENERAL, FG_INFO,
203 "Attempting to set starting position from runway code "
204 << id << " heading " << tgt_hdg );
206 // FGPath inpath( current_options.get_fg_root() );
207 // inpath.append( "Airports" );
208 // inpath.append( "apt_simple" );
209 // airports.load( inpath.c_str() );
211 // FGPath outpath( current_options.get_fg_root() );
212 // outpath.append( "Airports" );
213 // outpath.append( "simple.gdbm" );
214 // airports.dump_gdbm( outpath.c_str() );
216 if ( ! runways.search( id, &r ) ) {
217 FG_LOG( FG_GENERAL, FG_ALERT,
218 "Failed to find " << id << " in database." );
223 double min_diff = 360.0;
225 while ( r.id == id ) {
227 diff = tgt_hdg - r.heading;
228 while ( diff < -180.0 ) { diff += 360.0; }
230 FG_LOG( FG_GENERAL, FG_INFO,
231 "Runway " << r.rwy_no << " heading = " << r.heading <<
232 " diff = " << diff );
233 if ( diff < min_diff ) {
240 diff = tgt_hdg - r.heading - 180.0;
241 while ( diff < -180.0 ) { diff += 360.0; }
243 FG_LOG( FG_GENERAL, FG_INFO,
244 "Runway -" << r.rwy_no << " heading = " <<
246 " diff = " << diff );
247 if ( diff < min_diff ) {
256 FG_LOG( FG_GENERAL, FG_INFO, "closest runway = " << found_r.rwy_no
257 << " + " << found_dir );
263 double heading = found_r.heading + found_dir;
264 while ( heading >= 360.0 ) { heading -= 360.0; }
266 double lat2, lon2, az2;
267 double azimuth = found_r.heading + found_dir + 180.0;
268 while ( azimuth >= 360.0 ) { azimuth -= 360.0; }
270 FG_LOG( FG_GENERAL, FG_INFO,
271 "runway = " << found_r.lon << ", " << found_r.lat
272 << " length = " << found_r.length * FEET_TO_METER * 0.5
273 << " heading = " << azimuth );
274 geo_direct_wgs_84 ( 0, found_r.lat, found_r.lon,
275 azimuth, found_r.length * FEET_TO_METER * 0.5 - 5.0,
276 &lat2, &lon2, &az2 );
277 current_options.set_lon( lon2 );
278 current_options.set_lat( lat2 );
279 current_options.set_heading( heading );
281 FG_LOG( FG_GENERAL, FG_INFO,
282 "Position for " << id << " is ("
284 << lat2 << ") new heading is "
291 // Set initial position and orientation
292 bool fgInitPosition( void ) {
293 FGInterface *f = current_aircraft.fdm_state;
294 string id = current_options.get_airport_id();
296 // set initial position from default or command line coordinates
297 f->set_Longitude( current_options.get_lon() * DEG_TO_RAD );
298 f->set_Latitude( current_options.get_lat() * DEG_TO_RAD );
300 if ( scenery.cur_elev > current_options.get_altitude() - 1) {
301 current_options.set_altitude( scenery.cur_elev + 1 );
304 FG_LOG( FG_GENERAL, FG_INFO,
305 "starting altitude is = " << current_options.get_altitude() );
307 f->set_Altitude( current_options.get_altitude() * METER_TO_FEET );
308 fgFDMSetGroundElevation( current_options.get_flight_model(),
309 f->get_Altitude() * FEET_TO_METER );
311 FG_LOG( FG_GENERAL, FG_INFO,
312 "Initial position is: ("
313 << (f->get_Longitude() * RAD_TO_DEG) << ", "
314 << (f->get_Latitude() * RAD_TO_DEG) << ", "
315 << (f->get_Altitude() * FEET_TO_METER) << ")" );
321 // General house keeping initializations
322 bool fgInitGeneral( void ) {
325 #if defined(FX) && defined(XMESA)
326 char *mesa_win_state;
329 FG_LOG( FG_GENERAL, FG_INFO, "General Initialization" );
330 FG_LOG( FG_GENERAL, FG_INFO, "======= ==============" );
332 root = current_options.get_fg_root();
333 if ( ! root.length() ) {
334 // No root path set? Then bail ...
335 FG_LOG( FG_GENERAL, FG_ALERT,
336 "Cannot continue without environment variable FG_ROOT"
337 << "being defined." );
340 FG_LOG( FG_GENERAL, FG_INFO, "FG_ROOT = " << '"' << root << '"' << endl );
342 #if defined(FX) && defined(XMESA)
343 // initialize full screen flag
344 global_fullscreen = false;
345 if ( strstr ( general.get_glRenderer(), "Glide" ) ) {
346 // Test for the MESA_GLX_FX env variable
347 if ( (mesa_win_state = getenv( "MESA_GLX_FX" )) != NULL) {
348 // test if we are fullscreen mesa/glide
349 if ( (mesa_win_state[0] == 'f') ||
350 (mesa_win_state[0] == 'F') ) {
351 global_fullscreen = true;
361 // This is the top level init routine which calls all the other
362 // initialization routines. If you are adding a subsystem to flight
363 // gear, its initialization call should located in this routine.
364 // Returns non-zero if a problem encountered.
365 bool fgInitSubsystems( void ) {
366 fgLIGHT *l = &cur_light_params;
368 FG_LOG( FG_GENERAL, FG_INFO, "Initialize Subsystems");
369 FG_LOG( FG_GENERAL, FG_INFO, "========== ==========");
371 // Initialize the material property lib
372 FGPath mpath( current_options.get_fg_root() );
373 mpath.append( "materials" );
374 if ( material_lib.load( mpath.str() ) ) {
376 FG_LOG( FG_GENERAL, FG_ALERT, "Error loading material lib!" );
380 // Initialize the Scenery Management subsystem
381 if ( fgSceneryInit() ) {
382 // Material lib initialized ok.
384 FG_LOG( FG_GENERAL, FG_ALERT, "Error in Scenery initialization!" );
388 if ( global_tile_mgr.init() ) {
389 // Load the local scenery data
390 global_tile_mgr.update( current_options.get_lon(),
391 current_options.get_lat() );
393 FG_LOG( FG_GENERAL, FG_ALERT, "Error in Tile Manager initialization!" );
397 FG_LOG( FG_GENERAL, FG_DEBUG,
398 "Current terrain elevation after tile mgr init " <<
401 if ( current_options.get_flight_model() == FGInterface::FG_LARCSIM ) {
402 cur_fdm_state = new FGLaRCsim;
403 } else if ( current_options.get_flight_model() == FGInterface::FG_JSBSIM ) {
404 cur_fdm_state = new FGJSBsim;
405 } else if ( current_options.get_flight_model() ==
406 FGInterface::FG_BALLOONSIM ) {
407 cur_fdm_state = new FGBalloonSim;
408 } else if ( current_options.get_flight_model() ==
409 FGInterface::FG_MAGICCARPET ) {
410 cur_fdm_state = new FGMagicCarpet;
411 } else if ( current_options.get_flight_model() ==
412 FGInterface::FG_EXTERNAL ) {
413 cur_fdm_state = new FGExternal;
415 FG_LOG( FG_GENERAL, FG_ALERT,
416 "No flight model, can't init aircraft" );
420 // allocates structures so must happen before any of the flight
421 // model or control parameters are set
422 fgAircraftInit(); // In the future this might not be the case.
424 // set the initial position
427 // Calculate ground elevation at starting point (we didn't have
428 // tmp_abs_view_pos calculated when fgTileMgrUpdate() was called above
430 // calculalate a cartesian point somewhere along the line between
431 // the center of the earth and our view position. Doesn't have to
432 // be the exact elevation (this is good because we don't know it
435 // now handled inside of the fgTileMgrUpdate()
438 geod_pos = Point3D( cur_fdm_state->get_Longitude(), cur_fdm_state->get_Latitude(), 0.0);
439 tmp_abs_view_pos = fgGeodToCart(geod_pos);
441 FG_LOG( FG_GENERAL, FG_DEBUG,
442 "Initial abs_view_pos = " << tmp_abs_view_pos );
444 fgTileMgrCurElev( cur_fdm_state->get_Longitude(), cur_fdm_state->get_Latitude(),
446 FG_LOG( FG_GENERAL, FG_DEBUG,
447 "Altitude after update " << scenery.cur_elev );
450 fgFDMSetGroundElevation( current_options.get_flight_model(),
453 // Reset our altitude if we are below ground
454 FG_LOG( FG_GENERAL, FG_DEBUG, "Current altitude = " << cur_fdm_state->get_Altitude() );
455 FG_LOG( FG_GENERAL, FG_DEBUG, "Current runway altitude = " <<
456 cur_fdm_state->get_Runway_altitude() );
458 if ( cur_fdm_state->get_Altitude() < cur_fdm_state->get_Runway_altitude() + 3.758099) {
459 cur_fdm_state->set_Altitude( cur_fdm_state->get_Runway_altitude() + 3.758099 );
462 FG_LOG( FG_GENERAL, FG_INFO,
463 "Updated position (after elevation adj): ("
464 << (cur_fdm_state->get_Latitude() * RAD_TO_DEG) << ", "
465 << (cur_fdm_state->get_Longitude() * RAD_TO_DEG) << ", "
466 << (cur_fdm_state->get_Altitude() * FEET_TO_METER) << ")" );
468 // We need to calculate a few more values here that would normally
469 // be calculated by the FDM so that the current_view.UpdateViewMath()
470 // routine doesn't get hosed.
472 double sea_level_radius_meters;
474 // Set the FG variables first
475 fgGeodToGeoc( cur_fdm_state->get_Latitude(), cur_fdm_state->get_Altitude(),
476 &sea_level_radius_meters, &lat_geoc);
477 cur_fdm_state->set_Geocentric_Position( lat_geoc, cur_fdm_state->get_Longitude(),
478 cur_fdm_state->get_Altitude() +
479 (sea_level_radius_meters * METER_TO_FEET) );
480 cur_fdm_state->set_Sea_level_radius( sea_level_radius_meters * METER_TO_FEET );
482 cur_fdm_state->set_sin_cos_longitude(cur_fdm_state->get_Longitude());
483 cur_fdm_state->set_sin_cos_latitude(cur_fdm_state->get_Latitude());
485 cur_fdm_state->set_sin_lat_geocentric(sin(lat_geoc));
486 cur_fdm_state->set_cos_lat_geocentric(cos(lat_geoc));
488 // The following section sets up the flight model EOM parameters
489 // and should really be read in from one or more files.
492 cur_fdm_state->set_Velocities_Local( current_options.get_uBody(),
493 current_options.get_vBody(),
494 current_options.get_wBody());
496 // Initial Orientation
497 cur_fdm_state->set_Euler_Angles( current_options.get_roll() * DEG_TO_RAD,
498 current_options.get_pitch() * DEG_TO_RAD,
499 current_options.get_heading() * DEG_TO_RAD );
501 // Initial Angular Body rates
502 cur_fdm_state->set_Omega_Body( 7.206685E-05, 0.0, 9.492658E-05 );
504 cur_fdm_state->set_Earth_position_angle( 0.0 );
506 // Mass properties and geometry values
507 cur_fdm_state->set_Inertias( 8.547270E+01,
508 1.048000E+03, 3.000000E+03, 3.530000E+03, 0.000000E+00 );
510 // CG position w.r.t. ref. point
511 cur_fdm_state->set_CG_Position( 0.0, 0.0, 0.0 );
513 // Initialize the event manager
514 global_events.Init();
516 // Output event stats every 60 seconds
517 global_events.Register( "fgEVENT_MGR::PrintStats()",
518 fgMethodCallback<fgEVENT_MGR>( &global_events,
519 &fgEVENT_MGR::PrintStats),
520 fgEVENT::FG_EVENT_READY, 60000 );
522 // Initialize view parameters
523 FG_LOG( FG_GENERAL, FG_DEBUG, "Before current_view.init()");
526 FG_LOG( FG_GENERAL, FG_DEBUG, "After current_view.init()");
527 current_view.UpdateViewMath(*cur_fdm_state);
528 pilot_view.UpdateViewMath(*cur_fdm_state);
529 FG_LOG( FG_GENERAL, FG_DEBUG, " abs_view_pos = " << current_view.get_abs_view_pos());
530 // current_view.UpdateWorldToEye(f);
532 // Initialize the planetary subsystem
533 // global_events.Register( "fgPlanetsInit()", fgPlanetsInit,
534 // fgEVENT::FG_EVENT_READY, 600000);
536 // Initialize the sun's position
537 // global_events.Register( "fgSunInit()", fgSunInit,
538 // fgEVENT::FG_EVENT_READY, 30000 );
540 // Intialize the moon's position
541 // global_events.Register( "fgMoonInit()", fgMoonInit,
542 // fgEVENT::FG_EVENT_READY, 600000 );
544 // fgUpdateSunPos() needs a few position and view parameters set
545 // so it can calculate local relative sun angle and a few other
546 // things for correctly orienting the sky.
549 global_events.Register( "fgUpdateSunPos()", fgUpdateSunPos,
550 fgEVENT::FG_EVENT_READY, 60000);
551 global_events.Register( "fgUpdateMoonPos()", fgUpdateMoonPos,
552 fgEVENT::FG_EVENT_READY, 60000);
554 // Initialize Lighting interpolation tables
557 // update the lighting parameters (based on sun angle)
558 global_events.Register( "fgLight::Update()",
559 fgMethodCallback<fgLIGHT>( &cur_light_params,
561 fgEVENT::FG_EVENT_READY, 30000 );
562 // update the current timezone each 30 minutes
563 global_events.Register( "fgUpdateLocalTime()", fgUpdateLocalTime,
564 fgEVENT::FG_EVENT_READY, 1800000);
566 // Initialize the weather modeling subsystem
567 #ifndef FG_OLD_WEATHER
568 // Initialize the WeatherDatabase
569 FG_LOG(FG_GENERAL, FG_INFO, "Creating LocalWeatherDatabase");
571 sgSetVec3( position, current_aircraft.fdm_state->get_Latitude(),
572 current_aircraft.fdm_state->get_Longitude(),
573 current_aircraft.fdm_state->get_Altitude() * FEET_TO_METER );
574 FGLocalWeatherDatabase::theFGLocalWeatherDatabase =
575 new FGLocalWeatherDatabase( position, current_options.get_fg_root() );
576 // cout << theFGLocalWeatherDatabase << endl;
577 // cout << "visibility = "
578 // << theFGLocalWeatherDatabase->getWeatherVisibility() << endl;
580 WeatherDatabase = FGLocalWeatherDatabase::theFGLocalWeatherDatabase;
582 // register the periodic update of the weather
583 global_events.Register( "weather update", fgUpdateWeatherDatabase,
584 fgEVENT::FG_EVENT_READY, 30000);
586 current_weather.Init();
589 // Initialize vor/ndb/ils/fix list management and query systems
590 FG_LOG(FG_GENERAL, FG_INFO, "Loading Navaids");
592 FG_LOG(FG_GENERAL, FG_INFO, " VOR/NDB");
593 current_navlist = new FGNavList;
594 FGPath p_nav( current_options.get_fg_root() );
595 p_nav.append( "Navaids/default.nav" );
596 current_navlist->init( p_nav );
598 FG_LOG(FG_GENERAL, FG_INFO, " ILS");
599 current_ilslist = new FGILSList;
600 FGPath p_ils( current_options.get_fg_root() );
601 p_ils.append( "Navaids/default.ils" );
602 current_ilslist->init( p_ils );
604 FG_LOG(FG_GENERAL, FG_INFO, " Fixes");
605 current_fixlist = new FGFixList;
606 FGPath p_fix( current_options.get_fg_root() );
607 p_fix.append( "Navaids/default.fix" );
608 current_fixlist->init( p_fix );
610 // Initialize the underlying radio stack model
611 current_radiostack = new FGRadioStack;
613 current_radiostack->set_nav1_freq( 117.30 );
614 current_radiostack->set_nav1_alt_freq( 110.30 );
615 current_radiostack->set_nav1_sel_radial( 119.0 );
617 current_radiostack->set_nav2_freq( 111.80 );
618 current_radiostack->set_nav2_alt_freq( 115.70 );
619 current_radiostack->set_nav2_sel_radial( 029.0 );
621 current_radiostack->set_adf_freq( 266.0 );
624 // This block of settings are Alex's defaults for San Diego
625 current_radiostack->set_nav1_freq( 111.70 );
626 current_radiostack->set_nav1_alt_freq( 115.30 );
627 current_radiostack->set_nav1_sel_radial( 280.0 );
628 current_radiostack->set_nav2_freq( 117.80 );
629 current_radiostack->set_nav2_alt_freq( 114.00 );
630 current_radiostack->set_nav2_sel_radial( 68.0 );
631 current_radiostack->set_adf_freq( 210.0 );
632 // End of Alex's custom settings
635 current_radiostack->search( cur_fdm_state->get_Longitude(),
636 cur_fdm_state->get_Latitude(),
637 cur_fdm_state->get_Altitude() * FEET_TO_METER );
639 current_radiostack->update( cur_fdm_state->get_Longitude(),
640 cur_fdm_state->get_Latitude(),
641 cur_fdm_state->get_Altitude() * FEET_TO_METER );
643 // Search radio database once per second
644 global_events.Register( "fgRadioSearch()", fgRadioSearch,
645 fgEVENT::FG_EVENT_READY, 1000);
648 // Initialize the Cockpit subsystem
649 if( fgCockpitInit( ¤t_aircraft )) {
650 // Cockpit initialized ok.
652 FG_LOG( FG_GENERAL, FG_ALERT, "Error in Cockpit initialization!" );
656 // Initialize the flight model subsystem data structures base on
659 // fgFDMInit( current_options.get_flight_model(), cur_fdm_state,
660 // 1.0 / current_options.get_model_hz() );
661 cur_fdm_state->init( 1.0 / current_options.get_model_hz() );
663 // I'm just sticking this here for now, it should probably move
665 scenery.cur_elev = cur_fdm_state->get_Runway_altitude() * FEET_TO_METER;
667 if ( cur_fdm_state->get_Altitude() < cur_fdm_state->get_Runway_altitude() + 3.758099) {
668 cur_fdm_state->set_Altitude( cur_fdm_state->get_Runway_altitude() + 3.758099 );
671 FG_LOG( FG_GENERAL, FG_INFO,
672 "Updated position (after elevation adj): ("
673 << (cur_fdm_state->get_Latitude() * RAD_TO_DEG) << ", "
674 << (cur_fdm_state->get_Longitude() * RAD_TO_DEG) << ", "
675 << (cur_fdm_state->get_Altitude() * FEET_TO_METER) << ")" );
676 // end of thing that I just stuck in that I should probably move
679 if ( fgJoystickInit() ) {
680 // Joystick initialized ok.
682 FG_LOG( FG_GENERAL, FG_ALERT, "Error in Joystick initialization!" );
686 current_autopilot = new FGAutopilot;
687 current_autopilot->init();
689 // initialize the gui parts of the autopilot
695 // Initialize I/O channels
696 #if ! defined( MACOS )
700 // Initialize the 2D panel.
701 current_panel = fgCreateSmallSinglePropPanel(0, 0, 1024, 768);
703 // Initialize the BFI
706 FG_LOG( FG_GENERAL, FG_INFO, endl);
712 void fgReInitSubsystems( void )
714 bool freeze = globals->get_freeze();
716 globals->set_freeze( true );
718 if( global_tile_mgr.init() ) {
719 // Load the local scenery data
720 global_tile_mgr.update( current_options.get_lon(),
721 current_options.get_lat() );
723 FG_LOG( FG_GENERAL, FG_ALERT, "Error in Tile Manager initialization!" );
727 // cout << "current scenery elev = " << scenery.cur_elev << endl;
730 fgFDMSetGroundElevation( current_options.get_flight_model(),
733 // Reset our altitude if we are below ground
734 FG_LOG( FG_GENERAL, FG_DEBUG, "Current altitude = " << cur_fdm_state->get_Altitude() );
735 FG_LOG( FG_GENERAL, FG_DEBUG, "Current runway altitude = " <<
736 cur_fdm_state->get_Runway_altitude() );
738 if ( cur_fdm_state->get_Altitude() < cur_fdm_state->get_Runway_altitude() + 3.758099) {
739 cur_fdm_state->set_Altitude( cur_fdm_state->get_Runway_altitude() + 3.758099 );
741 double sea_level_radius_meters;
743 // Set the FG variables first
744 fgGeodToGeoc( cur_fdm_state->get_Latitude(), cur_fdm_state->get_Altitude(),
745 &sea_level_radius_meters, &lat_geoc);
746 cur_fdm_state->set_Geocentric_Position( lat_geoc, cur_fdm_state->get_Longitude(),
747 cur_fdm_state->get_Altitude() +
748 (sea_level_radius_meters * METER_TO_FEET) );
749 cur_fdm_state->set_Sea_level_radius( sea_level_radius_meters * METER_TO_FEET );
751 cur_fdm_state->set_sin_cos_longitude(cur_fdm_state->get_Longitude());
752 cur_fdm_state->set_sin_cos_latitude(cur_fdm_state->get_Latitude());
754 cur_fdm_state->set_sin_lat_geocentric(sin(lat_geoc));
755 cur_fdm_state->set_cos_lat_geocentric(cos(lat_geoc));
757 // The following section sets up the flight model EOM parameters
758 // and should really be read in from one or more files.
761 cur_fdm_state->set_Velocities_Local( current_options.get_uBody(),
762 current_options.get_vBody(),
763 current_options.get_wBody());
765 // Initial Orientation
766 cur_fdm_state->set_Euler_Angles( current_options.get_roll() * DEG_TO_RAD,
767 current_options.get_pitch() * DEG_TO_RAD,
768 current_options.get_heading() * DEG_TO_RAD );
770 // Initial Angular Body rates
771 cur_fdm_state->set_Omega_Body( 7.206685E-05, 0.0, 9.492658E-05 );
773 cur_fdm_state->set_Earth_position_angle( 0.0 );
775 // Mass properties and geometry values
776 cur_fdm_state->set_Inertias( 8.547270E+01,
777 1.048000E+03, 3.000000E+03, 3.530000E+03, 0.000000E+00 );
779 // CG position w.r.t. ref. point
780 cur_fdm_state->set_CG_Position( 0.0, 0.0, 0.0 );
782 // Initialize view parameters
783 current_view.set_view_offset( 0.0 );
784 current_view.set_goal_view_offset( 0.0 );
785 pilot_view.set_view_offset( 0.0 );
786 pilot_view.set_goal_view_offset( 0.0 );
788 FG_LOG( FG_GENERAL, FG_DEBUG, "After current_view.init()");
789 current_view.UpdateViewMath(*cur_fdm_state);
790 pilot_view.UpdateViewMath(*cur_fdm_state);
791 FG_LOG( FG_GENERAL, FG_DEBUG, " abs_view_pos = " << current_view.get_abs_view_pos());
793 // fgFDMInit( current_options.get_flight_model(), cur_fdm_state,
794 // 1.0 / current_options.get_model_hz() );
795 cur_fdm_state->init( 1.0 / current_options.get_model_hz() );
797 scenery.cur_elev = cur_fdm_state->get_Runway_altitude() * FEET_TO_METER;
799 if ( cur_fdm_state->get_Altitude() < cur_fdm_state->get_Runway_altitude() + 3.758099) {
800 cur_fdm_state->set_Altitude( cur_fdm_state->get_Runway_altitude() + 3.758099 );
803 controls.reset_all();
804 current_autopilot->reset();
807 globals->set_freeze( false );