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/point3d.hxx>
53 #include <simgear/math/polar3d.hxx>
54 #include <simgear/math/sg_geodesy.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/panel_io.hxx>
67 #include <FDM/ADA.hxx>
68 #include <FDM/Balloon.h>
69 #include <FDM/External.hxx>
70 #include <FDM/JSBSim.hxx>
71 #include <FDM/LaRCsim.hxx>
72 #include <FDM/MagicCarpet.hxx>
73 #include <Include/general.hxx>
74 #include <Joystick/joystick.hxx>
75 #include <Objects/matlib.hxx>
76 #include <Navaids/fixlist.hxx>
77 #include <Navaids/ilslist.hxx>
78 #include <Navaids/navlist.hxx>
79 #include <Scenery/scenery.hxx>
80 #include <Scenery/tilemgr.hxx>
81 #include <Time/event.hxx>
82 #include <Time/light.hxx>
83 #include <Time/sunpos.hxx>
84 #include <Time/moonpos.hxx>
85 #include <Time/tmp.hxx>
87 #ifndef FG_OLD_WEATHER
88 # include <WeatherCM/FGLocalWeatherDatabase.h>
90 # include <Weather/weather.hxx>
93 #include "fg_init.hxx"
95 #include "options.hxx"
96 #include "globals.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) and just set fg_root
109 bool fgInitFGRoot ( int argc, char **argv ) {
113 // First parse command line options looking for fg-root, this will
114 // override anything specified in a config file
115 root = fgScanForRoot(argc, argv);
117 // Next check home directory for .fgfsrc file
119 envp = ::getenv( "HOME" );
120 if ( envp != NULL ) {
121 FGPath config( envp );
122 config.append( ".fgfsrc" );
123 root = fgScanForRoot(config.str());
127 // Next check if fg-root is set as an env variable
129 envp = ::getenv( "FG_ROOT" );
130 if ( envp != NULL ) {
135 // Otherwise, default to a random compiled-in location if we can't
136 // find fg-root any other way.
139 root = "\\FlightGear";
140 #elif defined( macintosh )
147 FG_LOG(FG_INPUT, FG_INFO, "fg_root = " << root );
148 globals->set_fg_root(root);
154 // Read in configuration (file and command line)
155 bool fgInitConfig ( int argc, char **argv ) {
157 // First, set some sane default values
160 // Read global preferences from $FG_ROOT/preferences.xml
161 FGPath props_path(globals->get_fg_root());
162 props_path.append("preferences.xml");
163 FG_LOG(FG_INPUT, FG_INFO, "Reading global preferences");
164 if (!readProperties(props_path.str(), globals->get_props())) {
165 FG_LOG(FG_INPUT, FG_ALERT, "Failed to read global preferences from "
166 << props_path.str());
168 FG_LOG(FG_INPUT, FG_INFO, "Finished Reading global preferences");
171 // Attempt to locate and parse a config file
172 // First check fg_root
173 FGPath config( globals->get_fg_root() );
174 config.append( "system.fgfsrc" );
175 fgParseOptions(config.str());
177 // Next check home directory
178 char* envp = ::getenv( "HOME" );
179 if ( envp != NULL ) {
181 config.append( ".fgfsrc" );
182 fgParseOptions(config.str());
185 // Parse remaining command line options
186 // These will override anything specified in a config file
187 fgParseOptions(argc, argv);
193 // find basic airport location info from airport database
194 bool fgFindAirportID( const string& id, FGAirport *a ) {
196 FGPath path( globals->get_fg_root() );
197 path.append( "Airports" );
198 path.append( "simple.mk4" );
199 FGAirports airports( path.c_str() );
201 FG_LOG( FG_GENERAL, FG_INFO, "Searching for airport code = " << id );
203 if ( ! airports.search( id, a ) ) {
204 FG_LOG( FG_GENERAL, FG_ALERT,
205 "Failed to find " << id << " in " << path.str() );
212 FG_LOG( FG_GENERAL, FG_INFO,
213 "Position for " << id << " is ("
214 << a->longitude << ", "
215 << a->latitude << ")" );
221 // Set current_options lon/lat given an airport id
222 bool fgSetPosFromAirportID( const string& id ) {
226 FG_LOG( FG_GENERAL, FG_INFO,
227 "Attempting to set starting position from airport code " << id );
229 if ( fgFindAirportID( id, &a ) ) {
230 fgSetDouble("/position/longitude", a.longitude );
231 fgSetDouble("/position/latitude", a.latitude );
232 FG_LOG( FG_GENERAL, FG_INFO,
233 "Position for " << id << " is ("
234 << a.longitude << ", "
235 << a.latitude << ")" );
245 // Set current_options lon/lat given an airport id and heading (degrees)
246 bool fgSetPosFromAirportIDandHdg( const string& id, double tgt_hdg ) {
249 double found_dir = 0.0;
252 // set initial position from runway and heading
254 FGPath path( globals->get_fg_root() );
255 path.append( "Airports" );
256 path.append( "runways.mk4" );
257 FGRunways runways( path.c_str() );
259 FG_LOG( FG_GENERAL, FG_INFO,
260 "Attempting to set starting position from runway code "
261 << id << " heading " << tgt_hdg );
263 // FGPath inpath( globals->get_fg_root() );
264 // inpath.append( "Airports" );
265 // inpath.append( "apt_simple" );
266 // airports.load( inpath.c_str() );
268 // FGPath outpath( globals->get_fg_root() );
269 // outpath.append( "Airports" );
270 // outpath.append( "simple.gdbm" );
271 // airports.dump_gdbm( outpath.c_str() );
273 if ( ! runways.search( id, &r ) ) {
274 FG_LOG( FG_GENERAL, FG_ALERT,
275 "Failed to find " << id << " in database." );
280 double min_diff = 360.0;
282 while ( r.id == id ) {
284 diff = tgt_hdg - r.heading;
285 while ( diff < -180.0 ) { diff += 360.0; }
286 while ( diff > 180.0 ) { diff -= 360.0; }
288 FG_LOG( FG_GENERAL, FG_INFO,
289 "Runway " << r.rwy_no << " heading = " << r.heading <<
290 " diff = " << diff );
291 if ( diff < min_diff ) {
298 diff = tgt_hdg - r.heading - 180.0;
299 while ( diff < -180.0 ) { diff += 360.0; }
300 while ( diff > 180.0 ) { diff -= 360.0; }
302 FG_LOG( FG_GENERAL, FG_INFO,
303 "Runway -" << r.rwy_no << " heading = " <<
305 " diff = " << diff );
306 if ( diff < min_diff ) {
315 FG_LOG( FG_GENERAL, FG_INFO, "closest runway = " << found_r.rwy_no
316 << " + " << found_dir );
322 double heading = found_r.heading + found_dir;
323 while ( heading >= 360.0 ) { heading -= 360.0; }
325 double lat2, lon2, az2;
326 double azimuth = found_r.heading + found_dir + 180.0;
327 while ( azimuth >= 360.0 ) { azimuth -= 360.0; }
329 FG_LOG( FG_GENERAL, FG_INFO,
330 "runway = " << found_r.lon << ", " << found_r.lat
331 << " length = " << found_r.length * FEET_TO_METER * 0.5
332 << " heading = " << azimuth );
333 geo_direct_wgs_84 ( 0, found_r.lat, found_r.lon,
334 azimuth, found_r.length * FEET_TO_METER * 0.5 - 5.0,
335 &lat2, &lon2, &az2 );
336 fgSetDouble("/position/longitude", lon2 );
337 fgSetDouble("/position/latitude", lat2 );
338 fgSetDouble("/orientation/heading", heading );
340 FG_LOG( FG_GENERAL, FG_INFO,
341 "Position for " << id << " is ("
343 << lat2 << ") new heading is "
350 // Set initial position and orientation
351 bool fgInitPosition( void ) {
352 FGInterface *f = current_aircraft.fdm_state;
353 string id = fgGetString("/sim/startup/airport-id");
355 // set initial position from default or command line coordinates
356 f->set_Longitude( fgGetDouble("/position/longitude") * DEG_TO_RAD );
357 f->set_Latitude( fgGetDouble("/position/latitude") * DEG_TO_RAD );
359 FG_LOG( FG_GENERAL, FG_INFO,
360 "scenery.cur_elev = " << scenery.cur_elev );
362 // if ( scenery.cur_elev > fgGetDouble("/position/altitude") - 1) {
363 fgSetDouble("/position/altitude", scenery.cur_elev + 1 );
366 FG_LOG( FG_GENERAL, FG_INFO,
367 "starting altitude is = " <<
368 fgGetDouble("/position/altitude") );
370 f->set_Altitude( fgGetDouble("/position/altitude") );
371 FG_LOG( FG_GENERAL, FG_INFO,
372 "Initial position is: ("
373 << (f->get_Longitude() * RAD_TO_DEG) << ", "
374 << (f->get_Latitude() * RAD_TO_DEG) << ", "
375 << (f->get_Altitude() * FEET_TO_METER) << ")" );
381 // General house keeping initializations
382 bool fgInitGeneral( void ) {
385 #if defined(FX) && defined(XMESA)
386 char *mesa_win_state;
389 FG_LOG( FG_GENERAL, FG_INFO, "General Initialization" );
390 FG_LOG( FG_GENERAL, FG_INFO, "======= ==============" );
392 root = globals->get_fg_root();
393 if ( ! root.length() ) {
394 // No root path set? Then bail ...
395 FG_LOG( FG_GENERAL, FG_ALERT,
396 "Cannot continue without environment variable FG_ROOT"
397 << "being defined." );
400 FG_LOG( FG_GENERAL, FG_INFO, "FG_ROOT = " << '"' << root << '"' << endl );
402 #if defined(FX) && defined(XMESA)
403 // initialize full screen flag
404 global_fullscreen = false;
405 if ( strstr ( general.get_glRenderer(), "Glide" ) ) {
406 // Test for the MESA_GLX_FX env variable
407 if ( (mesa_win_state = getenv( "MESA_GLX_FX" )) != NULL) {
408 // test if we are fullscreen mesa/glide
409 if ( (mesa_win_state[0] == 'f') ||
410 (mesa_win_state[0] == 'F') ) {
411 global_fullscreen = true;
421 // set initial aircraft speed
423 fgVelocityInit( void )
425 if (!fgHasValue("/sim/startup/speed-set")) {
426 current_aircraft.fdm_state->set_V_calibrated_kts(0.0);
430 const string speedset = fgGetString("/sim/startup/speed-set");
431 if (speedset == "knots" || speedset == "KNOTS") {
432 current_aircraft.fdm_state
433 ->set_V_calibrated_kts(fgGetDouble("/velocities/airspeed"));
434 } else if (speedset == "mach" || speedset == "MACH") {
435 current_aircraft.fdm_state
436 ->set_Mach_number(fgGetDouble("/velocities/mach"));
437 } else if (speedset == "UVW" || speedset == "uvw") {
438 current_aircraft.fdm_state
439 ->set_Velocities_Wind_Body(fgGetDouble("/velocities/uBody"),
440 fgGetDouble("/velocities/vBody"),
441 fgGetDouble("/velocities/wBody"));
442 } else if (speedset == "NED" || speedset == "ned") {
443 current_aircraft.fdm_state
444 ->set_Velocities_Local(fgGetDouble("/velocities/speed-north"),
445 fgGetDouble("/velocities/speed-east"),
446 fgGetDouble("/velocities/speed-down"));
448 FG_LOG(FG_GENERAL, FG_ALERT,
449 "Unrecognized value for /sim/startup/speed-set: " << speedset);
450 current_aircraft.fdm_state->set_V_calibrated_kts(0.0);
455 // This is the top level init routine which calls all the other
456 // initialization routines. If you are adding a subsystem to flight
457 // gear, its initialization call should located in this routine.
458 // Returns non-zero if a problem encountered.
459 bool fgInitSubsystems( void ) {
460 fgLIGHT *l = &cur_light_params;
462 FG_LOG( FG_GENERAL, FG_INFO, "Initialize Subsystems");
463 FG_LOG( FG_GENERAL, FG_INFO, "========== ==========");
465 // Initialize the material property lib
466 FGPath mpath( globals->get_fg_root() );
467 mpath.append( "materials" );
468 if ( material_lib.load( mpath.str() ) ) {
470 FG_LOG( FG_GENERAL, FG_ALERT, "Error loading material lib!" );
474 // Initialize the Scenery Management subsystem
475 if ( fgSceneryInit() ) {
476 // Material lib initialized ok.
478 FG_LOG( FG_GENERAL, FG_ALERT, "Error in Scenery initialization!" );
482 if ( global_tile_mgr.init() ) {
483 // Load the local scenery data
484 global_tile_mgr.update( fgGetDouble("/position/longitude"),
485 fgGetDouble("/position/latitude") );
487 FG_LOG( FG_GENERAL, FG_ALERT, "Error in Tile Manager initialization!" );
491 FG_LOG( FG_GENERAL, FG_DEBUG,
492 "Current terrain elevation after tile mgr init " <<
495 double dt = 1.0 / fgGetInt("/sim/model-hz");
496 // cout << "dt = " << dt << endl;
498 const string &model = fgGetString("/sim/flight-model");
499 if (model == "larcsim") {
500 cur_fdm_state = new FGLaRCsim( dt );
501 } else if (model == "jsb") {
502 cur_fdm_state = new FGJSBsim( dt );
503 } else if (model == "ada") {
504 cur_fdm_state = new FGADA( dt );
505 } else if (model == "balloon") {
506 cur_fdm_state = new FGBalloonSim( dt );
507 } else if (model == "magic") {
508 cur_fdm_state = new FGMagicCarpet( dt );
509 } else if (model == "external") {
510 cur_fdm_state = new FGExternal( dt );
512 FG_LOG(FG_GENERAL, FG_ALERT,
513 "Unrecognized flight model '" << model
514 << ", can't init aircraft");
517 cur_fdm_state->stamp();
518 cur_fdm_state->set_remainder( 0 );
520 // allocates structures so must happen before any of the flight
521 // model or control parameters are set
522 fgAircraftInit(); // In the future this might not be the case.
524 fgFDMSetGroundElevation( fgGetString("/sim/flight-model"),
527 // set the initial position
530 // Calculate ground elevation at starting point (we didn't have
531 // tmp_abs_view_pos calculated when fgTileMgrUpdate() was called above
533 // calculalate a cartesian point somewhere along the line between
534 // the center of the earth and our view position. Doesn't have to
535 // be the exact elevation (this is good because we don't know it
538 // now handled inside of the fgTileMgrUpdate()
540 // Reset our altitude if we are below ground
541 FG_LOG( FG_GENERAL, FG_DEBUG, "Current altitude = "
542 << cur_fdm_state->get_Altitude() );
543 FG_LOG( FG_GENERAL, FG_DEBUG, "Current runway altitude = " <<
544 cur_fdm_state->get_Runway_altitude() );
546 if ( cur_fdm_state->get_Altitude() < cur_fdm_state->get_Runway_altitude() +
548 cur_fdm_state->set_Altitude( cur_fdm_state->get_Runway_altitude() +
552 FG_LOG( FG_GENERAL, FG_INFO,
553 "Updated position (after elevation adj): ("
554 << (cur_fdm_state->get_Latitude() * RAD_TO_DEG) << ", "
555 << (cur_fdm_state->get_Longitude() * RAD_TO_DEG) << ", "
556 << (cur_fdm_state->get_Altitude() * FEET_TO_METER) << ")" );
558 // We need to calculate a few sea_level_radius here so we can pass
559 // the correct value to the view class
560 double sea_level_radius_meters;
562 sgGeodToGeoc( cur_fdm_state->get_Latitude(),
563 cur_fdm_state->get_Altitude(),
564 &sea_level_radius_meters, &lat_geoc);
565 cur_fdm_state->set_Sea_level_radius( sea_level_radius_meters *
568 // The following section sets up the flight model EOM parameters
569 // and should really be read in from one or more files.
574 // Initial Orientation
576 // set_Euler_Angles( fgGetDouble("/orientation/roll") * DEG_TO_RAD,
577 // fgGetDouble("/orientation/pitch") * DEG_TO_RAD,
578 // fgGetDouble("/orientation/heading") * DEG_TO_RAD );
580 // Initialize the event manager
581 global_events.Init();
583 // Output event stats every 60 seconds
584 global_events.Register( "fgEVENT_MGR::PrintStats()",
585 fgMethodCallback<fgEVENT_MGR>( &global_events,
586 &fgEVENT_MGR::PrintStats),
587 fgEVENT::FG_EVENT_READY, 60000 );
589 // Initialize win_ratio parameters
590 for ( int i = 0; i < globals->get_viewmgr()->size(); ++i ) {
591 globals->get_viewmgr()->get_view(i)->
592 set_win_ratio( fgGetInt("/sim/startup/xsize") /
593 fgGetInt("/sim/startup/ysize") );
596 // Initialize pilot view
597 FGViewerRPH *pilot_view =
598 (FGViewerRPH *)globals->get_viewmgr()->get_view( 0 );
600 pilot_view->set_geod_view_pos( cur_fdm_state->get_Longitude(),
601 cur_fdm_state->get_Lat_geocentric(),
602 cur_fdm_state->get_Altitude() *
604 pilot_view->set_sea_level_radius( cur_fdm_state->get_Sea_level_radius() *
606 pilot_view->set_rph( cur_fdm_state->get_Phi(),
607 cur_fdm_state->get_Theta(),
608 cur_fdm_state->get_Psi() );
610 // set current view to 0 (first) which is our main pilot view
611 globals->set_current_view( pilot_view );
613 FG_LOG( FG_GENERAL, FG_DEBUG, " abs_view_pos = "
614 << globals->get_current_view()->get_abs_view_pos());
616 // fgUpdateSunPos() needs a few position and view parameters set
617 // so it can calculate local relative sun angle and a few other
618 // things for correctly orienting the sky.
621 global_events.Register( "fgUpdateSunPos()", fgUpdateSunPos,
622 fgEVENT::FG_EVENT_READY, 60000);
623 global_events.Register( "fgUpdateMoonPos()", fgUpdateMoonPos,
624 fgEVENT::FG_EVENT_READY, 60000);
626 // Initialize Lighting interpolation tables
629 // update the lighting parameters (based on sun angle)
630 global_events.Register( "fgLight::Update()",
631 fgMethodCallback<fgLIGHT>( &cur_light_params,
633 fgEVENT::FG_EVENT_READY, 30000 );
634 // update the current timezone each 30 minutes
635 global_events.Register( "fgUpdateLocalTime()", fgUpdateLocalTime,
636 fgEVENT::FG_EVENT_READY, 1800000);
638 // Initialize the weather modeling subsystem
639 #ifndef FG_OLD_WEATHER
640 // Initialize the WeatherDatabase
641 FG_LOG(FG_GENERAL, FG_INFO, "Creating LocalWeatherDatabase");
643 sgSetVec3( position, current_aircraft.fdm_state->get_Latitude(),
644 current_aircraft.fdm_state->get_Longitude(),
645 current_aircraft.fdm_state->get_Altitude() * FEET_TO_METER );
646 FGLocalWeatherDatabase::theFGLocalWeatherDatabase =
647 new FGLocalWeatherDatabase( position,
648 globals->get_fg_root() );
649 // cout << theFGLocalWeatherDatabase << endl;
650 // cout << "visibility = "
651 // << theFGLocalWeatherDatabase->getWeatherVisibility() << endl;
653 WeatherDatabase = FGLocalWeatherDatabase::theFGLocalWeatherDatabase;
655 double init_vis = fgGetDouble("/environment/visibility");
656 if ( init_vis > 0 ) {
657 WeatherDatabase->setWeatherVisibility( init_vis );
660 // register the periodic update of the weather
661 global_events.Register( "weather update", fgUpdateWeatherDatabase,
662 fgEVENT::FG_EVENT_READY, 30000);
664 current_weather.Init();
667 // Initialize vor/ndb/ils/fix list management and query systems
668 FG_LOG(FG_GENERAL, FG_INFO, "Loading Navaids");
670 FG_LOG(FG_GENERAL, FG_INFO, " VOR/NDB");
671 current_navlist = new FGNavList;
672 FGPath p_nav( globals->get_fg_root() );
673 p_nav.append( "Navaids/default.nav" );
674 current_navlist->init( p_nav );
676 FG_LOG(FG_GENERAL, FG_INFO, " ILS");
677 current_ilslist = new FGILSList;
678 FGPath p_ils( globals->get_fg_root() );
679 p_ils.append( "Navaids/default.ils" );
680 current_ilslist->init( p_ils );
682 FG_LOG(FG_GENERAL, FG_INFO, " Fixes");
683 current_fixlist = new FGFixList;
684 FGPath p_fix( globals->get_fg_root() );
685 p_fix.append( "Navaids/default.fix" );
686 current_fixlist->init( p_fix );
688 // Radio stack subsystem.
689 current_radiostack = new FGRadioStack;
690 current_radiostack->init();
691 current_radiostack->bind();
693 // Initialize the Cockpit subsystem
694 if( fgCockpitInit( ¤t_aircraft )) {
695 // Cockpit initialized ok.
697 FG_LOG( FG_GENERAL, FG_ALERT, "Error in Cockpit initialization!" );
701 // Initialize the flight model subsystem data structures base on
704 cur_fdm_state->init();
705 cur_fdm_state->bind();
706 // if ( cur_fdm_state->init( 1.0 / fgGetInt("/sim/model-hz") ) ) {
707 // // fdm init successful
709 // FG_LOG( FG_GENERAL, FG_ALERT, "FDM init() failed! Cannot continue." );
713 // *ABCD* I'm just sticking this here for now, it should probably
715 scenery.cur_elev = cur_fdm_state->get_Runway_altitude() * FEET_TO_METER;
717 if ( cur_fdm_state->get_Altitude() <
718 cur_fdm_state->get_Runway_altitude() + 3.758099)
720 cur_fdm_state->set_Altitude( cur_fdm_state->get_Runway_altitude() +
724 FG_LOG( FG_GENERAL, FG_INFO,
725 "Updated position (after elevation adj): ("
726 << (cur_fdm_state->get_Latitude() * RAD_TO_DEG) << ", "
727 << (cur_fdm_state->get_Longitude() * RAD_TO_DEG) << ", "
728 << (cur_fdm_state->get_Altitude() * FEET_TO_METER) << ")" );
729 // *ABCD* end of thing that I just stuck in that I should probably
733 if ( ! fgJoystickInit() ) {
734 FG_LOG( FG_GENERAL, FG_ALERT, "Error in Joystick initialization!" );
738 current_autopilot = new FGAutopilot;
739 current_autopilot->init();
741 // initialize the gui parts of the autopilot
747 // Initialize I/O channels
748 #if ! defined( macintosh )
752 // Initialize the 2D panel.
753 string panel_path = fgGetString("/sim/panel/path",
754 "Panels/Default/default.xml");
755 current_panel = fgReadPanel(panel_path);
756 if (current_panel == 0) {
757 FG_LOG( FG_INPUT, FG_ALERT,
758 "Error reading new panel from " << panel_path );
760 FG_LOG( FG_INPUT, FG_INFO, "Loaded new panel from " << panel_path );
761 current_panel->init();
762 current_panel->bind();
765 // Initialize the BFI
771 FG_LOG( FG_GENERAL, FG_INFO, endl);
777 void fgReInitSubsystems( void )
779 bool freeze = globals->get_freeze();
781 globals->set_freeze( true );
783 // Initialize the Scenery Management subsystem
784 if ( ! fgSceneryInit() ) {
785 FG_LOG( FG_GENERAL, FG_ALERT, "Error in Scenery initialization!" );
789 if( global_tile_mgr.init() ) {
790 // Load the local scenery data
791 global_tile_mgr.update( fgGetDouble("/position/longitude"),
792 fgGetDouble("/position/latitude") );
794 FG_LOG( FG_GENERAL, FG_ALERT, "Error in Tile Manager initialization!" );
798 // cout << "current scenery elev = " << scenery.cur_elev << endl;
800 fgFDMSetGroundElevation( fgGetString("/sim/flight-model"),
804 // Reset our altitude if we are below ground
805 FG_LOG( FG_GENERAL, FG_DEBUG, "Current altitude = "
806 << cur_fdm_state->get_Altitude() );
807 FG_LOG( FG_GENERAL, FG_DEBUG, "Current runway altitude = "
808 << cur_fdm_state->get_Runway_altitude() );
810 if ( cur_fdm_state->get_Altitude() <
811 cur_fdm_state->get_Runway_altitude() + 3.758099)
813 cur_fdm_state->set_Altitude( cur_fdm_state->get_Runway_altitude() +
816 double sea_level_radius_meters;
818 sgGeodToGeoc( cur_fdm_state->get_Latitude(), cur_fdm_state->get_Altitude(),
819 &sea_level_radius_meters, &lat_geoc);
820 cur_fdm_state->set_Sea_level_radius( sea_level_radius_meters *
823 // The following section sets up the flight model EOM parameters
824 // and should really be read in from one or more files.
829 // Initial Orientation
831 // set_Euler_Angles( fgGetDouble("/orientation/roll") * DEG_TO_RAD,
832 // fgGetDouble("/orientation/pitch") * DEG_TO_RAD,
833 // fgGetDouble("/orientation/heading") * DEG_TO_RAD );
835 // Initialize view parameters
836 FGViewerRPH *pilot_view =
837 (FGViewerRPH *)globals->get_viewmgr()->get_view( 0 );
839 pilot_view->set_view_offset( 0.0 );
840 pilot_view->set_goal_view_offset( 0.0 );
842 pilot_view->set_geod_view_pos( cur_fdm_state->get_Longitude(),
843 cur_fdm_state->get_Lat_geocentric(),
844 cur_fdm_state->get_Altitude() *
846 pilot_view->set_sea_level_radius( cur_fdm_state->get_Sea_level_radius() *
848 pilot_view->set_rph( cur_fdm_state->get_Phi(),
849 cur_fdm_state->get_Theta(),
850 cur_fdm_state->get_Psi() );
852 // set current view to 0 (first) which is our main pilot view
853 globals->set_current_view( pilot_view );
855 FG_LOG( FG_GENERAL, FG_DEBUG, " abs_view_pos = "
856 << globals->get_current_view()->get_abs_view_pos());
858 cur_fdm_state->init();
859 cur_fdm_state->bind();
860 // cur_fdm_state->init( 1.0 / fgGetInt("/sim/model-hz") );
862 scenery.cur_elev = cur_fdm_state->get_Runway_altitude() * FEET_TO_METER;
864 if ( cur_fdm_state->get_Altitude() <
865 cur_fdm_state->get_Runway_altitude() + 3.758099)
867 cur_fdm_state->set_Altitude( cur_fdm_state->get_Runway_altitude() +
871 controls.reset_all();
872 current_autopilot->reset();
875 globals->set_freeze( false );