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; }
229 while ( diff > 180.0 ) { diff -= 360.0; }
231 FG_LOG( FG_GENERAL, FG_INFO,
232 "Runway " << r.rwy_no << " heading = " << r.heading <<
233 " diff = " << diff );
234 if ( diff < min_diff ) {
241 diff = tgt_hdg - r.heading - 180.0;
242 while ( diff < -180.0 ) { diff += 360.0; }
243 while ( diff > 180.0 ) { diff -= 360.0; }
245 FG_LOG( FG_GENERAL, FG_INFO,
246 "Runway -" << r.rwy_no << " heading = " <<
248 " diff = " << diff );
249 if ( diff < min_diff ) {
258 FG_LOG( FG_GENERAL, FG_INFO, "closest runway = " << found_r.rwy_no
259 << " + " << found_dir );
265 double heading = found_r.heading + found_dir;
266 while ( heading >= 360.0 ) { heading -= 360.0; }
268 double lat2, lon2, az2;
269 double azimuth = found_r.heading + found_dir + 180.0;
270 while ( azimuth >= 360.0 ) { azimuth -= 360.0; }
272 FG_LOG( FG_GENERAL, FG_INFO,
273 "runway = " << found_r.lon << ", " << found_r.lat
274 << " length = " << found_r.length * FEET_TO_METER * 0.5
275 << " heading = " << azimuth );
276 geo_direct_wgs_84 ( 0, found_r.lat, found_r.lon,
277 azimuth, found_r.length * FEET_TO_METER * 0.5 - 5.0,
278 &lat2, &lon2, &az2 );
279 current_options.set_lon( lon2 );
280 current_options.set_lat( lat2 );
281 current_options.set_heading( heading );
283 FG_LOG( FG_GENERAL, FG_INFO,
284 "Position for " << id << " is ("
286 << lat2 << ") new heading is "
293 // Set initial position and orientation
294 bool fgInitPosition( void ) {
295 FGInterface *f = current_aircraft.fdm_state;
296 string id = current_options.get_airport_id();
298 // set initial position from default or command line coordinates
299 f->set_Longitude( current_options.get_lon() * DEG_TO_RAD );
300 f->set_Latitude( current_options.get_lat() * DEG_TO_RAD );
302 if ( scenery.cur_elev > current_options.get_altitude() - 1) {
303 current_options.set_altitude( scenery.cur_elev + 1 );
306 FG_LOG( FG_GENERAL, FG_INFO,
307 "starting altitude is = " << current_options.get_altitude() );
309 f->set_Altitude( current_options.get_altitude() * METER_TO_FEET );
310 fgFDMSetGroundElevation( current_options.get_flight_model(),
311 f->get_Altitude() * FEET_TO_METER );
313 FG_LOG( FG_GENERAL, FG_INFO,
314 "Initial position is: ("
315 << (f->get_Longitude() * RAD_TO_DEG) << ", "
316 << (f->get_Latitude() * RAD_TO_DEG) << ", "
317 << (f->get_Altitude() * FEET_TO_METER) << ")" );
323 // General house keeping initializations
324 bool fgInitGeneral( void ) {
327 #if defined(FX) && defined(XMESA)
328 char *mesa_win_state;
331 FG_LOG( FG_GENERAL, FG_INFO, "General Initialization" );
332 FG_LOG( FG_GENERAL, FG_INFO, "======= ==============" );
334 root = current_options.get_fg_root();
335 if ( ! root.length() ) {
336 // No root path set? Then bail ...
337 FG_LOG( FG_GENERAL, FG_ALERT,
338 "Cannot continue without environment variable FG_ROOT"
339 << "being defined." );
342 FG_LOG( FG_GENERAL, FG_INFO, "FG_ROOT = " << '"' << root << '"' << endl );
344 #if defined(FX) && defined(XMESA)
345 // initialize full screen flag
346 global_fullscreen = false;
347 if ( strstr ( general.get_glRenderer(), "Glide" ) ) {
348 // Test for the MESA_GLX_FX env variable
349 if ( (mesa_win_state = getenv( "MESA_GLX_FX" )) != NULL) {
350 // test if we are fullscreen mesa/glide
351 if ( (mesa_win_state[0] == 'f') ||
352 (mesa_win_state[0] == 'F') ) {
353 global_fullscreen = true;
363 // This is the top level init routine which calls all the other
364 // initialization routines. If you are adding a subsystem to flight
365 // gear, its initialization call should located in this routine.
366 // Returns non-zero if a problem encountered.
367 bool fgInitSubsystems( void ) {
368 fgLIGHT *l = &cur_light_params;
370 FG_LOG( FG_GENERAL, FG_INFO, "Initialize Subsystems");
371 FG_LOG( FG_GENERAL, FG_INFO, "========== ==========");
373 // Initialize the material property lib
374 FGPath mpath( current_options.get_fg_root() );
375 mpath.append( "materials" );
376 if ( material_lib.load( mpath.str() ) ) {
378 FG_LOG( FG_GENERAL, FG_ALERT, "Error loading material lib!" );
382 // Initialize the Scenery Management subsystem
383 if ( fgSceneryInit() ) {
384 // Material lib initialized ok.
386 FG_LOG( FG_GENERAL, FG_ALERT, "Error in Scenery initialization!" );
390 if ( global_tile_mgr.init() ) {
391 // Load the local scenery data
392 global_tile_mgr.update( current_options.get_lon(),
393 current_options.get_lat() );
395 FG_LOG( FG_GENERAL, FG_ALERT, "Error in Tile Manager initialization!" );
399 FG_LOG( FG_GENERAL, FG_DEBUG,
400 "Current terrain elevation after tile mgr init " <<
403 if ( current_options.get_flight_model() == FGInterface::FG_LARCSIM ) {
404 cur_fdm_state = new FGLaRCsim;
405 } else if ( current_options.get_flight_model() == FGInterface::FG_JSBSIM ) {
406 cur_fdm_state = new FGJSBsim;
407 } else if ( current_options.get_flight_model() ==
408 FGInterface::FG_BALLOONSIM ) {
409 cur_fdm_state = new FGBalloonSim;
410 } else if ( current_options.get_flight_model() ==
411 FGInterface::FG_MAGICCARPET ) {
412 cur_fdm_state = new FGMagicCarpet;
413 } else if ( current_options.get_flight_model() ==
414 FGInterface::FG_EXTERNAL ) {
415 cur_fdm_state = new FGExternal;
417 FG_LOG( FG_GENERAL, FG_ALERT,
418 "No flight model, can't init aircraft" );
422 // allocates structures so must happen before any of the flight
423 // model or control parameters are set
424 fgAircraftInit(); // In the future this might not be the case.
426 // set the initial position
429 // Calculate ground elevation at starting point (we didn't have
430 // tmp_abs_view_pos calculated when fgTileMgrUpdate() was called above
432 // calculalate a cartesian point somewhere along the line between
433 // the center of the earth and our view position. Doesn't have to
434 // be the exact elevation (this is good because we don't know it
437 // now handled inside of the fgTileMgrUpdate()
440 geod_pos = Point3D( cur_fdm_state->get_Longitude(), cur_fdm_state->get_Latitude(), 0.0);
441 tmp_abs_view_pos = fgGeodToCart(geod_pos);
443 FG_LOG( FG_GENERAL, FG_DEBUG,
444 "Initial abs_view_pos = " << tmp_abs_view_pos );
446 fgTileMgrCurElev( cur_fdm_state->get_Longitude(), cur_fdm_state->get_Latitude(),
448 FG_LOG( FG_GENERAL, FG_DEBUG,
449 "Altitude after update " << scenery.cur_elev );
452 fgFDMSetGroundElevation( current_options.get_flight_model(),
455 // Reset our altitude if we are below ground
456 FG_LOG( FG_GENERAL, FG_DEBUG, "Current altitude = " << cur_fdm_state->get_Altitude() );
457 FG_LOG( FG_GENERAL, FG_DEBUG, "Current runway altitude = " <<
458 cur_fdm_state->get_Runway_altitude() );
460 if ( cur_fdm_state->get_Altitude() < cur_fdm_state->get_Runway_altitude() + 3.758099) {
461 cur_fdm_state->set_Altitude( cur_fdm_state->get_Runway_altitude() + 3.758099 );
464 FG_LOG( FG_GENERAL, FG_INFO,
465 "Updated position (after elevation adj): ("
466 << (cur_fdm_state->get_Latitude() * RAD_TO_DEG) << ", "
467 << (cur_fdm_state->get_Longitude() * RAD_TO_DEG) << ", "
468 << (cur_fdm_state->get_Altitude() * FEET_TO_METER) << ")" );
470 // We need to calculate a few more values here that would normally
471 // be calculated by the FDM so that the current_view.UpdateViewMath()
472 // routine doesn't get hosed.
474 double sea_level_radius_meters;
476 // Set the FG variables first
477 fgGeodToGeoc( cur_fdm_state->get_Latitude(), cur_fdm_state->get_Altitude(),
478 &sea_level_radius_meters, &lat_geoc);
479 cur_fdm_state->set_Geocentric_Position( lat_geoc, cur_fdm_state->get_Longitude(),
480 cur_fdm_state->get_Altitude() +
481 (sea_level_radius_meters * METER_TO_FEET) );
482 cur_fdm_state->set_Sea_level_radius( sea_level_radius_meters * METER_TO_FEET );
484 cur_fdm_state->set_sin_cos_longitude(cur_fdm_state->get_Longitude());
485 cur_fdm_state->set_sin_cos_latitude(cur_fdm_state->get_Latitude());
487 cur_fdm_state->set_sin_lat_geocentric(sin(lat_geoc));
488 cur_fdm_state->set_cos_lat_geocentric(cos(lat_geoc));
490 // The following section sets up the flight model EOM parameters
491 // and should really be read in from one or more files.
494 cur_fdm_state->set_Velocities_Local( current_options.get_uBody(),
495 current_options.get_vBody(),
496 current_options.get_wBody());
498 // Initial Orientation
499 cur_fdm_state->set_Euler_Angles( current_options.get_roll() * DEG_TO_RAD,
500 current_options.get_pitch() * DEG_TO_RAD,
501 current_options.get_heading() * DEG_TO_RAD );
503 // Initial Angular Body rates
504 cur_fdm_state->set_Omega_Body( 7.206685E-05, 0.0, 9.492658E-05 );
506 cur_fdm_state->set_Earth_position_angle( 0.0 );
508 // Mass properties and geometry values
509 cur_fdm_state->set_Inertias( 8.547270E+01,
510 1.048000E+03, 3.000000E+03, 3.530000E+03, 0.000000E+00 );
512 // CG position w.r.t. ref. point
513 cur_fdm_state->set_CG_Position( 0.0, 0.0, 0.0 );
515 // Initialize the event manager
516 global_events.Init();
518 // Output event stats every 60 seconds
519 global_events.Register( "fgEVENT_MGR::PrintStats()",
520 fgMethodCallback<fgEVENT_MGR>( &global_events,
521 &fgEVENT_MGR::PrintStats),
522 fgEVENT::FG_EVENT_READY, 60000 );
524 // Initialize view parameters
525 FG_LOG( FG_GENERAL, FG_DEBUG, "Before current_view.init()");
528 FG_LOG( FG_GENERAL, FG_DEBUG, "After current_view.init()");
529 current_view.UpdateViewMath(*cur_fdm_state);
530 pilot_view.UpdateViewMath(*cur_fdm_state);
531 FG_LOG( FG_GENERAL, FG_DEBUG, " abs_view_pos = " << current_view.get_abs_view_pos());
532 // current_view.UpdateWorldToEye(f);
534 // Initialize the planetary subsystem
535 // global_events.Register( "fgPlanetsInit()", fgPlanetsInit,
536 // fgEVENT::FG_EVENT_READY, 600000);
538 // Initialize the sun's position
539 // global_events.Register( "fgSunInit()", fgSunInit,
540 // fgEVENT::FG_EVENT_READY, 30000 );
542 // Intialize the moon's position
543 // global_events.Register( "fgMoonInit()", fgMoonInit,
544 // fgEVENT::FG_EVENT_READY, 600000 );
546 // fgUpdateSunPos() needs a few position and view parameters set
547 // so it can calculate local relative sun angle and a few other
548 // things for correctly orienting the sky.
551 global_events.Register( "fgUpdateSunPos()", fgUpdateSunPos,
552 fgEVENT::FG_EVENT_READY, 60000);
553 global_events.Register( "fgUpdateMoonPos()", fgUpdateMoonPos,
554 fgEVENT::FG_EVENT_READY, 60000);
556 // Initialize Lighting interpolation tables
559 // update the lighting parameters (based on sun angle)
560 global_events.Register( "fgLight::Update()",
561 fgMethodCallback<fgLIGHT>( &cur_light_params,
563 fgEVENT::FG_EVENT_READY, 30000 );
564 // update the current timezone each 30 minutes
565 global_events.Register( "fgUpdateLocalTime()", fgUpdateLocalTime,
566 fgEVENT::FG_EVENT_READY, 1800000);
568 // Initialize the weather modeling subsystem
569 #ifndef FG_OLD_WEATHER
570 // Initialize the WeatherDatabase
571 FG_LOG(FG_GENERAL, FG_INFO, "Creating LocalWeatherDatabase");
573 sgSetVec3( position, current_aircraft.fdm_state->get_Latitude(),
574 current_aircraft.fdm_state->get_Longitude(),
575 current_aircraft.fdm_state->get_Altitude() * FEET_TO_METER );
576 FGLocalWeatherDatabase::theFGLocalWeatherDatabase =
577 new FGLocalWeatherDatabase( position, current_options.get_fg_root() );
578 // cout << theFGLocalWeatherDatabase << endl;
579 // cout << "visibility = "
580 // << theFGLocalWeatherDatabase->getWeatherVisibility() << endl;
582 WeatherDatabase = FGLocalWeatherDatabase::theFGLocalWeatherDatabase;
584 // register the periodic update of the weather
585 global_events.Register( "weather update", fgUpdateWeatherDatabase,
586 fgEVENT::FG_EVENT_READY, 30000);
588 current_weather.Init();
591 // Initialize vor/ndb/ils/fix list management and query systems
592 FG_LOG(FG_GENERAL, FG_INFO, "Loading Navaids");
594 FG_LOG(FG_GENERAL, FG_INFO, " VOR/NDB");
595 current_navlist = new FGNavList;
596 FGPath p_nav( current_options.get_fg_root() );
597 p_nav.append( "Navaids/default.nav" );
598 current_navlist->init( p_nav );
600 FG_LOG(FG_GENERAL, FG_INFO, " ILS");
601 current_ilslist = new FGILSList;
602 FGPath p_ils( current_options.get_fg_root() );
603 p_ils.append( "Navaids/default.ils" );
604 current_ilslist->init( p_ils );
606 FG_LOG(FG_GENERAL, FG_INFO, " Fixes");
607 current_fixlist = new FGFixList;
608 FGPath p_fix( current_options.get_fg_root() );
609 p_fix.append( "Navaids/default.fix" );
610 current_fixlist->init( p_fix );
612 // Initialize the underlying radio stack model
613 current_radiostack = new FGRadioStack;
615 current_radiostack->set_nav1_freq( 117.30 );
616 current_radiostack->set_nav1_alt_freq( 110.30 );
617 current_radiostack->set_nav1_sel_radial( 119.0 );
619 current_radiostack->set_nav2_freq( 111.80 );
620 current_radiostack->set_nav2_alt_freq( 115.70 );
621 current_radiostack->set_nav2_sel_radial( 029.0 );
623 current_radiostack->set_adf_freq( 266.0 );
626 // This block of settings are Alex's defaults for San Diego
627 current_radiostack->set_nav1_freq( 111.70 );
628 current_radiostack->set_nav1_alt_freq( 115.30 );
629 current_radiostack->set_nav1_sel_radial( 280.0 );
630 current_radiostack->set_nav2_freq( 117.80 );
631 current_radiostack->set_nav2_alt_freq( 114.00 );
632 current_radiostack->set_nav2_sel_radial( 68.0 );
633 current_radiostack->set_adf_freq( 210.0 );
634 // End of Alex's custom settings
637 current_radiostack->search( cur_fdm_state->get_Longitude(),
638 cur_fdm_state->get_Latitude(),
639 cur_fdm_state->get_Altitude() * FEET_TO_METER );
641 current_radiostack->update( cur_fdm_state->get_Longitude(),
642 cur_fdm_state->get_Latitude(),
643 cur_fdm_state->get_Altitude() * FEET_TO_METER );
645 // Search radio database once per second
646 global_events.Register( "fgRadioSearch()", fgRadioSearch,
647 fgEVENT::FG_EVENT_READY, 1000);
650 // Initialize the Cockpit subsystem
651 if( fgCockpitInit( ¤t_aircraft )) {
652 // Cockpit initialized ok.
654 FG_LOG( FG_GENERAL, FG_ALERT, "Error in Cockpit initialization!" );
658 // Initialize the flight model subsystem data structures base on
661 // fgFDMInit( current_options.get_flight_model(), cur_fdm_state,
662 // 1.0 / current_options.get_model_hz() );
663 cur_fdm_state->init( 1.0 / current_options.get_model_hz() );
665 // I'm just sticking this here for now, it should probably move
667 scenery.cur_elev = cur_fdm_state->get_Runway_altitude() * FEET_TO_METER;
669 if ( cur_fdm_state->get_Altitude() < cur_fdm_state->get_Runway_altitude() + 3.758099) {
670 cur_fdm_state->set_Altitude( cur_fdm_state->get_Runway_altitude() + 3.758099 );
673 FG_LOG( FG_GENERAL, FG_INFO,
674 "Updated position (after elevation adj): ("
675 << (cur_fdm_state->get_Latitude() * RAD_TO_DEG) << ", "
676 << (cur_fdm_state->get_Longitude() * RAD_TO_DEG) << ", "
677 << (cur_fdm_state->get_Altitude() * FEET_TO_METER) << ")" );
678 // end of thing that I just stuck in that I should probably move
681 if ( fgJoystickInit() ) {
682 // Joystick initialized ok.
684 FG_LOG( FG_GENERAL, FG_ALERT, "Error in Joystick initialization!" );
688 current_autopilot = new FGAutopilot;
689 current_autopilot->init();
691 // initialize the gui parts of the autopilot
697 // Initialize I/O channels
698 #if ! defined( macintosh )
702 // Initialize the 2D panel.
703 current_panel = fgCreateSmallSinglePropPanel(0, 0, 1024, 768);
705 // Initialize the BFI
708 FG_LOG( FG_GENERAL, FG_INFO, endl);
714 void fgReInitSubsystems( void )
716 bool freeze = globals->get_freeze();
718 globals->set_freeze( true );
720 if( global_tile_mgr.init() ) {
721 // Load the local scenery data
722 global_tile_mgr.update( current_options.get_lon(),
723 current_options.get_lat() );
725 FG_LOG( FG_GENERAL, FG_ALERT, "Error in Tile Manager initialization!" );
729 // cout << "current scenery elev = " << scenery.cur_elev << endl;
732 fgFDMSetGroundElevation( current_options.get_flight_model(),
735 // Reset our altitude if we are below ground
736 FG_LOG( FG_GENERAL, FG_DEBUG, "Current altitude = " << cur_fdm_state->get_Altitude() );
737 FG_LOG( FG_GENERAL, FG_DEBUG, "Current runway altitude = " <<
738 cur_fdm_state->get_Runway_altitude() );
740 if ( cur_fdm_state->get_Altitude() < cur_fdm_state->get_Runway_altitude() + 3.758099) {
741 cur_fdm_state->set_Altitude( cur_fdm_state->get_Runway_altitude() + 3.758099 );
743 double sea_level_radius_meters;
745 // Set the FG variables first
746 fgGeodToGeoc( cur_fdm_state->get_Latitude(), cur_fdm_state->get_Altitude(),
747 &sea_level_radius_meters, &lat_geoc);
748 cur_fdm_state->set_Geocentric_Position( lat_geoc, cur_fdm_state->get_Longitude(),
749 cur_fdm_state->get_Altitude() +
750 (sea_level_radius_meters * METER_TO_FEET) );
751 cur_fdm_state->set_Sea_level_radius( sea_level_radius_meters * METER_TO_FEET );
753 cur_fdm_state->set_sin_cos_longitude(cur_fdm_state->get_Longitude());
754 cur_fdm_state->set_sin_cos_latitude(cur_fdm_state->get_Latitude());
756 cur_fdm_state->set_sin_lat_geocentric(sin(lat_geoc));
757 cur_fdm_state->set_cos_lat_geocentric(cos(lat_geoc));
759 // The following section sets up the flight model EOM parameters
760 // and should really be read in from one or more files.
763 cur_fdm_state->set_Velocities_Local( current_options.get_uBody(),
764 current_options.get_vBody(),
765 current_options.get_wBody());
767 // Initial Orientation
768 cur_fdm_state->set_Euler_Angles( current_options.get_roll() * DEG_TO_RAD,
769 current_options.get_pitch() * DEG_TO_RAD,
770 current_options.get_heading() * DEG_TO_RAD );
772 // Initial Angular Body rates
773 cur_fdm_state->set_Omega_Body( 7.206685E-05, 0.0, 9.492658E-05 );
775 cur_fdm_state->set_Earth_position_angle( 0.0 );
777 // Mass properties and geometry values
778 cur_fdm_state->set_Inertias( 8.547270E+01,
779 1.048000E+03, 3.000000E+03, 3.530000E+03, 0.000000E+00 );
781 // CG position w.r.t. ref. point
782 cur_fdm_state->set_CG_Position( 0.0, 0.0, 0.0 );
784 // Initialize view parameters
785 current_view.set_view_offset( 0.0 );
786 current_view.set_goal_view_offset( 0.0 );
787 pilot_view.set_view_offset( 0.0 );
788 pilot_view.set_goal_view_offset( 0.0 );
790 FG_LOG( FG_GENERAL, FG_DEBUG, "After current_view.init()");
791 current_view.UpdateViewMath(*cur_fdm_state);
792 pilot_view.UpdateViewMath(*cur_fdm_state);
793 FG_LOG( FG_GENERAL, FG_DEBUG, " abs_view_pos = " << current_view.get_abs_view_pos());
795 // fgFDMInit( current_options.get_flight_model(), cur_fdm_state,
796 // 1.0 / current_options.get_model_hz() );
797 cur_fdm_state->init( 1.0 / current_options.get_model_hz() );
799 scenery.cur_elev = cur_fdm_state->get_Runway_altitude() * FEET_TO_METER;
801 if ( cur_fdm_state->get_Altitude() < cur_fdm_state->get_Runway_altitude() + 3.758099) {
802 cur_fdm_state->set_Altitude( cur_fdm_state->get_Runway_altitude() + 3.758099 );
805 controls.reset_all();
806 current_autopilot->reset();
809 globals->set_freeze( false );