]> git.mxchange.org Git - flightgear.git/blob - Main/GLUTmain.c
Working on improving the lighting/shading.
[flightgear.git] / Main / GLUTmain.c
1 /**************************************************************************
2  * GLmain.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 #include <stdio.h>
28
29 #ifdef WIN32
30 #  include <windows.h>                     
31 #endif
32
33 #ifdef GLUT
34     #include <GL/glut.h>
35     #include "GLUTkey.h"
36 #endif
37
38 #include "../constants.h"
39
40 #include "../Aircraft/aircraft.h"
41 #include "../Scenery/mesh.h"
42 #include "../Scenery/scenery.h"
43 #include "../Math/fg_geodesy.h"
44 #include "../Math/fg_random.h"
45 #include "../Math/mat3.h"
46 #include "../Math/polar.h"
47 #include "../Time/fg_time.h"
48 #include "../Time/fg_timer.h"
49 #include "../Time/sunpos.h"
50 #include "../Weather/weather.h"
51
52
53 /* This is a record containing all the info for the aircraft currently
54    being operated */
55 struct aircraft_params current_aircraft;
56
57 /* view parameters */
58 static GLfloat win_ratio = 1.0;
59
60 /* sun direction */
61 static GLfloat sun_vec[4] = {1.0, 0.0, 0.0, 0.0 };
62
63 /* temporary hack */
64 /* extern struct mesh *mesh_ptr; */
65 /* Function prototypes */
66 /* GLint fgSceneryCompile_OLD(); */
67 /* static void fgSceneryDraw_OLD(); */
68
69 /* pointer to scenery structure */
70 /* static GLint scenery, runway; */
71
72 /* Another hack */
73 double fogDensity = 60000.0; /* in meters */
74 double view_offset = 0.0;
75 double goal_view_offset = 0.0;
76
77 /* Another hack */
78 #define DEFAULT_TIMER_HZ 20
79 #define DEFAULT_MULTILOOP 6
80 #define DEFAULT_MODEL_HZ (DEFAULT_TIMER_HZ * DEFAULT_MULTILOOP)
81
82 double Simtime;
83
84 /* Another hack */
85 int use_signals = 0;
86
87
88 /**************************************************************************
89  * fgInitVisuals() -- Initialize various GL/view parameters
90  **************************************************************************/
91
92 static void fgInitVisuals() {
93     /* if the 4th field is 0.0, this specifies a direction ... */
94     static GLfloat fogColor[4] = {0.65, 0.65, 0.85, 1.0};
95     
96     glEnable( GL_DEPTH_TEST );
97     /* glFrontFace(GL_CW); */
98     glEnable( GL_CULL_FACE );
99
100     /* If enabled, normal vectors specified with glNormal are scaled
101        to unit length after transformation.  See glNormal. */
102     glEnable( GL_NORMALIZE );
103
104     glLightfv( GL_LIGHT0, GL_POSITION, sun_vec );
105     glEnable( GL_LIGHTING );
106     glEnable( GL_LIGHT0 );
107
108     glShadeModel( GL_FLAT ); /* glShadeModel( GL_SMOOTH ); */
109
110     glEnable( GL_FOG );
111     glFogi (GL_FOG_MODE, GL_LINEAR);
112     /* glFogf (GL_FOG_START, 1.0); */
113     glFogf (GL_FOG_END, fogDensity);
114     glFogfv (GL_FOG_COLOR, fogColor);
115     /* glFogf (GL_FOG_DENSITY, fogDensity); */
116     /* glHint (GL_FOG_HINT, GL_FASTEST); */
117
118     glClearColor(0.6, 0.6, 0.9, 1.0);
119 }
120
121
122 /**************************************************************************
123  * Update the view volume, position, and orientation
124  **************************************************************************/
125
126 static void fgUpdateViewParams() {
127     struct fgCartesianPoint view_pos /*, alt_up */;
128     struct flight_params *f;
129     struct time_params *t;
130     MAT3mat R, TMP, UP, LOCAL, VIEW;
131     MAT3vec vec, view_up, forward, view_forward, local_up, nup, nsun;
132     double sun_angle, temp, ambient, diffuse;
133     GLfloat color[4] = { 1.0, 1.0, 0.50, 1.0 };
134     GLfloat amb[4], diff[4];
135
136     f = &current_aircraft.flight;
137     t = &cur_time_params;
138
139     /* Tell GL we are about to modify the projection parameters */
140     glMatrixMode(GL_PROJECTION);
141     glLoadIdentity();
142     gluPerspective(45.0, 1.0/win_ratio, 1.0, 200000.0);
143
144     glMatrixMode(GL_MODELVIEW);
145     glLoadIdentity();
146     
147     /* calculate view position in current FG view coordinate system */
148     view_pos = fgPolarToCart(FG_Longitude, FG_Lat_geocentric, 
149                              FG_Radius_to_vehicle * FEET_TO_METER + 1.0);
150     view_pos.x -= scenery.center.x;
151     view_pos.y -= scenery.center.y;
152     view_pos.z -= scenery.center.z;
153
154     printf("View pos = %.4f, %.4f, %.4f\n", view_pos.x, view_pos.y, view_pos.z);
155
156     /* Derive the LOCAL aircraft rotation matrix (roll, pitch, yaw) */
157     MAT3_SET_VEC(vec, 0.0, 0.0, 1.0);
158     MAT3rotate(R, vec, FG_Phi);
159     /* printf("Roll matrix\n"); */
160     /* MAT3print(R, stdout); */
161
162     MAT3_SET_VEC(vec, 0.0, 1.0, 0.0);
163     /* MAT3mult_vec(vec, vec, R); */
164     MAT3rotate(TMP, vec, FG_Theta);
165     /* printf("Pitch matrix\n"); */
166     /* MAT3print(TMP, stdout); */
167     MAT3mult(R, R, TMP);
168
169     MAT3_SET_VEC(vec, 1.0, 0.0, 0.0);
170     /* MAT3mult_vec(vec, vec, R); */
171     /* MAT3rotate(TMP, vec, FG_Psi - FG_PI_2); */
172     MAT3rotate(TMP, vec, -FG_Psi);
173     /* printf("Yaw matrix\n");
174     MAT3print(TMP, stdout); */
175     MAT3mult(LOCAL, R, TMP);
176     /* printf("LOCAL matrix\n"); */
177     /* MAT3print(LOCAL, stdout); */
178
179     /* Derive the local UP transformation matrix based on *geodetic*
180      * coordinates */
181     MAT3_SET_VEC(vec, 0.0, 0.0, 1.0);
182     MAT3rotate(R, vec, FG_Longitude);     /* R = rotate about Z axis */
183     /* printf("Longitude matrix\n"); */
184     /* MAT3print(R, stdout); */
185
186     MAT3_SET_VEC(vec, 0.0, 1.0, 0.0);
187     MAT3mult_vec(vec, vec, R);
188     MAT3rotate(TMP, vec, -FG_Latitude);  /* TMP = rotate about X axis */
189     /* printf("Latitude matrix\n"); */
190     /* MAT3print(TMP, stdout); */
191
192     MAT3mult(UP, R, TMP);
193     /* printf("Local up matrix\n"); */
194     /* MAT3print(UP, stdout); */
195
196     MAT3_SET_VEC(local_up, 1.0, 0.0, 0.0);
197     MAT3mult_vec(local_up, local_up, UP);
198
199     printf("    Local Up = (%.4f, %.4f, %.4f)\n", local_up[0], local_up[1], 
200            local_up[2]);
201     
202     /* Alternative method to Derive local up vector based on
203      * *geodetic* coordinates */
204     /* alt_up = fgPolarToCart(FG_Longitude, FG_Latitude, 1.0); */
205     /* printf("    Alt Up = (%.4f, %.4f, %.4f)\n", 
206        alt_up.x, alt_up.y, alt_up.z); */
207
208     /* Derive the VIEW matrix */
209     MAT3mult(VIEW, LOCAL, UP);
210     /* printf("VIEW matrix\n"); */
211     /* MAT3print(VIEW, stdout); */
212
213     /* generate the current up, forward, and fwrd-view vectors */
214     MAT3_SET_VEC(vec, 1.0, 0.0, 0.0);
215     MAT3mult_vec(view_up, vec, VIEW);
216
217     MAT3_SET_VEC(vec, 0.0, 0.0, 1.0);
218     MAT3mult_vec(forward, vec, VIEW);
219     printf("Forward vector is (%.2f,%.2f,%.2f)\n", forward[0], forward[1], 
220            forward[2]);
221
222     MAT3rotate(TMP, view_up, view_offset);
223     MAT3mult_vec(view_forward, forward, TMP);
224
225     /* set up our view volume */
226     gluLookAt(view_pos.x, view_pos.y, view_pos.z,
227               view_pos.x + view_forward[0], view_pos.y + view_forward[1], 
228               view_pos.z + view_forward[2],
229               view_up[0], view_up[1], view_up[2]);
230
231     /* set the sun position */
232     glLightfv( GL_LIGHT0, GL_POSITION, sun_vec );
233
234     /* calculate lighting parameters based on sun's relative angle to
235      * local up */
236     MAT3_COPY_VEC(nup, local_up);
237     nsun[0] = t->fg_sunpos.x; 
238     nsun[1] = t->fg_sunpos.y;
239     nsun[2] = t->fg_sunpos.z;
240     MAT3_NORMALIZE_VEC(nup, temp);
241     MAT3_NORMALIZE_VEC(nsun, temp);
242
243     sun_angle = acos(MAT3_DOT_PRODUCT(nup, nsun));
244     printf("SUN ANGLE relative to current location = %.3f\n", sun_angle);
245
246     if ( (sun_angle >= -FG_PI) && (sun_angle <= FG_PI) ) {
247         /* day time */
248         /* ya kind'a have to plot this to see the magic */
249         ambient = 0.4 * cos(0.15*sun_angle*sun_angle);
250         diffuse = 0.4 * cos(0.45*sun_angle);
251     } else {
252         /* night time */
253         ambient = 0.4;
254         diffuse = 0.0;
255     }
256
257     amb[0] = color[0] * ambient;
258     amb[1] = color[1] * ambient;
259     amb[2] = color[2] * ambient;
260     amb[3] = color[3];
261
262     diff[0] = color[0] * diffuse;
263     diff[1] = color[1] * diffuse;
264     diff[2] = color[2] * diffuse;
265     diff[3] = color[3];
266
267     glMaterialfv(GL_FRONT, GL_AMBIENT, amb );
268     glMaterialfv(GL_FRONT, GL_DIFFUSE, diff );
269 }
270
271
272 /**************************************************************************
273  * Update all Visuals (redraws anything graphics related)
274  **************************************************************************/
275
276 static void fgUpdateVisuals( void ) {
277     /* update view volume parameters */
278     fgUpdateViewParams();
279
280     glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
281
282     /* Tell GL we are switching to model view parameters */
283     glMatrixMode(GL_MODELVIEW);
284     /* glLoadIdentity(); */
285
286     /* draw scenery */
287     fgSceneryRender();
288
289     #ifdef GLUT
290       glutSwapBuffers();
291     #endif
292 }
293
294
295 /**************************************************************************
296  * Update internal time dependent calculations (i.e. flight model)
297  **************************************************************************/
298
299 void fgUpdateTimeDepCalcs(int multi_loop) {
300     struct flight_params *f;
301     struct time_params *t;
302     int i;
303
304     f = &current_aircraft.flight;
305     t = &cur_time_params;
306
307     /* update the flight model */
308     if ( multi_loop < 0 ) {
309         multi_loop = DEFAULT_MULTILOOP;
310     }
311
312     /* printf("updating flight model x %d\n", multi_loop); */
313     fgFlightModelUpdate(FG_LARCSIM, f, multi_loop);
314
315     /* refresh shared sun position and sun_vec */
316     fgUpdateSunPos();
317
318     /* the sun position has to be translated just like everything else */
319     sun_vec[0] = t->fg_sunpos.x - scenery.center.x; 
320     sun_vec[1] = t->fg_sunpos.y - scenery.center.y;
321     sun_vec[2] = t->fg_sunpos.z - scenery.center.z;
322     /* make this a directional light source only */
323     sun_vec[3] = 0.0;
324
325     /* update the view angle */
326     for ( i = 0; i < multi_loop; i++ ) {
327         if ( fabs(goal_view_offset - view_offset) < 0.05 ) {
328             view_offset = goal_view_offset;
329             break;
330         } else {
331             /* move view_offset towards goal_view_offset */
332             if ( goal_view_offset > view_offset ) {
333                 if ( goal_view_offset - view_offset < FG_PI ) {
334                     view_offset += 0.01;
335                 } else {
336                     view_offset -= 0.01;
337                 }
338             } else {
339                 if ( view_offset - goal_view_offset < FG_PI ) {
340                     view_offset -= 0.01;
341                 } else {
342                     view_offset += 0.01;
343                 }
344             }
345             if ( view_offset > FG_2PI ) {
346                 view_offset -= FG_2PI;
347             } else if ( view_offset < 0 ) {
348                 view_offset += FG_2PI;
349             }
350         }
351     }
352 }
353
354
355 void fgInitTimeDepCalcs() {
356     /* initialize timer */
357
358 #ifdef USE_ITIMER
359     fgTimerInit( 1.0 / DEFAULT_TIMER_HZ, fgUpdateTimeDepCalcs );
360 #endif USE_ITIMER
361
362 }
363
364
365 /**************************************************************************
366  * Scenery management routines
367  **************************************************************************/
368
369 /* static void fgSceneryInit_OLD() { */
370     /* make scenery */
371 /*     scenery = fgSceneryCompile_OLD();
372     runway = fgRunwayHack_OLD(0.69, 53.07);
373 } */
374
375
376 /* create the scenery */
377 /* GLint fgSceneryCompile_OLD() {
378     GLint scenery;
379
380     scenery = mesh2GL(mesh_ptr_OLD);
381
382     return(scenery);
383 }
384 */
385
386 /* hack in a runway */
387 /* GLint fgRunwayHack_OLD(double width, double length) {
388     static GLfloat concrete[4] = { 0.5, 0.5, 0.5, 1.0 };
389     static GLfloat line[4]     = { 0.9, 0.9, 0.9, 1.0 };
390     int i;
391     int num_lines = 16;
392     float line_len, line_width_2, cur_pos;
393
394     runway = glGenLists(1);
395     glNewList(runway, GL_COMPILE);
396     */
397     /* draw concrete */
398 /*    glBegin(GL_POLYGON);
399     glMaterialfv( GL_FRONT, GL_AMBIENT_AND_DIFFUSE, concrete );
400     glNormal3f(0.0, 0.0, 1.0);
401
402     glVertex3d( 0.0,   -width/2.0, 0.0);
403     glVertex3d( 0.0,    width/2.0, 0.0);
404     glVertex3d(length,  width/2.0, 0.0);
405     glVertex3d(length, -width/2.0, 0.0);
406     glEnd();
407     */
408     /* draw center line */
409 /*    glMaterialfv( GL_FRONT, GL_AMBIENT_AND_DIFFUSE, line );
410     line_len = length / ( 2 * num_lines + 1);
411     printf("line_len = %.3f\n", line_len);
412     line_width_2 = 0.02;
413     cur_pos = line_len;
414     for ( i = 0; i < num_lines; i++ ) {
415         glBegin(GL_POLYGON);
416         glVertex3d( cur_pos, -line_width_2, 0.005);
417         glVertex3d( cur_pos,  line_width_2, 0.005);
418         cur_pos += line_len;
419         glVertex3d( cur_pos,  line_width_2, 0.005);
420         glVertex3d( cur_pos, -line_width_2, 0.005);
421         cur_pos += line_len;
422         glEnd();
423     }
424
425     glEndList();
426
427     return(runway);
428 }
429 */
430
431 /* draw the scenery */
432 /*static void fgSceneryDraw_OLD() {
433     static float z = 32.35;
434
435     glPushMatrix();
436
437     glCallList(scenery);
438
439     printf("*** Drawing runway at %.2f\n", z);
440
441     glTranslatef( -398391.28, 120070.41, 32.35);
442     glRotatef(170.0, 0.0, 0.0, 1.0);
443     glCallList(runway);
444
445     glPopMatrix();
446 }
447 */
448
449 /* What should we do when we have nothing else to do?  How about get
450  * ready for the next move and update the display? */
451 static void fgMainLoop( void ) {
452     static int remainder = 0;
453     int elapsed, multi_loop;
454     double rough_elev;
455     struct flight_params *f;
456
457     f = &current_aircraft.flight;
458
459     elapsed = fgGetTimeInterval();
460     printf("Time interval is = %d, previous remainder is = %d\n", elapsed, 
461            remainder);
462     printf("--> Frame rate is = %.2f\n", 1000.0 / (float)elapsed);
463     elapsed += remainder;
464
465     multi_loop = ((float)elapsed * 0.001) * DEFAULT_MODEL_HZ;
466     remainder = elapsed - ((multi_loop*1000) / DEFAULT_MODEL_HZ);
467     printf("Model iterations needed = %d, new remainder = %d\n", multi_loop, 
468            remainder);
469
470     aircraft_debug(1);
471     fgUpdateVisuals();
472
473     if ( ! use_signals ) {
474         /* flight model */
475         fgUpdateTimeDepCalcs(multi_loop);
476     }
477
478     /* I'm just sticking this here for now, it should probably move 
479      * eventually */
480     rough_elev = mesh_altitude(FG_Longitude * RAD_TO_ARCSEC, 
481                                FG_Latitude  * RAD_TO_ARCSEC);
482     printf("Ground elevation is %.2f meters here.\n", rough_elev);
483     /* FG_Runway_altitude = rough_elev * METER_TO_FEET; */
484
485     if ( FG_Altitude * FEET_TO_METER < rough_elev + 3.758099) {
486         /* set this here, otherwise if we set runway height above our
487            current height we get a really nasty bounce. */
488         FG_Runway_altitude = FG_Altitude - 3.758099;
489
490         /* now set aircraft altitude above ground */
491         FG_Altitude = rough_elev * METER_TO_FEET + 3.758099;
492         printf("<*> resetting altitude to %.0f meters\n", 
493                FG_Altitude * FEET_TO_METER);
494     }
495
496     /* update the weather for our current position */
497     fgWeatherUpdate(FG_Longitude * RAD_TO_ARCSEC, 
498                     FG_Latitude * RAD_TO_ARCSEC, 
499                     FG_Altitude * FEET_TO_METER);
500 }
501
502
503 /**************************************************************************
504  * Handle new window size or exposure
505  **************************************************************************/
506
507 static void fgReshape( int width, int height ) {
508     /* Do this so we can call fgReshape(0,0) ourselves without having to know
509      * what the values of width & height are. */
510     if ( (height > 0) && (width > 0) ) {
511         win_ratio = (GLfloat) height / (GLfloat) width;
512     }
513
514     /* Inform gl of our view window size */
515     glViewport(0, 0, (GLint)width, (GLint)height);
516
517     fgUpdateViewParams();
518     
519     glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
520 }
521
522
523 /**************************************************************************
524  * Main ...
525  **************************************************************************/
526
527 int main( int argc, char *argv[] ) {
528     struct flight_params *f;
529     double rough_elev;
530
531     f = &current_aircraft.flight;
532
533     printf("Flight Gear: prototype code to test OpenGL, LaRCsim, and VRML\n\n");
534
535
536     /**********************************************************************
537      * Initialize the Window/Graphics environment.
538      **********************************************************************/
539
540     #ifdef GLUT
541       /* initialize GLUT */
542       glutInit(&argc, argv);
543
544       /* Define Display Parameters */
545       glutInitDisplayMode( GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE );
546
547       /* Define initial window size */
548       glutInitWindowSize(640, 480);
549
550       /* Initialize windows */
551       glutCreateWindow("Flight Gear");
552     #endif
553
554     /* seed the random number generater */
555     fg_srandom();
556
557     /* setup view parameters, only makes GL calls */
558     fgInitVisuals();
559
560
561     /****************************************************************
562      * The following section sets up the flight model EOM parameters and 
563      * should really be read in from one or more files.
564      ****************************************************************/
565
566     /* Globe Aiport, AZ */
567     FG_Runway_altitude = 3234.5;
568     FG_Runway_latitude = 120070.41;
569     FG_Runway_longitude = -398391.28;
570     FG_Runway_heading = 102.0 * DEG_TO_RAD;
571
572     /* Initial Position at GLOBE airport */
573     FG_Latitude  = (  120070.41 / 3600.0 ) * DEG_TO_RAD;
574     FG_Longitude = ( -398391.28 / 3600.0 ) * DEG_TO_RAD;
575     FG_Altitude = FG_Runway_altitude + 3.758099;
576
577     /* Initial Position north of the city of Globe */
578     /* FG_Latitude  = (  120625.64 / 3600.0 ) * DEG_TO_RAD; */
579     /* FG_Longitude = ( -398673.28 / 3600.0 ) * DEG_TO_RAD; */
580     /* FG_Altitude = 0.0 + 3.758099; */
581
582     printf("Initial position is: (%.4f, %.4f, %.2f)\n", FG_Latitude, 
583            FG_Longitude, FG_Altitude);
584
585       /* Initial Velocity */
586     FG_V_north = 0.0 /*  7.287719E+00 */;
587     FG_V_east  = 0.0 /*  1.521770E+03 */;
588     FG_V_down  = 0.0 /* -1.265722E-05 */;
589
590     /* Initial Orientation */
591     FG_Phi   = -2.658474E-06;
592     FG_Theta =  7.401790E-03;
593     FG_Psi   =  270.0 * DEG_TO_RAD;
594     /* FG_Psi   =  0.0 * DEG_TO_RAD; */
595
596     /* Initial Angular B rates */
597     FG_P_body = 7.206685E-05;
598     FG_Q_body = 0.000000E+00;
599     FG_R_body = 9.492658E-05;
600
601     FG_Earth_position_angle = 0.000000E+00;
602
603     /* Mass properties and geometry values */
604     FG_Mass = 8.547270E+01;
605     FG_I_xx = 1.048000E+03;
606     FG_I_yy = 3.000000E+03;
607     FG_I_zz = 3.530000E+03;
608     FG_I_xz = 0.000000E+00;
609
610     /* CG position w.r.t. ref. point */
611     FG_Dx_cg = 0.000000E+00;
612     FG_Dy_cg = 0.000000E+00;
613     FG_Dz_cg = 0.000000E+00;
614
615     /* Set initial position and slew parameters */
616     /* fgSlewInit(-398391.3, 120070.41, 244, 3.1415); */ /* GLOBE Airport */
617     /* fgSlewInit(-335340,162540, 15, 4.38); */
618     /* fgSlewInit(-398673.28,120625.64, 53, 4.38); */
619
620    /* Initialize the Scenery Management system */
621     fgSceneryInit();
622
623     /* Tell the Scenery Management system where we are so it can load
624      * the correct scenery data */
625     fgSceneryUpdate(FG_Latitude, FG_Longitude, FG_Altitude);
626
627     /* I'm just sticking this here for now, it should probably move 
628      * eventually */
629     rough_elev = mesh_altitude(FG_Longitude * RAD_TO_DEG * 3600.0, 
630                                FG_Latitude  * RAD_TO_DEG * 3600.0);
631     printf("Ground elevation is %.2f meters here.\n", rough_elev);
632     if ( rough_elev > -9990.0 ) {
633         FG_Runway_altitude = rough_elev * METER_TO_FEET;
634     }
635
636     if ( FG_Altitude < FG_Runway_altitude ) {
637         FG_Altitude = FG_Runway_altitude + 3.758099;
638     }
639     /* end of thing that I just stuck in that I should probably move */
640
641     /* Initialize the flight model data structures base on above values */
642     fgFlightModelInit( FG_LARCSIM, f, 1.0 / DEFAULT_MODEL_HZ );
643
644     if ( use_signals ) {
645         /* init timer routines, signals, etc.  Arrange for an alarm
646            signal to be generated, etc. */
647         fgInitTimeDepCalcs();
648     }
649
650     /* Initialize the weather modeling subsystem */
651     fgWeatherInit();
652
653     /**********************************************************************
654      * Initialize the Event Handlers.
655      **********************************************************************/
656
657     #ifdef GLUT
658       /* call fgReshape() on window resizes */
659       glutReshapeFunc( fgReshape );
660
661       /* call key() on keyboard event */
662       glutKeyboardFunc( GLUTkey );
663       glutSpecialFunc( GLUTspecialkey );
664
665       /* call fgMainLoop() whenever there is nothing else to do */
666       glutIdleFunc( fgMainLoop );
667
668       /* draw the scene */
669       glutDisplayFunc( fgUpdateVisuals );
670
671       /* pass control off to the GLUT event handler */
672       glutMainLoop();
673     #endif
674
675     return(0);
676 }
677
678
679 #ifdef NO_PRINTF
680   #include <stdarg.h>
681   int printf (const char *format, ...) {
682   }
683 #endif
684
685
686 /* $Log$
687 /* Revision 1.7  1997/08/16 12:22:38  curt
688 /* Working on improving the lighting/shading.
689 /*
690  * Revision 1.6  1997/08/13 20:24:56  curt
691  * Changes due to changing sunpos interface.
692  *
693  * Revision 1.5  1997/08/06 21:08:32  curt
694  * Sun position now *really* works (I think) ... I still have sun time warping
695  * code in place, probably should remove it soon.
696  *
697  * Revision 1.4  1997/08/06 15:41:26  curt
698  * Working on correct sun position.
699  *
700  * Revision 1.3  1997/08/06 00:24:22  curt
701  * Working on correct real time sun lighting.
702  *
703  * Revision 1.2  1997/08/04 20:25:15  curt
704  * Organizational tweaking.
705  *
706  * Revision 1.1  1997/08/02 18:45:00  curt
707  * Renamed GLmain.c GLUTmain.c
708  *
709  * Revision 1.43  1997/08/02 16:23:47  curt
710  * Misc. tweaks.
711  *
712  * Revision 1.42  1997/08/01 19:43:33  curt
713  * Making progress with coordinate system overhaul.
714  *
715  * Revision 1.41  1997/07/31 22:52:37  curt
716  * Working on redoing internal coordinate systems & scenery transformations.
717  *
718  * Revision 1.40  1997/07/30 16:12:42  curt
719  * Moved fg_random routines from Util/ to Math/
720  *
721  * Revision 1.39  1997/07/21 14:45:01  curt
722  * Minor tweaks.
723  *
724  * Revision 1.38  1997/07/19 23:04:47  curt
725  * Added an initial weather section.
726  *
727  * Revision 1.37  1997/07/19 22:34:02  curt
728  * Moved PI definitions to ../constants.h
729  * Moved random() stuff to ../Utils/ and renamed fg_random()
730  *
731  * Revision 1.36  1997/07/18 23:41:25  curt
732  * Tweaks for building with Cygnus Win32 compiler.
733  *
734  * Revision 1.35  1997/07/18 14:28:34  curt
735  * Hacked in some support for wind/turbulence.
736  *
737  * Revision 1.34  1997/07/16 20:04:48  curt
738  * Minor tweaks to aid Win32 port.
739  *
740  * Revision 1.33  1997/07/12 03:50:20  curt
741  * Added an #include <Windows32/Base.h> to help compiling for Win32
742  *
743  * Revision 1.32  1997/07/11 03:23:18  curt
744  * Solved some scenery display/orientation problems.  Still have a positioning
745  * (or transformation?) problem.
746  *
747  * Revision 1.31  1997/07/11 01:29:58  curt
748  * More tweaking of terrian floor.
749  *
750  * Revision 1.30  1997/07/10 04:26:37  curt
751  * We now can interpolated ground elevation for any position in the grid.  We
752  * can use this to enforce a "hard" ground.  We still need to enforce some
753  * bounds checking so that we don't try to lookup data points outside the
754  * grid data set.
755  *
756  * Revision 1.29  1997/07/09 21:31:12  curt
757  * Working on making the ground "hard."
758  *
759  * Revision 1.28  1997/07/08 18:20:12  curt
760  * Working on establishing a hard ground.
761  *
762  * Revision 1.27  1997/07/07 20:59:49  curt
763  * Working on scenery transformations to enable us to fly fluidly over the
764  * poles with no discontinuity/distortion in scenery.
765  *
766  * Revision 1.26  1997/07/05 20:43:34  curt
767  * renamed mat3 directory to Math so we could add other math related routines.
768  *
769  * Revision 1.25  1997/06/29 21:19:17  curt
770  * Working on scenery management system.
771  *
772  * Revision 1.24  1997/06/26 22:14:53  curt
773  * Beginning work on a scenery management system.
774  *
775  * Revision 1.23  1997/06/26 19:08:33  curt
776  * Restructuring make, adding automatic "make dep" support.
777  *
778  * Revision 1.22  1997/06/25 15:39:47  curt
779  * Minor changes to compile with rsxnt/win32.
780  *
781  * Revision 1.21  1997/06/22 21:44:41  curt
782  * Working on intergrating the VRML (subset) parser.
783  *
784  * Revision 1.20  1997/06/21 17:12:53  curt
785  * Capitalized subdirectory names.
786  *
787  * Revision 1.19  1997/06/18 04:10:31  curt
788  * A couple more runway tweaks ...
789  *
790  * Revision 1.18  1997/06/18 02:21:24  curt
791  * Hacked in a runway
792  *
793  * Revision 1.17  1997/06/17 16:51:58  curt
794  * Timer interval stuff now uses gettimeofday() instead of ftime()
795  *
796  * Revision 1.16  1997/06/17 04:19:16  curt
797  * More timer related tweaks with respect to view direction changes.
798  *
799  * Revision 1.15  1997/06/17 03:41:10  curt
800  * Nonsignal based interval timing is now working.
801  * This would be a good time to look at cleaning up the code structure a bit.
802  *
803  * Revision 1.14  1997/06/16 19:32:51  curt
804  * Starting to add general timer support.
805  *
806  * Revision 1.13  1997/06/02 03:40:06  curt
807  * A tiny bit more view tweaking.
808  *
809  * Revision 1.12  1997/06/02 03:01:38  curt
810  * Working on views (side, front, back, transitions, etc.)
811  *
812  * Revision 1.11  1997/05/31 19:16:25  curt
813  * Elevator trim added.
814  *
815  * Revision 1.10  1997/05/31 04:13:52  curt
816  * WE CAN NOW FLY!!!
817  *
818  * Continuing work on the LaRCsim flight model integration.
819  * Added some MSFS-like keyboard input handling.
820  *
821  * Revision 1.9  1997/05/30 19:27:01  curt
822  * The LaRCsim flight model is starting to look like it is working.
823  *
824  * Revision 1.8  1997/05/30 03:54:10  curt
825  * Made a bit more progress towards integrating the LaRCsim flight model.
826  *
827  * Revision 1.7  1997/05/29 22:39:49  curt
828  * Working on incorporating the LaRCsim flight model.
829  *
830  * Revision 1.6  1997/05/29 12:31:39  curt
831  * Minor tweaks, moving towards general flight model integration.
832  *
833  * Revision 1.5  1997/05/29 02:33:23  curt
834  * Updated to reflect changing interfaces in other "modules."
835  *
836  * Revision 1.4  1997/05/27 17:44:31  curt
837  * Renamed & rearranged variables and routines.   Added some initial simple
838  * timer/alarm routines so the flight model can be updated on a regular 
839  * interval.
840  *
841  * Revision 1.3  1997/05/23 15:40:25  curt
842  * Added GNU copyright headers.
843  * Fog now works!
844  *
845  * Revision 1.2  1997/05/23 00:35:12  curt
846  * Trying to get fog to work ...
847  *
848  * Revision 1.1  1997/05/21 15:57:51  curt
849  * Renamed due to added GLUT support.
850  *
851  * Revision 1.3  1997/05/19 18:22:42  curt
852  * Parameter tweaking ... starting to stub in fog support.
853  *
854  * Revision 1.2  1997/05/17 00:17:34  curt
855  * Trying to stub in support for standard OpenGL.
856  *
857  * Revision 1.1  1997/05/16 16:05:52  curt
858  * Initial revision.
859  *
860  */