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