]> git.mxchange.org Git - flightgear.git/blob - Main/GLUTmain.c
Removed "depend" files from cvs control. Other minor make tweaks.
[flightgear.git] / Main / GLUTmain.c
1 /**************************************************************************
2  * GLUTmain.c -- top level sim routines
3  *
4  * Written by Curtis Olson for OpenGL, started May 1997.
5  *
6  * Copyright (C) 1997  Curtis L. Olson  - curt@infoplane.com
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License as
10  * published by the Free Software Foundation; either version 2 of the
11  * License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful, but
14  * WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21  *
22  * $Id$
23  * (Log is kept at end of this file)
24  **************************************************************************/
25
26
27 #ifdef WIN32
28 #  include <windows.h>                     
29 #endif
30
31 #include <GL/glut.h>
32 #include <XGL/xgl.h>
33 #include <stdio.h>
34
35 #include <Main/GLUTkey.h>
36 #include <Main/fg_init.h>
37 #include <Main/fg_debug.h>
38 #include <Main/views.h>
39
40 #include <Include/fg_constants.h>
41 #include <Include/general.h>
42
43 #include <Aircraft/aircraft.h>
44 #include <Astro/moon.h>
45 #include <Astro/planets.h>
46 #include <Astro/sky.h>
47 #include <Astro/stars.h>
48 #include <Astro/sun.h>
49 #include <Cockpit/cockpit.h>
50 #include <Joystick/joystick.h>
51 #include <Math/fg_geodesy.h>
52 #include <Math/mat3.h>
53 #include <Math/polar.h>
54 #include <Scenery/scenery.h>
55 #include <Scenery/tilemgr.h>
56 #include <Time/event.h>
57 #include <Time/fg_time.h>
58 #include <Time/fg_timer.h>
59 #include <Time/sunpos.h>
60 #include <Weather/weather.h>
61
62
63 /* This is a record containing global housekeeping information */
64 struct fgGENERAL general;
65
66 /* view parameters */
67 static GLfloat win_ratio = 1.0;
68 static GLint winWidth, winHeight;
69
70 /* temporary hack */
71 /* pointer to scenery structure */
72 /* static GLint scenery, runway; */
73
74 /* double Simtime; */
75
76 /* Another hack */
77 int use_signals = 0;
78
79 /* Yet another hack. This one used by the HUD code. Michele */
80 int show_hud;
81
82 /* Yet another other hack. Used for my prototype instrument code. (Durk) */
83 int displayInstruments; 
84
85
86 /**************************************************************************
87  * fgInitVisuals() -- Initialize various GL/view parameters
88  **************************************************************************/
89
90 static void fgInitVisuals( void ) {
91     struct fgLIGHT *l;
92     struct fgTIME *t;
93     struct fgWEATHER *w;
94
95     l = &cur_light_params;
96     t = &cur_time_params;
97     w = &current_weather;
98
99     
100     /* xglDisable( GL_DITHER ); */
101
102     /* If enabled, normal vectors specified with glNormal are scaled
103        to unit length after transformation.  See glNormal. */
104     xglEnable( GL_NORMALIZE );
105
106     xglEnable( GL_LIGHTING );
107     xglEnable( GL_LIGHT0 );
108     xglLightfv( GL_LIGHT0, GL_POSITION, l->sun_vec );
109
110     xglFogi (GL_FOG_MODE, GL_LINEAR);
111     /* xglFogf (GL_FOG_START, 1.0); */
112     xglFogf (GL_FOG_END, w->visibility);
113     /* xglFogf (GL_FOG_DENSITY, w->visibility); */
114     xglHint (GL_FOG_HINT, GL_NICEST /* GL_FASTEST */ );
115
116     /* draw wire frame */
117     /* xglPolygonMode(GL_FRONT_AND_BACK,GL_LINE); */
118 }
119
120
121 /**************************************************************************
122  * Update the view volume, position, and orientation
123  **************************************************************************/
124
125 static void fgUpdateViewParams( void ) {
126     fgFLIGHT *f;
127     struct fgLIGHT *l;
128     struct fgTIME *t;
129     struct fgVIEW *v;
130
131     f = current_aircraft.flight;
132     l = &cur_light_params;
133     t = &cur_time_params;
134     v = &current_view;
135
136     fgViewUpdate(f, v, l);
137
138     if (displayInstruments)
139       {
140         xglViewport(0, (GLint)(winHeight / 2 ) , (GLint)winWidth, (GLint)winHeight / 2);
141         /* Tell GL we are about to modify the projection parameters */    
142         xglMatrixMode(GL_PROJECTION);
143         xglLoadIdentity();
144         gluPerspective(55.0, 2.0/win_ratio, 1.0, 100000.0);
145       }
146     else
147       {
148         xglViewport(0, 0 , (GLint)winWidth, (GLint) winHeight);
149         /* Tell GL we are about to modify the projection parameters */    
150         xglMatrixMode(GL_PROJECTION);
151         xglLoadIdentity();
152         gluPerspective(55.0, 1.0/win_ratio, 1.0, 100000.0);
153       }
154
155     xglMatrixMode(GL_MODELVIEW);
156     xglLoadIdentity();
157     
158     /* set up our view volume (default) */
159     gluLookAt(v->view_pos.x, v->view_pos.y, v->view_pos.z,
160                v->view_pos.x + v->view_forward[0], 
161                v->view_pos.y + v->view_forward[1], 
162                v->view_pos.z + v->view_forward[2],
163                v->view_up[0], v->view_up[1], v->view_up[2]);
164
165     /* lock view horizontally towards sun (testing) */
166     /* gluLookAt(v->view_pos.x, v->view_pos.y, v->view_pos.z,
167                v->view_pos.x + v->surface_to_sun[0], 
168                v->view_pos.y + v->surface_to_sun[1], 
169                v->view_pos.z + v->surface_to_sun[2],
170                v->view_up[0], v->view_up[1], v->view_up[2]); */
171
172     /* lock view horizontally towards south (testing) */
173     /* gluLookAt(v->view_pos.x, v->view_pos.y, v->view_pos.z,
174                v->view_pos.x + v->surface_south[0], 
175                v->view_pos.y + v->surface_south[1], 
176                v->view_pos.z + v->surface_south[2],
177                v->view_up[0], v->view_up[1], v->view_up[2]); */
178
179     /* set the sun position */
180     xglLightfv( GL_LIGHT0, GL_POSITION, l->sun_vec );
181 }
182
183
184 /*************************************************************************
185  * Draw a basic instrument panel
186  ************************************************************************/
187 static void fgUpdateInstrViewParams( void ) {
188     xglViewport(0, 0 , (GLint)winWidth, (GLint)winHeight / 2);
189   
190     xglMatrixMode(GL_PROJECTION);
191     xglPushMatrix();
192   
193     xglLoadIdentity();
194     gluOrtho2D(0, 640, 0, 480);
195     xglMatrixMode(GL_MODELVIEW);
196     xglPushMatrix();
197     xglLoadIdentity();
198     
199     xglColor3f(1.0, 1.0, 1.0);
200     xglIndexi(7);
201   
202     xglDisable(GL_DEPTH_TEST);
203     xglDisable(GL_LIGHTING);
204   
205     xglLineWidth(1);
206     xglColor3f (0.5, 0.5, 0.5);
207
208     xglBegin(GL_QUADS);
209     xglVertex2f(0.0, 0.00);
210     xglVertex2f(0.0, 480.0);
211     xglVertex2f(640.0,480.0);
212     xglVertex2f(640.0, 0.0);
213     xglEnd();
214
215     xglRectf(0.0,0.0, 640, 480);
216     xglEnable(GL_DEPTH_TEST);
217     xglEnable(GL_LIGHTING);
218     xglMatrixMode(GL_PROJECTION);
219     xglPopMatrix();
220     xglMatrixMode(GL_MODELVIEW);
221     xglPopMatrix();
222 }
223
224
225 /**************************************************************************
226  * Update all Visuals (redraws anything graphics related)
227  **************************************************************************/
228
229 static void fgRenderFrame( void ) {
230     struct fgLIGHT *l;
231     struct fgTIME *t;
232     struct fgVIEW *v;
233     double angle;
234     GLfloat white[4] = { 1.0, 1.0, 1.0, 1.0 };
235
236     l = &cur_light_params;
237     t = &cur_time_params;
238     v = &current_view;
239
240     /* update view volume parameters */
241     fgUpdateViewParams();
242
243     xglClear( GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT );
244
245     /* Tell GL we are switching to model view parameters */
246     xglMatrixMode(GL_MODELVIEW);
247     /* xglLoadIdentity(); */
248
249     /* draw sky */
250     xglDisable( GL_DEPTH_TEST );
251     xglDisable( GL_LIGHTING );
252     xglDisable( GL_CULL_FACE );
253     xglDisable( GL_FOG );
254     xglShadeModel( GL_SMOOTH );
255     fgSkyRender();
256
257     /* setup transformation for drawing astronomical objects */
258     xglPushMatrix();
259     /* Translate to view position */
260     xglTranslatef( v->view_pos.x, v->view_pos.y, v->view_pos.z );
261     /* Rotate based on gst (sidereal time) */
262     angle = t->gst * 15.041085; /* should be 15.041085, Curt thought it was 15*/
263     /* printf("Rotating astro objects by %.2f degrees\n",angle); */
264     xglRotatef( angle, 0.0, 0.0, -1.0 );
265
266     /* draw stars and planets */
267     fgStarsRender();
268     fgPlanetsRender();
269
270     /* draw the sun */
271     fgSunRender();
272
273     /* render the moon */
274     xglEnable( GL_LIGHTING );
275     /* set lighting parameters */
276     xglLightfv(GL_LIGHT0, GL_AMBIENT, white );
277     xglLightfv(GL_LIGHT0, GL_DIFFUSE, white );
278     xglEnable( GL_CULL_FACE );
279     
280     /* Let's try some blending technique's (Durk)*/
281     glEnable(GL_BLEND);
282     glBlendFunc(GL_ONE, GL_ONE);
283     fgMoonRender();
284     glDisable(GL_BLEND);
285
286     xglPopMatrix();
287
288     /* draw scenery */
289     xglShadeModel( /* GL_FLAT */ GL_SMOOTH ); 
290     xglEnable( GL_DEPTH_TEST );
291     xglEnable( GL_FOG );
292     xglFogfv (GL_FOG_COLOR, l->fog_color);
293     /* set lighting parameters */
294     xglLightfv(GL_LIGHT0, GL_AMBIENT, l->scene_ambient );
295     xglLightfv(GL_LIGHT0, GL_DIFFUSE, l->scene_diffuse );
296     fgTileMgrRender();
297     /* fgSceneryRender(); */
298
299     /* display HUD */
300     if( show_hud ) {
301         fgCockpitUpdate();
302     }
303
304     /* display instruments */
305     if (displayInstruments) {
306         fgUpdateInstrViewParams();
307     }
308
309     #ifdef GLUT
310       xglutSwapBuffers();
311     #endif
312 }
313
314
315 /**************************************************************************
316  * Update internal time dependent calculations (i.e. flight model)
317  **************************************************************************/
318
319 void fgUpdateTimeDepCalcs(int multi_loop) {
320     fgFLIGHT *f;
321     struct fgTIME *t;
322     struct fgVIEW *v;
323     int i;
324
325     f = current_aircraft.flight;
326     t = &cur_time_params;
327     v = &current_view;
328
329     /* update the flight model */
330     if ( multi_loop < 0 ) {
331         multi_loop = DEFAULT_MULTILOOP;
332     }
333
334     /* printf("updating flight model x %d\n", multi_loop); */
335     fgFlightModelUpdate(FG_LARCSIM, f, multi_loop);
336
337     /* update the view angle */
338     for ( i = 0; i < multi_loop; i++ ) {
339         if ( fabs(v->goal_view_offset - v->view_offset) < 0.05 ) {
340             v->view_offset = v->goal_view_offset;
341             break;
342         } else {
343             /* move v->view_offset towards v->goal_view_offset */
344             if ( v->goal_view_offset > v->view_offset ) {
345                 if ( v->goal_view_offset - v->view_offset < FG_PI ) {
346                     v->view_offset += 0.01;
347                 } else {
348                     v->view_offset -= 0.01;
349                 }
350             } else {
351                 if ( v->view_offset - v->goal_view_offset < FG_PI ) {
352                     v->view_offset -= 0.01;
353                 } else {
354                     v->view_offset += 0.01;
355                 }
356             }
357             if ( v->view_offset > FG_2PI ) {
358                 v->view_offset -= FG_2PI;
359             } else if ( v->view_offset < 0 ) {
360                 v->view_offset += FG_2PI;
361             }
362         }
363     }
364 }
365
366
367 void fgInitTimeDepCalcs( void ) {
368     /* initialize timer */
369
370 #ifdef USE_ITIMER
371     fgTimerInit( 1.0 / DEFAULT_TIMER_HZ, fgUpdateTimeDepCalcs );
372 #endif USE_ITIMER
373
374 }
375
376
377 /**************************************************************************
378  * Scenery management routines
379  **************************************************************************/
380
381 /* static void fgSceneryInit_OLD() { */
382     /* make scenery */
383 /*     scenery = fgSceneryCompile_OLD();
384     runway = fgRunwayHack_OLD(0.69, 53.07);
385 } */
386
387
388 /* create the scenery */
389 /* GLint fgSceneryCompile_OLD() {
390     GLint scenery;
391
392     scenery = mesh2GL(mesh_ptr_OLD);
393
394     return(scenery);
395 }
396 */
397
398 /* hack in a runway */
399 /* GLint fgRunwayHack_OLD(double width, double length) {
400     static GLfloat concrete[4] = { 0.5, 0.5, 0.5, 1.0 };
401     static GLfloat line[4]     = { 0.9, 0.9, 0.9, 1.0 };
402     int i;
403     int num_lines = 16;
404     float line_len, line_width_2, cur_pos;
405
406     runway = xglGenLists(1);
407     xglNewList(runway, GL_COMPILE);
408     */
409     /* draw concrete */
410 /*    xglBegin(GL_POLYGON);
411     xglMaterialfv( GL_FRONT, GL_AMBIENT_AND_DIFFUSE, concrete );
412     xglNormal3f(0.0, 0.0, 1.0);
413
414     xglVertex3d( 0.0,   -width/2.0, 0.0);
415     xglVertex3d( 0.0,    width/2.0, 0.0);
416     xglVertex3d(length,  width/2.0, 0.0);
417     xglVertex3d(length, -width/2.0, 0.0);
418     xglEnd();
419     */
420     /* draw center line */
421 /*    xglMaterialfv( GL_FRONT, GL_AMBIENT_AND_DIFFUSE, line );
422     line_len = length / ( 2 * num_lines + 1);
423     printf("line_len = %.3f\n", line_len);
424     line_width_2 = 0.02;
425     cur_pos = line_len;
426     for ( i = 0; i < num_lines; i++ ) {
427         xglBegin(GL_POLYGON);
428         xglVertex3d( cur_pos, -line_width_2, 0.005);
429         xglVertex3d( cur_pos,  line_width_2, 0.005);
430         cur_pos += line_len;
431         xglVertex3d( cur_pos,  line_width_2, 0.005);
432         xglVertex3d( cur_pos, -line_width_2, 0.005);
433         cur_pos += line_len;
434         xglEnd();
435     }
436
437     xglEndList();
438
439     return(runway);
440 }
441 */
442
443 /* draw the scenery */
444 /*static void fgSceneryDraw_OLD() {
445     static float z = 32.35;
446
447     xglPushMatrix();
448
449     xglCallList(scenery);
450
451     printf("*** Drawing runway at %.2f\n", z);
452
453     xglTranslatef( -398391.28, 120070.41, 32.35);
454     xglRotatef(170.0, 0.0, 0.0, 1.0);
455     xglCallList(runway);
456
457     xglPopMatrix();
458 }
459 */
460
461
462 /* What should we do when we have nothing else to do?  How about get
463  * ready for the next move and update the display? */
464 static void fgMainLoop( void ) {
465     static int remainder = 0;
466     int elapsed, multi_loop;
467     double cur_elev;
468     /* double joy_x, joy_y; */
469     /* int joy_b1, joy_b2; */
470     fgAIRCRAFT *a;
471     fgFLIGHT *f;
472     struct fgTIME *t;
473
474     fgPrintf( FG_ALL, FG_DEBUG, "Running Main Loop\n");
475     fgPrintf( FG_ALL, FG_DEBUG, "======= ==== ====\n");
476
477     a = &current_aircraft;
478     f = a->flight;
479     t = &cur_time_params;
480
481     /* update "time" */
482     fgTimeUpdate(f, t);
483
484     /* Read joystick */
485     /* fgJoystickRead( &joy_x, &joy_y, &joy_b1, &joy_b2 );
486     printf( "Joystick X %f  Y %f  B1 %d  B2 %d\n",  
487             joy_x, joy_y, joy_b1, joy_b2 );
488     fgElevSet( -joy_y );
489     fgAileronSet( joy_x ); */
490
491     /* Calculate model iterations needed */
492     elapsed = fgGetTimeInterval();
493     fgPrintf( FG_ALL, FG_BULK, "Time interval is = %d, previous remainder is = %d\n", 
494               elapsed, remainder);
495     fgPrintf( FG_ALL, FG_BULK, "--> Frame rate is = %.2f\n", 1000.0 / (float)elapsed);
496     elapsed += remainder;
497
498     multi_loop = ((float)elapsed * 0.001) * DEFAULT_MODEL_HZ;
499     remainder = elapsed - ((multi_loop*1000) / DEFAULT_MODEL_HZ);
500     fgPrintf( FG_ALL, FG_BULK, "Model iterations needed = %d, new remainder = %d\n", 
501               multi_loop, remainder);
502
503     /* Run flight model */
504     if ( ! use_signals ) {
505         /* flight model */
506         fgUpdateTimeDepCalcs(multi_loop);
507     }
508
509     /* I'm just sticking this here for now, it should probably move 
510      * eventually */
511     /* cur_elev = mesh_altitude(FG_Longitude * RAD_TO_ARCSEC, 
512                                FG_Latitude  * RAD_TO_ARCSEC); */
513     /* there is no ground collision detection really, so for now I
514      * just hard code the ground elevation to be 0 */
515     cur_elev = 0;
516
517     /* printf("Ground elevation is %.2f meters here.\n", cur_elev); */
518     /* FG_Runway_altitude = cur_elev * METER_TO_FEET; */
519
520     if ( FG_Altitude * FEET_TO_METER < cur_elev + 3.758099) {
521         /* set this here, otherwise if we set runway height above our
522            current height we get a really nasty bounce. */
523         FG_Runway_altitude = FG_Altitude - 3.758099;
524
525         /* now set aircraft altitude above ground */
526         FG_Altitude = cur_elev * METER_TO_FEET + 3.758099;
527         fgPrintf( FG_ALL, FG_BULK, "<*> resetting altitude to %.0f meters\n", 
528                FG_Altitude * FEET_TO_METER);
529     }
530
531     fgAircraftOutputCurrent(a);
532
533     /* see if we need to load any new scenery tiles */
534     fgTileMgrUpdate();
535
536     /* Process/manage pending events */
537     fgEventProcess();
538
539     /* redraw display */
540     fgRenderFrame();
541
542     fgPrintf( FG_ALL, FG_DEBUG, "\n");
543 }
544
545
546 /**************************************************************************
547  * Handle new window size or exposure
548  **************************************************************************/
549
550 static void fgReshape( int width, int height ) {
551     /* Do this so we can call fgReshape(0,0) ourselves without having to know
552      * what the values of width & height are. */
553     if ( (height > 0) && (width > 0) ) {
554         win_ratio = (GLfloat) height / (GLfloat) width;
555     }
556
557     winWidth = width;
558     winHeight = height;
559
560     /* Inform gl of our view window size (now handled elsewhere) */
561     /* xglViewport(0, 0, (GLint)width, (GLint)height); */
562
563     fgUpdateViewParams();
564     
565     /* xglClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); */
566 }
567
568
569 /**************************************************************************
570  * Main ...
571  **************************************************************************/
572
573 int main( int argc, char *argv[] ) {
574     fgFLIGHT *f;
575
576     f = current_aircraft.flight;
577
578     printf("Flight Gear:  Version %s\n\n", VERSION);
579
580     /**********************************************************************
581      * Initialize the Window/Graphics environment.
582      **********************************************************************/
583
584     #ifdef GLUT
585       /* initialize GLUT */
586       xglutInit(&argc, argv);
587
588       /* Define Display Parameters */
589       xglutInitDisplayMode( GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE );
590
591       /* Define initial window size */
592       xglutInitWindowSize(640, 480);
593
594       /* Initialize windows */
595       xglutCreateWindow("Flight Gear");
596     #endif
597
598     /* This is the general house keeping init routine */
599     fgInitGeneral();
600
601     /* This is the top level init routine which calls all the other
602      * subsystem initialization routines.  If you are adding a
603      * subsystem to flight gear, its initialization call should
604      * located in this routine.*/
605     fgInitSubsystems();
606
607     /* setup view parameters, only makes GL calls */
608     fgInitVisuals();
609
610     if ( use_signals ) {
611         /* init timer routines, signals, etc.  Arrange for an alarm
612            signal to be generated, etc. */
613         fgInitTimeDepCalcs();
614     }
615
616    /**********************************************************************
617      * Initialize the Event Handlers.
618      **********************************************************************/
619
620     #ifdef GLUT
621       /* call fgReshape() on window resizes */
622       xglutReshapeFunc( fgReshape );
623
624       /* call key() on keyboard event */
625       xglutKeyboardFunc( GLUTkey );
626       glutSpecialFunc( GLUTspecialkey );
627
628       /* call fgMainLoop() whenever there is nothing else to do */
629       xglutIdleFunc( fgMainLoop );
630
631       /* draw the scene */
632       xglutDisplayFunc( fgRenderFrame );
633
634       /* pass control off to the GLUT event handler */
635       glutMainLoop();
636     #endif
637
638     return(0);
639 }
640
641
642 #ifdef __SUNPRO_CC
643     extern "C" {
644         void __eprintf( void ) {
645         }
646     }
647 #endif
648
649 /* $Log$
650 /* Revision 1.59  1998/02/09 22:56:54  curt
651 /* Removed "depend" files from cvs control.  Other minor make tweaks.
652 /*
653  * Revision 1.58  1998/02/09 15:07:49  curt
654  * Minor tweaks.
655  *
656  * Revision 1.57  1998/02/07 15:29:40  curt
657  * Incorporated HUD changes and struct/typedef changes from Charlie Hotchkiss
658  * <chotchkiss@namg.us.anritsu.com>
659  *
660  * Revision 1.56  1998/02/03 23:20:23  curt
661  * Lots of little tweaks to fix various consistency problems discovered by
662  * Solaris' CC.  Fixed a bug in fg_debug.c with how the fgPrintf() wrapper
663  * passed arguments along to the real printf().  Also incorporated HUD changes
664  * by Michele America.
665  *
666  * Revision 1.55  1998/02/02 20:53:58  curt
667  * Incorporated Durk's changes.
668  *
669  * Revision 1.54  1998/01/31 00:43:10  curt
670  * Added MetroWorks patches from Carmen Volpe.
671  *
672  * Revision 1.53  1998/01/27 18:35:54  curt
673  * Minor tweaks.
674  *
675  * Revision 1.52  1998/01/27 00:47:56  curt
676  * Incorporated Paul Bleisch's <bleisch@chromatic.com> new debug message
677  * system and commandline/config file processing code.
678  *
679  * Revision 1.51  1998/01/26 15:57:05  curt
680  * Tweaks for dynamic scenery development.
681  *
682  * Revision 1.50  1998/01/19 19:27:07  curt
683  * Merged in make system changes from Bob Kuehne <rpk@sgi.com>
684  * This should simplify things tremendously.
685  *
686  * Revision 1.49  1998/01/19 18:40:31  curt
687  * Tons of little changes to clean up the code and to remove fatal errors
688  * when building with the c++ compiler.
689  *
690  * Revision 1.48  1998/01/19 18:35:46  curt
691  * Minor tweaks and fixes for cygwin32.
692  *
693  * Revision 1.47  1998/01/13 00:23:08  curt
694  * Initial changes to support loading and management of scenery tiles.  Note,
695  * there's still a fair amount of work left to be done.
696  *
697  * Revision 1.46  1998/01/08 02:22:06  curt
698  * Beginning to integrate Tile management subsystem.
699  *
700  * Revision 1.45  1998/01/07 03:18:55  curt
701  * Moved astronomical stuff from .../Src/Scenery to .../Src/Astro/
702  *
703  * Revision 1.44  1997/12/30 22:22:31  curt
704  * Further integration of event manager.
705  *
706  * Revision 1.43  1997/12/30 20:47:43  curt
707  * Integrated new event manager with subsystem initializations.
708  *
709  * Revision 1.42  1997/12/30 16:36:47  curt
710  * Merged in Durk's changes ...
711  *
712  * Revision 1.41  1997/12/30 13:06:56  curt
713  * A couple lighting tweaks ...
714  *
715  * Revision 1.40  1997/12/30 01:38:37  curt
716  * Switched back to per vertex normals and smooth shading for terrain.
717  *
718  * Revision 1.39  1997/12/22 23:45:45  curt
719  * First stab at sunset/sunrise sky glow effects.
720  *
721  * Revision 1.38  1997/12/22 04:14:28  curt
722  * Aligned sky with sun so dusk/dawn effects can be correct relative to the sun.
723  *
724  * Revision 1.37  1997/12/19 23:34:03  curt
725  * Lot's of tweaking with sky rendering and lighting.
726  *
727  * Revision 1.36  1997/12/19 16:44:57  curt
728  * Working on scene rendering order and options.
729  *
730  * Revision 1.35  1997/12/18 23:32:32  curt
731  * First stab at sky dome actually starting to look reasonable. :-)
732  *
733  * Revision 1.34  1997/12/17 23:13:34  curt
734  * Began working on rendering a sky.
735  *
736  * Revision 1.33  1997/12/15 23:54:45  curt
737  * Add xgl wrappers for debugging.
738  * Generate terrain normals on the fly.
739  *
740  * Revision 1.32  1997/12/15 20:59:08  curt
741  * Misc. tweaks.
742  *
743  * Revision 1.31  1997/12/12 21:41:25  curt
744  * More light/material property tweaking ... still a ways off.
745  *
746  * Revision 1.30  1997/12/12 19:52:47  curt
747  * Working on lightling and material properties.
748  *
749  * Revision 1.29  1997/12/11 04:43:54  curt
750  * Fixed sun vector and lighting problems.  I thing the moon is now lit
751  * correctly.
752  *
753  * Revision 1.28  1997/12/10 22:37:45  curt
754  * Prepended "fg" on the name of all global structures that didn't have it yet.
755  * i.e. "struct WEATHER {}" became "struct fgWEATHER {}"
756  *
757  * Revision 1.27  1997/12/09 05:11:54  curt
758  * Working on tweaking lighting.
759  *
760  * Revision 1.26  1997/12/09 04:25:29  curt
761  * Working on adding a global lighting params structure.
762  *
763  * Revision 1.25  1997/12/08 22:54:09  curt
764  * Enabled GL_CULL_FACE.
765  *
766  * Revision 1.24  1997/11/25 19:25:32  curt
767  * Changes to integrate Durk's moon/sun code updates + clean up.
768  *
769  * Revision 1.23  1997/11/15 18:16:34  curt
770  * minor tweaks.
771  *
772  * Revision 1.22  1997/10/30 12:38:41  curt
773  * Working on new scenery subsystem.
774  *
775  * Revision 1.21  1997/09/23 00:29:38  curt
776  * Tweaks to get things to compile with gcc-win32.
777  *
778  * Revision 1.20  1997/09/22 14:44:19  curt
779  * Continuing to try to align stars correctly.
780  *
781  * Revision 1.19  1997/09/18 16:20:08  curt
782  * At dusk/dawn add/remove stars in stages.
783  *
784  * Revision 1.18  1997/09/16 22:14:51  curt
785  * Tweaked time of day lighting equations.  Don't draw stars during the day.
786  *
787  * Revision 1.17  1997/09/16 15:50:29  curt
788  * Working on star alignment and time issues.
789  *
790  * Revision 1.16  1997/09/13 02:00:06  curt
791  * Mostly working on stars and generating sidereal time for accurate star
792  * placement.
793  *
794  * Revision 1.15  1997/09/05 14:17:27  curt
795  * More tweaking with stars.
796  *
797  * Revision 1.14  1997/09/05 01:35:53  curt
798  * Working on getting stars right.
799  *
800  * Revision 1.13  1997/09/04 02:17:34  curt
801  * Shufflin' stuff.
802  *
803  * Revision 1.12  1997/08/27 21:32:24  curt
804  * Restructured view calculation code.  Added stars.
805  *
806  * Revision 1.11  1997/08/27 03:30:16  curt
807  * Changed naming scheme of basic shared structures.
808  *
809  * Revision 1.10  1997/08/25 20:27:22  curt
810  * Merged in initial HUD and Joystick code.
811  *
812  * Revision 1.9  1997/08/22 21:34:39  curt
813  * Doing a bit of reorganizing and house cleaning.
814  *
815  * Revision 1.8  1997/08/19 23:55:03  curt
816  * Worked on better simulating real lighting.
817  *
818  * Revision 1.7  1997/08/16 12:22:38  curt
819  * Working on improving the lighting/shading.
820  *
821  * Revision 1.6  1997/08/13 20:24:56  curt
822  * Changes due to changing sunpos interface.
823  *
824  * Revision 1.5  1997/08/06 21:08:32  curt
825  * Sun position now *really* works (I think) ... I still have sun time warping
826  * code in place, probably should remove it soon.
827  *
828  * Revision 1.4  1997/08/06 15:41:26  curt
829  * Working on correct sun position.
830  *
831  * Revision 1.3  1997/08/06 00:24:22  curt
832  * Working on correct real time sun lighting.
833  *
834  * Revision 1.2  1997/08/04 20:25:15  curt
835  * Organizational tweaking.
836  *
837  * Revision 1.1  1997/08/02 18:45:00  curt
838  * Renamed GLmain.c GLUTmain.c
839  *
840  * Revision 1.43  1997/08/02 16:23:47  curt
841  * Misc. tweaks.
842  *
843  * Revision 1.42  1997/08/01 19:43:33  curt
844  * Making progress with coordinate system overhaul.
845  *
846  * Revision 1.41  1997/07/31 22:52:37  curt
847  * Working on redoing internal coordinate systems & scenery transformations.
848  *
849  * Revision 1.40  1997/07/30 16:12:42  curt
850  * Moved fg_random routines from Util/ to Math/
851  *
852  * Revision 1.39  1997/07/21 14:45:01  curt
853  * Minor tweaks.
854  *
855  * Revision 1.38  1997/07/19 23:04:47  curt
856  * Added an initial weather section.
857  *
858  * Revision 1.37  1997/07/19 22:34:02  curt
859  * Moved PI definitions to ../constants.h
860  * Moved random() stuff to ../Utils/ and renamed fg_random()
861  *
862  * Revision 1.36  1997/07/18 23:41:25  curt
863  * Tweaks for building with Cygnus Win32 compiler.
864  *
865  * Revision 1.35  1997/07/18 14:28:34  curt
866  * Hacked in some support for wind/turbulence.
867  *
868  * Revision 1.34  1997/07/16 20:04:48  curt
869  * Minor tweaks to aid Win32 port.
870  *
871  * Revision 1.33  1997/07/12 03:50:20  curt
872  * Added an #include <Windows32/Base.h> to help compiling for Win32
873  *
874  * Revision 1.32  1997/07/11 03:23:18  curt
875  * Solved some scenery display/orientation problems.  Still have a positioning
876  * (or transformation?) problem.
877  *
878  * Revision 1.31  1997/07/11 01:29:58  curt
879  * More tweaking of terrian floor.
880  *
881  * Revision 1.30  1997/07/10 04:26:37  curt
882  * We now can interpolated ground elevation for any position in the grid.  We
883  * can use this to enforce a "hard" ground.  We still need to enforce some
884  * bounds checking so that we don't try to lookup data points outside the
885  * grid data set.
886  *
887  * Revision 1.29  1997/07/09 21:31:12  curt
888  * Working on making the ground "hard."
889  *
890  * Revision 1.28  1997/07/08 18:20:12  curt
891  * Working on establishing a hard ground.
892  *
893  * Revision 1.27  1997/07/07 20:59:49  curt
894  * Working on scenery transformations to enable us to fly fluidly over the
895  * poles with no discontinuity/distortion in scenery.
896  *
897  * Revision 1.26  1997/07/05 20:43:34  curt
898  * renamed mat3 directory to Math so we could add other math related routines.
899  *
900  * Revision 1.25  1997/06/29 21:19:17  curt
901  * Working on scenery management system.
902  *
903  * Revision 1.24  1997/06/26 22:14:53  curt
904  * Beginning work on a scenery management system.
905  *
906  * Revision 1.23  1997/06/26 19:08:33  curt
907  * Restructuring make, adding automatic "make dep" support.
908  *
909  * Revision 1.22  1997/06/25 15:39:47  curt
910  * Minor changes to compile with rsxnt/win32.
911  *
912  * Revision 1.21  1997/06/22 21:44:41  curt
913  * Working on intergrating the VRML (subset) parser.
914  *
915  * Revision 1.20  1997/06/21 17:12:53  curt
916  * Capitalized subdirectory names.
917  *
918  * Revision 1.19  1997/06/18 04:10:31  curt
919  * A couple more runway tweaks ...
920  *
921  * Revision 1.18  1997/06/18 02:21:24  curt
922  * Hacked in a runway
923  *
924  * Revision 1.17  1997/06/17 16:51:58  curt
925  * Timer interval stuff now uses gettimeofday() instead of ftime()
926  *
927  * Revision 1.16  1997/06/17 04:19:16  curt
928  * More timer related tweaks with respect to view direction changes.
929  *
930  * Revision 1.15  1997/06/17 03:41:10  curt
931  * Nonsignal based interval timing is now working.
932  * This would be a good time to look at cleaning up the code structure a bit.
933  *
934  * Revision 1.14  1997/06/16 19:32:51  curt
935  * Starting to add general timer support.
936  *
937  * Revision 1.13  1997/06/02 03:40:06  curt
938  * A tiny bit more view tweaking.
939  *
940  * Revision 1.12  1997/06/02 03:01:38  curt
941  * Working on views (side, front, back, transitions, etc.)
942  *
943  * Revision 1.11  1997/05/31 19:16:25  curt
944  * Elevator trim added.
945  *
946  * Revision 1.10  1997/05/31 04:13:52  curt
947  * WE CAN NOW FLY!!!
948  *
949  * Continuing work on the LaRCsim flight model integration.
950  * Added some MSFS-like keyboard input handling.
951  *
952  * Revision 1.9  1997/05/30 19:27:01  curt
953  * The LaRCsim flight model is starting to look like it is working.
954  *
955  * Revision 1.8  1997/05/30 03:54:10  curt
956  * Made a bit more progress towards integrating the LaRCsim flight model.
957  *
958  * Revision 1.7  1997/05/29 22:39:49  curt
959  * Working on incorporating the LaRCsim flight model.
960  *
961  * Revision 1.6  1997/05/29 12:31:39  curt
962  * Minor tweaks, moving towards general flight model integration.
963  *
964  * Revision 1.5  1997/05/29 02:33:23  curt
965  * Updated to reflect changing interfaces in other "modules."
966  *
967  * Revision 1.4  1997/05/27 17:44:31  curt
968  * Renamed & rearranged variables and routines.   Added some initial simple
969  * timer/alarm routines so the flight model can be updated on a regular 
970  * interval.
971  *
972  * Revision 1.3  1997/05/23 15:40:25  curt
973  * Added GNU copyright headers.
974  * Fog now works!
975  *
976  * Revision 1.2  1997/05/23 00:35:12  curt
977  * Trying to get fog to work ...
978  *
979  * Revision 1.1  1997/05/21 15:57:51  curt
980  * Renamed due to added GLUT support.
981  *
982  * Revision 1.3  1997/05/19 18:22:42  curt
983  * Parameter tweaking ... starting to stub in fog support.
984  *
985  * Revision 1.2  1997/05/17 00:17:34  curt
986  * Trying to stub in support for standard OpenGL.
987  *
988  * Revision 1.1  1997/05/16 16:05:52  curt
989  * Initial revision.
990  *
991  */