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