]> git.mxchange.org Git - flightgear.git/blob - src/Main/fg_init.cxx
Replaced gdbm with metakit. Involves a new simgear version and a new database
[flightgear.git] / src / Main / fg_init.cxx
1 //
2 // fg_init.cxx -- Flight Gear top level initialization routines
3 //
4 // Written by Curtis Olson, started August 1997.
5 //
6 // Copyright (C) 1997  Curtis L. Olson  - curt@infoplane.com
7 //
8 // This program is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU General Public License as
10 // published by the Free Software Foundation; either version 2 of the
11 // License, or (at your option) any later version.
12 //
13 // This program is distributed in the hope that it will be useful, but
14 // WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16 // General Public License for more details.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the Free Software
20 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 //
22 //
23 // $Id$
24
25
26 #ifdef HAVE_CONFIG_H
27 #  include <config.h>
28 #endif
29
30 // For BC 5.01 this must be included before OpenGL includes.
31 #ifdef FG_MATH_EXCEPTION_CLASH
32 #  include <math.h>
33 #endif
34
35 #include <GL/glut.h>
36 #include <simgear/xgl/xgl.h>
37
38 #include <stdio.h>
39 #include <stdlib.h>
40
41 // work around a stdc++ lib bug in some versions of linux, but doesn't
42 // seem to hurt to have this here for all versions of Linux.
43 #ifdef linux
44 #  define _G_NO_EXTERN_TEMPLATES
45 #endif
46
47 #include <simgear/compiler.h>
48
49 #include STL_STRING
50
51 #include <simgear/constants.h>
52 #include <simgear/debug/logstream.hxx>
53 #include <simgear/math/fg_geodesy.hxx>
54 #include <simgear/math/point3d.hxx>
55 #include <simgear/math/polar3d.hxx>
56 #include <simgear/misc/fgpath.hxx>
57
58 #include <Aircraft/aircraft.hxx>
59 #include <Airports/simple.hxx>
60 #include <Autopilot/auto_gui.hxx>
61 #include <Autopilot/newauto.hxx>
62 #include <Cockpit/cockpit.hxx>
63 #include <Cockpit/radiostack.hxx>
64 #include <Cockpit/panel.hxx>
65 #include <Cockpit/sp_panel.hxx>
66 #include <FDM/Balloon.h>
67 #include <FDM/External.hxx>
68 #include <FDM/JSBsim.hxx>
69 #include <FDM/LaRCsim.hxx>
70 #include <FDM/MagicCarpet.hxx>
71 #include <Include/general.hxx>
72 #include <Joystick/joystick.hxx>
73 #include <Navaids/fixlist.hxx>
74 #include <Navaids/ilslist.hxx>
75 #include <Navaids/navlist.hxx>
76 #include <Scenery/scenery.hxx>
77 #include <Scenery/tilemgr.hxx>
78 #include <Time/event.hxx>
79 #include <Time/fg_time.hxx>
80 #include <Time/light.hxx>
81 #include <Time/sunpos.hxx>
82 #include <Time/moonpos.hxx>
83
84 #ifndef FG_OLD_WEATHER
85 #  include <WeatherCM/FGLocalWeatherDatabase.h>
86 #else
87 #  include <Weather/weather.hxx>
88 #endif
89
90 #include "fg_init.hxx"
91 #include "fg_io.hxx"
92 #include "options.hxx"
93 #include "views.hxx"
94
95 #if defined(FX) && defined(XMESA)
96 #include <GL/xmesa.h>
97 #endif
98
99 FG_USING_STD(string);
100
101 extern const char *default_root;
102
103
104 // Read in configuration (file and command line)
105 bool fgInitConfig ( int argc, char **argv ) {
106     // Attempt to locate and parse a config file
107     // First check fg_root
108     FGPath config( current_options.get_fg_root() );
109     config.append( "system.fgfsrc" );
110     current_options.parse_config_file( config.str() );
111
112     // Next check home directory
113     char* envp = ::getenv( "HOME" );
114     if ( envp != NULL ) {
115         config.set( envp );
116         config.append( ".fgfsrc" );
117         current_options.parse_config_file( config.str() );
118     }
119
120     // Parse remaining command line options
121     // These will override anything specified in a config file
122     if ( current_options.parse_command_line(argc, argv) !=
123          fgOPTIONS::FG_OPTIONS_OK )
124     {
125         // Something must have gone horribly wrong with the command
126         // line parsing or maybe the user just requested help ... :-)
127         current_options.usage();
128         FG_LOG( FG_GENERAL, FG_ALERT, "\nExiting ...");
129         return false;
130     }
131
132    return true;
133 }
134
135
136 // Set initial position and orientation
137 bool fgInitPosition( void ) {
138     string id;
139     FGInterface *f;
140
141     f = current_aircraft.fdm_state;
142
143     id = current_options.get_airport_id();
144     if ( id.length() ) {
145         // set initial position from airport id
146
147         FGPath path( current_options.get_fg_root() );
148         path.append( "Airports" );
149         path.append( "simple.mk4" );
150         FGAirports airports( path.c_str() );
151         FGAirport a;
152
153         FG_LOG( FG_GENERAL, FG_INFO,
154                 "Attempting to set starting position from airport code "
155                 << id );
156
157         // FGPath inpath( current_options.get_fg_root() );
158         // inpath.append( "Airports" );
159         // inpath.append( "apt_simple" );
160         // airports.load( inpath.c_str() );
161
162         // FGPath outpath( current_options.get_fg_root() );
163         // outpath.append( "Airports" );
164         // outpath.append( "simple.gdbm" );
165         // airports.dump_gdbm( outpath.c_str() );
166
167         if ( ! airports.search( id, &a ) ) {
168             FG_LOG( FG_GENERAL, FG_ALERT,
169                     "Failed to find " << id << " in database." );
170             exit(-1);
171         } else {
172             f->set_Longitude( a.longitude * DEG_TO_RAD );
173             f->set_Latitude( a.latitude * DEG_TO_RAD );
174         }
175     } else {
176         // set initial position from default or command line coordinates
177
178         f->set_Longitude( current_options.get_lon() * DEG_TO_RAD );
179         f->set_Latitude( current_options.get_lat() * DEG_TO_RAD );
180     }
181
182     FG_LOG( FG_GENERAL, FG_INFO,
183             "starting altitude is = " << current_options.get_altitude() );
184
185     f->set_Altitude( current_options.get_altitude() * METER_TO_FEET );
186     fgFDMSetGroundElevation( current_options.get_flight_model(),
187                              (f->get_Altitude() - 3.758099) * FEET_TO_METER );
188
189     FG_LOG( FG_GENERAL, FG_INFO,
190             "Initial position is: ("
191             << (f->get_Longitude() * RAD_TO_DEG) << ", "
192             << (f->get_Latitude() * RAD_TO_DEG) << ", "
193             << (f->get_Altitude() * FEET_TO_METER) << ")" );
194
195     return true;
196 }
197
198
199 // General house keeping initializations
200 bool fgInitGeneral( void ) {
201     string root;
202
203 #if defined(FX) && defined(XMESA)
204     char *mesa_win_state;
205 #endif
206
207     FG_LOG( FG_GENERAL, FG_INFO, "General Initialization" );
208     FG_LOG( FG_GENERAL, FG_INFO, "======= ==============" );
209
210     root = current_options.get_fg_root();
211     if ( ! root.length() ) {
212         // No root path set? Then bail ...
213         FG_LOG( FG_GENERAL, FG_ALERT,
214                 "Cannot continue without environment variable FG_ROOT"
215                 << "being defined." );
216         exit(-1);
217     }
218     FG_LOG( FG_GENERAL, FG_INFO, "FG_ROOT = " << '"' << root << '"' << endl );
219
220 #if defined(FX) && defined(XMESA)
221     // initialize full screen flag
222     global_fullscreen = false;
223     if ( strstr ( general.get_glRenderer(), "Glide" ) ) {
224         // Test for the MESA_GLX_FX env variable
225         if ( (mesa_win_state = getenv( "MESA_GLX_FX" )) != NULL) {
226             // test if we are fullscreen mesa/glide
227             if ( (mesa_win_state[0] == 'f') ||
228                  (mesa_win_state[0] == 'F') ) {
229                 global_fullscreen = true;
230             }
231         }
232     }
233 #endif
234
235     return true;
236 }
237
238
239 // This is the top level init routine which calls all the other
240 // initialization routines.  If you are adding a subsystem to flight
241 // gear, its initialization call should located in this routine.
242 // Returns non-zero if a problem encountered.
243 bool fgInitSubsystems( void ) {
244     fgLIGHT *l = &cur_light_params;
245     FGTime *t = FGTime::cur_time_params;
246
247     FG_LOG( FG_GENERAL, FG_INFO, "Initialize Subsystems");
248     FG_LOG( FG_GENERAL, FG_INFO, "========== ==========");
249
250     if ( current_options.get_flight_model() == FGInterface::FG_LARCSIM ) {
251         cur_fdm_state = new FGLaRCsim;
252     } else if ( current_options.get_flight_model() == FGInterface::FG_JSBSIM ) {
253         cur_fdm_state = new FGJSBsim;
254     } else if ( current_options.get_flight_model() == 
255                 FGInterface::FG_BALLOONSIM ) {
256         cur_fdm_state = new FGBalloonSim;
257     } else if ( current_options.get_flight_model() == 
258                 FGInterface::FG_MAGICCARPET ) {
259         cur_fdm_state = new FGMagicCarpet;
260     } else if ( current_options.get_flight_model() == 
261                 FGInterface::FG_EXTERNAL ) {
262         cur_fdm_state = new FGExternal;
263     } else {
264         FG_LOG( FG_GENERAL, FG_ALERT,
265                 "No flight model, can't init aircraft" );
266         exit(-1);
267     }
268
269     // allocates structures so must happen before any of the flight
270     // model or control parameters are set
271     fgAircraftInit();   // In the future this might not be the case.
272
273     // set the initial position
274     fgInitPosition();
275
276     // Initialize the Scenery Management subsystem
277     if ( fgSceneryInit() ) {
278         // Scenery initialized ok.
279     } else {
280         FG_LOG( FG_GENERAL, FG_ALERT, "Error in Scenery initialization!" );
281         exit(-1);
282     }
283
284     if( global_tile_mgr.init() ) {
285         // Load the local scenery data
286         global_tile_mgr.update();
287     } else {
288         FG_LOG( FG_GENERAL, FG_ALERT, "Error in Tile Manager initialization!" );
289         exit(-1);
290     }
291
292     FG_LOG( FG_GENERAL, FG_DEBUG,
293             "Current terrain elevation after tile mgr init " <<
294             scenery.cur_elev );
295
296     // Calculate ground elevation at starting point (we didn't have
297     // tmp_abs_view_pos calculated when fgTileMgrUpdate() was called above
298     //
299     // calculalate a cartesian point somewhere along the line between
300     // the center of the earth and our view position.  Doesn't have to
301     // be the exact elevation (this is good because we don't know it
302     // yet :-)
303
304     // now handled inside of the fgTileMgrUpdate()
305
306     /*
307     geod_pos = Point3D( cur_fdm_state->get_Longitude(), cur_fdm_state->get_Latitude(), 0.0);
308     tmp_abs_view_pos = fgGeodToCart(geod_pos);
309
310     FG_LOG( FG_GENERAL, FG_DEBUG,
311             "Initial abs_view_pos = " << tmp_abs_view_pos );
312     scenery.cur_elev =
313         fgTileMgrCurElev( cur_fdm_state->get_Longitude(), cur_fdm_state->get_Latitude(),
314                           tmp_abs_view_pos );
315     FG_LOG( FG_GENERAL, FG_DEBUG,
316             "Altitude after update " << scenery.cur_elev );
317     */
318
319     fgFDMSetGroundElevation( current_options.get_flight_model(),
320                              scenery.cur_elev );
321
322     // Reset our altitude if we are below ground
323     FG_LOG( FG_GENERAL, FG_DEBUG, "Current altitude = " << cur_fdm_state->get_Altitude() );
324     FG_LOG( FG_GENERAL, FG_DEBUG, "Current runway altitude = " <<
325             cur_fdm_state->get_Runway_altitude() );
326
327     if ( cur_fdm_state->get_Altitude() < cur_fdm_state->get_Runway_altitude() + 3.758099) {
328         cur_fdm_state->set_Altitude( cur_fdm_state->get_Runway_altitude() + 3.758099 );
329     }
330
331     FG_LOG( FG_GENERAL, FG_INFO,
332             "Updated position (after elevation adj): ("
333             << (cur_fdm_state->get_Latitude() * RAD_TO_DEG) << ", "
334             << (cur_fdm_state->get_Longitude() * RAD_TO_DEG) << ", "
335             << (cur_fdm_state->get_Altitude() * FEET_TO_METER) << ")" );
336
337     // We need to calculate a few more values here that would normally
338     // be calculated by the FDM so that the current_view.UpdateViewMath()
339     // routine doesn't get hosed.
340
341     double sea_level_radius_meters;
342     double lat_geoc;
343     // Set the FG variables first
344     fgGeodToGeoc( cur_fdm_state->get_Latitude(), cur_fdm_state->get_Altitude(),
345                   &sea_level_radius_meters, &lat_geoc);
346     cur_fdm_state->set_Geocentric_Position( lat_geoc, cur_fdm_state->get_Longitude(),
347                                 cur_fdm_state->get_Altitude() +
348                                 (sea_level_radius_meters * METER_TO_FEET) );
349     cur_fdm_state->set_Sea_level_radius( sea_level_radius_meters * METER_TO_FEET );
350
351     cur_fdm_state->set_sin_cos_longitude(cur_fdm_state->get_Longitude());
352     cur_fdm_state->set_sin_cos_latitude(cur_fdm_state->get_Latitude());
353         
354     cur_fdm_state->set_sin_lat_geocentric(sin(lat_geoc));
355     cur_fdm_state->set_cos_lat_geocentric(cos(lat_geoc));
356
357     // The following section sets up the flight model EOM parameters
358     // and should really be read in from one or more files.
359
360     // Initial Velocity
361     cur_fdm_state->set_Velocities_Local( current_options.get_uBody(),
362                              current_options.get_vBody(),
363                              current_options.get_wBody());
364
365     // Initial Orientation
366     cur_fdm_state->set_Euler_Angles( current_options.get_roll() * DEG_TO_RAD,
367                          current_options.get_pitch() * DEG_TO_RAD,
368                          current_options.get_heading() * DEG_TO_RAD );
369
370     // Initial Angular Body rates
371     cur_fdm_state->set_Omega_Body( 7.206685E-05, 0.0, 9.492658E-05 );
372
373     cur_fdm_state->set_Earth_position_angle( 0.0 );
374
375     // Mass properties and geometry values
376     cur_fdm_state->set_Inertias( 8.547270E+01,
377                      1.048000E+03, 3.000000E+03, 3.530000E+03, 0.000000E+00 );
378
379     // CG position w.r.t. ref. point
380     cur_fdm_state->set_CG_Position( 0.0, 0.0, 0.0 );
381
382     // Initialize the event manager
383     global_events.Init();
384
385     // Output event stats every 60 seconds
386     global_events.Register( "fgEVENT_MGR::PrintStats()",
387                             fgMethodCallback<fgEVENT_MGR>( &global_events,
388                                                    &fgEVENT_MGR::PrintStats),
389                             fgEVENT::FG_EVENT_READY, 60000 );
390
391     // Initialize view parameters
392     FG_LOG( FG_GENERAL, FG_DEBUG, "Before current_view.init()");
393     current_view.Init();
394     pilot_view.Init();
395     FG_LOG( FG_GENERAL, FG_DEBUG, "After current_view.init()");
396     current_view.UpdateViewMath(*cur_fdm_state);
397     pilot_view.UpdateViewMath(*cur_fdm_state);
398     FG_LOG( FG_GENERAL, FG_DEBUG, "  abs_view_pos = " << current_view.get_abs_view_pos());
399     // current_view.UpdateWorldToEye(f);
400
401     // Initialize the planetary subsystem
402     // global_events.Register( "fgPlanetsInit()", fgPlanetsInit,
403     //                      fgEVENT::FG_EVENT_READY, 600000);
404
405     // Initialize the sun's position
406     // global_events.Register( "fgSunInit()", fgSunInit,
407     //                      fgEVENT::FG_EVENT_READY, 30000 );
408
409     // Intialize the moon's position
410     // global_events.Register( "fgMoonInit()", fgMoonInit,
411     //                      fgEVENT::FG_EVENT_READY, 600000 );
412
413     // fgUpdateSunPos() needs a few position and view parameters set
414     // so it can calculate local relative sun angle and a few other
415     // things for correctly orienting the sky.
416     fgUpdateSunPos();
417     fgUpdateMoonPos();
418     global_events.Register( "fgUpdateSunPos()", fgUpdateSunPos,
419                             fgEVENT::FG_EVENT_READY, 60000);
420     global_events.Register( "fgUpdateMoonPos()", fgUpdateMoonPos,
421                             fgEVENT::FG_EVENT_READY, 60000);
422
423     // Initialize Lighting interpolation tables
424     l->Init();
425
426     // update the lighting parameters (based on sun angle)
427     global_events.Register( "fgLight::Update()",
428                             fgMethodCallback<fgLIGHT>( &cur_light_params,
429                                                        &fgLIGHT::Update),
430                             fgEVENT::FG_EVENT_READY, 30000 );
431     // update the current timezone each 30 minutes
432     global_events.Register( "fgTIME::updateLocal()",
433                             fgMethodCallback<FGTime>(FGTime::cur_time_params, 
434                                                      &FGTime::updateLocal),
435                             fgEVENT::FG_EVENT_READY, 1800000);
436
437     // Initialize the weather modeling subsystem
438 #ifndef FG_OLD_WEATHER
439     // Initialize the WeatherDatabase
440     FG_LOG(FG_GENERAL, FG_INFO, "Creating LocalWeatherDatabase");
441     sgVec3 position;
442     sgSetVec3( position, current_aircraft.fdm_state->get_Latitude(),
443                current_aircraft.fdm_state->get_Longitude(),
444                current_aircraft.fdm_state->get_Altitude() * FEET_TO_METER );
445     FGLocalWeatherDatabase::theFGLocalWeatherDatabase = 
446         new FGLocalWeatherDatabase( position );
447     // cout << theFGLocalWeatherDatabase << endl;
448     // cout << "visibility = " 
449     //      << theFGLocalWeatherDatabase->getWeatherVisibility() << endl;
450
451     WeatherDatabase = FGLocalWeatherDatabase::theFGLocalWeatherDatabase;
452      
453     // register the periodic update of the weather
454     global_events.Register( "weather update", fgUpdateWeatherDatabase,
455                             fgEVENT::FG_EVENT_READY, 30000);
456 #else
457     current_weather.Init();
458 #endif
459
460     // Initialize vor/ndb/ils/fix list management and query systems
461     FG_LOG(FG_GENERAL, FG_INFO, "Loading Navaids");
462
463     FG_LOG(FG_GENERAL, FG_INFO, "  VOR/NDB");
464     current_navlist = new FGNavList;
465     FGPath p_nav( current_options.get_fg_root() );
466     p_nav.append( "Navaids/default.nav" );
467     current_navlist->init( p_nav );
468
469     FG_LOG(FG_GENERAL, FG_INFO, "  ILS");
470     current_ilslist = new FGILSList;
471     FGPath p_ils( current_options.get_fg_root() );
472     p_ils.append( "Navaids/default.ils" );
473     current_ilslist->init( p_ils );
474
475     FG_LOG(FG_GENERAL, FG_INFO, "  Fixes");
476     current_fixlist = new FGFixList;
477     FGPath p_fix( current_options.get_fg_root() );
478     p_fix.append( "Navaids/default.fix" );
479     current_fixlist->init( p_fix );
480
481     // Initialize the underlying radio stack model
482     current_radiostack = new FGRadioStack;
483
484     current_radiostack->set_nav1_freq( 117.30 );
485     current_radiostack->set_nav1_alt_freq( 110.30 );
486     current_radiostack->set_nav1_sel_radial( 119.0 );
487
488     current_radiostack->set_nav2_freq( 111.80 );
489     current_radiostack->set_nav2_alt_freq( 115.70 );
490     current_radiostack->set_nav2_sel_radial( 029.0 );
491
492     current_radiostack->set_adf_freq( 266.0 );
493
494     current_radiostack->search( cur_fdm_state->get_Longitude(),
495                                 cur_fdm_state->get_Latitude(),
496                                 cur_fdm_state->get_Altitude() * FEET_TO_METER );
497
498     current_radiostack->update( cur_fdm_state->get_Longitude(),
499                                 cur_fdm_state->get_Latitude(),
500                                 cur_fdm_state->get_Altitude() * FEET_TO_METER );
501
502     // Search radio database once per second
503     global_events.Register( "fgRadioSearch()", fgRadioSearch,
504                             fgEVENT::FG_EVENT_READY, 1000);
505
506
507     // Initialize the Cockpit subsystem
508     if( fgCockpitInit( &current_aircraft )) {
509         // Cockpit initialized ok.
510     } else {
511         FG_LOG( FG_GENERAL, FG_ALERT, "Error in Cockpit initialization!" );
512         exit(-1);
513     }
514
515     // Initialize the flight model subsystem data structures base on
516     // above values
517
518     // fgFDMInit( current_options.get_flight_model(), cur_fdm_state,
519     //            1.0 / current_options.get_model_hz() );
520     cur_fdm_state->init( 1.0 / current_options.get_model_hz() );
521
522     // I'm just sticking this here for now, it should probably move
523     // eventually
524     scenery.cur_elev = cur_fdm_state->get_Runway_altitude() * FEET_TO_METER;
525
526     if ( cur_fdm_state->get_Altitude() < cur_fdm_state->get_Runway_altitude() + 3.758099) {
527         cur_fdm_state->set_Altitude( cur_fdm_state->get_Runway_altitude() + 3.758099 );
528     }
529
530     FG_LOG( FG_GENERAL, FG_INFO,
531             "Updated position (after elevation adj): ("
532             << (cur_fdm_state->get_Latitude() * RAD_TO_DEG) << ", "
533             << (cur_fdm_state->get_Longitude() * RAD_TO_DEG) << ", "
534             << (cur_fdm_state->get_Altitude() * FEET_TO_METER) << ")" );
535     // end of thing that I just stuck in that I should probably move
536
537     // Joystick support
538     if ( fgJoystickInit() ) {
539         // Joystick initialized ok.
540     } else {
541         FG_LOG( FG_GENERAL, FG_ALERT, "Error in Joystick initialization!" );
542     }
543
544     // Autopilot init
545     current_autopilot = new FGAutopilot;
546     current_autopilot->init();
547
548     // initialize the gui parts of the autopilot
549     NewTgtAirportInit();
550     fgAPAdjustInit() ;
551     NewHeadingInit();
552     NewAltitudeInit();
553
554     // Initialize I/O channels
555 #if ! defined( MACOS )
556     fgIOInit();
557 #endif
558
559     // Initialize the 2D panel.
560     current_panel = fgCreateSmallSinglePropPanel(0, 0, 1024, 768);
561
562     FG_LOG( FG_GENERAL, FG_INFO, endl);
563
564     return true;
565 }
566
567
568 void fgReInitSubsystems( void )
569 {
570     FGTime *t = FGTime::cur_time_params;
571     
572     int toggle_pause = t->getPause();
573     
574     if( !toggle_pause )
575         t->togglePauseMode();
576     
577     fgInitPosition();
578     if( global_tile_mgr.init() ) {
579         // Load the local scenery data
580         global_tile_mgr.update();
581     } else {
582         FG_LOG( FG_GENERAL, FG_ALERT, "Error in Tile Manager initialization!" );
583                 exit(-1);
584     }
585     fgFDMSetGroundElevation( current_options.get_flight_model(), 
586                              scenery.cur_elev );
587
588     // Reset our altitude if we are below ground
589     FG_LOG( FG_GENERAL, FG_DEBUG, "Current altitude = " << cur_fdm_state->get_Altitude() );
590     FG_LOG( FG_GENERAL, FG_DEBUG, "Current runway altitude = " << 
591             cur_fdm_state->get_Runway_altitude() );
592
593     if ( cur_fdm_state->get_Altitude() < cur_fdm_state->get_Runway_altitude() + 3.758099) {
594         cur_fdm_state->set_Altitude( cur_fdm_state->get_Runway_altitude() + 3.758099 );
595     }
596     double sea_level_radius_meters;
597     double lat_geoc;
598     // Set the FG variables first
599     fgGeodToGeoc( cur_fdm_state->get_Latitude(), cur_fdm_state->get_Altitude(), 
600                   &sea_level_radius_meters, &lat_geoc);
601     cur_fdm_state->set_Geocentric_Position( lat_geoc, cur_fdm_state->get_Longitude(), 
602                                 cur_fdm_state->get_Altitude() + 
603                                 (sea_level_radius_meters * METER_TO_FEET) );
604     cur_fdm_state->set_Sea_level_radius( sea_level_radius_meters * METER_TO_FEET );
605         
606     cur_fdm_state->set_sin_cos_longitude(cur_fdm_state->get_Longitude());
607     cur_fdm_state->set_sin_cos_latitude(cur_fdm_state->get_Latitude());
608         
609     cur_fdm_state->set_sin_lat_geocentric(sin(lat_geoc));
610     cur_fdm_state->set_cos_lat_geocentric(cos(lat_geoc));
611
612     // The following section sets up the flight model EOM parameters
613     // and should really be read in from one or more files.
614
615     // Initial Velocity
616     cur_fdm_state->set_Velocities_Local( current_options.get_uBody(),
617                              current_options.get_vBody(),
618                              current_options.get_wBody());
619
620     // Initial Orientation
621     cur_fdm_state->set_Euler_Angles( current_options.get_roll() * DEG_TO_RAD,
622                          current_options.get_pitch() * DEG_TO_RAD,
623                          current_options.get_heading() * DEG_TO_RAD );
624
625     // Initial Angular Body rates
626     cur_fdm_state->set_Omega_Body( 7.206685E-05, 0.0, 9.492658E-05 );
627
628     cur_fdm_state->set_Earth_position_angle( 0.0 );
629
630     // Mass properties and geometry values
631     cur_fdm_state->set_Inertias( 8.547270E+01, 
632                      1.048000E+03, 3.000000E+03, 3.530000E+03, 0.000000E+00 );
633
634     // CG position w.r.t. ref. point
635     cur_fdm_state->set_CG_Position( 0.0, 0.0, 0.0 );
636
637     // Initialize view parameters
638     current_view.set_view_offset( 0.0 );
639     current_view.set_goal_view_offset( 0.0 );
640     pilot_view.set_view_offset( 0.0 );
641     pilot_view.set_goal_view_offset( 0.0 );
642
643     FG_LOG( FG_GENERAL, FG_DEBUG, "After current_view.init()");
644     current_view.UpdateViewMath(*cur_fdm_state);
645     pilot_view.UpdateViewMath(*cur_fdm_state);
646     FG_LOG( FG_GENERAL, FG_DEBUG, "  abs_view_pos = " << current_view.get_abs_view_pos());
647
648     // fgFDMInit( current_options.get_flight_model(), cur_fdm_state, 
649     //            1.0 / current_options.get_model_hz() );
650     cur_fdm_state->init( 1.0 / current_options.get_model_hz() );
651
652     scenery.cur_elev = cur_fdm_state->get_Runway_altitude() * FEET_TO_METER;
653
654     if ( cur_fdm_state->get_Altitude() < cur_fdm_state->get_Runway_altitude() + 3.758099) {
655         cur_fdm_state->set_Altitude( cur_fdm_state->get_Runway_altitude() + 3.758099 );
656     }
657
658     controls.reset_all();
659     current_autopilot->reset();
660
661     if( !toggle_pause )
662         t->togglePauseMode();
663 }