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