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