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