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