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