]> git.mxchange.org Git - flightgear.git/blob - Main/fg_init.cxx
MSVC++ portability tweaks contributed by Bernie Bright.
[flightgear.git] / 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 // (Log is kept at end of this file)
25
26
27 #ifdef HAVE_CONFIG_H
28 #  include <config.h>
29 #endif
30
31 #include <GL/glut.h>
32 #include <XGL/xgl.h>
33
34 #include <stdio.h>
35 #include <stdlib.h>
36
37 // work around a stdc++ lib bug in some versions of linux, but doesn't
38 // seem to hurt to have this here for all versions of Linux.
39 #ifdef linux
40 #  define _G_NO_EXTERN_TEMPLATES
41 #endif
42
43 #include <Include/compiler.h>
44
45 #include STL_STRING
46
47 #include <Debug/logstream.hxx>
48 #include <Aircraft/aircraft.hxx>
49 #include <Airports/simple.hxx>
50 #include <Astro/sky.hxx>
51 #include <Astro/stars.hxx>
52 #include <Astro/solarsystem.hxx>
53 #include <Autopilot/autopilot.hxx>
54 #include <Cockpit/cockpit.hxx>
55 #include <Include/fg_constants.h>
56 #include <Include/general.hxx>
57 #include <Joystick/joystick.hxx>
58 #include <Math/fg_geodesy.hxx>
59 #include <Math/point3d.hxx>
60 #include <Math/polar3d.hxx>
61 #include <Scenery/scenery.hxx>
62 #include <Scenery/tilemgr.hxx>
63 #include <Time/event.hxx>
64 #include <Time/fg_time.hxx>
65 #include <Time/light.hxx>
66 #include <Time/sunpos.hxx>
67 #include <Weather/weather.hxx>
68
69 #include "fg_init.hxx"
70 #include "options.hxx"
71 #include "views.hxx"
72 #include "fg_serial.hxx"
73
74 #if defined(FX) && defined(XMESA)
75 #include <GL/xmesa.h>
76 #endif
77
78 FG_USING_STD(string);
79
80 extern const char *default_root;
81
82
83 // Set initial position and orientation
84 int fgInitPosition( void ) {
85     string id;
86     FGInterface *f;
87
88     f = current_aircraft.fdm_state;
89
90     id = current_options.get_airport_id();
91     if ( id.length() ) {
92         // set initial position from airport id
93
94         fgAIRPORTS airports;
95         fgAIRPORT a;
96
97         FG_LOG( FG_GENERAL, FG_INFO, 
98                 "Attempting to set starting position from airport code "
99                 << id );
100
101         airports.load("apt_simple");
102         if ( ! airports.search( id, &a ) ) {
103             FG_LOG( FG_GENERAL, FG_ALERT, 
104                     "Failed to find " << id << " in database." );
105             exit(-1);
106         } else {
107             f->set_Longitude( a.longitude * DEG_TO_RAD );
108             f->set_Latitude( a.latitude * DEG_TO_RAD );
109         }
110     } else {
111         // set initial position from default or command line coordinates
112
113         f->set_Longitude( current_options.get_lon() * DEG_TO_RAD );
114         f->set_Latitude( current_options.get_lat() * DEG_TO_RAD );
115     }
116     FG_LOG( FG_GENERAL, FG_INFO, 
117             "starting altitude is = " << current_options.get_altitude() );
118
119     f->set_Altitude( current_options.get_altitude() * METER_TO_FEET );
120     fgFDMSetGroundElevation( current_options.get_flight_model(),
121                              (f->get_Altitude() - 3.758099) * FEET_TO_METER );
122
123     FG_LOG( FG_GENERAL, FG_INFO,
124             "Initial position is: ("
125             << (f->get_Longitude() * RAD_TO_DEG) << ", " 
126             << (f->get_Latitude() * RAD_TO_DEG) << ", " 
127             << (f->get_Altitude() * FEET_TO_METER) << ")" );
128
129     return(1);
130 }
131
132
133 // General house keeping initializations
134 int fgInitGeneral( void ) {
135     string root;
136     char *mesa_win_state;
137
138     FG_LOG( FG_GENERAL, FG_INFO, "General Initialization" );
139     FG_LOG( FG_GENERAL, FG_INFO, "======= ==============" );
140
141     root = current_options.get_fg_root();
142     if ( ! root.length() ) {
143         // No root path set? Then bail ...
144         FG_LOG( FG_GENERAL, FG_ALERT, 
145                 "Cannot continue without environment variable FG_ROOT"
146                 << "being defined." );
147         exit(-1);
148     }
149     FG_LOG( FG_GENERAL, FG_INFO, "FG_ROOT = " << root << endl );
150
151 #if defined(FX) && defined(XMESA)
152     // initialize full screen flag
153     global_fullscreen = false;
154     if ( strstr ( general.get_glRenderer(), "Glide" ) ) {
155         // Test for the MESA_GLX_FX env variable
156         if ( (mesa_win_state = getenv( "MESA_GLX_FX" )) != NULL) {
157             // test if we are fullscreen mesa/glide
158             if ( (mesa_win_state[0] == 'f') || 
159                  (mesa_win_state[0] == 'F') ) {
160                 global_fullscreen = true;
161             }
162         }
163     }
164 #endif
165
166     return ( 1 ); 
167 }
168
169
170 // This is the top level init routine which calls all the other
171 // initialization routines.  If you are adding a subsystem to flight
172 // gear, its initialization call should located in this routine.
173 // Returns non-zero if a problem encountered.
174 int fgInitSubsystems( void )
175 {
176     FGInterface *f; // assigned later
177     fgLIGHT *l = &cur_light_params;
178     fgTIME *t = &cur_time_params;
179     FGView *v = &current_view;
180
181     FG_LOG( FG_GENERAL, FG_INFO, "Initialize Subsystems");
182     FG_LOG( FG_GENERAL, FG_INFO, "========== ==========");
183
184     // allocates structures so must happen before any of the flight
185     // model or control parameters are set
186     fgAircraftInit();   // In the future this might not be the case.
187     f = current_aircraft.fdm_state;
188
189     // set the initial position
190     fgInitPosition();
191
192     // Initialize the Scenery Management subsystem
193     if ( fgSceneryInit() ) {
194         // Scenery initialized ok.
195     } else {
196         FG_LOG( FG_GENERAL, FG_ALERT, "Error in Scenery initialization!" );
197         exit(-1);
198     }
199
200     if( fgTileMgrInit() ) {
201         // Load the local scenery data
202         fgTileMgrUpdate();
203     } else {
204         FG_LOG( FG_GENERAL, FG_ALERT, "Error in Tile Manager initialization!" );
205         exit(-1);
206     }
207
208     FG_LOG( FG_GENERAL, FG_DEBUG, 
209             "Current terrain elevation after tile mgr init " << 
210             scenery.cur_elev );
211
212     // Calculate ground elevation at starting point (we didn't have
213     // tmp_abs_view_pos calculated when fgTileMgrUpdate() was called above
214     //
215     // calculalate a cartesian point somewhere along the line between
216     // the center of the earth and our view position.  Doesn't have to
217     // be the exact elevation (this is good because we don't know it
218     // yet :-)
219
220     // now handled inside of the fgTileMgrUpdate()
221
222     /*
223     geod_pos = Point3D( f->get_Longitude(), f->get_Latitude(), 0.0);
224     tmp_abs_view_pos = fgGeodToCart(geod_pos);
225
226     FG_LOG( FG_GENERAL, FG_DEBUG, 
227             "Initial abs_view_pos = " << tmp_abs_view_pos );
228     scenery.cur_elev = 
229         fgTileMgrCurElev( f->get_Longitude(), f->get_Latitude(), 
230                           tmp_abs_view_pos );
231     FG_LOG( FG_GENERAL, FG_DEBUG, 
232             "Altitude after update " << scenery.cur_elev );
233     */
234
235     fgFDMSetGroundElevation( current_options.get_flight_model(), 
236                              scenery.cur_elev );
237
238     // Reset our altitude if we are below ground
239     FG_LOG( FG_GENERAL, FG_DEBUG, "Current altitude = " << f->get_Altitude() );
240     FG_LOG( FG_GENERAL, FG_DEBUG, "Current runway altitude = " << 
241             f->get_Runway_altitude() );
242
243     if ( f->get_Altitude() < f->get_Runway_altitude() + 3.758099) {
244         f->set_Altitude( f->get_Runway_altitude() + 3.758099 );
245     }
246
247     FG_LOG( FG_GENERAL, FG_INFO,
248             "Updated position (after elevation adj): ("
249             << (f->get_Latitude() * RAD_TO_DEG) << ", " 
250             << (f->get_Longitude() * RAD_TO_DEG) << ", " 
251             << (f->get_Altitude() * FEET_TO_METER) << ")" );
252
253     // We need to calculate a few more values here that would normally
254     // be calculated by the FDM so that the v->UpdateViewMath()
255     // routine doesn't get hosed.
256
257     double sea_level_radius_meters;
258     double lat_geoc;
259     // Set the FG variables first
260     fgGeodToGeoc( f->get_Latitude(), f->get_Altitude(), 
261                   &sea_level_radius_meters, &lat_geoc);
262     f->set_Geocentric_Position( lat_geoc, f->get_Longitude(), 
263                                 f->get_Altitude() + 
264                                 (sea_level_radius_meters * METER_TO_FEET) );
265     f->set_Sea_level_radius( sea_level_radius_meters * METER_TO_FEET );
266
267     // The following section sets up the flight model EOM parameters
268     // and should really be read in from one or more files.
269
270     // Initial Velocity
271     f->set_Velocities_Local( 0.0, 0.0, 0.0 );
272
273     // Initial Orientation
274     f->set_Euler_Angles( current_options.get_roll() * DEG_TO_RAD,
275                          current_options.get_pitch() * DEG_TO_RAD,
276                          current_options.get_heading() * DEG_TO_RAD );
277
278     // Initial Angular Body rates
279     f->set_Omega_Body( 7.206685E-05, 0.0, 9.492658E-05 );
280
281     f->set_Earth_position_angle( 0.0 );
282
283     // Mass properties and geometry values
284     f->set_Inertias( 8.547270E+01, 
285                      1.048000E+03, 3.000000E+03, 3.530000E+03, 0.000000E+00 );
286
287     // CG position w.r.t. ref. point
288     f->set_CG_Position( 0.0, 0.0, 0.0 );
289
290     // Initialize the event manager
291     global_events.Init();
292
293     // Output event stats every 60 seconds
294     global_events.Register( "fgEVENT_MGR::PrintStats()",
295                             fgMethodCallback<fgEVENT_MGR>( &global_events,
296                                                    &fgEVENT_MGR::PrintStats),
297                             fgEVENT::FG_EVENT_READY, 60000 );
298
299     // Initialize the time dependent variables
300     fgTimeInit(t);
301     fgTimeUpdate(f, t);
302
303     // Initialize view parameters
304     FG_LOG( FG_GENERAL, FG_DEBUG, "Before v->init()");
305     v->Init();
306     FG_LOG( FG_GENERAL, FG_DEBUG, "After v->init()");
307     v->UpdateViewMath(f);
308     FG_LOG( FG_GENERAL, FG_DEBUG, "  abs_view_pos = " << v->get_abs_view_pos());
309     v->UpdateWorldToEye(f);
310
311     // Build the solar system
312     //fgSolarSystemInit(*t);
313     FG_LOG(FG_GENERAL, FG_INFO, "Building SolarSystem");
314     SolarSystem::theSolarSystem = new SolarSystem(t);
315
316     // Initialize the Stars subsystem
317     if( fgStarsInit() ) {
318         // Stars initialized ok.
319     } else {
320         FG_LOG( FG_GENERAL, FG_ALERT, "Error in Stars initialization!" );
321         exit(-1);
322     }
323
324     // Initialize the planetary subsystem
325     // global_events.Register( "fgPlanetsInit()", fgPlanetsInit, 
326     //                      fgEVENT::FG_EVENT_READY, 600000);
327
328     // Initialize the sun's position 
329     // global_events.Register( "fgSunInit()", fgSunInit, 
330     //                      fgEVENT::FG_EVENT_READY, 30000 );
331
332     // Intialize the moon's position
333     // global_events.Register( "fgMoonInit()", fgMoonInit, 
334     //                      fgEVENT::FG_EVENT_READY, 600000 );
335
336     // register the periodic update of Sun, moon, and planets
337     global_events.Register( "ssolsysUpdate", solarSystemRebuild,
338                             fgEVENT::FG_EVENT_READY, 600000);
339     
340     // fgUpdateSunPos() needs a few position and view parameters set
341     // so it can calculate local relative sun angle and a few other
342     // things for correctly orienting the sky.
343     fgUpdateSunPos();
344     global_events.Register( "fgUpdateSunPos()", fgUpdateSunPos,
345                             fgEVENT::FG_EVENT_READY, 60000);
346
347     // Initialize Lighting interpolation tables
348     l->Init();
349
350     // update the lighting parameters (based on sun angle)
351     global_events.Register( "fgLight::Update()",
352                             fgMethodCallback<fgLIGHT>( &cur_light_params,
353                                                        &fgLIGHT::Update),
354                             fgEVENT::FG_EVENT_READY, 30000 );
355
356     // Initialize the weather modeling subsystem
357     current_weather.Init();
358
359     // Initialize the Cockpit subsystem
360     if( fgCockpitInit( &current_aircraft )) {
361         // Cockpit initialized ok.
362     } else {
363         FG_LOG( FG_GENERAL, FG_ALERT, "Error in Cockpit initialization!" );
364         exit(-1);
365     }
366
367     // Initialize the "sky"
368     fgSkyInit();
369
370     // Initialize the flight model subsystem data structures base on
371     // above values
372
373     fgFDMInit( current_options.get_flight_model(), cur_fdm_state, 
374                        1.0 / DEFAULT_MODEL_HZ );
375
376     // I'm just sticking this here for now, it should probably move
377     // eventually
378     scenery.cur_elev = f->get_Runway_altitude() * FEET_TO_METER;
379
380     if ( f->get_Altitude() < f->get_Runway_altitude() + 3.758099) {
381         f->set_Altitude( f->get_Runway_altitude() + 3.758099 );
382     }
383
384     FG_LOG( FG_GENERAL, FG_INFO,
385             "Updated position (after elevation adj): ("
386             << (f->get_Latitude() * RAD_TO_DEG) << ", " 
387             << (f->get_Longitude() * RAD_TO_DEG) << ", "
388             << (f->get_Altitude() * FEET_TO_METER) << ")" );
389     // end of thing that I just stuck in that I should probably move
390
391     // Joystick support
392     if ( fgJoystickInit() ) {
393         // Joystick initialized ok.
394     } else {
395         FG_LOG( FG_GENERAL, FG_ALERT, "Error in Joystick initialization!" );
396     }
397
398     // Autopilot init added here, by Jeff Goeke-Smith
399     fgAPInit(&current_aircraft);
400
401     // Initialize serial ports
402     fgSerialInit();
403
404     FG_LOG( FG_GENERAL, FG_INFO, endl);
405
406     return(1);
407 }
408
409
410 // $Log$
411 // Revision 1.70  1999/03/11 23:09:49  curt
412 // When "Help" is selected from the menu check to see if netscape is running.
413 // If so, command it to go to the flight gear user guide url.  Otherwise
414 // start a new version of netscape with this url.
415 //
416 // Revision 1.69  1999/03/08 21:56:39  curt
417 // Added panel changes sent in by Friedemann.
418 // Added a splash screen randomization since we have several nice splash screens.
419 //
420 // Revision 1.68  1999/03/02 01:03:15  curt
421 // Tweaks for building with native SGI compilers.
422 //
423 // Revision 1.67  1999/02/26 22:09:48  curt
424 // Added initial support for native SGI compilers.
425 //
426 // Revision 1.66  1999/02/05 21:29:10  curt
427 // Modifications to incorporate Jon S. Berndts flight model code.
428 //
429 // Revision 1.65  1999/02/02 20:13:36  curt
430 // MSVC++ portability changes by Bernie Bright:
431 //
432 // Lib/Serial/serial.[ch]xx: Initial Windows support - incomplete.
433 // Simulator/Astro/stars.cxx: typo? included <stdio> instead of <cstdio>
434 // Simulator/Cockpit/hud.cxx: Added Standard headers
435 // Simulator/Cockpit/panel.cxx: Redefinition of default parameter
436 // Simulator/Flight/flight.cxx: Replaced cout with FG_LOG.  Deleted <stdio.h>
437 // Simulator/Main/fg_init.cxx:
438 // Simulator/Main/GLUTmain.cxx:
439 // Simulator/Main/options.hxx: Shuffled <fg_serial.hxx> dependency
440 // Simulator/Objects/material.hxx:
441 // Simulator/Time/timestamp.hxx: VC++ friend kludge
442 // Simulator/Scenery/tile.[ch]xx: Fixed using std::X declarations
443 // Simulator/Main/views.hxx: Added a constant
444 //
445 // Revision 1.64  1999/02/01 21:15:43  curt
446 // Removed unused variables.
447 //
448 // Revision 1.63  1999/01/27 04:49:19  curt
449 // Game mode fixes from Norman Vine.
450 // Initial altitude setting tweaks and fixes (especially for when starting
451 // below sea level.)
452 //
453 // Revision 1.62  1999/01/20 13:42:25  curt
454 // Tweaked FDM interface.
455 // Testing check sum support for NMEA serial output.
456 //
457 // Revision 1.61  1999/01/08 03:23:57  curt
458 // Beginning work on compensating for sim time vs. real world time "jitter".
459 //
460 // Revision 1.60  1999/01/07 20:25:09  curt
461 // Updated struct fgGENERAL to class FGGeneral.
462 //
463 // Revision 1.59  1998/12/18 23:40:57  curt
464 // New frame rate counting mechanism.
465 //
466 // Revision 1.58  1998/12/09 18:50:25  curt
467 // Converted "class fgVIEW" to "class FGView" and updated to make data
468 // members private and make required accessor functions.
469 //
470 // Revision 1.57  1998/12/06 14:52:56  curt
471 // Fixed a problem with the initial starting altitude.  "v->abs_view_pos" wasn't
472 // being calculated correctly at the beginning causing the first terrain
473 // intersection to fail, returning a ground altitude of zero, causing the plane
474 // to free fall for one frame, until the ground altitude was corrected, but now
475 // being under the ground we got a big bounce and the plane always ended up
476 // upside down.
477 //
478 // Revision 1.56  1998/12/06 13:51:23  curt
479 // Turned "struct fgWEATHER" into "class FGWeather".
480 //
481 // Revision 1.55  1998/12/05 15:54:20  curt
482 // Renamed class fgFLIGHT to class FGState as per request by JSB.
483 //
484 // Revision 1.54  1998/12/05 14:19:53  curt
485 // Looking into a problem with cur_view_params.abs_view_pos initialization.
486 //
487 // Revision 1.53  1998/12/03 04:25:05  curt
488 // Working on fixing up new fgFLIGHT class.
489 //
490 // Revision 1.52  1998/12/03 01:17:17  curt
491 // Converted fgFLIGHT to a class.
492 //
493 // Revision 1.51  1998/11/20 01:02:37  curt
494 // Try to detect Mesa/Glide/Voodoo and chose the appropriate resolution.
495 //
496 // Revision 1.50  1998/11/16 14:00:01  curt
497 // Added pow() macro bug work around.
498 // Added support for starting FGFS at various resolutions.
499 // Added some initial serial port support.
500 // Specify default log levels in main().
501 //
502 // Revision 1.49  1998/11/11 00:24:02  curt
503 // Added Michael Johnson's audio patches for testing.
504 // Also did a few tweaks to avoid numerical problems when starting at a place
505 // with no (or bogus) scenery.
506 //
507 // Revision 1.48  1998/11/07 19:07:10  curt
508 // Enable release builds using the --without-logging option to the configure
509 // script.  Also a couple log message cleanups, plus some C to C++ comment
510 // conversion.
511 //
512 // Revision 1.47  1998/11/06 21:18:10  curt
513 // Converted to new logstream debugging facility.  This allows release
514 // builds with no messages at all (and no performance impact) by using
515 // the -DFG_NDEBUG flag.
516 //
517 // Revision 1.46  1998/10/27 02:14:38  curt
518 // Changes to support GLUT joystick routines as fall back.
519 //
520 // Revision 1.45  1998/10/25 10:57:21  curt
521 // Changes to use the new joystick library if it is available.
522 //
523 // Revision 1.44  1998/10/18 01:17:17  curt
524 // Point3D tweaks.
525 //
526 // Revision 1.43  1998/10/17 01:34:22  curt
527 // C++ ifying ...
528 //
529 // Revision 1.42  1998/10/16 23:27:54  curt
530 // C++-ifying.
531 //
532 // Revision 1.41  1998/10/16 00:54:01  curt
533 // Converted to Point3D class.
534 //
535 // Revision 1.40  1998/10/02 12:46:49  curt
536 // Added an "auto throttle"
537 //
538 // Revision 1.39  1998/09/29 02:03:39  curt
539 // Autopilot mods.
540 //
541 // Revision 1.38  1998/09/15 04:27:30  curt
542 // Changes for new Astro code.
543 //
544 // Revision 1.37  1998/09/15 02:09:26  curt
545 // Include/fg_callback.hxx
546 //   Moved code inline to stop g++ 2.7 from complaining.
547 //
548 // Simulator/Time/event.[ch]xx
549 //   Changed return type of fgEVENT::printStat().  void caused g++ 2.7 to
550 //   complain bitterly.
551 //
552 // Minor bugfix and changes.
553 //
554 // Simulator/Main/GLUTmain.cxx
555 //   Added missing type to idle_state definition - eliminates a warning.
556 //
557 // Simulator/Main/fg_init.cxx
558 //   Changes to airport lookup.
559 //
560 // Simulator/Main/options.cxx
561 //   Uses fg_gzifstream when loading config file.
562 //
563 // Revision 1.36  1998/09/08 21:40:08  curt
564 // Fixes by Charlie Hotchkiss.
565 //
566 // Revision 1.35  1998/08/29 13:09:26  curt
567 // Changes to event manager from Bernie Bright.
568 //
569 // Revision 1.34  1998/08/27 17:02:06  curt
570 // Contributions from Bernie Bright <bbright@c031.aone.net.au>
571 // - use strings for fg_root and airport_id and added methods to return
572 //   them as strings,
573 // - inlined all access methods,
574 // - made the parsing functions private methods,
575 // - deleted some unused functions.
576 // - propogated some of these changes out a bit further.
577 //
578 // Revision 1.33  1998/08/25 20:53:32  curt
579 // Shuffled $FG_ROOT file layout.
580 //
581 // Revision 1.32  1998/08/25 16:59:09  curt
582 // Directory reshuffling.
583 //
584 // Revision 1.31  1998/08/22  14:49:57  curt
585 // Attempting to iron out seg faults and crashes.
586 // Did some shuffling to fix a initialization order problem between view
587 // position, scenery elevation.
588 //
589 // Revision 1.30  1998/08/20 20:32:33  curt
590 // Reshuffled some of the code in and around views.[ch]xx
591 //
592 // Revision 1.29  1998/07/30 23:48:27  curt
593 // Output position & orientation when pausing.
594 // Eliminated libtool use.
595 // Added options to specify initial position and orientation.
596 // Changed default fov to 55 degrees.
597 // Added command line option to start in paused or unpaused state.
598 //
599 // Revision 1.28  1998/07/27 18:41:25  curt
600 // Added a pause command "p"
601 // Fixed some initialization order problems between pui and glut.
602 // Added an --enable/disable-sound option.
603 //
604 // Revision 1.27  1998/07/24 21:39:10  curt
605 // Debugging output tweaks.
606 // Cast glGetString to (char *) to avoid compiler errors.
607 // Optimizations to fgGluLookAt() by Norman Vine.
608 //
609 // Revision 1.26  1998/07/22 21:40:44  curt
610 // Clear to adjusted fog color (for sunrise/sunset effects)
611 // Make call to fog sunrise/sunset adjustment method.
612 // Add a stdc++ library bug work around to fg_init.cxx
613 //
614 // Revision 1.25  1998/07/13 21:01:38  curt
615 // Wrote access functions for current fgOPTIONS.
616 //
617 // Revision 1.24  1998/07/13 15:32:39  curt
618 // Clear color buffer if drawing wireframe.
619 // When specifying and airport, start elevation at -1000 and let the system
620 // position you at ground level.
621 //
622 // Revision 1.23  1998/07/12 03:14:43  curt
623 // Added ground collision detection.
624 // Did some serious horsing around to be able to "hug" the ground properly
625 //   and still be able to take off.
626 // Set the near clip plane to 1.0 meters when less than 10 meters above the
627 //   ground.
628 // Did some serious horsing around getting the initial airplane position to be
629 //   correct based on rendered terrain elevation.
630 // Added a little cheat/hack that will prevent the view position from ever
631 //   dropping below the terrain, even when the flight model doesn't quite
632 //   put you as high as you'd like.
633 //
634 // Revision 1.22  1998/07/04 00:52:25  curt
635 // Add my own version of gluLookAt() (which is nearly identical to the
636 // Mesa/glu version.)  But, by calculating the Model View matrix our selves
637 // we can save this matrix without having to read it back in from the video
638 // card.  This hopefully allows us to save a few cpu cycles when rendering
639 // out the fragments because we can just use glLoadMatrixd() with the
640 // precalculated matrix for each tile rather than doing a push(), translate(),
641 // pop() for every fragment.
642 //
643 // Panel status defaults to off for now until it gets a bit more developed.
644 //
645 // Extract OpenGL driver info on initialization.
646 //
647 // Revision 1.21  1998/06/27 16:54:33  curt
648 // Replaced "extern displayInstruments" with a entry in fgOPTIONS.
649 // Don't change the view port when displaying the panel.
650 //
651 // Revision 1.20  1998/06/17 21:35:12  curt
652 // Refined conditional audio support compilation.
653 // Moved texture parameter setup calls to ../Scenery/materials.cxx
654 // #include <string.h> before various STL includes.
655 // Make HUD default state be enabled.
656 //
657 // Revision 1.19  1998/06/08 17:57:05  curt
658 // Minor sound/startup position tweaks.
659 //
660 // Revision 1.18  1998/06/03 00:47:14  curt
661 // Updated to compile in audio support if OSS available.
662 // Updated for new version of Steve's audio library.
663 // STL includes don't use .h
664 // Small view optimizations.
665 //
666 // Revision 1.17  1998/06/01 17:54:42  curt
667 // Added Linux audio support.
668 // avoid glClear( COLOR_BUFFER_BIT ) when not using it to set the sky color.
669 // map stl tweaks.
670 //
671 // Revision 1.16  1998/05/29 20:37:24  curt
672 // Tweaked material properties & lighting a bit in GLUTmain.cxx.
673 // Read airport list into a "map" STL for dynamic list sizing and fast tree
674 // based lookups.
675 //
676 // Revision 1.15  1998/05/22 21:28:53  curt
677 // Modifications to use the new fgEVENT_MGR class.
678 //
679 // Revision 1.14  1998/05/20 20:51:35  curt
680 // Tweaked smooth shaded texture lighting properties.
681 // Converted fgLIGHT to a C++ class.
682 //
683 // Revision 1.13  1998/05/16 13:08:35  curt
684 // C++ - ified views.[ch]xx
685 // Shuffled some additional view parameters into the fgVIEW class.
686 // Changed tile-radius to tile-diameter because it is a much better
687 //   name.
688 // Added a WORLD_TO_EYE transformation to views.cxx.  This allows us
689 //  to transform world space to eye space for view frustum culling.
690 //
691 // Revision 1.12  1998/05/13 18:29:58  curt
692 // Added a keyboard binding to dynamically adjust field of view.
693 // Added a command line option to specify fov.
694 // Adjusted terrain color.
695 // Root path info moved to fgOPTIONS.
696 // Added ability to parse options out of a config file.
697 //
698 // Revision 1.11  1998/05/07 23:14:15  curt
699 // Added "D" key binding to set autopilot heading.
700 // Made frame rate calculation average out over last 10 frames.
701 // Borland C++ floating point exception workaround.
702 // Added a --tile-radius=n option.
703 //
704 // Revision 1.10  1998/05/06 03:16:24  curt
705 // Added an averaged global frame rate counter.
706 // Added an option to control tile radius.
707 //
708 // Revision 1.9  1998/05/03 00:47:31  curt
709 // Added an option to enable/disable full-screen mode.
710 //
711 // Revision 1.8  1998/04/30 12:34:18  curt
712 // Added command line rendering options:
713 //   enable/disable fog/haze
714 //   specify smooth/flat shading
715 //   disable sky blending and just use a solid color
716 //   enable wireframe drawing mode
717 //
718 // Revision 1.7  1998/04/28 01:20:22  curt
719 // Type-ified fgTIME and fgVIEW.
720 // Added a command line option to disable textures.
721 //
722 // Revision 1.6  1998/04/26 05:10:03  curt
723 // "struct fgLIGHT" -> "fgLIGHT" because fgLIGHT is typedef'd.
724 //
725 // Revision 1.5  1998/04/25 22:06:30  curt
726 // Edited cvs log messages in source files ... bad bad bad!
727 //
728 // Revision 1.4  1998/04/25 20:24:01  curt
729 // Cleaned up initialization sequence to eliminate interdependencies
730 // between sun position, lighting, and view position.  This creates a
731 // valid single pass initialization path.
732 //
733 // Revision 1.3  1998/04/25 15:11:11  curt
734 // Added an command line option to set starting position based on airport ID.
735 //
736 // Revision 1.2  1998/04/24 00:49:20  curt
737 // Wrapped "#include <config.h>" in "#ifdef HAVE_CONFIG_H"
738 // Trying out some different option parsing code.
739 // Some code reorganization.
740 //
741 // Revision 1.1  1998/04/22 13:25:44  curt
742 // C++ - ifing the code.
743 // Starting a bit of reorganization of lighting code.
744 //
745 // Revision 1.56  1998/04/18 04:11:28  curt
746 // Moved fg_debug to it's own library, added zlib support.
747 //
748 // Revision 1.55  1998/04/14 02:21:03  curt
749 // Incorporated autopilot heading hold contributed by:  Jeff Goeke-Smith
750 // <jgoeke@voyager.net>
751 //
752 // Revision 1.54  1998/04/08 23:35:36  curt
753 // Tweaks to Gnu automake/autoconf system.
754 //
755 // Revision 1.53  1998/04/03 22:09:06  curt
756 // Converting to Gnu autoconf system.
757 //
758 // Revision 1.52  1998/03/23 21:24:38  curt
759 // Source code formating tweaks.
760 //
761 // Revision 1.51  1998/03/14 00:31:22  curt
762 // Beginning initial terrain texturing experiments.
763 //
764 // Revision 1.50  1998/03/09 22:46:19  curt
765 // Minor tweaks.
766 //
767 // Revision 1.49  1998/02/23 19:07:59  curt
768 // Incorporated Durk's Astro/ tweaks.  Includes unifying the sun position
769 // calculation code between sun display, and other FG sections that use this
770 // for things like lighting.
771 //
772 // Revision 1.48  1998/02/21 14:53:15  curt
773 // Added Charlie's HUD changes.
774 //
775 // Revision 1.47  1998/02/19 13:05:53  curt
776 // Incorporated some HUD tweaks from Michelle America.
777 // Tweaked the sky's sunset/rise colors.
778 // Other misc. tweaks.
779 //
780 // Revision 1.46  1998/02/18 15:07:06  curt
781 // Tweaks to build with SGI OpenGL (and therefor hopefully other accelerated
782 // drivers will work.)
783 //
784 // Revision 1.45  1998/02/16 13:39:43  curt
785 // Miscellaneous weekend tweaks.  Fixed? a cache problem that caused whole
786 // tiles to occasionally be missing.
787 //
788 // Revision 1.44  1998/02/12 21:59:50  curt
789 // Incorporated code changes contributed by Charlie Hotchkiss
790 // <chotchkiss@namg.us.anritsu.com>
791 //
792 // Revision 1.43  1998/02/11 02:50:40  curt
793 // Minor changes.
794 //
795 // Revision 1.42  1998/02/09 22:56:58  curt
796 // Removed "depend" files from cvs control.  Other minor make tweaks.
797 //
798 // Revision 1.41  1998/02/09 15:07:50  curt
799 // Minor tweaks.
800 //
801 // Revision 1.40  1998/02/07 15:29:44  curt
802 // Incorporated HUD changes and struct/typedef changes from Charlie Hotchkiss
803 // <chotchkiss@namg.us.anritsu.com>
804 //
805 // Revision 1.39  1998/02/03 23:20:25  curt
806 // Lots of little tweaks to fix various consistency problems discovered by
807 // Solaris' CC.  Fixed a bug in fg_debug.c with how the fgPrintf() wrapper
808 // passed arguments along to the real printf().  Also incorporated HUD changes
809 // by Michele America.
810 //
811 // Revision 1.38  1998/02/02 20:53:58  curt
812 // Incorporated Durk's changes.
813 //
814 // Revision 1.37  1998/02/01 03:39:54  curt
815 // Minor tweaks.
816 //
817 // Revision 1.36  1998/01/31 00:43:13  curt
818 // Added MetroWorks patches from Carmen Volpe.
819 //
820 // Revision 1.35  1998/01/27 00:47:57  curt
821 // Incorporated Paul Bleisch's <pbleisch@acm.org> new debug message
822 // system and commandline/config file processing code.
823 //
824 // Revision 1.34  1998/01/22 02:59:37  curt
825 // Changed #ifdef FILE_H to #ifdef _FILE_H
826 //
827 // Revision 1.33  1998/01/21 21:11:34  curt
828 // Misc. tweaks.
829 //
830 // Revision 1.32  1998/01/19 19:27:08  curt
831 // Merged in make system changes from Bob Kuehne <rpk@sgi.com>
832 // This should simplify things tremendously.
833 //
834 // Revision 1.31  1998/01/19 18:40:32  curt
835 // Tons of little changes to clean up the code and to remove fatal errors
836 // when building with the c++ compiler.
837 //
838 // Revision 1.30  1998/01/13 00:23:09  curt
839 // Initial changes to support loading and management of scenery tiles.  Note,
840 // there's still a fair amount of work left to be done.
841 //
842 // Revision 1.29  1998/01/08 02:22:08  curt
843 // Beginning to integrate Tile management subsystem.
844 //
845 // Revision 1.28  1998/01/07 03:18:58  curt
846 // Moved astronomical stuff from .../Src/Scenery to .../Src/Astro/
847 //
848 // Revision 1.27  1998/01/05 18:44:35  curt
849 // Add an option to advance/decrease time from keyboard.
850 //
851 // Revision 1.26  1997/12/30 23:09:04  curt
852 // Tweaking initialization sequences.
853 //
854 // Revision 1.25  1997/12/30 22:22:33  curt
855 // Further integration of event manager.
856 //
857 // Revision 1.24  1997/12/30 20:47:44  curt
858 // Integrated new event manager with subsystem initializations.
859 //
860 // Revision 1.23  1997/12/30 16:36:50  curt
861 // Merged in Durk's changes ...
862 //
863 // Revision 1.22  1997/12/19 23:34:05  curt
864 // Lot's of tweaking with sky rendering and lighting.
865 //
866 // Revision 1.21  1997/12/19 16:45:00  curt
867 // Working on scene rendering order and options.
868 //
869 // Revision 1.20  1997/12/18 23:32:33  curt
870 // First stab at sky dome actually starting to look reasonable. :-)
871 //
872 // Revision 1.19  1997/12/17 23:13:36  curt
873 // Began working on rendering a sky.
874 //
875 // Revision 1.18  1997/12/15 23:54:49  curt
876 // Add xgl wrappers for debugging.
877 // Generate terrain normals on the fly.
878 //
879 // Revision 1.17  1997/12/15 20:59:09  curt
880 // Misc. tweaks.
881 //
882 // Revision 1.16  1997/12/12 19:52:48  curt
883 // Working on lightling and material properties.
884 //
885 // Revision 1.15  1997/12/11 04:43:55  curt
886 // Fixed sun vector and lighting problems.  I thing the moon is now lit
887 // correctly.
888 //
889 // Revision 1.14  1997/12/10 22:37:47  curt
890 // Prepended "fg" on the name of all global structures that didn't have it yet.
891 // i.e. "struct WEATHER {}" became "struct fgWEATHER {}"
892 //
893 // Revision 1.13  1997/11/25 19:25:32  curt
894 // Changes to integrate Durk's moon/sun code updates + clean up.
895 //
896 // Revision 1.12  1997/11/15 18:16:35  curt
897 // minor tweaks.
898 //
899 // Revision 1.11  1997/10/30 12:38:42  curt
900 // Working on new scenery subsystem.
901 //
902 // Revision 1.10  1997/10/25 03:24:23  curt
903 // Incorporated sun, moon, and star positioning code contributed by Durk Talsma.
904 //
905 // Revision 1.9  1997/09/23 00:29:39  curt
906 // Tweaks to get things to compile with gcc-win32.
907 //
908 // Revision 1.8  1997/09/22 14:44:20  curt
909 // Continuing to try to align stars correctly.
910 //
911 // Revision 1.7  1997/09/16 15:50:30  curt
912 // Working on star alignment and time issues.
913 //
914 // Revision 1.6  1997/09/05 14:17:30  curt
915 // More tweaking with stars.
916 //
917 // Revision 1.5  1997/09/04 02:17:36  curt
918 // Shufflin' stuff.
919 //
920 // Revision 1.4  1997/08/27 21:32:26  curt
921 // Restructured view calculation code.  Added stars.
922 //
923 // Revision 1.3  1997/08/27 03:30:19  curt
924 // Changed naming scheme of basic shared structures.
925 //
926 // Revision 1.2  1997/08/25 20:27:23  curt
927 // Merged in initial HUD and Joystick code.
928 //
929 // Revision 1.1  1997/08/23 01:46:20  curt
930 // Initial revision.
931 //
932