]> git.mxchange.org Git - flightgear.git/blob - src/Main/fg_init.cxx
6aac3191b0b9e58f430003eeaa35425b32c09044
[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 <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 <Include/compiler.h>
48
49 #include STL_STRING
50
51 #include <Debug/logstream.hxx>
52 #include <Aircraft/aircraft.hxx>
53 #include <Airports/simple.hxx>
54 #include <Astro/sky.hxx>
55 #include <Astro/stars.hxx>
56 #include <Astro/solarsystem.hxx>
57 #include <Autopilot/autopilot.hxx>
58 #include <Cockpit/cockpit.hxx>
59 #include <FDM/Balloon.h>
60 #include <FDM/External.hxx>
61 #include <FDM/JSBsim.hxx>
62 #include <FDM/LaRCsim.hxx>
63 #include <FDM/MagicCarpet.hxx>
64 #include <Include/fg_constants.h>
65 #include <Include/general.hxx>
66 #include <Joystick/joystick.hxx>
67 #include <Math/fg_geodesy.hxx>
68 #include <Math/point3d.hxx>
69 #include <Math/polar3d.hxx>
70 #include <Misc/fgpath.hxx>
71 #include <Scenery/scenery.hxx>
72 #include <Scenery/tilemgr.hxx>
73 #include <Time/event.hxx>
74 #include <Time/fg_time.hxx>
75 #include <Time/light.hxx>
76 #include <Time/sunpos.hxx>
77 #include <Time/moonpos.hxx>
78
79 #ifndef FG_OLD_WEATHER
80 #  include <WeatherCM/FGLocalWeatherDatabase.h>
81 #else
82 #  include <Weather/weather.hxx>
83 #endif
84
85 #include "fg_init.hxx"
86 #include "fg_io.hxx"
87 #include "options.hxx"
88 #include "views.hxx"
89
90 #if defined(FX) && defined(XMESA)
91 #include <GL/xmesa.h>
92 #endif
93
94 FG_USING_STD(string);
95
96 extern const char *default_root;
97
98
99 // Read in configuration (file and command line)
100 bool fgInitConfig ( int argc, char **argv ) {
101     // Attempt to locate and parse a config file
102     // First check fg_root
103     FGPath config( current_options.get_fg_root() );
104     config.append( "system.fgfsrc" );
105     current_options.parse_config_file( config.str() );
106
107     // Next check home directory
108     char* envp = ::getenv( "HOME" );
109     if ( envp != NULL ) {
110         config.set( envp );
111         config.append( ".fgfsrc" );
112         current_options.parse_config_file( config.str() );
113     }
114
115     // Parse remaining command line options
116     // These will override anything specified in a config file
117     if ( current_options.parse_command_line(argc, argv) !=
118          fgOPTIONS::FG_OPTIONS_OK )
119     {
120         // Something must have gone horribly wrong with the command
121         // line parsing or maybe the user just requested help ... :-)
122         current_options.usage();
123         FG_LOG( FG_GENERAL, FG_ALERT, "\nExiting ...");
124         return false;
125     }
126
127    return true;
128 }
129
130
131 // Set initial position and orientation
132 bool fgInitPosition( void ) {
133     string id;
134     FGInterface *f;
135
136     f = current_aircraft.fdm_state;
137
138     id = current_options.get_airport_id();
139     if ( id.length() ) {
140         // set initial position from airport id
141
142         fgAIRPORTS airports;
143         fgAIRPORT a;
144
145         FG_LOG( FG_GENERAL, FG_INFO,
146                 "Attempting to set starting position from airport code "
147                 << id );
148
149         airports.load("apt_simple");
150         if ( ! airports.search( id, &a ) ) {
151             FG_LOG( FG_GENERAL, FG_ALERT,
152                     "Failed to find " << id << " in database." );
153             exit(-1);
154         } else {
155             f->set_Longitude( a.longitude * DEG_TO_RAD );
156             f->set_Latitude( a.latitude * DEG_TO_RAD );
157         }
158     } else {
159         // set initial position from default or command line coordinates
160
161         f->set_Longitude( current_options.get_lon() * DEG_TO_RAD );
162         f->set_Latitude( current_options.get_lat() * DEG_TO_RAD );
163     }
164
165     FG_LOG( FG_GENERAL, FG_INFO,
166             "starting altitude is = " << current_options.get_altitude() );
167
168     f->set_Altitude( current_options.get_altitude() * METER_TO_FEET );
169     fgFDMSetGroundElevation( current_options.get_flight_model(),
170                              (f->get_Altitude() - 3.758099) * FEET_TO_METER );
171
172     FG_LOG( FG_GENERAL, FG_INFO,
173             "Initial position is: ("
174             << (f->get_Longitude() * RAD_TO_DEG) << ", "
175             << (f->get_Latitude() * RAD_TO_DEG) << ", "
176             << (f->get_Altitude() * FEET_TO_METER) << ")" );
177
178     return true;
179 }
180
181
182 // General house keeping initializations
183 bool fgInitGeneral( void ) {
184     string root;
185
186 #if defined(FX) && defined(XMESA)
187     char *mesa_win_state;
188 #endif
189
190     FG_LOG( FG_GENERAL, FG_INFO, "General Initialization" );
191     FG_LOG( FG_GENERAL, FG_INFO, "======= ==============" );
192
193     root = current_options.get_fg_root();
194     if ( ! root.length() ) {
195         // No root path set? Then bail ...
196         FG_LOG( FG_GENERAL, FG_ALERT,
197                 "Cannot continue without environment variable FG_ROOT"
198                 << "being defined." );
199         exit(-1);
200     }
201     FG_LOG( FG_GENERAL, FG_INFO, "FG_ROOT = " << '"' << root << '"' << endl );
202
203 #if defined(FX) && defined(XMESA)
204     // initialize full screen flag
205     global_fullscreen = false;
206     if ( strstr ( general.get_glRenderer(), "Glide" ) ) {
207         // Test for the MESA_GLX_FX env variable
208         if ( (mesa_win_state = getenv( "MESA_GLX_FX" )) != NULL) {
209             // test if we are fullscreen mesa/glide
210             if ( (mesa_win_state[0] == 'f') ||
211                  (mesa_win_state[0] == 'F') ) {
212                 global_fullscreen = true;
213             }
214         }
215     }
216 #endif
217
218     return true;
219 }
220
221
222 // This is the top level init routine which calls all the other
223 // initialization routines.  If you are adding a subsystem to flight
224 // gear, its initialization call should located in this routine.
225 // Returns non-zero if a problem encountered.
226 bool fgInitSubsystems( void ) {
227     FGTime::cur_time_params = new FGTime();
228
229     fgLIGHT *l = &cur_light_params;
230     FGTime *t = FGTime::cur_time_params;
231
232     FG_LOG( FG_GENERAL, FG_INFO, "Initialize Subsystems");
233     FG_LOG( FG_GENERAL, FG_INFO, "========== ==========");
234
235     if ( current_options.get_flight_model() == FGInterface::FG_LARCSIM ) {
236         cur_fdm_state = new FGLaRCsim;
237     } else if ( current_options.get_flight_model() == FGInterface::FG_JSBSIM ) {
238         cur_fdm_state = new FGJSBsim;
239     } else if ( current_options.get_flight_model() == 
240                 FGInterface::FG_BALLOONSIM ) {
241         cur_fdm_state = new FGBalloonSim;
242     } else if ( current_options.get_flight_model() == 
243                 FGInterface::FG_MAGICCARPET ) {
244         cur_fdm_state = new FGMagicCarpet;
245     } else if ( current_options.get_flight_model() == 
246                 FGInterface::FG_EXTERNAL ) {
247         cur_fdm_state = new FGExternal;
248     } else {
249         FG_LOG( FG_GENERAL, FG_ALERT,
250                 "No flight model, can't init aircraft" );
251         exit(-1);
252     }
253
254     // allocates structures so must happen before any of the flight
255     // model or control parameters are set
256     fgAircraftInit();   // In the future this might not be the case.
257
258     // set the initial position
259     fgInitPosition();
260
261     // Initialize the Scenery Management subsystem
262     if ( fgSceneryInit() ) {
263         // Scenery initialized ok.
264     } else {
265         FG_LOG( FG_GENERAL, FG_ALERT, "Error in Scenery initialization!" );
266         exit(-1);
267     }
268
269     if( global_tile_mgr.init() ) {
270         // Load the local scenery data
271         global_tile_mgr.update();
272     } else {
273         FG_LOG( FG_GENERAL, FG_ALERT, "Error in Tile Manager initialization!" );
274         exit(-1);
275     }
276
277     FG_LOG( FG_GENERAL, FG_DEBUG,
278             "Current terrain elevation after tile mgr init " <<
279             scenery.cur_elev );
280
281     // Calculate ground elevation at starting point (we didn't have
282     // tmp_abs_view_pos calculated when fgTileMgrUpdate() was called above
283     //
284     // calculalate a cartesian point somewhere along the line between
285     // the center of the earth and our view position.  Doesn't have to
286     // be the exact elevation (this is good because we don't know it
287     // yet :-)
288
289     // now handled inside of the fgTileMgrUpdate()
290
291     /*
292     geod_pos = Point3D( cur_fdm_state->get_Longitude(), cur_fdm_state->get_Latitude(), 0.0);
293     tmp_abs_view_pos = fgGeodToCart(geod_pos);
294
295     FG_LOG( FG_GENERAL, FG_DEBUG,
296             "Initial abs_view_pos = " << tmp_abs_view_pos );
297     scenery.cur_elev =
298         fgTileMgrCurElev( cur_fdm_state->get_Longitude(), cur_fdm_state->get_Latitude(),
299                           tmp_abs_view_pos );
300     FG_LOG( FG_GENERAL, FG_DEBUG,
301             "Altitude after update " << scenery.cur_elev );
302     */
303
304     fgFDMSetGroundElevation( current_options.get_flight_model(),
305                              scenery.cur_elev );
306
307     // Reset our altitude if we are below ground
308     FG_LOG( FG_GENERAL, FG_DEBUG, "Current altitude = " << cur_fdm_state->get_Altitude() );
309     FG_LOG( FG_GENERAL, FG_DEBUG, "Current runway altitude = " <<
310             cur_fdm_state->get_Runway_altitude() );
311
312     if ( cur_fdm_state->get_Altitude() < cur_fdm_state->get_Runway_altitude() + 3.758099) {
313         cur_fdm_state->set_Altitude( cur_fdm_state->get_Runway_altitude() + 3.758099 );
314     }
315
316     FG_LOG( FG_GENERAL, FG_INFO,
317             "Updated position (after elevation adj): ("
318             << (cur_fdm_state->get_Latitude() * RAD_TO_DEG) << ", "
319             << (cur_fdm_state->get_Longitude() * RAD_TO_DEG) << ", "
320             << (cur_fdm_state->get_Altitude() * FEET_TO_METER) << ")" );
321
322     // We need to calculate a few more values here that would normally
323     // be calculated by the FDM so that the current_view.UpdateViewMath()
324     // routine doesn't get hosed.
325
326     double sea_level_radius_meters;
327     double lat_geoc;
328     // Set the FG variables first
329     fgGeodToGeoc( cur_fdm_state->get_Latitude(), cur_fdm_state->get_Altitude(),
330                   &sea_level_radius_meters, &lat_geoc);
331     cur_fdm_state->set_Geocentric_Position( lat_geoc, cur_fdm_state->get_Longitude(),
332                                 cur_fdm_state->get_Altitude() +
333                                 (sea_level_radius_meters * METER_TO_FEET) );
334     cur_fdm_state->set_Sea_level_radius( sea_level_radius_meters * METER_TO_FEET );
335
336     cur_fdm_state->set_sin_cos_longitude(cur_fdm_state->get_Longitude());
337     cur_fdm_state->set_sin_cos_latitude(cur_fdm_state->get_Latitude());
338         
339     cur_fdm_state->set_sin_lat_geocentric(sin(lat_geoc));
340     cur_fdm_state->set_cos_lat_geocentric(cos(lat_geoc));
341
342     // The following section sets up the flight model EOM parameters
343     // and should really be read in from one or more files.
344
345     // Initial Velocity
346     cur_fdm_state->set_Velocities_Local( current_options.get_uBody(),
347                              current_options.get_vBody(),
348                              current_options.get_wBody());
349
350     // Initial Orientation
351     cur_fdm_state->set_Euler_Angles( current_options.get_roll() * DEG_TO_RAD,
352                          current_options.get_pitch() * DEG_TO_RAD,
353                          current_options.get_heading() * DEG_TO_RAD );
354
355     // Initial Angular Body rates
356     cur_fdm_state->set_Omega_Body( 7.206685E-05, 0.0, 9.492658E-05 );
357
358     cur_fdm_state->set_Earth_position_angle( 0.0 );
359
360     // Mass properties and geometry values
361     cur_fdm_state->set_Inertias( 8.547270E+01,
362                      1.048000E+03, 3.000000E+03, 3.530000E+03, 0.000000E+00 );
363
364     // CG position w.r.t. ref. point
365     cur_fdm_state->set_CG_Position( 0.0, 0.0, 0.0 );
366
367     // Initialize the event manager
368     global_events.Init();
369
370     // Output event stats every 60 seconds
371     global_events.Register( "fgEVENT_MGR::PrintStats()",
372                             fgMethodCallback<fgEVENT_MGR>( &global_events,
373                                                    &fgEVENT_MGR::PrintStats),
374                             fgEVENT::FG_EVENT_READY, 60000 );
375
376     // Initialize the time dependent variables
377     t->init(*cur_fdm_state);
378     t->update(*cur_fdm_state);
379
380     // Initialize view parameters
381     FG_LOG( FG_GENERAL, FG_DEBUG, "Before current_view.init()");
382     current_view.Init();
383     pilot_view.Init();
384     FG_LOG( FG_GENERAL, FG_DEBUG, "After current_view.init()");
385     current_view.UpdateViewMath(*cur_fdm_state);
386     pilot_view.UpdateViewMath(*cur_fdm_state);
387     FG_LOG( FG_GENERAL, FG_DEBUG, "  abs_view_pos = " << current_view.get_abs_view_pos());
388     // current_view.UpdateWorldToEye(f);
389
390     // Build the solar system
391     //fgSolarSystemInit(*t);
392     FG_LOG(FG_GENERAL, FG_INFO, "Building SolarSystem");
393     SolarSystem::theSolarSystem = new SolarSystem(t);
394
395     // Initialize the Stars subsystem
396     if( fgStarsInit() ) {
397         // Stars initialized ok.
398     } else {
399         FG_LOG( FG_GENERAL, FG_ALERT, "Error in Stars initialization!" );
400         exit(-1);
401     }
402
403     // Initialize the planetary subsystem
404     // global_events.Register( "fgPlanetsInit()", fgPlanetsInit,
405     //                      fgEVENT::FG_EVENT_READY, 600000);
406
407     // Initialize the sun's position
408     // global_events.Register( "fgSunInit()", fgSunInit,
409     //                      fgEVENT::FG_EVENT_READY, 30000 );
410
411     // Intialize the moon's position
412     // global_events.Register( "fgMoonInit()", fgMoonInit,
413     //                      fgEVENT::FG_EVENT_READY, 600000 );
414
415     // register the periodic update of Sun, moon, and planets
416     global_events.Register( "ssolsysUpdate", solarSystemRebuild,
417                             fgEVENT::FG_EVENT_READY, 600000);
418
419     // fgUpdateSunPos() needs a few position and view parameters set
420     // so it can calculate local relative sun angle and a few other
421     // things for correctly orienting the sky.
422     fgUpdateSunPos();
423     fgUpdateMoonPos();
424     global_events.Register( "fgUpdateSunPos()", fgUpdateSunPos,
425                             fgEVENT::FG_EVENT_READY, 60000);
426     global_events.Register( "fgUpdateMoonPos()", fgUpdateMoonPos,
427                             fgEVENT::FG_EVENT_READY, 60000);
428
429     // Initialize Lighting interpolation tables
430     l->Init();
431
432     // update the lighting parameters (based on sun angle)
433     global_events.Register( "fgLight::Update()",
434                             fgMethodCallback<fgLIGHT>( &cur_light_params,
435                                                        &fgLIGHT::Update),
436                             fgEVENT::FG_EVENT_READY, 30000 );
437     // update the current timezone each 30 minutes
438     global_events.Register( "fgTIME::updateLocal()",
439                             fgMethodCallback<FGTime>(FGTime::cur_time_params, 
440                                                      &FGTime::updateLocal),
441                             fgEVENT::FG_EVENT_READY, 1800000);
442
443     // Initialize the weather modeling subsystem
444 #ifndef FG_OLD_WEATHER
445     // Initialize the WeatherDatabase
446     FG_LOG(FG_GENERAL, FG_INFO, "Creating LocalWeatherDatabase");
447     sgVec3 position;
448     sgSetVec3( position, current_aircraft.fdm_state->get_Latitude(),
449                current_aircraft.fdm_state->get_Longitude(),
450                current_aircraft.fdm_state->get_Altitude() * FEET_TO_METER );
451     FGLocalWeatherDatabase::theFGLocalWeatherDatabase = 
452         new FGLocalWeatherDatabase( position );
453     // cout << theFGLocalWeatherDatabase << endl;
454     // cout << "visibility = " 
455     //      << theFGLocalWeatherDatabase->getWeatherVisibility() << endl;
456
457     WeatherDatabase = FGLocalWeatherDatabase::theFGLocalWeatherDatabase;
458      
459     // register the periodic update of the weather
460     global_events.Register( "weather update", fgUpdateWeatherDatabase,
461                             fgEVENT::FG_EVENT_READY, 30000);
462 #else
463     current_weather.Init();
464 #endif
465
466     // Initialize the Cockpit subsystem
467     if( fgCockpitInit( &current_aircraft )) {
468         // Cockpit initialized ok.
469     } else {
470         FG_LOG( FG_GENERAL, FG_ALERT, "Error in Cockpit initialization!" );
471         exit(-1);
472     }
473
474     // Initialize the "sky"
475     fgSkyInit();
476
477     // Initialize the flight model subsystem data structures base on
478     // above values
479
480     // fgFDMInit( current_options.get_flight_model(), cur_fdm_state,
481     //            1.0 / current_options.get_model_hz() );
482     cur_fdm_state->init( 1.0 / current_options.get_model_hz() );
483
484     // I'm just sticking this here for now, it should probably move
485     // eventually
486     scenery.cur_elev = cur_fdm_state->get_Runway_altitude() * FEET_TO_METER;
487
488     if ( cur_fdm_state->get_Altitude() < cur_fdm_state->get_Runway_altitude() + 3.758099) {
489         cur_fdm_state->set_Altitude( cur_fdm_state->get_Runway_altitude() + 3.758099 );
490     }
491
492     FG_LOG( FG_GENERAL, FG_INFO,
493             "Updated position (after elevation adj): ("
494             << (cur_fdm_state->get_Latitude() * RAD_TO_DEG) << ", "
495             << (cur_fdm_state->get_Longitude() * RAD_TO_DEG) << ", "
496             << (cur_fdm_state->get_Altitude() * FEET_TO_METER) << ")" );
497     // end of thing that I just stuck in that I should probably move
498
499     // Joystick support
500     if ( fgJoystickInit() ) {
501         // Joystick initialized ok.
502     } else {
503         FG_LOG( FG_GENERAL, FG_ALERT, "Error in Joystick initialization!" );
504     }
505
506     // Autopilot init added here, by Jeff Goeke-Smith
507     fgAPInit(&current_aircraft);
508
509     // Initialize I/O channels
510 #if ! defined( MACOS )
511     fgIOInit();
512 #endif
513
514     FG_LOG( FG_GENERAL, FG_INFO, endl);
515
516     return true;
517 }
518
519
520 void fgReInitSubsystems( void )
521 {
522     FGTime *t = FGTime::cur_time_params;
523     
524     int toggle_pause = t->getPause();
525     
526     if( !toggle_pause )
527         t->togglePauseMode();
528     
529     fgInitPosition();
530     if( global_tile_mgr.init() ) {
531         // Load the local scenery data
532         global_tile_mgr.update();
533     } else {
534         FG_LOG( FG_GENERAL, FG_ALERT, "Error in Tile Manager initialization!" );
535                 exit(-1);
536     }
537     fgFDMSetGroundElevation( current_options.get_flight_model(), 
538                              scenery.cur_elev );
539
540     // Reset our altitude if we are below ground
541     FG_LOG( FG_GENERAL, FG_DEBUG, "Current altitude = " << cur_fdm_state->get_Altitude() );
542     FG_LOG( FG_GENERAL, FG_DEBUG, "Current runway altitude = " << 
543             cur_fdm_state->get_Runway_altitude() );
544
545     if ( cur_fdm_state->get_Altitude() < cur_fdm_state->get_Runway_altitude() + 3.758099) {
546         cur_fdm_state->set_Altitude( cur_fdm_state->get_Runway_altitude() + 3.758099 );
547     }
548     double sea_level_radius_meters;
549     double lat_geoc;
550     // Set the FG variables first
551     fgGeodToGeoc( cur_fdm_state->get_Latitude(), cur_fdm_state->get_Altitude(), 
552                   &sea_level_radius_meters, &lat_geoc);
553     cur_fdm_state->set_Geocentric_Position( lat_geoc, cur_fdm_state->get_Longitude(), 
554                                 cur_fdm_state->get_Altitude() + 
555                                 (sea_level_radius_meters * METER_TO_FEET) );
556     cur_fdm_state->set_Sea_level_radius( sea_level_radius_meters * METER_TO_FEET );
557         
558     cur_fdm_state->set_sin_cos_longitude(cur_fdm_state->get_Longitude());
559     cur_fdm_state->set_sin_cos_latitude(cur_fdm_state->get_Latitude());
560         
561     cur_fdm_state->set_sin_lat_geocentric(sin(lat_geoc));
562     cur_fdm_state->set_cos_lat_geocentric(cos(lat_geoc));
563
564     // The following section sets up the flight model EOM parameters
565     // and should really be read in from one or more files.
566
567     // Initial Velocity
568     cur_fdm_state->set_Velocities_Local( current_options.get_uBody(),
569                              current_options.get_vBody(),
570                              current_options.get_wBody());
571
572     // Initial Orientation
573     cur_fdm_state->set_Euler_Angles( current_options.get_roll() * DEG_TO_RAD,
574                          current_options.get_pitch() * DEG_TO_RAD,
575                          current_options.get_heading() * DEG_TO_RAD );
576
577     // Initial Angular Body rates
578     cur_fdm_state->set_Omega_Body( 7.206685E-05, 0.0, 9.492658E-05 );
579
580     cur_fdm_state->set_Earth_position_angle( 0.0 );
581
582     // Mass properties and geometry values
583     cur_fdm_state->set_Inertias( 8.547270E+01, 
584                      1.048000E+03, 3.000000E+03, 3.530000E+03, 0.000000E+00 );
585
586     // CG position w.r.t. ref. point
587     cur_fdm_state->set_CG_Position( 0.0, 0.0, 0.0 );
588
589     // Initialize view parameters
590     current_view.set_view_offset( 0.0 );
591     current_view.set_goal_view_offset( 0.0 );
592     pilot_view.set_view_offset( 0.0 );
593     pilot_view.set_goal_view_offset( 0.0 );
594
595     FG_LOG( FG_GENERAL, FG_DEBUG, "After current_view.init()");
596     current_view.UpdateViewMath(*cur_fdm_state);
597     pilot_view.UpdateViewMath(*cur_fdm_state);
598     FG_LOG( FG_GENERAL, FG_DEBUG, "  abs_view_pos = " << current_view.get_abs_view_pos());
599
600     // fgFDMInit( current_options.get_flight_model(), cur_fdm_state, 
601     //            1.0 / current_options.get_model_hz() );
602     cur_fdm_state->init( 1.0 / current_options.get_model_hz() );
603
604     scenery.cur_elev = cur_fdm_state->get_Runway_altitude() * FEET_TO_METER;
605
606     if ( cur_fdm_state->get_Altitude() < cur_fdm_state->get_Runway_altitude() + 3.758099) {
607         cur_fdm_state->set_Altitude( cur_fdm_state->get_Runway_altitude() + 3.758099 );
608     }
609
610     controls.reset_all();
611     fgAPReset();
612
613     if( !toggle_pause )
614         t->togglePauseMode();
615 }