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/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) and just set fg_root
109 bool fgInitFGRoot ( 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.scan_config_file_for_root( config.str() );
116 // Next check home directory
117 char* envp = ::getenv( "HOME" );
118 if ( envp != NULL ) {
120 config.append( ".fgfsrc" );
121 current_options.scan_config_file_for_root( config.str() );
124 // Parse remaining command line options
125 // These will override anything specified in a config file
126 current_options.scan_command_line_for_root(argc, argv);
132 // Read in configuration (file and command line)
133 bool fgInitConfig ( int argc, char **argv ) {
134 // Attempt to locate and parse a config file
135 // First check fg_root
136 FGPath config( current_options.get_fg_root() );
137 config.append( "system.fgfsrc" );
138 current_options.parse_config_file( config.str() );
140 // Next check home directory
141 char* envp = ::getenv( "HOME" );
142 if ( envp != NULL ) {
144 config.append( ".fgfsrc" );
145 current_options.parse_config_file( config.str() );
148 // Parse remaining command line options
149 // These will override anything specified in a config file
150 if ( current_options.parse_command_line(argc, argv) !=
151 fgOPTIONS::FG_OPTIONS_OK )
153 // Something must have gone horribly wrong with the command
154 // line parsing or maybe the user just requested help ... :-)
155 current_options.usage();
156 FG_LOG( FG_GENERAL, FG_ALERT, "\nExiting ...");
164 // Set current_options lon/lat given an airport id
165 bool fgSetPosFromAirportID( const string& id ) {
170 // set initial position from airport id
172 FGPath path( current_options.get_fg_root() );
173 path.append( "Airports" );
174 path.append( "simple.mk4" );
175 FGAirports airports( path.c_str() );
177 FG_LOG( FG_GENERAL, FG_INFO,
178 "Attempting to set starting position from airport code "
181 // FGPath inpath( current_options.get_fg_root() );
182 // inpath.append( "Airports" );
183 // inpath.append( "apt_simple" );
184 // airports.load( inpath.c_str() );
186 // FGPath outpath( current_options.get_fg_root() );
187 // outpath.append( "Airports" );
188 // outpath.append( "simple.gdbm" );
189 // airports.dump_gdbm( outpath.c_str() );
191 if ( ! airports.search( id, &a ) ) {
192 FG_LOG( FG_GENERAL, FG_ALERT,
193 "Failed to find " << id << " in database." );
196 current_options.set_lon( a.longitude );
197 current_options.set_lat( a.latitude );
198 current_properties.setDoubleValue("/position/longitude",
200 current_properties.setDoubleValue("/position/latitude",
207 FG_LOG( FG_GENERAL, FG_INFO,
208 "Position for " << id << " is ("
209 << a.longitude << ", "
210 << a.latitude << ")" );
216 // Set current_options lon/lat given an airport id and heading (degrees)
217 bool fgSetPosFromAirportIDandHdg( const string& id, double tgt_hdg ) {
223 // set initial position from runway and heading
225 FGPath path( current_options.get_fg_root() );
226 path.append( "Airports" );
227 path.append( "runways.mk4" );
228 FGRunways runways( path.c_str() );
230 FG_LOG( FG_GENERAL, FG_INFO,
231 "Attempting to set starting position from runway code "
232 << id << " heading " << tgt_hdg );
234 // FGPath inpath( current_options.get_fg_root() );
235 // inpath.append( "Airports" );
236 // inpath.append( "apt_simple" );
237 // airports.load( inpath.c_str() );
239 // FGPath outpath( current_options.get_fg_root() );
240 // outpath.append( "Airports" );
241 // outpath.append( "simple.gdbm" );
242 // airports.dump_gdbm( outpath.c_str() );
244 if ( ! runways.search( id, &r ) ) {
245 FG_LOG( FG_GENERAL, FG_ALERT,
246 "Failed to find " << id << " in database." );
251 double min_diff = 360.0;
253 while ( r.id == id ) {
255 diff = tgt_hdg - r.heading;
256 while ( diff < -180.0 ) { diff += 360.0; }
257 while ( diff > 180.0 ) { diff -= 360.0; }
259 FG_LOG( FG_GENERAL, FG_INFO,
260 "Runway " << r.rwy_no << " heading = " << r.heading <<
261 " diff = " << diff );
262 if ( diff < min_diff ) {
269 diff = tgt_hdg - r.heading - 180.0;
270 while ( diff < -180.0 ) { diff += 360.0; }
271 while ( diff > 180.0 ) { diff -= 360.0; }
273 FG_LOG( FG_GENERAL, FG_INFO,
274 "Runway -" << r.rwy_no << " heading = " <<
276 " diff = " << diff );
277 if ( diff < min_diff ) {
286 FG_LOG( FG_GENERAL, FG_INFO, "closest runway = " << found_r.rwy_no
287 << " + " << found_dir );
293 double heading = found_r.heading + found_dir;
294 while ( heading >= 360.0 ) { heading -= 360.0; }
296 double lat2, lon2, az2;
297 double azimuth = found_r.heading + found_dir + 180.0;
298 while ( azimuth >= 360.0 ) { azimuth -= 360.0; }
300 FG_LOG( FG_GENERAL, FG_INFO,
301 "runway = " << found_r.lon << ", " << found_r.lat
302 << " length = " << found_r.length * FEET_TO_METER * 0.5
303 << " heading = " << azimuth );
304 geo_direct_wgs_84 ( 0, found_r.lat, found_r.lon,
305 azimuth, found_r.length * FEET_TO_METER * 0.5 - 5.0,
306 &lat2, &lon2, &az2 );
307 current_options.set_lon( lon2 );
308 current_options.set_lat( lat2 );
309 current_options.set_heading( heading );
310 current_properties.setDoubleValue("/position/longitude", lon2);
311 current_properties.setDoubleValue("/position/latitude", lat2);
312 current_properties.setDoubleValue("/orientation/heading", heading);
314 FG_LOG( FG_GENERAL, FG_INFO,
315 "Position for " << id << " is ("
317 << lat2 << ") new heading is "
324 // Set initial position and orientation
325 bool fgInitPosition( void ) {
326 FGInterface *f = current_aircraft.fdm_state;
327 string id = current_options.get_airport_id();
329 // set initial position from default or command line coordinates
330 f->set_Longitude( current_options.get_lon() * DEG_TO_RAD );
331 f->set_Latitude( current_options.get_lat() * DEG_TO_RAD );
333 if ( scenery.cur_elev > current_options.get_altitude() - 1) {
334 current_options.set_altitude( scenery.cur_elev + 1 );
337 FG_LOG( FG_GENERAL, FG_INFO,
338 "starting altitude is = " << current_options.get_altitude() );
340 f->set_Altitude( current_options.get_altitude() * METER_TO_FEET );
341 fgFDMSetGroundElevation( current_options.get_flight_model(),
342 f->get_Altitude() * FEET_TO_METER );
344 FG_LOG( FG_GENERAL, FG_INFO,
345 "Initial position is: ("
346 << (f->get_Longitude() * RAD_TO_DEG) << ", "
347 << (f->get_Latitude() * RAD_TO_DEG) << ", "
348 << (f->get_Altitude() * FEET_TO_METER) << ")" );
354 // General house keeping initializations
355 bool fgInitGeneral( void ) {
358 #if defined(FX) && defined(XMESA)
359 char *mesa_win_state;
362 FG_LOG( FG_GENERAL, FG_INFO, "General Initialization" );
363 FG_LOG( FG_GENERAL, FG_INFO, "======= ==============" );
365 root = current_options.get_fg_root();
366 if ( ! root.length() ) {
367 // No root path set? Then bail ...
368 FG_LOG( FG_GENERAL, FG_ALERT,
369 "Cannot continue without environment variable FG_ROOT"
370 << "being defined." );
373 FG_LOG( FG_GENERAL, FG_INFO, "FG_ROOT = " << '"' << root << '"' << endl );
375 #if defined(FX) && defined(XMESA)
376 // initialize full screen flag
377 global_fullscreen = false;
378 if ( strstr ( general.get_glRenderer(), "Glide" ) ) {
379 // Test for the MESA_GLX_FX env variable
380 if ( (mesa_win_state = getenv( "MESA_GLX_FX" )) != NULL) {
381 // test if we are fullscreen mesa/glide
382 if ( (mesa_win_state[0] == 'f') ||
383 (mesa_win_state[0] == 'F') ) {
384 global_fullscreen = true;
394 // This is the top level init routine which calls all the other
395 // initialization routines. If you are adding a subsystem to flight
396 // gear, its initialization call should located in this routine.
397 // Returns non-zero if a problem encountered.
398 bool fgInitSubsystems( void ) {
399 fgLIGHT *l = &cur_light_params;
401 FG_LOG( FG_GENERAL, FG_INFO, "Initialize Subsystems");
402 FG_LOG( FG_GENERAL, FG_INFO, "========== ==========");
404 // Initialize the material property lib
405 FGPath mpath( current_options.get_fg_root() );
406 mpath.append( "materials" );
407 if ( material_lib.load( mpath.str() ) ) {
409 FG_LOG( FG_GENERAL, FG_ALERT, "Error loading material lib!" );
413 // Initialize the Scenery Management subsystem
414 if ( fgSceneryInit() ) {
415 // Material lib initialized ok.
417 FG_LOG( FG_GENERAL, FG_ALERT, "Error in Scenery initialization!" );
421 if ( global_tile_mgr.init() ) {
422 // Load the local scenery data
423 global_tile_mgr.update( current_options.get_lon(),
424 current_options.get_lat() );
426 FG_LOG( FG_GENERAL, FG_ALERT, "Error in Tile Manager initialization!" );
430 FG_LOG( FG_GENERAL, FG_DEBUG,
431 "Current terrain elevation after tile mgr init " <<
434 if ( current_options.get_flight_model() == FGInterface::FG_LARCSIM ) {
435 cur_fdm_state = new FGLaRCsim;
436 } else if ( current_options.get_flight_model() == FGInterface::FG_JSBSIM ) {
437 cur_fdm_state = new FGJSBsim;
438 } else if ( current_options.get_flight_model() ==
439 FGInterface::FG_BALLOONSIM ) {
440 cur_fdm_state = new FGBalloonSim;
441 } else if ( current_options.get_flight_model() ==
442 FGInterface::FG_MAGICCARPET ) {
443 cur_fdm_state = new FGMagicCarpet;
444 } else if ( current_options.get_flight_model() ==
445 FGInterface::FG_EXTERNAL ) {
446 cur_fdm_state = new FGExternal;
448 FG_LOG( FG_GENERAL, FG_ALERT,
449 "No flight model, can't init aircraft" );
453 // allocates structures so must happen before any of the flight
454 // model or control parameters are set
455 fgAircraftInit(); // In the future this might not be the case.
457 // set the initial position
460 // Calculate ground elevation at starting point (we didn't have
461 // tmp_abs_view_pos calculated when fgTileMgrUpdate() was called above
463 // calculalate a cartesian point somewhere along the line between
464 // the center of the earth and our view position. Doesn't have to
465 // be the exact elevation (this is good because we don't know it
468 // now handled inside of the fgTileMgrUpdate()
471 geod_pos = Point3D( cur_fdm_state->get_Longitude(), cur_fdm_state->get_Latitude(), 0.0);
472 tmp_abs_view_pos = sgGeodToCart(geod_pos);
474 FG_LOG( FG_GENERAL, FG_DEBUG,
475 "Initial abs_view_pos = " << tmp_abs_view_pos );
477 fgTileMgrCurElev( cur_fdm_state->get_Longitude(), cur_fdm_state->get_Latitude(),
479 FG_LOG( FG_GENERAL, FG_DEBUG,
480 "Altitude after update " << scenery.cur_elev );
483 fgFDMSetGroundElevation( current_options.get_flight_model(),
486 // Reset our altitude if we are below ground
487 FG_LOG( FG_GENERAL, FG_DEBUG, "Current altitude = " << cur_fdm_state->get_Altitude() );
488 FG_LOG( FG_GENERAL, FG_DEBUG, "Current runway altitude = " <<
489 cur_fdm_state->get_Runway_altitude() );
491 if ( cur_fdm_state->get_Altitude() < cur_fdm_state->get_Runway_altitude() + 3.758099) {
492 cur_fdm_state->set_Altitude( cur_fdm_state->get_Runway_altitude() + 3.758099 );
495 FG_LOG( FG_GENERAL, FG_INFO,
496 "Updated position (after elevation adj): ("
497 << (cur_fdm_state->get_Latitude() * RAD_TO_DEG) << ", "
498 << (cur_fdm_state->get_Longitude() * RAD_TO_DEG) << ", "
499 << (cur_fdm_state->get_Altitude() * FEET_TO_METER) << ")" );
501 // We need to calculate a few more values here that would normally
502 // be calculated by the FDM so that the current_view.UpdateViewMath()
503 // routine doesn't get hosed.
505 double sea_level_radius_meters;
507 // Set the FG variables first
508 sgGeodToGeoc( cur_fdm_state->get_Latitude(), cur_fdm_state->get_Altitude(),
509 &sea_level_radius_meters, &lat_geoc);
510 cur_fdm_state->set_Geocentric_Position( lat_geoc, cur_fdm_state->get_Longitude(),
511 cur_fdm_state->get_Altitude() +
512 (sea_level_radius_meters * METER_TO_FEET) );
513 cur_fdm_state->set_Sea_level_radius( sea_level_radius_meters * METER_TO_FEET );
515 cur_fdm_state->set_sin_cos_longitude(cur_fdm_state->get_Longitude());
516 cur_fdm_state->set_sin_cos_latitude(cur_fdm_state->get_Latitude());
518 cur_fdm_state->set_sin_lat_geocentric(sin(lat_geoc));
519 cur_fdm_state->set_cos_lat_geocentric(cos(lat_geoc));
521 // The following section sets up the flight model EOM parameters
522 // and should really be read in from one or more files.
525 cur_fdm_state->set_Velocities_Local( current_options.get_uBody(),
526 current_options.get_vBody(),
527 current_options.get_wBody());
529 // Initial Orientation
530 cur_fdm_state->set_Euler_Angles( current_options.get_roll() * DEG_TO_RAD,
531 current_options.get_pitch() * DEG_TO_RAD,
532 current_options.get_heading() * DEG_TO_RAD );
534 // Initial Angular Body rates
535 cur_fdm_state->set_Omega_Body( 7.206685E-05, 0.0, 9.492658E-05 );
537 cur_fdm_state->set_Earth_position_angle( 0.0 );
539 // Mass properties and geometry values
540 cur_fdm_state->set_Inertias( 8.547270E+01,
541 1.048000E+03, 3.000000E+03, 3.530000E+03, 0.000000E+00 );
543 // CG position w.r.t. ref. point
544 cur_fdm_state->set_CG_Position( 0.0, 0.0, 0.0 );
546 // Initialize the event manager
547 global_events.Init();
549 // Output event stats every 60 seconds
550 global_events.Register( "fgEVENT_MGR::PrintStats()",
551 fgMethodCallback<fgEVENT_MGR>( &global_events,
552 &fgEVENT_MGR::PrintStats),
553 fgEVENT::FG_EVENT_READY, 60000 );
555 // Initialize view parameters
556 FG_LOG( FG_GENERAL, FG_DEBUG, "Before current_view.init()");
559 FG_LOG( FG_GENERAL, FG_DEBUG, "After current_view.init()");
560 current_view.UpdateViewMath(*cur_fdm_state);
561 pilot_view.UpdateViewMath(*cur_fdm_state);
562 FG_LOG( FG_GENERAL, FG_DEBUG, " abs_view_pos = " << current_view.get_abs_view_pos());
563 // current_view.UpdateWorldToEye(f);
565 // Initialize the planetary subsystem
566 // global_events.Register( "fgPlanetsInit()", fgPlanetsInit,
567 // fgEVENT::FG_EVENT_READY, 600000);
569 // Initialize the sun's position
570 // global_events.Register( "fgSunInit()", fgSunInit,
571 // fgEVENT::FG_EVENT_READY, 30000 );
573 // Intialize the moon's position
574 // global_events.Register( "fgMoonInit()", fgMoonInit,
575 // fgEVENT::FG_EVENT_READY, 600000 );
577 // fgUpdateSunPos() needs a few position and view parameters set
578 // so it can calculate local relative sun angle and a few other
579 // things for correctly orienting the sky.
582 global_events.Register( "fgUpdateSunPos()", fgUpdateSunPos,
583 fgEVENT::FG_EVENT_READY, 60000);
584 global_events.Register( "fgUpdateMoonPos()", fgUpdateMoonPos,
585 fgEVENT::FG_EVENT_READY, 60000);
587 // Initialize Lighting interpolation tables
590 // update the lighting parameters (based on sun angle)
591 global_events.Register( "fgLight::Update()",
592 fgMethodCallback<fgLIGHT>( &cur_light_params,
594 fgEVENT::FG_EVENT_READY, 30000 );
595 // update the current timezone each 30 minutes
596 global_events.Register( "fgUpdateLocalTime()", fgUpdateLocalTime,
597 fgEVENT::FG_EVENT_READY, 1800000);
599 // Initialize the weather modeling subsystem
600 #ifndef FG_OLD_WEATHER
601 // Initialize the WeatherDatabase
602 FG_LOG(FG_GENERAL, FG_INFO, "Creating LocalWeatherDatabase");
604 sgSetVec3( position, current_aircraft.fdm_state->get_Latitude(),
605 current_aircraft.fdm_state->get_Longitude(),
606 current_aircraft.fdm_state->get_Altitude() * FEET_TO_METER );
607 FGLocalWeatherDatabase::theFGLocalWeatherDatabase =
608 new FGLocalWeatherDatabase( position, current_options.get_fg_root() );
609 // cout << theFGLocalWeatherDatabase << endl;
610 // cout << "visibility = "
611 // << theFGLocalWeatherDatabase->getWeatherVisibility() << endl;
613 WeatherDatabase = FGLocalWeatherDatabase::theFGLocalWeatherDatabase;
615 // register the periodic update of the weather
616 global_events.Register( "weather update", fgUpdateWeatherDatabase,
617 fgEVENT::FG_EVENT_READY, 30000);
619 current_weather.Init();
622 // Initialize vor/ndb/ils/fix list management and query systems
623 FG_LOG(FG_GENERAL, FG_INFO, "Loading Navaids");
625 FG_LOG(FG_GENERAL, FG_INFO, " VOR/NDB");
626 current_navlist = new FGNavList;
627 FGPath p_nav( current_options.get_fg_root() );
628 p_nav.append( "Navaids/default.nav" );
629 current_navlist->init( p_nav );
631 FG_LOG(FG_GENERAL, FG_INFO, " ILS");
632 current_ilslist = new FGILSList;
633 FGPath p_ils( current_options.get_fg_root() );
634 p_ils.append( "Navaids/default.ils" );
635 current_ilslist->init( p_ils );
637 FG_LOG(FG_GENERAL, FG_INFO, " Fixes");
638 current_fixlist = new FGFixList;
639 FGPath p_fix( current_options.get_fg_root() );
640 p_fix.append( "Navaids/default.fix" );
641 current_fixlist->init( p_fix );
643 // Initialize the underlying radio stack model
644 current_radiostack = new FGRadioStack;
646 // current_radiostack->set_nav1_freq( 117.30 );
647 // current_radiostack->set_nav1_alt_freq( 110.30 );
648 // current_radiostack->set_nav1_sel_radial( 119.0 );
650 // current_radiostack->set_nav2_freq( 111.80 );
651 // current_radiostack->set_nav2_alt_freq( 115.70 );
652 // current_radiostack->set_nav2_sel_radial( 029.0 );
654 // current_radiostack->set_adf_freq( 266.0 );
657 // This block of settings are Alex's defaults for San Diego
658 current_radiostack->set_nav1_freq( 111.70 );
659 current_radiostack->set_nav1_alt_freq( 115.30 );
660 current_radiostack->set_nav1_sel_radial( 280.0 );
661 current_radiostack->set_nav2_freq( 117.80 );
662 current_radiostack->set_nav2_alt_freq( 114.00 );
663 current_radiostack->set_nav2_sel_radial( 68.0 );
664 current_radiostack->set_adf_freq( 210.0 );
665 // End of Alex's custom settings
668 current_radiostack->search( cur_fdm_state->get_Longitude(),
669 cur_fdm_state->get_Latitude(),
670 cur_fdm_state->get_Altitude() * FEET_TO_METER );
672 current_radiostack->update( cur_fdm_state->get_Longitude(),
673 cur_fdm_state->get_Latitude(),
674 cur_fdm_state->get_Altitude() * FEET_TO_METER );
676 // Search radio database once per second
677 global_events.Register( "fgRadioSearch()", fgRadioSearch,
678 fgEVENT::FG_EVENT_READY, 1000);
681 // Initialize the Cockpit subsystem
682 if( fgCockpitInit( ¤t_aircraft )) {
683 // Cockpit initialized ok.
685 FG_LOG( FG_GENERAL, FG_ALERT, "Error in Cockpit initialization!" );
689 // Initialize the flight model subsystem data structures base on
692 // fgFDMInit( current_options.get_flight_model(), cur_fdm_state,
693 // 1.0 / current_options.get_model_hz() );
694 cur_fdm_state->init( 1.0 / current_options.get_model_hz() );
696 // I'm just sticking this here for now, it should probably move
698 scenery.cur_elev = cur_fdm_state->get_Runway_altitude() * FEET_TO_METER;
700 if ( cur_fdm_state->get_Altitude() < cur_fdm_state->get_Runway_altitude() + 3.758099) {
701 cur_fdm_state->set_Altitude( cur_fdm_state->get_Runway_altitude() + 3.758099 );
704 FG_LOG( FG_GENERAL, FG_INFO,
705 "Updated position (after elevation adj): ("
706 << (cur_fdm_state->get_Latitude() * RAD_TO_DEG) << ", "
707 << (cur_fdm_state->get_Longitude() * RAD_TO_DEG) << ", "
708 << (cur_fdm_state->get_Altitude() * FEET_TO_METER) << ")" );
709 // end of thing that I just stuck in that I should probably move
712 if ( fgJoystickInit() ) {
713 // Joystick initialized ok.
715 FG_LOG( FG_GENERAL, FG_ALERT, "Error in Joystick initialization!" );
719 current_autopilot = new FGAutopilot;
720 current_autopilot->init();
722 // initialize the gui parts of the autopilot
728 // Initialize I/O channels
729 #if ! defined( macintosh )
733 // Initialize the 2D panel.
735 current_properties.getStringValue("/sim/panel/path",
736 "Panels/Default/default.xml");
737 current_panel = fgReadPanel(panel_path);
738 if (current_panel == 0) {
739 FG_LOG(FG_INPUT, FG_ALERT,
740 "Error reading new panel from " << panel_path);
742 FG_LOG(FG_INPUT, FG_INFO, "Loaded new panel from " << panel_path);
744 // Initialize the BFI
747 FG_LOG( FG_GENERAL, FG_INFO, endl);
753 void fgReInitSubsystems( void )
755 bool freeze = globals->get_freeze();
757 globals->set_freeze( true );
759 if( global_tile_mgr.init() ) {
760 // Load the local scenery data
761 global_tile_mgr.update( current_options.get_lon(),
762 current_options.get_lat() );
764 FG_LOG( FG_GENERAL, FG_ALERT, "Error in Tile Manager initialization!" );
768 // cout << "current scenery elev = " << scenery.cur_elev << endl;
771 fgFDMSetGroundElevation( current_options.get_flight_model(),
774 // Reset our altitude if we are below ground
775 FG_LOG( FG_GENERAL, FG_DEBUG, "Current altitude = " << cur_fdm_state->get_Altitude() );
776 FG_LOG( FG_GENERAL, FG_DEBUG, "Current runway altitude = " <<
777 cur_fdm_state->get_Runway_altitude() );
779 if ( cur_fdm_state->get_Altitude() < cur_fdm_state->get_Runway_altitude() + 3.758099) {
780 cur_fdm_state->set_Altitude( cur_fdm_state->get_Runway_altitude() + 3.758099 );
782 double sea_level_radius_meters;
784 // Set the FG variables first
785 sgGeodToGeoc( cur_fdm_state->get_Latitude(), cur_fdm_state->get_Altitude(),
786 &sea_level_radius_meters, &lat_geoc);
787 cur_fdm_state->set_Geocentric_Position( lat_geoc, cur_fdm_state->get_Longitude(),
788 cur_fdm_state->get_Altitude() +
789 (sea_level_radius_meters * METER_TO_FEET) );
790 cur_fdm_state->set_Sea_level_radius( sea_level_radius_meters * METER_TO_FEET );
792 cur_fdm_state->set_sin_cos_longitude(cur_fdm_state->get_Longitude());
793 cur_fdm_state->set_sin_cos_latitude(cur_fdm_state->get_Latitude());
795 cur_fdm_state->set_sin_lat_geocentric(sin(lat_geoc));
796 cur_fdm_state->set_cos_lat_geocentric(cos(lat_geoc));
798 // The following section sets up the flight model EOM parameters
799 // and should really be read in from one or more files.
802 cur_fdm_state->set_Velocities_Local( current_options.get_uBody(),
803 current_options.get_vBody(),
804 current_options.get_wBody());
806 // Initial Orientation
807 cur_fdm_state->set_Euler_Angles( current_options.get_roll() * DEG_TO_RAD,
808 current_options.get_pitch() * DEG_TO_RAD,
809 current_options.get_heading() * DEG_TO_RAD );
811 // Initial Angular Body rates
812 cur_fdm_state->set_Omega_Body( 7.206685E-05, 0.0, 9.492658E-05 );
814 cur_fdm_state->set_Earth_position_angle( 0.0 );
816 // Mass properties and geometry values
817 cur_fdm_state->set_Inertias( 8.547270E+01,
818 1.048000E+03, 3.000000E+03, 3.530000E+03, 0.000000E+00 );
820 // CG position w.r.t. ref. point
821 cur_fdm_state->set_CG_Position( 0.0, 0.0, 0.0 );
823 // Initialize view parameters
824 current_view.set_view_offset( 0.0 );
825 current_view.set_goal_view_offset( 0.0 );
826 pilot_view.set_view_offset( 0.0 );
827 pilot_view.set_goal_view_offset( 0.0 );
829 FG_LOG( FG_GENERAL, FG_DEBUG, "After current_view.init()");
830 current_view.UpdateViewMath(*cur_fdm_state);
831 pilot_view.UpdateViewMath(*cur_fdm_state);
832 FG_LOG( FG_GENERAL, FG_DEBUG, " abs_view_pos = " << current_view.get_abs_view_pos());
834 // fgFDMInit( current_options.get_flight_model(), cur_fdm_state,
835 // 1.0 / current_options.get_model_hz() );
836 cur_fdm_state->init( 1.0 / current_options.get_model_hz() );
838 scenery.cur_elev = cur_fdm_state->get_Runway_altitude() * FEET_TO_METER;
840 if ( cur_fdm_state->get_Altitude() < cur_fdm_state->get_Runway_altitude() + 3.758099) {
841 cur_fdm_state->set_Altitude( cur_fdm_state->get_Runway_altitude() + 3.758099 );
844 controls.reset_all();
845 current_autopilot->reset();
848 globals->set_freeze( false );