2 // GLUTmain.cxx -- top level sim routines
4 // Written by Curtis Olson for OpenGL, started May 1997.
6 // Copyright (C) 1997 Curtis L. Olson - curt@infoplane.com
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.
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.
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.
23 // (Log is kept at end of this file)
44 #include <Include/fg_constants.h> // for VERSION
45 #include <Include/general.h>
47 #include <Aircraft/aircraft.h>
48 #include <Astro/moon.hxx>
49 #include <Astro/planets.hxx>
50 #include <Astro/sky.hxx>
51 #include <Astro/stars.hxx>
52 #include <Astro/sun.hxx>
54 #include <Cockpit/cockpit.hxx>
55 #include <Debug/fg_debug.h>
56 #include <Joystick/joystick.h>
57 #include <Math/fg_geodesy.h>
58 #include <Math/mat3.h>
59 #include <Math/polar3d.h>
60 #include <Scenery/scenery.hxx>
61 #include <Scenery/tilemgr.hxx>
62 #include <Time/event.hxx>
63 #include <Time/fg_time.hxx>
64 #include <Time/fg_timer.hxx>
65 #include <Time/sunpos.hxx>
66 #include <Weather/weather.h>
68 #include "GLUTkey.hxx"
69 #include "fg_init.hxx"
70 #include "options.hxx"
74 // This is a record containing global housekeeping information
80 // Yet another other hack. Used for my prototype instrument code. (Durk)
81 int displayInstruments;
83 // Global structures for the Audio library
84 slScheduler audio_sched ;
90 // The following defines flight gear options. Because glutlib will also
91 // want to parse its own options, those options must not be included here
92 // or they will get parsed by the main program option parser. Hence case
93 // is significant for any option added that might be in conflict with
96 // glutlib parses for:
98 // -direct (invalid in Win32)
102 // -indirect (invalid in Win32)
105 // Note that glutlib depends upon strings while this program's
106 // option parser wants only initial characters followed by numbers
111 // fgInitVisuals() -- Initialize various GL/view parameters
112 static void fgInitVisuals( void ) {
117 l = &cur_light_params;
118 o = ¤t_options;
119 w = ¤t_weather;
121 // Go full screen if requested ...
122 if ( o->fullscreen ) {
126 // If enabled, normal vectors specified with glNormal are scaled
127 // to unit length after transformation. See glNormal.
128 xglEnable( GL_NORMALIZE );
130 xglEnable( GL_LIGHTING );
131 xglEnable( GL_LIGHT0 );
132 xglLightfv( GL_LIGHT0, GL_POSITION, l->sun_vec );
134 xglFogi (GL_FOG_MODE, GL_LINEAR);
135 xglFogf (GL_FOG_START, w->visibility / 1000000.0 );
136 xglFogf (GL_FOG_END, w->visibility);
137 // xglFogf (GL_FOG_DENSITY, w->visibility);
139 xglHint (GL_FOG_HINT, GL_NICEST );
141 xglHint (GL_FOG_HINT, GL_FASTEST );
143 if ( o->wireframe ) {
145 xglPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
148 // This is the default anyways, but it can't hurt
149 xglFrontFace ( GL_CCW );
153 // Update the view volume, position, and orientation
154 static void fgUpdateViewParams( void ) {
160 f = current_aircraft.flight;
161 l = &cur_light_params;
162 o = ¤t_options;
166 v->UpdateWorldToEye(f);
168 if (displayInstruments) {
169 xglViewport( 0, (GLint)((v->winHeight) / 2 ) ,
170 (GLint)(v->winWidth), (GLint)(v->winHeight) / 2 );
171 // Tell GL we are about to modify the projection parameters
172 xglMatrixMode(GL_PROJECTION);
174 gluPerspective(o->fov, v->win_ratio / 2.0, 1.0, 100000.0);
176 xglViewport(0, 0 , (GLint)(v->winWidth), (GLint)(v->winHeight) );
177 // Tell GL we are about to modify the projection parameters
178 xglMatrixMode(GL_PROJECTION);
180 gluPerspective(o->fov, v->win_ratio, 10.0, 100000.0);
183 xglMatrixMode(GL_MODELVIEW);
186 // set up our view volume (default)
187 gluLookAt(v->view_pos.x, v->view_pos.y, v->view_pos.z,
188 v->view_pos.x + v->view_forward[0],
189 v->view_pos.y + v->view_forward[1],
190 v->view_pos.z + v->view_forward[2],
191 v->view_up[0], v->view_up[1], v->view_up[2]);
193 // look almost straight up (testing and eclipse watching)
194 /* gluLookAt(v->view_pos.x, v->view_pos.y, v->view_pos.z,
195 v->view_pos.x + v->view_up[0] + .001,
196 v->view_pos.y + v->view_up[1] + .001,
197 v->view_pos.z + v->view_up[2] + .001,
198 v->view_up[0], v->view_up[1], v->view_up[2]); */
200 // lock view horizontally towards sun (testing)
201 /* gluLookAt(v->view_pos.x, v->view_pos.y, v->view_pos.z,
202 v->view_pos.x + v->surface_to_sun[0],
203 v->view_pos.y + v->surface_to_sun[1],
204 v->view_pos.z + v->surface_to_sun[2],
205 v->view_up[0], v->view_up[1], v->view_up[2]); */
207 // lock view horizontally towards south (testing)
208 /* gluLookAt(v->view_pos.x, v->view_pos.y, v->view_pos.z,
209 v->view_pos.x + v->surface_south[0],
210 v->view_pos.y + v->surface_south[1],
211 v->view_pos.z + v->surface_south[2],
212 v->view_up[0], v->view_up[1], v->view_up[2]); */
214 // set the sun position
215 xglLightfv( GL_LIGHT0, GL_POSITION, l->sun_vec );
219 // Draw a basic instrument panel
220 static void fgUpdateInstrViewParams( void ) {
225 xglViewport(0, 0 , (GLint)(v->winWidth), (GLint)(v->winHeight) / 2);
227 xglMatrixMode(GL_PROJECTION);
231 gluOrtho2D(0, 640, 0, 480);
232 xglMatrixMode(GL_MODELVIEW);
236 xglColor3f(1.0, 1.0, 1.0);
239 xglDisable(GL_DEPTH_TEST);
240 xglDisable(GL_LIGHTING);
243 xglColor3f (0.5, 0.5, 0.5);
246 xglVertex2f(0.0, 0.00);
247 xglVertex2f(0.0, 480.0);
248 xglVertex2f(640.0,480.0);
249 xglVertex2f(640.0, 0.0);
252 xglRectf(0.0,0.0, 640, 480);
253 xglEnable(GL_DEPTH_TEST);
254 xglEnable(GL_LIGHTING);
255 xglMatrixMode(GL_PROJECTION);
257 xglMatrixMode(GL_MODELVIEW);
262 // Update all Visuals (redraws anything graphics related)
263 static void fgRenderFrame( void ) {
269 GLfloat black[4] = { 0.0, 0.0, 0.0, 1.0 };
270 GLfloat white[4] = { 1.0, 1.0, 1.0, 1.0 };
271 GLfloat terrain_color[4] = { 0.54, 0.44, 0.29, 1.0 };
273 l = &cur_light_params;
274 o = ¤t_options;
275 t = &cur_time_params;
278 // update view volume parameters
279 fgUpdateViewParams();
282 glClearColor(black[0], black[1], black[2], black[3]);
283 xglClear( GL_DEPTH_BUFFER_BIT );
285 glClearColor(l->sky_color[0], l->sky_color[1],
286 l->sky_color[2], l->sky_color[3]);
287 xglClear( GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT );
290 // Tell GL we are switching to model view parameters
291 xglMatrixMode(GL_MODELVIEW);
292 // xglLoadIdentity();
295 xglDisable( GL_DEPTH_TEST );
296 xglDisable( GL_LIGHTING );
297 xglDisable( GL_CULL_FACE );
298 xglDisable( GL_FOG );
299 xglShadeModel( GL_SMOOTH );
304 // setup transformation for drawing astronomical objects
306 // Translate to view position
307 xglTranslatef( v->view_pos.x, v->view_pos.y, v->view_pos.z );
308 // Rotate based on gst (sidereal time)
309 angle = t->gst * 15.041085; /* should be 15.041085, Curt thought it was 15*/
310 // printf("Rotating astro objects by %.2f degrees\n",angle);
311 xglRotatef( angle, 0.0, 0.0, -1.0 );
313 // draw stars and planets
321 xglEnable( GL_LIGHTING );
322 // set lighting parameters
323 xglLightfv(GL_LIGHT0, GL_AMBIENT, white );
324 xglLightfv(GL_LIGHT0, GL_DIFFUSE, white );
325 xglEnable( GL_CULL_FACE );
327 // Let's try some blending technique's (Durk)
329 glBlendFunc(GL_ONE, GL_ONE);
337 xglShadeModel( GL_SMOOTH );
339 xglShadeModel( GL_FLAT );
341 xglEnable( GL_DEPTH_TEST );
344 xglFogfv (GL_FOG_COLOR, l->fog_color);
346 // set lighting parameters
347 xglLightfv(GL_LIGHT0, GL_AMBIENT, l->scene_ambient );
348 xglLightfv(GL_LIGHT0, GL_DIFFUSE, l->scene_diffuse );
351 // texture parameters
352 xglEnable( GL_TEXTURE_2D );
353 xglTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT ) ;
354 xglTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT ) ;
355 xglTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ) ;
356 xglTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
357 GL_LINEAR /* GL_LINEAR_MIPMAP_LINEAR */ ) ;
358 xglTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ) ;
359 xglHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST ) ;
360 // set base color (I don't think this is doing anything here)
361 xglMaterialfv (GL_FRONT, GL_AMBIENT, white);
362 xglMaterialfv (GL_FRONT, GL_DIFFUSE, white);
364 xglDisable( GL_TEXTURE_2D );
365 xglMaterialfv (GL_FRONT, GL_AMBIENT, terrain_color);
366 xglMaterialfv (GL_FRONT, GL_DIFFUSE, terrain_color);
367 // xglMaterialfv (GL_FRONT, GL_AMBIENT, white);
368 // xglMaterialfv (GL_FRONT, GL_DIFFUSE, white);
373 xglDisable( GL_TEXTURE_2D );
376 if( o->hud_status ) {
380 // display instruments
381 if (displayInstruments) {
382 fgUpdateInstrViewParams();
389 // Update internal time dependent calculations (i.e. flight model)
390 void fgUpdateTimeDepCalcs(int multi_loop) {
396 f = current_aircraft.flight;
397 t = &cur_time_params;
400 // update the flight model
401 if ( multi_loop < 0 ) {
402 multi_loop = DEFAULT_MULTILOOP;
405 // printf("updating flight model x %d\n", multi_loop);
406 fgFlightModelUpdate(FG_LARCSIM, f, multi_loop);
408 // update the view angle
409 for ( i = 0; i < multi_loop; i++ ) {
410 if ( fabs(v->goal_view_offset - v->view_offset) < 0.05 ) {
411 v->view_offset = v->goal_view_offset;
414 // move v->view_offset towards v->goal_view_offset
415 if ( v->goal_view_offset > v->view_offset ) {
416 if ( v->goal_view_offset - v->view_offset < FG_PI ) {
417 v->view_offset += 0.01;
419 v->view_offset -= 0.01;
422 if ( v->view_offset - v->goal_view_offset < FG_PI ) {
423 v->view_offset -= 0.01;
425 v->view_offset += 0.01;
428 if ( v->view_offset > FG_2PI ) {
429 v->view_offset -= FG_2PI;
430 } else if ( v->view_offset < 0 ) {
431 v->view_offset += FG_2PI;
438 void fgInitTimeDepCalcs( void ) {
441 #ifdef HAVE_SETITIMER
442 fgTimerInit( 1.0 / DEFAULT_TIMER_HZ, fgUpdateTimeDepCalcs );
443 #endif HAVE_SETITIMER
448 // What should we do when we have nothing else to do? Let's get ready
449 // for the next move and update the display?
450 static void fgMainLoop( void ) {
455 static int remainder = 0;
456 int elapsed, multi_loop;
460 // double joy_x, joy_y;
461 // int joy_b1, joy_b2;
463 a = ¤t_aircraft;
466 t = &cur_time_params;
468 fgPrintf( FG_ALL, FG_DEBUG, "Running Main Loop\n");
469 fgPrintf( FG_ALL, FG_DEBUG, "======= ==== ====\n");
475 /* fgJoystickRead( &joy_x, &joy_y, &joy_b1, &joy_b2 );
476 printf( "Joystick X %f Y %f B1 %d B2 %d\n",
477 joy_x, joy_y, joy_b1, joy_b2 );
479 fgAileronSet( joy_x ); */
481 // Get elapsed time for this past frame
482 elapsed = fgGetTimeInterval();
483 fgPrintf( FG_ALL, FG_BULK,
484 "Time interval is = %d, previous remainder is = %d\n",
487 // Calculate frame rate average
488 if ( elapsed > 0.0 ) {
490 for ( i = FG_FRAME_RATE_HISTORY - 2; i >= 0; i-- ) {
491 accum += g->frames[i];
492 // printf("frame[%d] = %.2f\n", i, g->frames[i]);
493 g->frames[i+1] = g->frames[i];
495 g->frames[0] = 1000.0 / (float)elapsed;
496 // printf("frame[0] = %.2f\n", g->frames[0]);
497 accum += g->frames[0];
498 g->frame_rate = accum / (float)FG_FRAME_RATE_HISTORY;
499 // printf("ave = %.2f\n", g->frame_rate);
502 // Calculate model iterations needed for next frame
503 fgPrintf( FG_ALL, FG_DEBUG,
504 "--> Frame rate is = %.2f\n", g->frame_rate);
505 elapsed += remainder;
507 multi_loop = (int)(((float)elapsed * 0.001) * DEFAULT_MODEL_HZ);
508 remainder = elapsed - ((multi_loop*1000) / DEFAULT_MODEL_HZ);
509 fgPrintf( FG_ALL, FG_BULK,
510 "Model iterations needed = %d, new remainder = %d\n",
511 multi_loop, remainder);
514 if ( ! use_signals ) {
516 fgUpdateTimeDepCalcs(multi_loop);
519 // I'm just sticking this here for now, it should probably move
521 /* cur_elev = mesh_altitude(FG_Longitude * RAD_TO_ARCSEC,
522 FG_Latitude * RAD_TO_ARCSEC); */
523 // there is no ground collision detection really, so for now I
524 // just hard code the ground elevation to be 0 */
527 // printf("Ground elevation is %.2f meters here.\n", cur_elev);
528 // FG_Runway_altitude = cur_elev * METER_TO_FEET;
530 if ( FG_Altitude * FEET_TO_METER < cur_elev + 3.758099) {
531 // set this here, otherwise if we set runway height above our
532 // current height we get a really nasty bounce.
533 FG_Runway_altitude = FG_Altitude - 3.758099;
535 // now set aircraft altitude above ground
536 FG_Altitude = cur_elev * METER_TO_FEET + 3.758099;
537 fgPrintf( FG_ALL, FG_BULK, "<*> resetting altitude to %.0f meters\n",
538 FG_Altitude * FEET_TO_METER);
541 fgAircraftOutputCurrent(a);
543 // see if we need to load any new scenery tiles
546 // Process/manage pending events
547 global_events.Process();
549 // Run audio scheduler
550 audio_sched.update();
555 fgPrintf( FG_ALL, FG_DEBUG, "\n");
559 // Handle new window size or exposure
560 static void fgReshape( int width, int height ) {
565 // Do this so we can call fgReshape(0,0) ourselves without having
566 // to know what the values of width & height are.
567 if ( (height > 0) && (width > 0) ) {
568 v->win_ratio = (GLfloat) width / (GLfloat) height;
572 v->winHeight = height;
574 // Inform gl of our view window size (now handled elsewhere)
575 // xglViewport(0, 0, (GLint)width, (GLint)height);
576 fgUpdateViewParams();
578 // xglClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
582 // Initialize GLUT and define a main window
583 int fgGlutInit( int *argc, char **argv ) {
584 // GLUT will extract all glut specific options so later on we only
585 // need wory about our own.
586 xglutInit(argc, argv);
588 // Define Display Parameters
589 xglutInitDisplayMode( GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE );
591 // Define initial window size
592 xglutInitWindowSize(640, 480);
594 // Initialize windows
595 xglutCreateWindow("Flight Gear");
601 // Initialize GLUT event handlers
602 int fgGlutInitEvents( void ) {
603 // call fgReshape() on window resizes
604 xglutReshapeFunc( fgReshape );
606 // call GLUTkey() on keyboard event
607 xglutKeyboardFunc( GLUTkey );
608 glutSpecialFunc( GLUTspecialkey );
610 // call fgMainLoop() whenever there is
611 // nothing else to do
612 xglutIdleFunc( fgMainLoop );
615 xglutDisplayFunc( fgRenderFrame );
622 int main( int argc, char **argv ) {
626 int result; // Used in command line argument.
628 f = current_aircraft.flight;
629 o = ¤t_options;
632 _control87(MCW_EM, MCW_EM); /* defined in float.h */
635 // Initialize the debugging output system
638 fgPrintf(FG_GENERAL, FG_INFO, "Flight Gear: Version %s\n\n", VERSION);
640 // Initialize the Window/Graphics environment.
641 if( !fgGlutInit(&argc, argv) ) {
642 fgPrintf( FG_GENERAL, FG_EXIT, "GLUT initialization failed ...\n" );
645 // Attempt to locate and parse a config file
646 // First check fg_root
647 strcpy(config, o->fg_root);
648 strcat(config, "/system.fgfsrc");
649 result = o->parse_config_file(config);
651 // Next check home directory
652 if ( getenv("HOME") != NULL ) {
653 strcpy(config, getenv("HOME"));
654 strcat(config, "/.fgfsrc");
655 result = o->parse_config_file(config);
658 // Parse remaining command line options
659 // These will override anything specified in a config file
660 result = o->parse_command_line(argc, argv);
661 if ( result != FG_OPTIONS_OK ) {
662 // Something must have gone horribly wrong with the command
663 // line parsing or maybe the user just requested help ... :-)
665 fgPrintf( FG_GENERAL, FG_EXIT, "\nExiting ...\n");
668 // These are a few miscellaneous things that aren't really
669 // "subsystems" but still need to be initialized.
670 if( !fgInitGeneral()) {
671 fgPrintf( FG_GENERAL, FG_EXIT, "General initializations failed ...\n" );
674 // This is the top level init routine which calls all the other
675 // subsystem initialization routines. If you are adding a
676 // subsystem to flight gear, its initialization call should
677 // located in this routine.
678 if( !fgInitSubsystems()) {
679 fgPrintf( FG_GENERAL, FG_EXIT,
680 "Subsystem initializations failed ...\n" );
683 // setup OpenGL view parameters
687 // init timer routines, signals, etc. Arrange for an alarm
688 // signal to be generated, etc.
689 fgInitTimeDepCalcs();
692 // Initialize the various GLUT Event Handlers.
693 if( !fgGlutInitEvents() ) {
694 fgPrintf( FG_GENERAL, FG_EXIT,
695 "GLUT event handler initialization failed ...\n" );
699 audio_mixer . setMasterVolume ( 30 ) ; /* 50% of max volume. */
700 audio_sched . setRate ( 8000 ) ; /* 8KHz sample rate. */
701 // audio_sched . setSafetyMargin ( 0.128 ) ;
702 audio_sched . stereo ( SL_FALSE ) ; /* Monophonic. */
703 audio_sched . setBps ( 8 ) ; /* 8 bit samples. */
704 s1 = new slSample ( "/dos/X-System-HSR/sounds/xp_recip.wav" );
705 s2 = new slSample ( "/dos/X-System-HSR/sounds/wind.wav" );
706 s2 -> adjustVolume(0.5);
707 audio_sched . loopSample ( s1 );
708 audio_sched . loopSample ( s2 );
710 // pass control off to the master GLUT event handler
713 // we never actually get here ... but just in case ... :-)
720 void __eprintf( void ) {
727 // Revision 1.19 1998/06/01 17:54:40 curt
728 // Added Linux audio support.
729 // avoid glClear( COLOR_BUFFER_BIT ) when not using it to set the sky color.
732 // Revision 1.18 1998/05/29 20:37:19 curt
733 // Tweaked material properties & lighting a bit in GLUTmain.cxx.
734 // Read airport list into a "map" STL for dynamic list sizing and fast tree
737 // Revision 1.17 1998/05/22 21:28:52 curt
738 // Modifications to use the new fgEVENT_MGR class.
740 // Revision 1.16 1998/05/20 20:51:33 curt
741 // Tweaked smooth shaded texture lighting properties.
742 // Converted fgLIGHT to a C++ class.
744 // Revision 1.15 1998/05/16 13:08:34 curt
745 // C++ - ified views.[ch]xx
746 // Shuffled some additional view parameters into the fgVIEW class.
747 // Changed tile-radius to tile-diameter because it is a much better
749 // Added a WORLD_TO_EYE transformation to views.cxx. This allows us
750 // to transform world space to eye space for view frustum culling.
752 // Revision 1.14 1998/05/13 18:29:57 curt
753 // Added a keyboard binding to dynamically adjust field of view.
754 // Added a command line option to specify fov.
755 // Adjusted terrain color.
756 // Root path info moved to fgOPTIONS.
757 // Added ability to parse options out of a config file.
759 // Revision 1.13 1998/05/11 18:18:15 curt
760 // For flat shading use "glHint (GL_FOG_HINT, GL_FASTEST )"
762 // Revision 1.12 1998/05/07 23:14:15 curt
763 // Added "D" key binding to set autopilot heading.
764 // Made frame rate calculation average out over last 10 frames.
765 // Borland C++ floating point exception workaround.
766 // Added a --tile-radius=n option.
768 // Revision 1.11 1998/05/06 03:16:23 curt
769 // Added an averaged global frame rate counter.
770 // Added an option to control tile radius.
772 // Revision 1.10 1998/05/03 00:47:31 curt
773 // Added an option to enable/disable full-screen mode.
775 // Revision 1.9 1998/04/30 12:34:17 curt
776 // Added command line rendering options:
777 // enable/disable fog/haze
778 // specify smooth/flat shading
779 // disable sky blending and just use a solid color
780 // enable wireframe drawing mode
782 // Revision 1.8 1998/04/28 01:20:21 curt
783 // Type-ified fgTIME and fgVIEW.
784 // Added a command line option to disable textures.
786 // Revision 1.7 1998/04/26 05:10:02 curt
787 // "struct fgLIGHT" -> "fgLIGHT" because fgLIGHT is typedef'd.
789 // Revision 1.6 1998/04/25 22:06:30 curt
790 // Edited cvs log messages in source files ... bad bad bad!
792 // Revision 1.5 1998/04/25 20:24:01 curt
793 // Cleaned up initialization sequence to eliminate interdependencies
794 // between sun position, lighting, and view position. This creates a
795 // valid single pass initialization path.
797 // Revision 1.4 1998/04/24 14:19:30 curt
800 // Revision 1.3 1998/04/24 00:49:18 curt
801 // Wrapped "#include <config.h>" in "#ifdef HAVE_CONFIG_H"
802 // Trying out some different option parsing code.
803 // Some code reorganization.
805 // Revision 1.2 1998/04/22 13:25:41 curt
806 // C++ - ifing the code.
807 // Starting a bit of reorganization of lighting code.
809 // Revision 1.1 1998/04/21 17:02:39 curt
810 // Prepairing for C++ integration.
812 // Revision 1.71 1998/04/18 04:11:26 curt
813 // Moved fg_debug to it's own library, added zlib support.
815 // Revision 1.70 1998/04/14 02:21:02 curt
816 // Incorporated autopilot heading hold contributed by: Jeff Goeke-Smith
817 // <jgoeke@voyager.net>
819 // Revision 1.69 1998/04/08 23:35:34 curt
820 // Tweaks to Gnu automake/autoconf system.
822 // Revision 1.68 1998/04/03 22:09:03 curt
823 // Converting to Gnu autoconf system.
825 // Revision 1.67 1998/03/23 21:24:37 curt
826 // Source code formating tweaks.
828 // Revision 1.66 1998/03/14 00:31:20 curt
829 // Beginning initial terrain texturing experiments.
831 // Revision 1.65 1998/03/09 22:45:57 curt
832 // Minor tweaks for building on sparc platform.
834 // Revision 1.64 1998/02/20 00:16:23 curt
835 // Thursday's tweaks.
837 // Revision 1.63 1998/02/16 16:17:39 curt
840 // Revision 1.62 1998/02/16 13:39:42 curt
841 // Miscellaneous weekend tweaks. Fixed? a cache problem that caused whole
842 // tiles to occasionally be missing.
844 // Revision 1.61 1998/02/12 21:59:46 curt
845 // Incorporated code changes contributed by Charlie Hotchkiss
846 // <chotchkiss@namg.us.anritsu.com>
848 // Revision 1.60 1998/02/11 02:50:40 curt
851 // Revision 1.59 1998/02/09 22:56:54 curt
852 // Removed "depend" files from cvs control. Other minor make tweaks.
854 // Revision 1.58 1998/02/09 15:07:49 curt
857 // Revision 1.57 1998/02/07 15:29:40 curt
858 // Incorporated HUD changes and struct/typedef changes from Charlie Hotchkiss
859 // <chotchkiss@namg.us.anritsu.com>
861 // Revision 1.56 1998/02/03 23:20:23 curt
862 // Lots of little tweaks to fix various consistency problems discovered by
863 // Solaris' CC. Fixed a bug in fg_debug.c with how the fgPrintf() wrapper
864 // passed arguments along to the real printf(). Also incorporated HUD changes
865 // by Michele America.
867 // Revision 1.55 1998/02/02 20:53:58 curt
868 // Incorporated Durk's changes.
870 // Revision 1.54 1998/01/31 00:43:10 curt
871 // Added MetroWorks patches from Carmen Volpe.
873 // Revision 1.53 1998/01/27 18:35:54 curt
876 // Revision 1.52 1998/01/27 00:47:56 curt
877 // Incorporated Paul Bleisch's <pbleisch@acm.org> new debug message
878 // system and commandline/config file processing code.
880 // Revision 1.51 1998/01/26 15:57:05 curt
881 // Tweaks for dynamic scenery development.
883 // Revision 1.50 1998/01/19 19:27:07 curt
884 // Merged in make system changes from Bob Kuehne <rpk@sgi.com>
885 // This should simplify things tremendously.
887 // Revision 1.49 1998/01/19 18:40:31 curt
888 // Tons of little changes to clean up the code and to remove fatal errors
889 // when building with the c++ compiler.
891 // Revision 1.48 1998/01/19 18:35:46 curt
892 // Minor tweaks and fixes for cygwin32.
894 // Revision 1.47 1998/01/13 00:23:08 curt
895 // Initial changes to support loading and management of scenery tiles. Note,
896 // there's still a fair amount of work left to be done.
898 // Revision 1.46 1998/01/08 02:22:06 curt
899 // Beginning to integrate Tile management subsystem.
901 // Revision 1.45 1998/01/07 03:18:55 curt
902 // Moved astronomical stuff from .../Src/Scenery to .../Src/Astro/
904 // Revision 1.44 1997/12/30 22:22:31 curt
905 // Further integration of event manager.
907 // Revision 1.43 1997/12/30 20:47:43 curt
908 // Integrated new event manager with subsystem initializations.
910 // Revision 1.42 1997/12/30 16:36:47 curt
911 // Merged in Durk's changes ...
913 // Revision 1.41 1997/12/30 13:06:56 curt
914 // A couple lighting tweaks ...
916 // Revision 1.40 1997/12/30 01:38:37 curt
917 // Switched back to per vertex normals and smooth shading for terrain.
919 // Revision 1.39 1997/12/22 23:45:45 curt
920 // First stab at sunset/sunrise sky glow effects.
922 // Revision 1.38 1997/12/22 04:14:28 curt
923 // Aligned sky with sun so dusk/dawn effects can be correct relative to the sun.
925 // Revision 1.37 1997/12/19 23:34:03 curt
926 // Lot's of tweaking with sky rendering and lighting.
928 // Revision 1.36 1997/12/19 16:44:57 curt
929 // Working on scene rendering order and options.
931 // Revision 1.35 1997/12/18 23:32:32 curt
932 // First stab at sky dome actually starting to look reasonable. :-)
934 // Revision 1.34 1997/12/17 23:13:34 curt
935 // Began working on rendering a sky.
937 // Revision 1.33 1997/12/15 23:54:45 curt
938 // Add xgl wrappers for debugging.
939 // Generate terrain normals on the fly.
941 // Revision 1.32 1997/12/15 20:59:08 curt
944 // Revision 1.31 1997/12/12 21:41:25 curt
945 // More light/material property tweaking ... still a ways off.
947 // Revision 1.30 1997/12/12 19:52:47 curt
948 // Working on lightling and material properties.
950 // Revision 1.29 1997/12/11 04:43:54 curt
951 // Fixed sun vector and lighting problems. I thing the moon is now lit
954 // Revision 1.28 1997/12/10 22:37:45 curt
955 // Prepended "fg" on the name of all global structures that didn't have it yet.
956 // i.e. "struct WEATHER {}" became "struct fgWEATHER {}"
958 // Revision 1.27 1997/12/09 05:11:54 curt
959 // Working on tweaking lighting.
961 // Revision 1.26 1997/12/09 04:25:29 curt
962 // Working on adding a global lighting params structure.
964 // Revision 1.25 1997/12/08 22:54:09 curt
965 // Enabled GL_CULL_FACE.
967 // Revision 1.24 1997/11/25 19:25:32 curt
968 // Changes to integrate Durk's moon/sun code updates + clean up.
970 // Revision 1.23 1997/11/15 18:16:34 curt
973 // Revision 1.22 1997/10/30 12:38:41 curt
974 // Working on new scenery subsystem.
976 // Revision 1.21 1997/09/23 00:29:38 curt
977 // Tweaks to get things to compile with gcc-win32.
979 // Revision 1.20 1997/09/22 14:44:19 curt
980 // Continuing to try to align stars correctly.
982 // Revision 1.19 1997/09/18 16:20:08 curt
983 // At dusk/dawn add/remove stars in stages.
985 // Revision 1.18 1997/09/16 22:14:51 curt
986 // Tweaked time of day lighting equations. Don't draw stars during the day.
988 // Revision 1.17 1997/09/16 15:50:29 curt
989 // Working on star alignment and time issues.
991 // Revision 1.16 1997/09/13 02:00:06 curt
992 // Mostly working on stars and generating sidereal time for accurate star
995 // Revision 1.15 1997/09/05 14:17:27 curt
996 // More tweaking with stars.
998 // Revision 1.14 1997/09/05 01:35:53 curt
999 // Working on getting stars right.
1001 // Revision 1.13 1997/09/04 02:17:34 curt
1004 // Revision 1.12 1997/08/27 21:32:24 curt
1005 // Restructured view calculation code. Added stars.
1007 // Revision 1.11 1997/08/27 03:30:16 curt
1008 // Changed naming scheme of basic shared structures.
1010 // Revision 1.10 1997/08/25 20:27:22 curt
1011 // Merged in initial HUD and Joystick code.
1013 // Revision 1.9 1997/08/22 21:34:39 curt
1014 // Doing a bit of reorganizing and house cleaning.
1016 // Revision 1.8 1997/08/19 23:55:03 curt
1017 // Worked on better simulating real lighting.
1019 // Revision 1.7 1997/08/16 12:22:38 curt
1020 // Working on improving the lighting/shading.
1022 // Revision 1.6 1997/08/13 20:24:56 curt
1023 // Changes due to changing sunpos interface.
1025 // Revision 1.5 1997/08/06 21:08:32 curt
1026 // Sun position now really* works (I think) ... I still have sun time warping
1027 // code in place, probably should remove it soon.
1029 // Revision 1.4 1997/08/06 15:41:26 curt
1030 // Working on correct sun position.
1032 // Revision 1.3 1997/08/06 00:24:22 curt
1033 // Working on correct real time sun lighting.
1035 // Revision 1.2 1997/08/04 20:25:15 curt
1036 // Organizational tweaking.
1038 // Revision 1.1 1997/08/02 18:45:00 curt
1039 // Renamed GLmain.c GLUTmain.c
1041 // Revision 1.43 1997/08/02 16:23:47 curt
1044 // Revision 1.42 1997/08/01 19:43:33 curt
1045 // Making progress with coordinate system overhaul.
1047 // Revision 1.41 1997/07/31 22:52:37 curt
1048 // Working on redoing internal coordinate systems & scenery transformations.
1050 // Revision 1.40 1997/07/30 16:12:42 curt
1051 // Moved fg_random routines from Util/ to Math/
1053 // Revision 1.39 1997/07/21 14:45:01 curt
1056 // Revision 1.38 1997/07/19 23:04:47 curt
1057 // Added an initial weather section.
1059 // Revision 1.37 1997/07/19 22:34:02 curt
1060 // Moved PI definitions to ../constants.h
1061 // Moved random() stuff to ../Utils/ and renamed fg_random()
1063 // Revision 1.36 1997/07/18 23:41:25 curt
1064 // Tweaks for building with Cygnus Win32 compiler.
1066 // Revision 1.35 1997/07/18 14:28:34 curt
1067 // Hacked in some support for wind/turbulence.
1069 // Revision 1.34 1997/07/16 20:04:48 curt
1070 // Minor tweaks to aid Win32 port.
1072 // Revision 1.33 1997/07/12 03:50:20 curt
1073 // Added an #include <Windows32/Base.h> to help compiling for Win32
1075 // Revision 1.32 1997/07/11 03:23:18 curt
1076 // Solved some scenery display/orientation problems. Still have a positioning
1077 // (or transformation?) problem.
1079 // Revision 1.31 1997/07/11 01:29:58 curt
1080 // More tweaking of terrian floor.
1082 // Revision 1.30 1997/07/10 04:26:37 curt
1083 // We now can interpolated ground elevation for any position in the grid. We
1084 // can use this to enforce a "hard" ground. We still need to enforce some
1085 // bounds checking so that we don't try to lookup data points outside the
1088 // Revision 1.29 1997/07/09 21:31:12 curt
1089 // Working on making the ground "hard."
1091 // Revision 1.28 1997/07/08 18:20:12 curt
1092 // Working on establishing a hard ground.
1094 // Revision 1.27 1997/07/07 20:59:49 curt
1095 // Working on scenery transformations to enable us to fly fluidly over the
1096 // poles with no discontinuity/distortion in scenery.
1098 // Revision 1.26 1997/07/05 20:43:34 curt
1099 // renamed mat3 directory to Math so we could add other math related routines.
1101 // Revision 1.25 1997/06/29 21:19:17 curt
1102 // Working on scenery management system.
1104 // Revision 1.24 1997/06/26 22:14:53 curt
1105 // Beginning work on a scenery management system.
1107 // Revision 1.23 1997/06/26 19:08:33 curt
1108 // Restructuring make, adding automatic "make dep" support.
1110 // Revision 1.22 1997/06/25 15:39:47 curt
1111 // Minor changes to compile with rsxnt/win32.
1113 // Revision 1.21 1997/06/22 21:44:41 curt
1114 // Working on intergrating the VRML (subset) parser.
1116 // Revision 1.20 1997/06/21 17:12:53 curt
1117 // Capitalized subdirectory names.
1119 // Revision 1.19 1997/06/18 04:10:31 curt
1120 // A couple more runway tweaks ...
1122 // Revision 1.18 1997/06/18 02:21:24 curt
1123 // Hacked in a runway
1125 // Revision 1.17 1997/06/17 16:51:58 curt
1126 // Timer interval stuff now uses gettimeofday() instead of ftime()
1128 // Revision 1.16 1997/06/17 04:19:16 curt
1129 // More timer related tweaks with respect to view direction changes.
1131 // Revision 1.15 1997/06/17 03:41:10 curt
1132 // Nonsignal based interval timing is now working.
1133 // This would be a good time to look at cleaning up the code structure a bit.
1135 // Revision 1.14 1997/06/16 19:32:51 curt
1136 // Starting to add general timer support.
1138 // Revision 1.13 1997/06/02 03:40:06 curt
1139 // A tiny bit more view tweaking.
1141 // Revision 1.12 1997/06/02 03:01:38 curt
1142 // Working on views (side, front, back, transitions, etc.)
1144 // Revision 1.11 1997/05/31 19:16:25 curt
1145 // Elevator trim added.
1147 // Revision 1.10 1997/05/31 04:13:52 curt
1148 // WE CAN NOW FLY!!!
1150 // Continuing work on the LaRCsim flight model integration.
1151 // Added some MSFS-like keyboard input handling.
1153 // Revision 1.9 1997/05/30 19:27:01 curt
1154 // The LaRCsim flight model is starting to look like it is working.
1156 // Revision 1.8 1997/05/30 03:54:10 curt
1157 // Made a bit more progress towards integrating the LaRCsim flight model.
1159 // Revision 1.7 1997/05/29 22:39:49 curt
1160 // Working on incorporating the LaRCsim flight model.
1162 // Revision 1.6 1997/05/29 12:31:39 curt
1163 // Minor tweaks, moving towards general flight model integration.
1165 // Revision 1.5 1997/05/29 02:33:23 curt
1166 // Updated to reflect changing interfaces in other "modules."
1168 // Revision 1.4 1997/05/27 17:44:31 curt
1169 // Renamed & rearranged variables and routines. Added some initial simple
1170 // timer/alarm routines so the flight model can be updated on a regular
1173 // Revision 1.3 1997/05/23 15:40:25 curt
1174 // Added GNU copyright headers.
1177 // Revision 1.2 1997/05/23 00:35:12 curt
1178 // Trying to get fog to work ...
1180 // Revision 1.1 1997/05/21 15:57:51 curt
1181 // Renamed due to added GLUT support.
1183 // Revision 1.3 1997/05/19 18:22:42 curt
1184 // Parameter tweaking ... starting to stub in fog support.
1186 // Revision 1.2 1997/05/17 00:17:34 curt
1187 // Trying to stub in support for standard OpenGL.
1189 // Revision 1.1 1997/05/16 16:05:52 curt
1190 // Initial revision.