]> git.mxchange.org Git - flightgear.git/blob - Main/GLUTmain.cxx
"H" / "h" now control hud brightness as well with off being one of the
[flightgear.git] / Main / GLUTmain.cxx
1
2 //
3 // GLUTmain.cxx -- top level sim routines
4 //
5 // Written by Curtis Olson for OpenGL, started May 1997.
6 //
7 // Copyright (C) 1997  Curtis L. Olson  - curt@infoplane.com
8 //
9 // This program is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU General Public License as
11 // published by the Free Software Foundation; either version 2 of the
12 // License, or (at your option) any later version.
13 //
14 // This program is distributed in the hope that it will be useful, but
15 // WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 // General Public License for more details.
18 //
19 // You should have received a copy of the GNU General Public License
20 // along with this program; if not, write to the Free Software
21 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
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 #ifdef HAVE_WINDOWS_H
32 #  include <windows.h>                     
33 #  include <float.h>                    
34 #endif
35
36 #include <GL/glut.h>
37 #include <XGL/xgl.h>
38 #include <stdio.h>
39 #include <string.h>
40
41 #ifdef HAVE_STDLIB_H
42 #   include <stdlib.h>
43 #endif
44
45 #include <sys/stat.h> /* for stat() */
46
47 #ifdef HAVE_UNISTD_H
48 #  include <unistd.h>    /* for fork() && stat() */
49 #  include <sys/types.h> /* for wait() */
50 #  include <sys/wait.h>  /* for wait() */
51 #endif
52
53 #include <Include/fg_constants.h>  // for VERSION
54 #include <Include/general.h>
55
56 #include <Aircraft/aircraft.h>
57 #include <Astro/moon.hxx>
58 #include <Astro/planets.hxx>
59 #include <Astro/sky.hxx>
60 #include <Astro/stars.hxx>
61 #include <Astro/sun.hxx>
62
63 #ifdef ENABLE_AUDIO_SUPPORT
64 #  include <Audio/src/sl.h>
65 #  include <Audio/src/sm.h>
66 #endif
67
68 #include <Cockpit/cockpit.hxx>
69 #include <Debug/fg_debug.h>
70 #include <GUI/gui.h>
71 #include <Joystick/joystick.h>
72 #include <Math/fg_geodesy.h>
73 #include <Math/mat3.h>
74 #include <Math/polar3d.hxx>
75 #include <PUI/pu.h>
76 #include <Scenery/scenery.hxx>
77 #include <Scenery/tilemgr.hxx>
78 #include <Time/event.hxx>
79 #include <Time/fg_time.hxx>
80 #include <Time/fg_timer.hxx>
81 #include <Time/sunpos.hxx>
82 #include <Weather/weather.h>
83
84 #include "GLUTkey.hxx"
85 #include "fg_init.hxx"
86 #include "options.hxx"
87 #include "splash.hxx"
88 #include "views.hxx"
89
90
91 // This is a record containing global housekeeping information
92 fgGENERAL general;
93
94 // Specify our current idle function state.  This is used to run all
95 // our initializations out of the glutIdleLoop() so that we can get a
96 // splash screen up and running right away.
97 static idle_state = 0;
98
99 // Another hack
100 int use_signals = 0;
101
102 // Global structures for the Audio library
103 #ifdef ENABLE_AUDIO_SUPPORT
104 slScheduler *audio_sched;
105 smMixer *audio_mixer;
106 slSample *s1;
107 slSample *s2;
108 #endif
109
110
111 // The following defines flight gear options. Because glutlib will also
112 // want to parse its own options, those options must not be included here
113 // or they will get parsed by the main program option parser. Hence case
114 // is significant for any option added that might be in conflict with
115 // glutlib's parser.
116 //
117 // glutlib parses for:
118 //    -display
119 //    -direct   (invalid in Win32)
120 //    -geometry
121 //    -gldebug
122 //    -iconized
123 //    -indirect (invalid in Win32)
124 //    -synce
125 //
126 // Note that glutlib depends upon strings while this program's
127 // option parser wants only initial characters followed by numbers
128 // or pathnames.
129 //
130
131
132 // fgInitVisuals() -- Initialize various GL/view parameters
133 static void fgInitVisuals( void ) {
134     fgLIGHT *l;
135     struct fgWEATHER *w;
136
137     l = &cur_light_params;
138     w = &current_weather;
139
140     // Go full screen if requested ...
141     if ( current_options.get_fullscreen() ) {
142         glutFullScreen();
143     }
144
145     // If enabled, normal vectors specified with glNormal are scaled
146     // to unit length after transformation.  See glNormal.
147     xglEnable( GL_NORMALIZE );
148
149     xglEnable( GL_LIGHTING );
150     xglEnable( GL_LIGHT0 );
151     xglLightfv( GL_LIGHT0, GL_POSITION, l->sun_vec );
152
153     // xglFogi (GL_FOG_MODE, GL_LINEAR);
154     xglFogi (GL_FOG_MODE, GL_EXP2);
155     // Fog density is now set when the weather system is initialized
156     // xglFogf (GL_FOG_DENSITY, w->fog_density);
157     if ( (current_options.get_fog() == 1) || 
158          (current_options.get_shading() == 0) ) {
159         // if fastest fog requested, or if flat shading force fastest
160         xglHint ( GL_FOG_HINT, GL_FASTEST );
161     } else if ( current_options.get_fog() == 2 ) {
162         xglHint ( GL_FOG_HINT, GL_NICEST );
163     }
164     if ( current_options.get_wireframe() ) {
165         // draw wire frame
166         xglPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
167     }
168
169     // This is the default anyways, but it can't hurt
170     xglFrontFace ( GL_CCW );
171 }
172
173
174 // Update the view volume, position, and orientation
175 static void fgUpdateViewParams( void ) {
176     fgFLIGHT *f;
177     fgLIGHT *l;
178     fgVIEW *v;
179
180     f = current_aircraft.flight;
181     l = &cur_light_params;
182     v = &current_view;
183
184     v->Update(f);
185     v->UpdateWorldToEye(f);
186
187     // if (!o->panel_status) {
188     // xglViewport( 0, (GLint)((v->winHeight) / 2 ) , 
189     // (GLint)(v->winWidth), (GLint)(v->winHeight) / 2 );
190     // Tell GL we are about to modify the projection parameters
191     // xglMatrixMode(GL_PROJECTION);
192     // xglLoadIdentity();
193     // gluPerspective(o->fov, v->win_ratio / 2.0, 1.0, 100000.0);
194     // } else {
195     xglViewport(0, 0 , (GLint)(v->winWidth), (GLint)(v->winHeight) );
196     // Tell GL we are about to modify the projection parameters
197     xglMatrixMode(GL_PROJECTION);
198     xglLoadIdentity();
199     if ( FG_Altitude * FEET_TO_METER - scenery.cur_elev > 10.0 ) {
200         gluPerspective(current_options.get_fov(), v->win_ratio, 10.0, 100000.0);
201     } else {
202         gluPerspective(current_options.get_fov(), v->win_ratio, 1.0, 100000.0);
203         // printf("Near ground, minimizing near clip plane\n");
204     }
205     // }
206
207     xglMatrixMode(GL_MODELVIEW);
208     xglLoadIdentity();
209     
210     // set up our view volume (default)
211     fg_gluLookAt(v->view_pos.x, v->view_pos.y, v->view_pos.z,
212                v->view_pos.x + v->view_forward[0], 
213                v->view_pos.y + v->view_forward[1], 
214                v->view_pos.z + v->view_forward[2],
215                v->view_up[0], v->view_up[1], v->view_up[2]);
216
217     // look almost straight up (testing and eclipse watching)
218     /* fg_gluLookAt(v->view_pos.x, v->view_pos.y, v->view_pos.z,
219                v->view_pos.x + v->view_up[0] + .001, 
220                v->view_pos.y + v->view_up[1] + .001, 
221                v->view_pos.z + v->view_up[2] + .001,
222                v->view_up[0], v->view_up[1], v->view_up[2]); */
223
224     // lock view horizontally towards sun (testing)
225     /* fg_gluLookAt(v->view_pos.x, v->view_pos.y, v->view_pos.z,
226                v->view_pos.x + v->surface_to_sun[0], 
227                v->view_pos.y + v->surface_to_sun[1], 
228                v->view_pos.z + v->surface_to_sun[2],
229                v->view_up[0], v->view_up[1], v->view_up[2]); */
230
231     // lock view horizontally towards south (testing)
232     /* fg_gluLookAt(v->view_pos.x, v->view_pos.y, v->view_pos.z,
233                v->view_pos.x + v->surface_south[0], 
234                v->view_pos.y + v->surface_south[1], 
235                v->view_pos.z + v->surface_south[2],
236                v->view_up[0], v->view_up[1], v->view_up[2]); */
237
238     // set the sun position
239     xglLightfv( GL_LIGHT0, GL_POSITION, l->sun_vec );
240 }
241
242
243 #ifdef 0
244 // Draw a basic instrument panel
245 static void fgUpdateInstrViewParams( void ) {
246
247     exit(0);
248
249     fgVIEW *v;
250
251     v = &current_view;
252
253     xglViewport(0, 0 , (GLint)(v->winWidth), (GLint)(v->winHeight) / 2);
254   
255     xglMatrixMode(GL_PROJECTION);
256     xglPushMatrix();
257   
258     xglLoadIdentity();
259     gluOrtho2D(0, 640, 0, 480);
260     xglMatrixMode(GL_MODELVIEW);
261     xglPushMatrix();
262     xglLoadIdentity();
263
264     xglColor3f(1.0, 1.0, 1.0);
265     xglIndexi(7);
266   
267     xglDisable(GL_DEPTH_TEST);
268     xglDisable(GL_LIGHTING);
269   
270     xglLineWidth(1);
271     xglColor3f (0.5, 0.5, 0.5);
272
273     xglBegin(GL_QUADS);
274     xglVertex2f(0.0, 0.00);
275     xglVertex2f(0.0, 480.0);
276     xglVertex2f(640.0,480.0);
277     xglVertex2f(640.0, 0.0);
278     xglEnd();
279
280     xglRectf(0.0,0.0, 640, 480);
281     xglEnable(GL_DEPTH_TEST);
282     xglEnable(GL_LIGHTING);
283     xglMatrixMode(GL_PROJECTION);
284     xglPopMatrix();
285     xglMatrixMode(GL_MODELVIEW);
286     xglPopMatrix();
287 }
288 #endif
289
290
291 // Update all Visuals (redraws anything graphics related)
292 static void fgRenderFrame( void ) {
293     fgFLIGHT *f;
294     fgLIGHT *l;
295     fgTIME *t;
296     fgVIEW *v;
297     double angle;
298     GLfloat black[4] = { 0.0, 0.0, 0.0, 1.0 };
299     GLfloat white[4] = { 1.0, 1.0, 1.0, 1.0 };
300     GLfloat terrain_color[4] = { 0.54, 0.44, 0.29, 1.0 };
301     GLbitfield clear_mask;
302
303     f = current_aircraft.flight;
304     l = &cur_light_params;
305     t = &cur_time_params;
306     v = &current_view;
307
308     if ( idle_state != 1000 ) {
309         // still initializing, draw the splash screen
310         if ( current_options.get_splash_screen() == 1 ) {
311             fgSplashUpdate(0.0);
312         }
313     } else {
314         // idle_state is now 1000 meaning we've finished all our
315         // initializations and are running the main loop, so this will
316         // now work without seg faulting the system.
317
318         // printf("Ground = %.2f  Altitude = %.2f\n", scenery.cur_elev, 
319         //        FG_Altitude * FEET_TO_METER);
320     
321         // this is just a temporary hack, to make me understand Pui
322         timerText -> setLabel (ctime (&t->cur_time));
323         // end of hack
324
325         // update view volume parameters
326         fgUpdateViewParams();
327
328         clear_mask = GL_DEPTH_BUFFER_BIT;
329         if ( current_options.get_wireframe() ) {
330             clear_mask |= GL_COLOR_BUFFER_BIT;
331         }
332         if ( current_options.get_skyblend() ) {
333             glClearColor(black[0], black[1], black[2], black[3]);
334         } else {
335             glClearColor(l->sky_color[0], l->sky_color[1], 
336                          l->sky_color[2], l->sky_color[3]);
337             clear_mask |= GL_COLOR_BUFFER_BIT;
338         }
339         xglClear( clear_mask );
340
341         // Tell GL we are switching to model view parameters
342         xglMatrixMode(GL_MODELVIEW);
343         // xglLoadIdentity();
344
345         // draw sky
346         xglDisable( GL_DEPTH_TEST );
347         xglDisable( GL_LIGHTING );
348         xglDisable( GL_CULL_FACE );
349         xglDisable( GL_FOG );
350         xglShadeModel( GL_SMOOTH );
351         if ( current_options.get_skyblend() ) {
352             fgSkyRender();
353         }
354
355         // setup transformation for drawing astronomical objects
356         xglPushMatrix();
357         // Translate to view position
358         xglTranslatef( v->view_pos.x, v->view_pos.y, v->view_pos.z );
359         // Rotate based on gst (sidereal time)
360         // note: constant should be 15.041085, Curt thought it was 15
361         angle = t->gst * 15.041085;
362         // printf("Rotating astro objects by %.2f degrees\n",angle);
363         xglRotatef( angle, 0.0, 0.0, -1.0 );
364
365         // draw stars and planets
366         fgStarsRender();
367         fgPlanetsRender();
368
369         // draw the sun
370         fgSunRender();
371
372         // render the moon
373         xglEnable( GL_LIGHTING );
374         // set lighting parameters
375         xglLightfv(GL_LIGHT0, GL_AMBIENT, white );
376         xglLightfv(GL_LIGHT0, GL_DIFFUSE, white );
377         xglEnable( GL_CULL_FACE );
378     
379         // Let's try some blending technique's (Durk)
380         glEnable(GL_BLEND);
381         glBlendFunc(GL_ONE, GL_ONE);
382         fgMoonRender();
383         glDisable(GL_BLEND);
384
385         xglPopMatrix();
386
387         // draw scenery
388         if ( current_options.get_shading() ) {
389             xglShadeModel( GL_SMOOTH ); 
390         } else {
391             xglShadeModel( GL_FLAT ); 
392         }
393         xglEnable( GL_DEPTH_TEST );
394         if ( current_options.get_fog() > 0 ) {
395             xglEnable( GL_FOG );
396             xglFogfv (GL_FOG_COLOR, l->fog_color);
397         }
398         // set lighting parameters
399         xglLightfv(GL_LIGHT0, GL_AMBIENT, l->scene_ambient );
400         xglLightfv(GL_LIGHT0, GL_DIFFUSE, l->scene_diffuse );
401         
402         if ( current_options.get_textures() ) {
403             // texture parameters
404             xglEnable( GL_TEXTURE_2D );
405             xglTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ) ;
406             xglHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST ) ;
407             // set base color (I don't think this is doing anything here)
408             xglMaterialfv (GL_FRONT, GL_AMBIENT, white);
409             xglMaterialfv (GL_FRONT, GL_DIFFUSE, white);
410         } else {
411             xglDisable( GL_TEXTURE_2D );
412             xglMaterialfv (GL_FRONT, GL_AMBIENT, terrain_color);
413             xglMaterialfv (GL_FRONT, GL_DIFFUSE, terrain_color);
414             // xglMaterialfv (GL_FRONT, GL_AMBIENT, white);
415             // xglMaterialfv (GL_FRONT, GL_DIFFUSE, white);
416         }
417
418         fgTileMgrRender();
419
420         xglDisable( GL_TEXTURE_2D );
421
422         // display HUD && Panel
423         fgCockpitUpdate();
424         
425         // display instruments
426         // if (!o->panel_status) {
427         // fgUpdateInstrViewParams();
428         // }
429
430         // We can do translucent menus, so why not. :-)
431         xglEnable    ( GL_BLEND ) ;
432         xglBlendFunc ( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ) ;
433         puDisplay();
434         xglDisable   ( GL_BLEND ) ;
435     }
436
437     xglutSwapBuffers();
438 }
439
440
441 // Update internal time dependent calculations (i.e. flight model)
442 void fgUpdateTimeDepCalcs(int multi_loop) {
443     fgFLIGHT *f;
444     fgTIME *t;
445     fgVIEW *v;
446     int i;
447
448     f = current_aircraft.flight;
449     t = &cur_time_params;
450     v = &current_view;
451
452     // update the flight model
453     if ( multi_loop < 0 ) {
454         multi_loop = DEFAULT_MULTILOOP;
455     }
456
457     // printf("updating flight model x %d\n", multi_loop);
458     fgFlightModelUpdate(FG_LARCSIM, f, multi_loop);
459
460     // update the view angle
461     for ( i = 0; i < multi_loop; i++ ) {
462         if ( fabs(v->goal_view_offset - v->view_offset) < 0.05 ) {
463             v->view_offset = v->goal_view_offset;
464             break;
465         } else {
466             // move v->view_offset towards v->goal_view_offset
467             if ( v->goal_view_offset > v->view_offset ) {
468                 if ( v->goal_view_offset - v->view_offset < FG_PI ) {
469                     v->view_offset += 0.01;
470                 } else {
471                     v->view_offset -= 0.01;
472                 }
473             } else {
474                 if ( v->view_offset - v->goal_view_offset < FG_PI ) {
475                     v->view_offset -= 0.01;
476                 } else {
477                     v->view_offset += 0.01;
478                 }
479             }
480             if ( v->view_offset > FG_2PI ) {
481                 v->view_offset -= FG_2PI;
482             } else if ( v->view_offset < 0 ) {
483                 v->view_offset += FG_2PI;
484             }
485         }
486     }
487 }
488
489
490 void fgInitTimeDepCalcs( void ) {
491     // initialize timer
492
493 #ifdef HAVE_SETITIMER
494     fgTimerInit( 1.0 / DEFAULT_TIMER_HZ, fgUpdateTimeDepCalcs );
495 #endif HAVE_SETITIMER
496
497 }
498
499
500 // What should we do when we have nothing else to do?  Let's get ready
501 // for the next move and update the display?
502 static void fgMainLoop( void ) {
503     fgFLIGHT *f;
504     fgGENERAL *g;
505     fgTIME *t;
506     static int remainder = 0;
507     int elapsed, multi_loop;
508     int i;
509     double accum;
510     // double joy_x, joy_y;
511     // int joy_b1, joy_b2;
512
513     f = current_aircraft.flight;
514     g = &general;
515     t = &cur_time_params;
516
517     fgPrintf( FG_ALL, FG_DEBUG, "Running Main Loop\n");
518     fgPrintf( FG_ALL, FG_DEBUG, "======= ==== ====\n");
519
520     // Fix elevation.  I'm just sticking this here for now, it should
521     // probably move eventually
522
523     /* printf("Before - ground = %.2f  runway = %.2f  alt = %.2f\n",
524            scenery.cur_elev,
525            FG_Runway_altitude * FEET_TO_METER,
526            FG_Altitude * FEET_TO_METER); */
527
528     if ( scenery.cur_elev > -9990 ) {
529         if ( FG_Altitude * FEET_TO_METER < 
530              (scenery.cur_elev + 3.758099 * FEET_TO_METER - 3.0) ) {
531             // now set aircraft altitude above ground
532             printf("Current Altitude = %.2f < %.2f forcing to %.2f\n", 
533                    FG_Altitude * FEET_TO_METER,
534                    scenery.cur_elev + 3.758099 * FEET_TO_METER - 3.0,
535                    scenery.cur_elev + 3.758099 * FEET_TO_METER);
536             fgFlightModelSetAltitude( FG_LARCSIM, f, 
537                                       scenery.cur_elev + 
538                                       3.758099 * FEET_TO_METER);
539
540             fgPrintf( FG_ALL, FG_BULK, 
541                       "<*> resetting altitude to %.0f meters\n", 
542                       FG_Altitude * FEET_TO_METER);
543         }
544         FG_Runway_altitude = scenery.cur_elev * METER_TO_FEET;
545     }
546
547     /* printf("Adjustment - ground = %.2f  runway = %.2f  alt = %.2f\n",
548            scenery.cur_elev,
549            FG_Runway_altitude * FEET_TO_METER,
550            FG_Altitude * FEET_TO_METER); */
551
552     // update "time"
553     fgTimeUpdate(f, t);
554
555     // Read joystick
556     /* fgJoystickRead( &joy_x, &joy_y, &joy_b1, &joy_b2 );
557     printf( "Joystick X %f  Y %f  B1 %d  B2 %d\n",  
558             joy_x, joy_y, joy_b1, joy_b2 );
559     fgElevSet( -joy_y );
560     fgAileronSet( joy_x ); */
561
562     // Get elapsed time for this past frame
563     elapsed = fgGetTimeInterval();
564     fgPrintf( FG_ALL, FG_BULK, 
565               "Time interval is = %d, previous remainder is = %d\n", 
566               elapsed, remainder);
567
568     // Calculate frame rate average
569     if ( elapsed > 0.0 ) {
570         accum = 0.0;
571         for ( i = FG_FRAME_RATE_HISTORY - 2; i >= 0; i-- ) {
572             accum += g->frames[i];
573             // printf("frame[%d] = %.2f\n", i, g->frames[i]);
574             g->frames[i+1] = g->frames[i];
575         }
576         g->frames[0] = 1000.0 / (float)elapsed;
577         // printf("frame[0] = %.2f\n", g->frames[0]);
578         accum += g->frames[0];
579         g->frame_rate = accum / (float)FG_FRAME_RATE_HISTORY;
580         // printf("ave = %.2f\n", g->frame_rate);
581     }
582
583     // Calculate model iterations needed for next frame
584     fgPrintf( FG_ALL, FG_DEBUG, 
585               "--> Frame rate is = %.2f\n", g->frame_rate);
586     elapsed += remainder;
587
588     multi_loop = (int)(((float)elapsed * 0.001) * DEFAULT_MODEL_HZ);
589     remainder = elapsed - ((multi_loop*1000) / DEFAULT_MODEL_HZ);
590     fgPrintf( FG_ALL, FG_BULK, 
591               "Model iterations needed = %d, new remainder = %d\n", 
592               multi_loop, remainder);
593         
594     /* printf("right before fm - ground = %.2f  runway = %.2f  alt = %.2f\n",
595            scenery.cur_elev,
596            FG_Runway_altitude * FEET_TO_METER,
597            FG_Altitude * FEET_TO_METER); */
598
599     // Run flight model
600     if ( ! use_signals ) {
601         // flight model
602         fgUpdateTimeDepCalcs(multi_loop);
603     }
604
605     /* printf("After fm - ground = %.2f  runway = %.2f  alt = %.2f\n",
606            scenery.cur_elev,
607            FG_Runway_altitude * FEET_TO_METER,
608            FG_Altitude * FEET_TO_METER); */
609
610     // fgAircraftOutputCurrent(a);
611
612     // see if we need to load any new scenery tiles
613     fgTileMgrUpdate();
614
615     // Process/manage pending events
616     global_events.Process();
617
618     // Run audio scheduler
619 #ifdef ENABLE_AUDIO_SUPPORT
620     audio_sched -> update();
621 #endif
622
623     // redraw display
624     fgRenderFrame();
625
626     fgPrintf( FG_ALL, FG_DEBUG, "\n");
627 }
628
629
630 // This is the top level master main function that is registered as
631 // our idle funciton
632 //
633
634 // The first few passes take care of initialization things (a couple
635 // per pass) and once everything has been initialized fgMainLoop from
636 // then on.
637
638 static void fgIdleFunction ( void ) {
639     fgGENERAL *g;
640     char path[256], mp3file[256], command[256], slfile[256];
641     // static char *lockfile = "/tmp/mpg123.running";
642
643     g = &general;
644
645     // printf("idle state == %d\n", idle_state);
646
647     if ( idle_state == 0 ) {
648         // Initialize the splash screen right away
649         if ( current_options.get_splash_screen() ) {
650             fgSplashInit();
651         }
652         
653         idle_state++;
654     } else if ( idle_state == 1 ) {
655         // Start the intro music
656 #if !defined(WIN32)
657         if ( current_options.get_intro_music() ) {
658             current_options.get_fg_root(mp3file);
659             strcat(mp3file, "/Sounds/");
660             strcat(mp3file, "intro.mp3");
661             /* 
662             sprintf(command, 
663                     "(touch %s; mpg123 %s > /dev/null 2>&1; /bin/rm %s) &", 
664                     lockfile, mp3file, lockfile );
665                     */
666             sprintf(command, "mpg123 %s > /dev/null 2>&1", mp3file);
667             fgPrintf( FG_GENERAL, FG_INFO, 
668                       "Starting intro music: %s\n", mp3file);
669
670             int pid = fork () ;
671
672             if ( pid == 0 ) {
673                 system ( command );
674                 exit ( 0 ) ;
675             }
676         }
677 #endif
678
679         idle_state++;
680     } else if ( idle_state == 2 ) {
681         // These are a few miscellaneous things that aren't really
682         // "subsystems" but still need to be initialized.
683         if( !fgInitGeneral()) {
684             fgPrintf( FG_GENERAL, FG_EXIT, 
685                       "General initializations failed ...\n" );
686         }
687 #ifdef USE_GLIDE
688         if ( strstr ( g->glRenderer, "Glide" ) ) {
689             grTexLodBiasValue ( GR_TMU0, 1.0 ) ;
690         }
691 #endif
692
693         idle_state++;
694     } else if ( idle_state == 3 ) {
695         // This is the top level init routine which calls all the
696         // other subsystem initialization routines.  If you are adding
697         // a subsystem to flight gear, its initialization call should
698         // located in this routine.
699         if( !fgInitSubsystems()) {
700             fgPrintf( FG_GENERAL, FG_EXIT,
701                       "Subsystem initializations failed ...\n" );
702         }
703
704         idle_state++;
705     } else if ( idle_state == 4 ) {
706         // setup OpenGL view parameters
707         fgInitVisuals();
708
709         if ( use_signals ) {
710             // init timer routines, signals, etc.  Arrange for an alarm
711             // signal to be generated, etc.
712             fgInitTimeDepCalcs();
713         }
714
715         idle_state++;
716     } else if ( idle_state == 5 ) {
717         //Init the user interface
718         guiInit();
719
720         idle_state++;
721     } else if ( idle_state == 6 ) {
722         // Initialize audio support
723 #ifdef ENABLE_AUDIO_SUPPORT
724
725 #if !defined(WIN32)
726         if ( current_options.get_intro_music() ) {
727             // Let's wait for mpg123 to finish
728             // struct stat stat_buf;
729
730             fgPrintf( FG_GENERAL, FG_INFO, 
731                       "Waiting for mpg123 player to finish ...\n" );
732             /*
733             while ( stat(lockfile, &stat_buf) == 0 ) {
734                 // file exist, wait ...
735                 sleep(1);
736                 fgPrintf( FG_GENERAL, FG_INFO, ".");
737             }
738             fgPrintf( FG_GENERAL, FG_INFO, "\n");
739             */
740
741             wait(0);
742         }
743 #endif // WIN32
744
745         audio_sched = new slScheduler ( 8000 );
746         audio_mixer = new smMixer;
747         audio_mixer -> setMasterVolume ( 30 ) ;  /* 50% of max volume. */
748         audio_sched -> setSafetyMargin ( 1.0 ) ;
749         current_options.get_fg_root(path);
750         strcat(path, "/Sounds/");
751         strcpy(slfile, path);
752         strcat(slfile, "wasp.wav");
753
754         s1 = new slSample ( slfile );
755         // s1 = new slSample ( "/dos/X-System-HSR/sounds/xp_recip.wav", 
756         //                     audio_sched );
757         printf("Rate = %d  Bps = %d  Stereo = %d\n", 
758                s1 -> getRate(), s1 -> getBps(), s1 -> getStereo());
759         audio_sched -> loopSample ( s1 );
760         
761         // strcpy(slfile, path);
762         // strcat(slfile, "thunder.wav");
763         // s2 -> loadFile ( slfile );
764         // s2 -> adjustVolume(0.5);
765         // audio_sched -> playSample ( s2 );
766 #endif
767
768         sleep(1);
769         idle_state = 1000;
770     } 
771
772     if ( idle_state == 1000 ) {
773         // We've finished all our initialization steps, from now on we
774         // run the main loop.
775
776         fgMainLoop();
777     } else {
778         if ( current_options.get_splash_screen() == 1 ) {
779             fgSplashUpdate(0.0);
780         }
781     }
782 }
783
784
785 // Handle new window size or exposure
786 static void fgReshape( int width, int height ) {
787     fgVIEW *v;
788
789     v = &current_view;
790
791     // Do this so we can call fgReshape(0,0) ourselves without having
792     // to know what the values of width & height are.
793     if ( (height > 0) && (width > 0) ) {
794         v->win_ratio = (GLfloat) width / (GLfloat) height;
795     }
796
797     v->winWidth = width;
798     v->winHeight = height;
799
800     // Inform gl of our view window size (now handled elsewhere)
801     // xglViewport(0, 0, (GLint)width, (GLint)height);
802     if ( idle_state == 1000 ) {
803         // yes we've finished all our initializations and are running
804         // the main loop, so this will now work without seg faulting
805         // the system.
806         fgUpdateViewParams();
807     }
808     
809     // xglClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
810 }
811
812
813 // Initialize GLUT and define a main window
814 int fgGlutInit( int *argc, char **argv ) {
815     // GLUT will extract all glut specific options so later on we only
816     // need wory about our own.
817     xglutInit(argc, argv);
818
819     // Define Display Parameters
820     xglutInitDisplayMode( GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE );
821
822     // Define initial window size
823     xglutInitWindowSize(640, 480);
824
825     // Initialize windows
826     xglutCreateWindow("Flight Gear");
827
828     return(1);
829 }
830
831
832 // Initialize GLUT event handlers
833 int fgGlutInitEvents( void ) {
834     // call fgReshape() on window resizes
835     xglutReshapeFunc( fgReshape );
836
837     // call GLUTkey() on keyboard event
838     xglutKeyboardFunc( GLUTkey );
839     glutSpecialFunc( GLUTspecialkey );
840
841     // call guiMouseFunc() whenever our little rodent is used
842     glutMouseFunc ( guiMouseFunc );
843     glutMotionFunc (guiMotionFunc );
844     glutPassiveMotionFunc (guiMotionFunc );
845
846     // call fgMainLoop() whenever there is
847     // nothing else to do
848     xglutIdleFunc( fgIdleFunction );
849
850     // draw the scene
851     xglutDisplayFunc( fgRenderFrame );
852
853     return(1);
854 }
855
856
857 // Main ...
858 int main( int argc, char **argv ) {
859     fgFLIGHT *f;
860     char config[256];
861     int result;  // Used in command line argument.
862
863     f = current_aircraft.flight;
864
865 #ifdef HAVE_BC5PLUS
866     _control87(MCW_EM, MCW_EM);  /* defined in float.h */
867 #endif
868
869     // Initialize the debugging output system
870     fgInitDebug();
871
872     fgPrintf(FG_GENERAL, FG_INFO, "Flight Gear:  Version %s\n\n", VERSION);
873
874     // Initialize the Window/Graphics environment.
875     if( !fgGlutInit(&argc, argv) ) {
876         fgPrintf( FG_GENERAL, FG_EXIT, "GLUT initialization failed ...\n" );
877     }
878
879     // Initialize the various GLUT Event Handlers.
880     if( !fgGlutInitEvents() ) {
881         fgPrintf( FG_GENERAL, FG_EXIT, 
882                   "GLUT event handler initialization failed ...\n" );
883     }
884
885     // Attempt to locate and parse a config file
886     // First check fg_root
887     current_options.get_fg_root(config);
888     strcat(config, "/system.fgfsrc");
889     result = current_options.parse_config_file(config);
890
891     // Next check home directory
892     if ( getenv("HOME") != NULL ) {
893         strcpy(config, getenv("HOME"));
894         strcat(config, "/.fgfsrc");
895         result = current_options.parse_config_file(config);
896     }
897
898     // Parse remaining command line options
899     // These will override anything specified in a config file
900     result = current_options.parse_command_line(argc, argv);
901     if ( result != FG_OPTIONS_OK ) {
902         // Something must have gone horribly wrong with the command
903         // line parsing or maybe the user just requested help ... :-)
904         current_options.usage();
905         fgPrintf( FG_GENERAL, FG_EXIT, "\nExiting ...\n");
906     }
907
908     // pass control off to the master GLUT event handler
909     glutMainLoop();
910
911     // we never actually get here ... but just in case ... :-)
912     return(0);
913 }
914
915
916 // $Log$
917 // Revision 1.36  1998/07/16 17:33:35  curt
918 // "H" / "h" now control hud brightness as well with off being one of the
919 //   states.
920 // Better checking for xmesa/fx 3dfx fullscreen/window support for deciding
921 //   whether or not to build in the feature.
922 // Translucent menu support.
923 // HAVE_AUDIO_SUPPORT -> ENABLE_AUDIO_SUPPORT
924 // Use fork() / wait() for playing mp3 init music in background under unix.
925 // Changed default tile diameter to 5.
926 //
927 // Revision 1.35  1998/07/13 21:01:36  curt
928 // Wrote access functions for current fgOPTIONS.
929 //
930 // Revision 1.34  1998/07/13 15:32:37  curt
931 // Clear color buffer if drawing wireframe.
932 // When specifying and airport, start elevation at -1000 and let the system
933 // position you at ground level.
934 //
935 // Revision 1.33  1998/07/12 03:14:42  curt
936 // Added ground collision detection.
937 // Did some serious horsing around to be able to "hug" the ground properly
938 //   and still be able to take off.
939 // Set the near clip plane to 1.0 meters when less than 10 meters above the
940 //   ground.
941 // Did some serious horsing around getting the initial airplane position to be
942 //   correct based on rendered terrain elevation.
943 // Added a little cheat/hack that will prevent the view position from ever
944 //   dropping below the terrain, even when the flight model doesn't quite
945 //   put you as high as you'd like.
946 //
947 // Revision 1.32  1998/07/08 14:45:07  curt
948 // polar3d.h renamed to polar3d.hxx
949 // vector.h renamed to vector.hxx
950 // updated audio support so it waits to create audio classes (and tie up
951 //   /dev/dsp) until the mpg123 player is finished.
952 //
953 // Revision 1.31  1998/07/06 21:34:17  curt
954 // Added an enable/disable splash screen option.
955 // Added an enable/disable intro music option.
956 // Added an enable/disable instrument panel option.
957 // Added an enable/disable mouse pointer option.
958 // Added using namespace std for compilers that support this.
959 //
960 // Revision 1.30  1998/07/06 02:42:03  curt
961 // Added support for switching between fullscreen and window mode for
962 // Mesa/3dfx/glide.
963 //
964 // Added a basic splash screen.  Restructured the main loop and top level
965 // initialization routines to do this.
966 //
967 // Hacked in some support for playing a startup mp3 sound file while rest
968 // of sim initializes.  Currently only works in Unix using the mpg123 player.
969 // Waits for the mpg123 player to finish before initializing internal
970 // sound drivers.
971 //
972 // Revision 1.29  1998/07/04 00:52:22  curt
973 // Add my own version of gluLookAt() (which is nearly identical to the
974 // Mesa/glu version.)  But, by calculating the Model View matrix our selves
975 // we can save this matrix without having to read it back in from the video
976 // card.  This hopefully allows us to save a few cpu cycles when rendering
977 // out the fragments because we can just use glLoadMatrixd() with the
978 // precalculated matrix for each tile rather than doing a push(), translate(),
979 // pop() for every fragment.
980 //
981 // Panel status defaults to off for now until it gets a bit more developed.
982 //
983 // Extract OpenGL driver info on initialization.
984 //
985 // Revision 1.28  1998/06/27 16:54:32  curt
986 // Replaced "extern displayInstruments" with a entry in fgOPTIONS.
987 // Don't change the view port when displaying the panel.
988 //
989 // Revision 1.27  1998/06/17 21:35:10  curt
990 // Refined conditional audio support compilation.
991 // Moved texture parameter setup calls to ../Scenery/materials.cxx
992 // #include <string.h> before various STL includes.
993 // Make HUD default state be enabled.
994 //
995 // Revision 1.26  1998/06/13 00:40:32  curt
996 // Tweaked fog command line options.
997 //
998 // Revision 1.25  1998/06/12 14:27:26  curt
999 // Pui -> PUI, Gui -> GUI.
1000 //
1001 // Revision 1.24  1998/06/12 00:57:39  curt
1002 // Added support for Pui/Gui.
1003 // Converted fog to GL_FOG_EXP2.
1004 // Link to static simulator parts.
1005 // Update runfg.bat to try to be a little smarter.
1006 //
1007 // Revision 1.23  1998/06/08 17:57:04  curt
1008 // Minor sound/startup position tweaks.
1009 //
1010 // Revision 1.22  1998/06/05 18:18:40  curt
1011 // A bit of fiddling with audio ...
1012 //
1013 // Revision 1.21  1998/06/03 22:01:06  curt
1014 // Tweaking sound library usage.
1015 //
1016 // Revision 1.20  1998/06/03 00:47:11  curt
1017 // Updated to compile in audio support if OSS available.
1018 // Updated for new version of Steve's audio library.
1019 // STL includes don't use .h
1020 // Small view optimizations.
1021 //
1022 // Revision 1.19  1998/06/01 17:54:40  curt
1023 // Added Linux audio support.
1024 // avoid glClear( COLOR_BUFFER_BIT ) when not using it to set the sky color.
1025 // map stl tweaks.
1026 //
1027 // Revision 1.18  1998/05/29 20:37:19  curt
1028 // Tweaked material properties & lighting a bit in GLUTmain.cxx.
1029 // Read airport list into a "map" STL for dynamic list sizing and fast tree
1030 // based lookups.
1031 //
1032 // Revision 1.17  1998/05/22 21:28:52  curt
1033 // Modifications to use the new fgEVENT_MGR class.
1034 //
1035 // Revision 1.16  1998/05/20 20:51:33  curt
1036 // Tweaked smooth shaded texture lighting properties.
1037 // Converted fgLIGHT to a C++ class.
1038 //
1039 // Revision 1.15  1998/05/16 13:08:34  curt
1040 // C++ - ified views.[ch]xx
1041 // Shuffled some additional view parameters into the fgVIEW class.
1042 // Changed tile-radius to tile-diameter because it is a much better
1043 //   name.
1044 // Added a WORLD_TO_EYE transformation to views.cxx.  This allows us
1045 //  to transform world space to eye space for view frustum culling.
1046 //
1047 // Revision 1.14  1998/05/13 18:29:57  curt
1048 // Added a keyboard binding to dynamically adjust field of view.
1049 // Added a command line option to specify fov.
1050 // Adjusted terrain color.
1051 // Root path info moved to fgOPTIONS.
1052 // Added ability to parse options out of a config file.
1053 //
1054 // Revision 1.13  1998/05/11 18:18:15  curt
1055 // For flat shading use "glHint (GL_FOG_HINT, GL_FASTEST )"
1056 //
1057 // Revision 1.12  1998/05/07 23:14:15  curt
1058 // Added "D" key binding to set autopilot heading.
1059 // Made frame rate calculation average out over last 10 frames.
1060 // Borland C++ floating point exception workaround.
1061 // Added a --tile-radius=n option.
1062 //
1063 // Revision 1.11  1998/05/06 03:16:23  curt
1064 // Added an averaged global frame rate counter.
1065 // Added an option to control tile radius.
1066 //
1067 // Revision 1.10  1998/05/03 00:47:31  curt
1068 // Added an option to enable/disable full-screen mode.
1069 //
1070 // Revision 1.9  1998/04/30 12:34:17  curt
1071 // Added command line rendering options:
1072 //   enable/disable fog/haze
1073 //   specify smooth/flat shading
1074 //   disable sky blending and just use a solid color
1075 //   enable wireframe drawing mode
1076 //
1077 // Revision 1.8  1998/04/28 01:20:21  curt
1078 // Type-ified fgTIME and fgVIEW.
1079 // Added a command line option to disable textures.
1080 //
1081 // Revision 1.7  1998/04/26 05:10:02  curt
1082 // "struct fgLIGHT" -> "fgLIGHT" because fgLIGHT is typedef'd.
1083 //
1084 // Revision 1.6  1998/04/25 22:06:30  curt
1085 // Edited cvs log messages in source files ... bad bad bad!
1086 //
1087 // Revision 1.5  1998/04/25 20:24:01  curt
1088 // Cleaned up initialization sequence to eliminate interdependencies
1089 // between sun position, lighting, and view position.  This creates a
1090 // valid single pass initialization path.
1091 //
1092 // Revision 1.4  1998/04/24 14:19:30  curt
1093 // Fog tweaks.
1094 //
1095 // Revision 1.3  1998/04/24 00:49:18  curt
1096 // Wrapped "#include <config.h>" in "#ifdef HAVE_CONFIG_H"
1097 // Trying out some different option parsing code.
1098 // Some code reorganization.
1099 //
1100 // Revision 1.2  1998/04/22 13:25:41  curt
1101 // C++ - ifing the code.
1102 // Starting a bit of reorganization of lighting code.
1103 //
1104 // Revision 1.1  1998/04/21 17:02:39  curt
1105 // Prepairing for C++ integration.
1106 //
1107 // Revision 1.71  1998/04/18 04:11:26  curt
1108 // Moved fg_debug to it's own library, added zlib support.
1109 //
1110 // Revision 1.70  1998/04/14 02:21:02  curt
1111 // Incorporated autopilot heading hold contributed by:  Jeff Goeke-Smith
1112 // <jgoeke@voyager.net>
1113 //
1114 // Revision 1.69  1998/04/08 23:35:34  curt
1115 // Tweaks to Gnu automake/autoconf system.
1116 //
1117 // Revision 1.68  1998/04/03 22:09:03  curt
1118 // Converting to Gnu autoconf system.
1119 //
1120 // Revision 1.67  1998/03/23 21:24:37  curt
1121 // Source code formating tweaks.
1122 //
1123 // Revision 1.66  1998/03/14 00:31:20  curt
1124 // Beginning initial terrain texturing experiments.
1125 //
1126 // Revision 1.65  1998/03/09 22:45:57  curt
1127 // Minor tweaks for building on sparc platform.
1128 //
1129 // Revision 1.64  1998/02/20 00:16:23  curt
1130 // Thursday's tweaks.
1131 //
1132 // Revision 1.63  1998/02/16 16:17:39  curt
1133 // Minor tweaks.
1134 //
1135 // Revision 1.62  1998/02/16 13:39:42  curt
1136 // Miscellaneous weekend tweaks.  Fixed? a cache problem that caused whole
1137 // tiles to occasionally be missing.
1138 //
1139 // Revision 1.61  1998/02/12 21:59:46  curt
1140 // Incorporated code changes contributed by Charlie Hotchkiss
1141 // <chotchkiss@namg.us.anritsu.com>
1142 //
1143 // Revision 1.60  1998/02/11 02:50:40  curt
1144 // Minor changes.
1145 //
1146 // Revision 1.59  1998/02/09 22:56:54  curt
1147 // Removed "depend" files from cvs control.  Other minor make tweaks.
1148 //
1149 // Revision 1.58  1998/02/09 15:07:49  curt
1150 // Minor tweaks.
1151 //
1152 // Revision 1.57  1998/02/07 15:29:40  curt
1153 // Incorporated HUD changes and struct/typedef changes from Charlie Hotchkiss
1154 // <chotchkiss@namg.us.anritsu.com>
1155 //
1156 // Revision 1.56  1998/02/03 23:20:23  curt
1157 // Lots of little tweaks to fix various consistency problems discovered by
1158 // Solaris' CC.  Fixed a bug in fg_debug.c with how the fgPrintf() wrapper
1159 // passed arguments along to the real printf().  Also incorporated HUD changes
1160 // by Michele America.
1161 //
1162 // Revision 1.55  1998/02/02 20:53:58  curt
1163 // Incorporated Durk's changes.
1164 //
1165 // Revision 1.54  1998/01/31 00:43:10  curt
1166 // Added MetroWorks patches from Carmen Volpe.
1167 //
1168 // Revision 1.53  1998/01/27 18:35:54  curt
1169 // Minor tweaks.
1170 //
1171 // Revision 1.52  1998/01/27 00:47:56  curt
1172 // Incorporated Paul Bleisch's <pbleisch@acm.org> new debug message
1173 // system and commandline/config file processing code.
1174 //
1175 // Revision 1.51  1998/01/26 15:57:05  curt
1176 // Tweaks for dynamic scenery development.
1177 //
1178 // Revision 1.50  1998/01/19 19:27:07  curt
1179 // Merged in make system changes from Bob Kuehne <rpk@sgi.com>
1180 // This should simplify things tremendously.
1181 //
1182 // Revision 1.49  1998/01/19 18:40:31  curt
1183 // Tons of little changes to clean up the code and to remove fatal errors
1184 // when building with the c++ compiler.
1185 //
1186 // Revision 1.48  1998/01/19 18:35:46  curt
1187 // Minor tweaks and fixes for cygwin32.
1188 //
1189 // Revision 1.47  1998/01/13 00:23:08  curt
1190 // Initial changes to support loading and management of scenery tiles.  Note,
1191 // there's still a fair amount of work left to be done.
1192 //
1193 // Revision 1.46  1998/01/08 02:22:06  curt
1194 // Beginning to integrate Tile management subsystem.
1195 //
1196 // Revision 1.45  1998/01/07 03:18:55  curt
1197 // Moved astronomical stuff from .../Src/Scenery to .../Src/Astro/
1198 //
1199 // Revision 1.44  1997/12/30 22:22:31  curt
1200 // Further integration of event manager.
1201 //
1202 // Revision 1.43  1997/12/30 20:47:43  curt
1203 // Integrated new event manager with subsystem initializations.
1204 //
1205 // Revision 1.42  1997/12/30 16:36:47  curt
1206 // Merged in Durk's changes ...
1207 //
1208 // Revision 1.41  1997/12/30 13:06:56  curt
1209 // A couple lighting tweaks ...
1210 //
1211 // Revision 1.40  1997/12/30 01:38:37  curt
1212 // Switched back to per vertex normals and smooth shading for terrain.
1213 //
1214 // Revision 1.39  1997/12/22 23:45:45  curt
1215 // First stab at sunset/sunrise sky glow effects.
1216 //
1217 // Revision 1.38  1997/12/22 04:14:28  curt
1218 // Aligned sky with sun so dusk/dawn effects can be correct relative to the sun.
1219 //
1220 // Revision 1.37  1997/12/19 23:34:03  curt
1221 // Lot's of tweaking with sky rendering and lighting.
1222 //
1223 // Revision 1.36  1997/12/19 16:44:57  curt
1224 // Working on scene rendering order and options.
1225 //
1226 // Revision 1.35  1997/12/18 23:32:32  curt
1227 // First stab at sky dome actually starting to look reasonable. :-)
1228 //
1229 // Revision 1.34  1997/12/17 23:13:34  curt
1230 // Began working on rendering a sky.
1231 //
1232 // Revision 1.33  1997/12/15 23:54:45  curt
1233 // Add xgl wrappers for debugging.
1234 // Generate terrain normals on the fly.
1235 //
1236 // Revision 1.32  1997/12/15 20:59:08  curt
1237 // Misc. tweaks.
1238 //
1239 // Revision 1.31  1997/12/12 21:41:25  curt
1240 // More light/material property tweaking ... still a ways off.
1241 //
1242 // Revision 1.30  1997/12/12 19:52:47  curt
1243 // Working on lightling and material properties.
1244 //
1245 // Revision 1.29  1997/12/11 04:43:54  curt
1246 // Fixed sun vector and lighting problems.  I thing the moon is now lit
1247 // correctly.
1248 //
1249 // Revision 1.28  1997/12/10 22:37:45  curt
1250 // Prepended "fg" on the name of all global structures that didn't have it yet.
1251 // i.e. "struct WEATHER {}" became "struct fgWEATHER {}"
1252 //
1253 // Revision 1.27  1997/12/09 05:11:54  curt
1254 // Working on tweaking lighting.
1255 //
1256 // Revision 1.26  1997/12/09 04:25:29  curt
1257 // Working on adding a global lighting params structure.
1258 //
1259 // Revision 1.25  1997/12/08 22:54:09  curt
1260 // Enabled GL_CULL_FACE.
1261 //
1262 // Revision 1.24  1997/11/25 19:25:32  curt
1263 // Changes to integrate Durk's moon/sun code updates + clean up.
1264 //
1265 // Revision 1.23  1997/11/15 18:16:34  curt
1266 // minor tweaks.
1267 //
1268 // Revision 1.22  1997/10/30 12:38:41  curt
1269 // Working on new scenery subsystem.
1270 //
1271 // Revision 1.21  1997/09/23 00:29:38  curt
1272 // Tweaks to get things to compile with gcc-win32.
1273 //
1274 // Revision 1.20  1997/09/22 14:44:19  curt
1275 // Continuing to try to align stars correctly.
1276 //
1277 // Revision 1.19  1997/09/18 16:20:08  curt
1278 // At dusk/dawn add/remove stars in stages.
1279 //
1280 // Revision 1.18  1997/09/16 22:14:51  curt
1281 // Tweaked time of day lighting equations.  Don't draw stars during the day.
1282 //
1283 // Revision 1.17  1997/09/16 15:50:29  curt
1284 // Working on star alignment and time issues.
1285 //
1286 // Revision 1.16  1997/09/13 02:00:06  curt
1287 // Mostly working on stars and generating sidereal time for accurate star
1288 // placement.
1289 //
1290 // Revision 1.15  1997/09/05 14:17:27  curt
1291 // More tweaking with stars.
1292 //
1293 // Revision 1.14  1997/09/05 01:35:53  curt
1294 // Working on getting stars right.
1295 //
1296 // Revision 1.13  1997/09/04 02:17:34  curt
1297 // Shufflin' stuff.
1298 //
1299 // Revision 1.12  1997/08/27 21:32:24  curt
1300 // Restructured view calculation code.  Added stars.
1301 //
1302 // Revision 1.11  1997/08/27 03:30:16  curt
1303 // Changed naming scheme of basic shared structures.
1304 //
1305 // Revision 1.10  1997/08/25 20:27:22  curt
1306 // Merged in initial HUD and Joystick code.
1307 //
1308 // Revision 1.9  1997/08/22 21:34:39  curt
1309 // Doing a bit of reorganizing and house cleaning.
1310 //
1311 // Revision 1.8  1997/08/19 23:55:03  curt
1312 // Worked on better simulating real lighting.
1313 //
1314 // Revision 1.7  1997/08/16 12:22:38  curt
1315 // Working on improving the lighting/shading.
1316 //
1317 // Revision 1.6  1997/08/13 20:24:56  curt
1318 // Changes due to changing sunpos interface.
1319 //
1320 // Revision 1.5  1997/08/06 21:08:32  curt
1321 // Sun position now really* works (I think) ... I still have sun time warping
1322 // code in place, probably should remove it soon.
1323 //
1324 // Revision 1.4  1997/08/06 15:41:26  curt
1325 // Working on correct sun position.
1326 //
1327 // Revision 1.3  1997/08/06 00:24:22  curt
1328 // Working on correct real time sun lighting.
1329 //
1330 // Revision 1.2  1997/08/04 20:25:15  curt
1331 // Organizational tweaking.
1332 //
1333 // Revision 1.1  1997/08/02 18:45:00  curt
1334 // Renamed GLmain.c GLUTmain.c
1335 //
1336 // Revision 1.43  1997/08/02 16:23:47  curt
1337 // Misc. tweaks.
1338 //
1339 // Revision 1.42  1997/08/01 19:43:33  curt
1340 // Making progress with coordinate system overhaul.
1341 //
1342 // Revision 1.41  1997/07/31 22:52:37  curt
1343 // Working on redoing internal coordinate systems & scenery transformations.
1344 //
1345 // Revision 1.40  1997/07/30 16:12:42  curt
1346 // Moved fg_random routines from Util/ to Math/
1347 //
1348 // Revision 1.39  1997/07/21 14:45:01  curt
1349 // Minor tweaks.
1350 //
1351 // Revision 1.38  1997/07/19 23:04:47  curt
1352 // Added an initial weather section.
1353 //
1354 // Revision 1.37  1997/07/19 22:34:02  curt
1355 // Moved PI definitions to ../constants.h
1356 // Moved random() stuff to ../Utils/ and renamed fg_random()
1357 //
1358 // Revision 1.36  1997/07/18 23:41:25  curt
1359 // Tweaks for building with Cygnus Win32 compiler.
1360 //
1361 // Revision 1.35  1997/07/18 14:28:34  curt
1362 // Hacked in some support for wind/turbulence.
1363 //
1364 // Revision 1.34  1997/07/16 20:04:48  curt
1365 // Minor tweaks to aid Win32 port.
1366 //
1367 // Revision 1.33  1997/07/12 03:50:20  curt
1368 // Added an #include <Windows32/Base.h> to help compiling for Win32
1369 //
1370 // Revision 1.32  1997/07/11 03:23:18  curt
1371 // Solved some scenery display/orientation problems.  Still have a positioning
1372 // (or transformation?) problem.
1373 //
1374 // Revision 1.31  1997/07/11 01:29:58  curt
1375 // More tweaking of terrian floor.
1376 //
1377 // Revision 1.30  1997/07/10 04:26:37  curt
1378 // We now can interpolated ground elevation for any position in the grid.  We
1379 // can use this to enforce a "hard" ground.  We still need to enforce some
1380 // bounds checking so that we don't try to lookup data points outside the
1381 // grid data set.
1382 //
1383 // Revision 1.29  1997/07/09 21:31:12  curt
1384 // Working on making the ground "hard."
1385 //
1386 // Revision 1.28  1997/07/08 18:20:12  curt
1387 // Working on establishing a hard ground.
1388 //
1389 // Revision 1.27  1997/07/07 20:59:49  curt
1390 // Working on scenery transformations to enable us to fly fluidly over the
1391 // poles with no discontinuity/distortion in scenery.
1392 //
1393 // Revision 1.26  1997/07/05 20:43:34  curt
1394 // renamed mat3 directory to Math so we could add other math related routines.
1395 //
1396 // Revision 1.25  1997/06/29 21:19:17  curt
1397 // Working on scenery management system.
1398 //
1399 // Revision 1.24  1997/06/26 22:14:53  curt
1400 // Beginning work on a scenery management system.
1401 //
1402 // Revision 1.23  1997/06/26 19:08:33  curt
1403 // Restructuring make, adding automatic "make dep" support.
1404 //
1405 // Revision 1.22  1997/06/25 15:39:47  curt
1406 // Minor changes to compile with rsxnt/win32.
1407 //
1408 // Revision 1.21  1997/06/22 21:44:41  curt
1409 // Working on intergrating the VRML (subset) parser.
1410 //
1411 // Revision 1.20  1997/06/21 17:12:53  curt
1412 // Capitalized subdirectory names.
1413 //
1414 // Revision 1.19  1997/06/18 04:10:31  curt
1415 // A couple more runway tweaks ...
1416 //
1417 // Revision 1.18  1997/06/18 02:21:24  curt
1418 // Hacked in a runway
1419 //
1420 // Revision 1.17  1997/06/17 16:51:58  curt
1421 // Timer interval stuff now uses gettimeofday() instead of ftime()
1422 //
1423 // Revision 1.16  1997/06/17 04:19:16  curt
1424 // More timer related tweaks with respect to view direction changes.
1425 //
1426 // Revision 1.15  1997/06/17 03:41:10  curt
1427 // Nonsignal based interval timing is now working.
1428 // This would be a good time to look at cleaning up the code structure a bit.
1429 //
1430 // Revision 1.14  1997/06/16 19:32:51  curt
1431 // Starting to add general timer support.
1432 //
1433 // Revision 1.13  1997/06/02 03:40:06  curt
1434 // A tiny bit more view tweaking.
1435 //
1436 // Revision 1.12  1997/06/02 03:01:38  curt
1437 // Working on views (side, front, back, transitions, etc.)
1438 //
1439 // Revision 1.11  1997/05/31 19:16:25  curt
1440 // Elevator trim added.
1441 //
1442 // Revision 1.10  1997/05/31 04:13:52  curt
1443 // WE CAN NOW FLY!!!
1444 //
1445 // Continuing work on the LaRCsim flight model integration.
1446 // Added some MSFS-like keyboard input handling.
1447 //
1448 // Revision 1.9  1997/05/30 19:27:01  curt
1449 // The LaRCsim flight model is starting to look like it is working.
1450 //
1451 // Revision 1.8  1997/05/30 03:54:10  curt
1452 // Made a bit more progress towards integrating the LaRCsim flight model.
1453 //
1454 // Revision 1.7  1997/05/29 22:39:49  curt
1455 // Working on incorporating the LaRCsim flight model.
1456 //
1457 // Revision 1.6  1997/05/29 12:31:39  curt
1458 // Minor tweaks, moving towards general flight model integration.
1459 //
1460 // Revision 1.5  1997/05/29 02:33:23  curt
1461 // Updated to reflect changing interfaces in other "modules."
1462 //
1463 // Revision 1.4  1997/05/27 17:44:31  curt
1464 // Renamed & rearranged variables and routines.   Added some initial simple
1465 // timer/alarm routines so the flight model can be updated on a regular 
1466 // interval.
1467 //
1468 // Revision 1.3  1997/05/23 15:40:25  curt
1469 // Added GNU copyright headers.
1470 // Fog now works!
1471 //
1472 // Revision 1.2  1997/05/23 00:35:12  curt
1473 // Trying to get fog to work ...
1474 //
1475 // Revision 1.1  1997/05/21 15:57:51  curt
1476 // Renamed due to added GLUT support.
1477 //
1478 // Revision 1.3  1997/05/19 18:22:42  curt
1479 // Parameter tweaking ... starting to stub in fog support.
1480 //
1481 // Revision 1.2  1997/05/17 00:17:34  curt
1482 // Trying to stub in support for standard OpenGL.
1483 //
1484 // Revision 1.1  1997/05/16 16:05:52  curt
1485 // Initial revision.
1486 //