1 // main.cxx -- top level sim routines
3 // Written by Curtis Olson, started May 1997.
5 // Copyright (C) 1997 - 2002 Curtis L. Olson - curt@flightgear.org
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 // General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 #if defined(__linux__) && defined(__i386__)
29 # include <fpu_control.h>
33 #include <simgear/compiler.h>
39 #include <simgear/misc/exception.hxx>
40 #include <simgear/ephemeris/ephemeris.hxx>
41 #include <simgear/route/route.hxx>
43 #ifdef SG_MATH_EXCEPTION_CLASH
55 #include <string.h> // for strcmp()
62 #ifdef HAVE_SYS_STAT_H
63 # include <sys/stat.h> // for stat()
67 # include <unistd.h> // for stat()
70 #include <plib/netChat.h>
75 #include <simgear/constants.h> // for VERSION
76 #include <simgear/debug/logstream.hxx>
77 #include <simgear/math/polar3d.hxx>
78 #include <simgear/math/sg_random.h>
79 #include <simgear/misc/sg_path.hxx>
80 #ifdef FG_USE_CLOUDS_3D
81 # include <simgear/sky/clouds3d/SkySceneLoader.hpp>
82 # include <simgear/sky/clouds3d/SkyUtil.hpp>
84 #include <simgear/sky/sky.hxx>
85 #include <simgear/timing/sg_time.hxx>
87 #include <Include/general.hxx>
89 #include <Aircraft/aircraft.hxx>
91 #include <ATC/ATCmgr.hxx>
92 #include <ATC/ATCdisplay.hxx>
93 #include <ATC/AIMgr.hxx>
96 #include <Autopilot/newauto.hxx>
98 #include <Cockpit/hud.hxx>
99 #include <Cockpit/cockpit.hxx>
100 #include <Cockpit/radiostack.hxx>
102 #include <FDM/UIUCModel/uiuc_aircraftdir.h>
104 #include <Model/acmodel.hxx>
105 #include <Model/loader.hxx>
106 #include <Model/model.hxx>
107 #include <Model/modelmgr.hxx>
108 #include <Main/location.hxx>
109 #include <Model/panelnode.hxx>
110 #ifdef FG_NETWORK_OLK
111 #include <NetworkOLK/network.h>
115 #include <MultiPlayer/multiplaytxmgr.hxx>
116 #include <MultiPlayer/multiplayrxmgr.hxx>
119 #include <Objects/matlib.hxx>
120 #include <Scenery/scenery.hxx>
121 #include <Scenery/tilemgr.hxx>
122 #ifdef ENABLE_AUDIO_SUPPORT
123 # include <Sound/soundmgr.hxx>
124 # include <Sound/fg_fx.hxx>
125 # include <Sound/morse.hxx>
127 #include <Systems/system_mgr.hxx>
128 #include <Instrumentation/instrument_mgr.hxx>
129 #include <Time/FGEventMgr.hxx>
130 #include <Time/fg_timer.hxx>
131 #include <Time/light.hxx>
132 #include <Time/sunpos.hxx>
133 #include <Time/tmp.hxx>
136 #include <simgear/misc/sgstream.hxx>
137 #include <simgear/math/point3d.hxx>
138 #include <FDM/flight.hxx>
139 #include <FDM/ADA.hxx>
140 #include <Scenery/tileentry.hxx>
142 #include "fg_commands.hxx"
144 #ifdef FG_EXPERIMENTAL_POINT_LIGHTING
146 typedef void (APIENTRY * PFNGLPOINTPARAMETERFEXTPROC)(GLenum pname,
148 typedef void (APIENTRY * PFNGLPOINTPARAMETERFVEXTPROC)(GLenum pname,
149 const GLfloat *params);
151 PFNGLPOINTPARAMETERFEXTPROC glPointParameterfEXT = 0;
152 PFNGLPOINTPARAMETERFVEXTPROC glPointParameterfvEXT = 0;
156 typedef void (* OpenGLFuncExt)(GLenum pname, GLfloat param);
157 typedef void (* OpenGLFuncExtv)(GLenum pname, const GLfloat *params);
159 OpenGLFuncExt glPointParameterfEXT = 0;
160 OpenGLFuncExtv glPointParameterfvEXT = 0;
164 float default_attenuation[3] = {1.0, 0.0, 0.0};
165 //Required for using GL_extensions
166 void fgLoadDCS (void);
167 void fgUpdateDCS (void);
168 ssgSelector *ship_sel=NULL;
169 // upto 32 instances of a same object can be loaded.
170 ssgTransform *ship_pos[32];
171 double obj_lat[32],obj_lon[32],obj_alt[32],obj_pitch[32],obj_roll[32];
173 ssgSelector *lightpoints_brightness = new ssgSelector;
174 ssgTransform *lightpoints_transform = new ssgTransform;
175 FGTileEntry *dummy_tile;
178 // Clip plane settings...
179 float scene_nearplane = 0.5f;
180 float scene_farplane = 120000.0f;
182 static double delta_time_sec = 0;
186 # include <WeatherCM/FGLocalWeatherDatabase.h>
188 # include <Environment/environment_mgr.hxx>
193 #include "fg_init.hxx"
195 #include "fg_props.hxx"
196 #include "globals.hxx"
197 #include "splash.hxx"
198 #include "viewmgr.hxx"
199 #include "options.hxx"
200 #include "logger.hxx"
203 # include <console.h> // -dw- for command line dialog
207 FGEventMgr global_events;
209 // This is a record containing a bit of global housekeeping information
212 // Specify our current idle function state. This is used to run all
213 // our initializations out of the glutIdleLoop() so that we can get a
214 // splash screen up and running right away.
215 static int idle_state = 0;
216 static long global_multi_loop;
218 // fog constants. I'm a little nervous about putting actual code out
219 // here but it seems to work (?)
220 static const double m_log01 = -log( 0.01 );
221 static const double sqrt_m_log01 = sqrt( m_log01 );
222 static GLfloat fog_exp_density;
223 static GLfloat fog_exp2_density;
224 static GLfloat rwy_exp2_punch_through;
225 static GLfloat taxi_exp2_punch_through;
226 static GLfloat ground_exp2_punch_through;
228 #ifdef FG_NETWORK_OLK
229 ssgSelector *fgd_sel = NULL;
230 ssgTransform *fgd_pos = NULL;
236 #ifdef FG_USE_CLOUDS_3D
237 SkySceneLoader *sgClouds3d;
238 bool _bcloud_orig = true;
242 sgMat4 copy_of_ssgOpenGLAxisSwapMatrix =
244 { 1.0f, 0.0f, 0.0f, 0.0f },
245 { 0.0f, 0.0f, -1.0f, 0.0f },
246 { 0.0f, 1.0f, 0.0f, 0.0f },
247 { 0.0f, 0.0f, 0.0f, 1.0f }
250 // The following defines flightgear options. Because glutlib will also
251 // want to parse its own options, those options must not be included here
252 // or they will get parsed by the main program option parser. Hence case
253 // is significant for any option added that might be in conflict with
256 // glutlib parses for:
258 // -direct (invalid in Win32)
262 // -indirect (invalid in Win32)
265 // Note that glutlib depends upon strings while this program's
266 // option parser wants only initial characters followed by numbers
271 ssgSimpleState *cloud3d_imposter_state;
272 ssgSimpleState *default_state;
273 ssgSimpleState *hud_and_panel;
274 ssgSimpleState *menus;
276 SGTimeStamp last_time_stamp;
277 SGTimeStamp current_time_stamp;
280 void fgBuildRenderStates( void ) {
281 default_state = new ssgSimpleState;
282 default_state->ref();
283 default_state->disable( GL_TEXTURE_2D );
284 default_state->enable( GL_CULL_FACE );
285 default_state->enable( GL_COLOR_MATERIAL );
286 default_state->setColourMaterial( GL_AMBIENT_AND_DIFFUSE );
287 default_state->setMaterial( GL_EMISSION, 0, 0, 0, 1 );
288 default_state->setMaterial( GL_SPECULAR, 0, 0, 0, 1 );
289 default_state->disable( GL_BLEND );
290 default_state->disable( GL_ALPHA_TEST );
291 default_state->disable( GL_LIGHTING );
293 cloud3d_imposter_state = new ssgSimpleState;
294 cloud3d_imposter_state->ref();
295 cloud3d_imposter_state->enable( GL_TEXTURE_2D );
296 cloud3d_imposter_state->enable( GL_CULL_FACE );
297 cloud3d_imposter_state->enable( GL_COLOR_MATERIAL );
298 cloud3d_imposter_state->setColourMaterial( GL_AMBIENT_AND_DIFFUSE );
299 cloud3d_imposter_state->setMaterial( GL_DIFFUSE, 1, 1, 1, 1 );
300 cloud3d_imposter_state->setMaterial( GL_AMBIENT, 1, 1, 1, 1 );
301 cloud3d_imposter_state->setMaterial( GL_EMISSION, 0, 0, 0, 1 );
302 cloud3d_imposter_state->setMaterial( GL_SPECULAR, 0, 0, 0, 1 );
303 cloud3d_imposter_state->enable( GL_BLEND );
304 cloud3d_imposter_state->enable( GL_ALPHA_TEST );
305 cloud3d_imposter_state->disable( GL_LIGHTING );
307 hud_and_panel = new ssgSimpleState;
308 hud_and_panel->ref();
309 hud_and_panel->disable( GL_CULL_FACE );
310 hud_and_panel->disable( GL_TEXTURE_2D );
311 hud_and_panel->disable( GL_LIGHTING );
312 hud_and_panel->enable( GL_BLEND );
314 menus = new ssgSimpleState;
316 menus->disable( GL_CULL_FACE );
317 menus->disable( GL_TEXTURE_2D );
318 menus->enable( GL_BLEND );
322 // fgInitVisuals() -- Initialize various GL/view parameters
323 void fgInitVisuals( void ) {
326 l = &cur_light_params;
328 #ifndef GLUT_WRONG_VERSION
329 // Go full screen if requested ...
330 if ( fgGetBool("/sim/startup/fullscreen") ) {
335 // If enabled, normal vectors specified with glNormal are scaled
336 // to unit length after transformation. Enabling this has
337 // performance implications. See the docs for glNormal.
338 // glEnable( GL_NORMALIZE );
340 glEnable( GL_LIGHTING );
341 glEnable( GL_LIGHT0 );
342 // glLightfv( GL_LIGHT0, GL_POSITION, l->sun_vec ); // done later with ssg
345 sgSetVec3( sunpos, l->sun_vec[0], l->sun_vec[1], l->sun_vec[2] );
346 ssgGetLight( 0 ) -> setPosition( sunpos );
348 glFogi (GL_FOG_MODE, GL_EXP2);
349 if ( (!strcmp(fgGetString("/sim/rendering/fog"), "disabled")) ||
350 (!fgGetBool("/sim/rendering/shading"))) {
351 // if fastest fog requested, or if flat shading force fastest
352 glHint ( GL_FOG_HINT, GL_FASTEST );
353 } else if ( !strcmp(fgGetString("/sim/rendering/fog"), "nicest") ) {
354 glHint ( GL_FOG_HINT, GL_NICEST );
356 if ( fgGetBool("/sim/rendering/wireframe") ) {
358 glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
361 // This is the default anyways, but it can't hurt
362 glFrontFace ( GL_CCW );
365 // glEnable(GL_POINT_SMOOTH);
366 // glEnable(GL_LINE_SMOOTH);
367 // glEnable(GL_POLYGON_SMOOTH);
371 // For HiRes screen Dumps using Brian Pauls TR Library
372 void trRenderFrame( void ) {
374 if ( fgPanelVisible() ) {
375 GLfloat height = fgGetInt("/sim/startup/ysize");
377 (globals->get_current_panel()->getViewHeight() - globals->get_current_panel()->getYOffset())
378 * (height / 768.0) + 1;
379 glTranslatef( 0.0, view_h, 0.0 );
382 static GLfloat black[4] = { 0.0, 0.0, 0.0, 1.0 };
383 static GLfloat white[4] = { 1.0, 1.0, 1.0, 1.0 };
385 fgLIGHT *l = &cur_light_params;
387 glClearColor(l->adj_fog_color[0], l->adj_fog_color[1],
388 l->adj_fog_color[2], l->adj_fog_color[3]);
390 glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
392 // set the opengl state to known default values
393 default_state->force();
396 glFogf ( GL_FOG_DENSITY, fog_exp2_density);
397 glFogi ( GL_FOG_MODE, GL_EXP2 );
398 glFogfv ( GL_FOG_COLOR, l->adj_fog_color );
400 // GL_LIGHT_MODEL_AMBIENT has a default non-zero value so if
401 // we only update GL_AMBIENT for our lights we will never get
402 // a completely dark scene. So, we set GL_LIGHT_MODEL_AMBIENT
403 // explicitely to black.
404 glLightModelfv( GL_LIGHT_MODEL_AMBIENT, black );
405 glLightModeli( GL_LIGHT_MODEL_LOCAL_VIEWER, GL_FALSE );
407 ssgGetLight( 0 ) -> setColour( GL_AMBIENT, l->scene_ambient );
409 // texture parameters
410 glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ) ;
411 glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST ) ;
413 // we need a white diffuse light for the phase of the moon
414 ssgGetLight( 0 ) -> setColour( GL_DIFFUSE, white );
417 // draw the ssg scene
418 // return to the desired diffuse color
419 ssgGetLight( 0 ) -> setColour( GL_DIFFUSE, l->scene_diffuse );
420 glEnable( GL_DEPTH_TEST );
421 ssgSetNearFar( scene_nearplane, scene_farplane );
422 ssgCullAndDraw( globals->get_scenery()->get_scene_graph() );
425 glFogf (GL_FOG_DENSITY, rwy_exp2_punch_through);
426 ssgSetNearFar( scene_nearplane, scene_farplane );
427 ssgCullAndDraw( globals->get_scenery()->get_rwy_lights_root() );
429 ssgCullAndDraw( globals->get_scenery()->get_gnd_lights_root() );
431 if (fgGetBool("/environment/clouds/status"))
432 thesky->postDraw( cur_fdm_state->get_Altitude() * SG_FEET_TO_METER );
434 globals->get_model_mgr()->draw();
435 globals->get_aircraft_model()->draw();
439 // Update all Visuals (redraws anything graphics related)
440 void fgRenderFrame() {
442 GLfloat black[4] = { 0.0, 0.0, 0.0, 1.0 };
443 GLfloat white[4] = { 1.0, 1.0, 1.0, 1.0 };
445 // Process/manage pending events
446 global_events.update( delta_time_sec );
448 static const SGPropertyNode *longitude
449 = fgGetNode("/position/longitude-deg");
450 static const SGPropertyNode *latitude
451 = fgGetNode("/position/latitude-deg");
452 static const SGPropertyNode *altitude
453 = fgGetNode("/position/altitude-ft");
454 static const SGPropertyNode *groundlevel_nearplane
455 = fgGetNode("/sim/current-view/ground-level-nearplane-m");
457 // Update the default (kludged) properties.
460 FGViewer *current__view = globals->get_current_view();
462 fgLIGHT *l = &cur_light_params;
463 static double last_visibility = -9999;
466 double actual_visibility;
467 if (fgGetBool("/environment/clouds/status"))
468 actual_visibility = thesky->get_visibility();
470 actual_visibility = fgGetDouble("/environment/visibility-m");
471 if ( actual_visibility != last_visibility ) {
472 last_visibility = actual_visibility;
474 fog_exp_density = m_log01 / actual_visibility;
475 fog_exp2_density = sqrt_m_log01 / actual_visibility;
476 ground_exp2_punch_through = sqrt_m_log01 / (actual_visibility * 1.5);
477 if ( actual_visibility < 8000 ) {
478 rwy_exp2_punch_through = sqrt_m_log01 / (actual_visibility * 2.5);
479 taxi_exp2_punch_through = sqrt_m_log01 / (actual_visibility * 1.5);
481 rwy_exp2_punch_through = sqrt_m_log01 / ( 8000 * 2.5 );
482 taxi_exp2_punch_through = sqrt_m_log01 / ( 8000 * 1.5 );
487 // GLfloat black[4] = { 0.0, 0.0, 0.0, 1.0 };
488 // GLfloat white[4] = { 1.0, 1.0, 1.0, 1.0 };
489 // GLfloat terrain_color[4] = { 0.54, 0.44, 0.29, 1.0 };
490 // GLfloat mat_shininess[] = { 10.0 };
491 GLbitfield clear_mask;
493 if ( idle_state != 1000 ) {
494 // still initializing, draw the splash screen
495 if ( fgGetBool("/sim/startup/splash-screen") ) {
496 fgSplashUpdate(0.0, 1.0);
498 // Keep resetting sim time while the sim is initializing
499 globals->set_sim_time_sec( 0.0 );
501 // idle_state is now 1000 meaning we've finished all our
502 // initializations and are running the main loop, so this will
503 // now work without seg faulting the system.
505 // calculate our current position in cartesian space
506 globals->get_scenery()->set_center( globals->get_scenery()->get_next_center() );
509 fgReshape( fgGetInt("/sim/startup/xsize"),
510 fgGetInt("/sim/startup/ysize") );
512 if ( fgGetBool("/sim/rendering/clouds3d") ) {
513 glClear( GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT );
514 cloud3d_imposter_state->force();
516 glColor4f( 1.0, 1.0, 1.0, 1.0 );
517 glEnable(GL_DEPTH_TEST);
519 glBlendFunc( GL_ONE, GL_ONE_MINUS_SRC_ALPHA ) ;
521 #ifdef FG_USE_CLOUDS_3D
522 if ( _bcloud_orig ) {
523 Point3D c = globals->get_scenery()->get_center();
524 sgClouds3d->Set_Cloud_Orig( &c );
525 _bcloud_orig = false;
527 sgClouds3d->Update( current__view->get_absolute_view_pos() );
529 glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ) ;
530 glDisable(GL_DEPTH_TEST);
533 clear_mask = GL_DEPTH_BUFFER_BIT;
534 if ( fgGetBool("/sim/rendering/wireframe") ) {
535 clear_mask |= GL_COLOR_BUFFER_BIT;
538 if ( fgGetBool("/sim/rendering/skyblend") ) {
539 if ( fgGetBool("/sim/rendering/textures") ) {
540 // glClearColor(black[0], black[1], black[2], black[3]);
541 glClearColor(l->adj_fog_color[0], l->adj_fog_color[1],
542 l->adj_fog_color[2], l->adj_fog_color[3]);
543 clear_mask |= GL_COLOR_BUFFER_BIT;
546 glClearColor(l->sky_color[0], l->sky_color[1],
547 l->sky_color[2], l->sky_color[3]);
548 clear_mask |= GL_COLOR_BUFFER_BIT;
550 glClear( clear_mask );
552 // Tell GL we are switching to model view parameters
554 // I really should create a derived ssg node or use a call
555 // back or something so that I can draw the sky within the
556 // ssgCullAndDraw() function, but for now I just mimic what
557 // ssg does to set up the model view matrix
558 glMatrixMode(GL_MODELVIEW);
560 ssgSetCamera( (sgVec4 *)current__view->get_VIEW() );
562 // set the opengl state to known default values
563 default_state->force();
565 // update fog params if visibility has changed
566 double visibility_meters = fgGetDouble("/environment/visibility-m");
567 thesky->set_visibility(visibility_meters);
569 thesky->modify_vis( cur_fdm_state->get_Altitude() * SG_FEET_TO_METER,
570 ( global_multi_loop * fgGetInt("/sim/speed-up") )
571 / (double)fgGetInt("/sim/model-hz") );
573 // Set correct opengl fog density
574 glFogf (GL_FOG_DENSITY, fog_exp2_density);
576 // update the sky dome
577 if ( fgGetBool("/sim/rendering/skyblend") ) {
579 SG_LOG( SG_GENERAL, SG_BULK, "thesky->repaint() sky_color = "
580 << cur_light_params.sky_color[0] << " "
581 << cur_light_params.sky_color[1] << " "
582 << cur_light_params.sky_color[2] << " "
583 << cur_light_params.sky_color[3] );
584 SG_LOG( SG_GENERAL, SG_BULK, " fog = "
585 << cur_light_params.fog_color[0] << " "
586 << cur_light_params.fog_color[1] << " "
587 << cur_light_params.fog_color[2] << " "
588 << cur_light_params.fog_color[3] );
589 SG_LOG( SG_GENERAL, SG_BULK,
590 " sun_angle = " << cur_light_params.sun_angle
591 << " moon_angle = " << cur_light_params.moon_angle );
594 // Some insane defaults.
595 static int init = 50;
596 static double sun_pos_angle = 9999.0;
597 static double sun_pos_rotation = 9999.0;
598 static double cur_lat = 9999.0;
599 static double cur_long = 9999.0;
600 static double cur_alt = -9999.0;
602 if ((fabs(sun_pos_rotation - cur_light_params.sun_rotation) > 5e-3)
603 || (fabs(sun_pos_angle - cur_light_params.sun_angle) > 5e-3)
609 sun_pos_angle = cur_light_params.sun_angle;
610 sun_pos_rotation = cur_light_params.sun_rotation;
612 thesky->repaint( cur_light_params.sky_color,
613 cur_light_params.adj_fog_color,
614 cur_light_params.sun_angle,
615 cur_light_params.moon_angle,
616 globals->get_ephem()->getNumPlanets(),
617 globals->get_ephem()->getPlanets(),
618 globals->get_ephem()->getNumStars(),
619 globals->get_ephem()->getStars() );
623 SG_LOG( SG_GENERAL, SG_BULK,
624 "thesky->reposition( view_pos = " << view_pos[0] << " "
625 << view_pos[1] << " " << view_pos[2] );
626 SG_LOG( SG_GENERAL, SG_BULK,
627 " zero_elev = " << zero_elev[0] << " "
628 << zero_elev[1] << " " << zero_elev[2]
629 << " lon = " << cur_fdm_state->get_Longitude()
630 << " lat = " << cur_fdm_state->get_Latitude() );
631 SG_LOG( SG_GENERAL, SG_BULK,
632 " sun_rot = " << cur_light_params.sun_rotation
633 << " gst = " << SGTime::cur_time_params->getGst() );
634 SG_LOG( SG_GENERAL, SG_BULK,
635 " sun ra = " << globals->get_ephem()->getSunRightAscension()
636 << " sun dec = " << globals->get_ephem()->getSunDeclination()
637 << " moon ra = " << globals->get_ephem()->getMoonRightAscension()
638 << " moon dec = " << globals->get_ephem()->getMoonDeclination() );
641 if ((fabs(cur_long - current__view->getLongitude_deg()) > 5e-4)
642 || (fabs(cur_lat - current__view->getLatitude_deg()) > 5e-4)
643 || (fabs(cur_alt - current__view->getAltitudeASL_ft()) > 3)
648 if ((fabs(cur_long - current__view->getLongitude_deg()) > 2)
649 || (fabs(cur_lat - current__view->getLatitude_deg()) > 2))
652 cur_lat = current__view->getLatitude_deg();
653 cur_long = current__view->getLongitude_deg();
654 cur_alt = current__view->getAltitudeASL_ft();
656 thesky->reposition( current__view->get_view_pos(),
657 current__view->get_zero_elev(),
658 current__view->get_world_up(),
659 current__view->getLongitude_deg()
660 * SGD_DEGREES_TO_RADIANS,
661 current__view->getLatitude_deg()
662 * SGD_DEGREES_TO_RADIANS,
663 current__view->getAltitudeASL_ft()
665 cur_light_params.sun_rotation,
666 globals->get_time_params()->getGst(),
667 globals->get_ephem()->getSunRightAscension(),
668 globals->get_ephem()->getSunDeclination(),
670 globals->get_ephem()->getMoonRightAscension(),
671 globals->get_ephem()->getMoonDeclination(),
678 glEnable( GL_DEPTH_TEST );
679 if ( strcmp(fgGetString("/sim/rendering/fog"), "disabled") ) {
681 glFogi( GL_FOG_MODE, GL_EXP2 );
682 glFogfv( GL_FOG_COLOR, l->adj_fog_color );
685 // set sun/lighting parameters
686 ssgGetLight( 0 ) -> setPosition( l->sun_vec );
688 // GL_LIGHT_MODEL_AMBIENT has a default non-zero value so if
689 // we only update GL_AMBIENT for our lights we will never get
690 // a completely dark scene. So, we set GL_LIGHT_MODEL_AMBIENT
691 // explicitely to black.
692 glLightModelfv( GL_LIGHT_MODEL_AMBIENT, black );
694 ssgGetLight( 0 ) -> setColour( GL_AMBIENT, l->scene_ambient );
695 ssgGetLight( 0 ) -> setColour( GL_DIFFUSE, l->scene_diffuse );
696 ssgGetLight( 0 ) -> setColour( GL_SPECULAR, l->scene_specular );
698 // texture parameters
699 // glEnable( GL_TEXTURE_2D );
700 glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ) ;
701 glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST ) ;
703 // glMatrixMode( GL_PROJECTION );
705 ssgSetFOV( current__view->get_h_fov(),
706 current__view->get_v_fov() );
709 current_aircraft.fdm_state->get_Altitude() * SG_FEET_TO_METER
710 - globals->get_scenery()->get_cur_elev();
713 scene_nearplane = 10.0f;
714 scene_farplane = 120000.0f;
716 scene_nearplane = groundlevel_nearplane->getDoubleValue();
717 scene_farplane = 120000.0f;
720 ssgSetNearFar( scene_nearplane, scene_farplane );
722 // $$$ begin - added VS Renganthan 17 Oct 2K
725 // $$$ end - added VS Renganthan 17 Oct 2K
727 # ifdef FG_NETWORK_OLK
728 if ( fgGetBool("/sim/networking/network-olk") ) {
730 other = head->next; /* put listpointer to start */
731 while ( other != tail) { /* display all except myself */
732 if ( strcmp( other->ipadr, fgd_mcp_ip) != 0) {
733 other->fgd_sel->select(1);
734 sgSetCoord( &fgdpos, other->sgFGD_COORD );
735 other->fgd_pos->setTransform( &fgdpos );
740 // fgd_sel->select(1);
741 // sgCopyMat4( sgTUX, current_view.sgVIEW);
743 // sgSetCoord( &fgdpos, sgFGD_VIEW );
744 // fgd_pos->setTransform( &fgdpos);
749 // Update any multiplayer models
750 globals->get_multiplayer_rx_mgr()->Update();
753 if ( fgGetBool("/sim/rendering/skyblend") &&
754 fgGetBool("/sim/rendering/draw-otw") )
756 // draw the sky backdrop
758 // we need a white diffuse light for the phase of the moon
759 ssgGetLight( 0 ) -> setColour( GL_DIFFUSE, white );
763 // return to the desired diffuse color
764 ssgGetLight( 0 ) -> setColour( GL_DIFFUSE, l->scene_diffuse );
767 // draw the ssg scene
768 glEnable( GL_DEPTH_TEST );
770 ssgSetNearFar( scene_nearplane, scene_farplane );
772 if ( fgGetBool("/sim/rendering/wireframe") ) {
774 glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
776 if ( fgGetBool("/sim/rendering/draw-otw") ) {
777 ssgCullAndDraw( globals->get_scenery()->get_scene_graph() );
780 // This is a bit kludgy. Every 200 frames, do an extra
781 // traversal of the scene graph without drawing anything, but
782 // with the field-of-view set to 360x360 degrees. This
783 // ensures that out-of-range random objects that are not in
784 // the current view frustum will still be freed properly.
785 static int counter = 0;
787 if (counter == 200) {
790 // No need to put the near plane too close;
791 // this way, at least the aircraft can be
793 f.setNearFar(1000, 1000000);
795 ssgGetModelviewMatrix(m);
796 globals->get_scenery()->get_scene_graph()->cull(&f, m, true);
800 // change state for lighting here
802 // draw runway lighting
803 glFogf (GL_FOG_DENSITY, rwy_exp2_punch_through);
804 ssgSetNearFar( scene_nearplane, scene_farplane );
806 #ifdef FG_EXPERIMENTAL_POINT_LIGHTING
807 // Enable states for drawing points with GL_extension
808 glEnable(GL_POINT_SMOOTH);
810 if ( fgGetBool("/sim/rendering/distance-attenuation")
811 && glutExtensionSupported("GL_EXT_point_parameters") )
813 float quadratic[3] = {1.0, 0.001, 0.0000001};
814 // makes the points fade as they move away
815 glPointParameterfvEXT(GL_DISTANCE_ATTENUATION_EXT, quadratic);
816 glPointParameterfEXT(GL_POINT_SIZE_MIN_EXT, 1.0);
820 // blending function for runway lights
821 glBlendFunc ( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) ;
824 glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
825 glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
826 glEnable(GL_TEXTURE_GEN_S);
827 glEnable(GL_TEXTURE_GEN_T);
828 glPolygonMode(GL_FRONT, GL_POINT);
830 // draw runway lighting
831 if ( fgGetBool("/sim/rendering/draw-otw") ) {
832 ssgCullAndDraw( globals->get_scenery()->get_rwy_lights_root() );
835 // change punch through and then draw taxi lighting
836 glFogf ( GL_FOG_DENSITY, fog_exp2_density );
838 // sgSetVec3( taxi_fog, 0.0, 0.0, 0.0 );
839 // glFogfv ( GL_FOG_COLOR, taxi_fog );
840 if ( fgGetBool("/sim/rendering/draw-otw") ) {
841 ssgCullAndDraw( globals->get_scenery()->get_taxi_lights_root() );
845 glPolygonMode(GL_FRONT, GL_FILL);
846 glDisable(GL_TEXTURE_GEN_S);
847 glDisable(GL_TEXTURE_GEN_T);
849 //static int _frame_count = 0;
850 //if (_frame_count % 30 == 0) {
851 // printf("SSG: %s\n", ssgShowStats());
859 #ifdef FG_EXPERIMENTAL_POINT_LIGHTING
860 if ( fgGetBool("/sim/rendering/distance-attenuation")
861 && glutExtensionSupported("GL_EXT_point_parameters") )
863 glPointParameterfvEXT(GL_DISTANCE_ATTENUATION_EXT,
864 default_attenuation);
868 glDisable(GL_POINT_SMOOTH);
871 // draw ground lighting
872 glFogf (GL_FOG_DENSITY, ground_exp2_punch_through);
873 if ( fgGetBool("/sim/rendering/draw-otw") ) {
874 ssgCullAndDraw( globals->get_scenery()->get_gnd_lights_root() );
877 if ( fgGetBool("/sim/rendering/skyblend") ) {
878 // draw the sky cloud layers
879 if ( fgGetBool("/environment/clouds/status") &&
880 fgGetBool("/sim/rendering/draw-otw") )
882 thesky->postDraw( cur_fdm_state->get_Altitude()
883 * SG_FEET_TO_METER );
887 if ( fgGetBool("/sim/rendering/clouds3d") &&
888 fgGetBool("/sim/rendering/draw-otw") )
891 glDisable( GL_LIGHTING );
892 // cout << "drawing new clouds" << endl;
894 glEnable(GL_DEPTH_TEST);
896 glBlendFunc( GL_ONE, GL_ONE_MINUS_SRC_ALPHA ) ;
899 glEnable( GL_TEXTURE_2D );
900 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
901 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
902 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
903 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
906 #ifdef FG_USE_CLOUDS_3D
907 sgClouds3d->Draw((sgVec4 *)current__view->get_VIEW());
910 glEnable( GL_LIGHTING );
911 glEnable( GL_DEPTH_TEST );
912 glBlendFunc ( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ) ;
915 if ( fgGetBool("/sim/rendering/draw-otw") ) {
916 globals->get_model_mgr()->draw();
917 globals->get_aircraft_model()->draw();
920 // display HUD && Panel
922 glDisable( GL_DEPTH_TEST );
923 // glDisable( GL_CULL_FACE );
924 // glDisable( GL_TEXTURE_2D );
926 // update the controls subsystem
927 globals->get_controls()->update(delta_time_sec);
929 hud_and_panel->apply();
932 // Use the hud_and_panel ssgSimpleState for rendering the ATC output
933 // This only works properly if called before the panel call
934 if((fgGetBool("/sim/ATC/enabled")) || (fgGetBool("/sim/ai-traffic/enabled")))
935 globals->get_ATC_display()->update(delta_time_sec);
937 // update the panel subsystem
938 if ( globals->get_current_panel() != NULL ) {
939 globals->get_current_panel()->update(delta_time_sec);
943 // We can do translucent menus, so why not. :-)
945 glBlendFunc ( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ) ;
947 // glDisable ( GL_BLEND ) ;
949 glEnable( GL_DEPTH_TEST );
952 // Fade out the splash screen over the first three seconds.
953 double t = globals->get_sim_time_sec();
955 fgSplashUpdate(0.0, 1.0);
956 } else if ( t <= 3.0) {
957 fgSplashUpdate(0.0, (3.0 - t) / 2.0);
965 // Update internal time dependent calculations (i.e. flight model)
966 // FIXME: this distinction is obsolete; all subsystems now get delta
968 void fgUpdateTimeDepCalcs() {
969 static bool inited = false;
971 //SG_LOG(SG_FLIGHT,SG_INFO, "Updating time dep calcs()");
973 fgLIGHT *l = &cur_light_params;
975 // Initialize the FDM here if it hasn't been and if we have a
976 // scenery elevation hit.
978 // cout << "cur_fdm_state->get_inited() = " << cur_fdm_state->get_inited()
979 // << " cur_elev = " << scenery.get_cur_elev() << endl;
981 if ( !cur_fdm_state->get_inited() &&
982 globals->get_scenery()->get_cur_elev() > -9990 )
984 SG_LOG(SG_FLIGHT,SG_INFO, "Finally initializing fdm");
985 cur_fdm_state->init();
986 if ( cur_fdm_state->get_bound() ) {
987 cur_fdm_state->unbind();
989 cur_fdm_state->bind();
993 globals->get_environment_mgr()->update(delta_time_sec);
996 // conceptually, the following block could be done for each fdm
998 if ( !cur_fdm_state->get_inited() ) {
999 // do nothing, fdm isn't inited yet
1001 // we have been inited, and we are good to go ...
1007 globals->get_autopilot()->update(delta_time_sec);
1008 cur_fdm_state->update(delta_time_sec);
1011 globals->get_model_mgr()->update(delta_time_sec);
1012 globals->get_aircraft_model()->update(delta_time_sec);
1014 // update the view angle
1015 globals->get_viewmgr()->update(delta_time_sec);
1019 // Update solar system
1020 globals->get_ephem()->update( globals->get_time_params()->getMjd(),
1021 globals->get_time_params()->getLst(),
1022 cur_fdm_state->get_Latitude() );
1024 // Update radio stack model
1025 current_radiostack->update(delta_time_sec);
1029 void fgInitTimeDepCalcs( void ) {
1034 static const double alt_adjust_ft = 3.758099;
1035 static const double alt_adjust_m = alt_adjust_ft * SG_FEET_TO_METER;
1038 // What should we do when we have nothing else to do? Let's get ready
1039 // for the next move and update the display?
1040 static void fgMainLoop( void ) {
1042 static const SGPropertyNode *longitude
1043 = fgGetNode("/position/longitude-deg");
1044 static const SGPropertyNode *latitude
1045 = fgGetNode("/position/latitude-deg");
1046 static const SGPropertyNode *altitude
1047 = fgGetNode("/position/altitude-ft");
1048 static const SGPropertyNode *clock_freeze
1049 = fgGetNode("/sim/freeze/clock", true);
1050 static const SGPropertyNode *cur_time_override
1051 = fgGetNode("/sim/time/cur-time-override", true);
1053 // Update the elapsed time.
1054 static bool first_time = true;
1056 last_time_stamp.stamp();
1059 current_time_stamp.stamp();
1060 delta_time_sec = double(current_time_stamp - last_time_stamp) / 1000000.0;
1061 if (clock_freeze->getBoolValue())
1063 last_time_stamp = current_time_stamp;
1064 globals->inc_sim_time_sec( delta_time_sec );
1066 static long remainder = 0;
1068 #ifdef FANCY_FRAME_COUNTER
1072 static time_t last_time = 0;
1073 static int frames = 0;
1074 #endif // FANCY_FRAME_COUNTER
1076 SGTime *t = globals->get_time_params();
1078 sglog().setLogLevels( SG_ALL, (sgDebugPriority)fgGetInt("/sim/log-level") );
1080 FGLocation * acmodel_location = 0;
1081 if(cur_fdm_state->getACModel() != 0) {
1082 acmodel_location = (FGLocation *) cur_fdm_state->getACModel()->get3DModel()->getFGLocation();
1085 SG_LOG( SG_ALL, SG_DEBUG, "Running Main Loop");
1086 SG_LOG( SG_ALL, SG_DEBUG, "======= ==== ====");
1088 #ifdef FG_NETWORK_OLK
1089 if ( fgGetBool("/sim/networking/network-olk") ) {
1090 if ( net_is_registered == 0 ) { // We first have to reg. to fgd
1091 // printf("FGD: Netupdate\n");
1092 fgd_send_com( "A", FGFS_host); // Send Mat4 data
1093 fgd_send_com( "B", FGFS_host); // Recv Mat4 data
1098 #if defined( ENABLE_PLIB_JOYSTICK )
1099 // Read joystick and update control settings
1100 // if ( fgGetString("/sim/control-mode") == "joystick" )
1102 // fgJoystickRead();
1104 #elif defined( ENABLE_GLUT_JOYSTICK )
1105 // Glut joystick support works by feeding a joystick handler
1106 // function to glut. This is taken care of once in the joystick
1107 // init routine and we don't have to worry about it again.
1110 // Fix elevation. I'm just sticking this here for now, it should
1111 // probably move eventually
1113 /* printf("Before - ground = %.2f runway = %.2f alt = %.2f\n",
1114 scenery.get_cur_elev(),
1115 cur_fdm_state->get_Runway_altitude() * SG_FEET_TO_METER,
1116 cur_fdm_state->get_Altitude() * SG_FEET_TO_METER); */
1118 // Curt is this code used? I don't see any problems when I comment it out.
1119 if ( acmodel_location != 0 ) {
1120 if ( acmodel_location->get_cur_elev_m() > -9990 && cur_fdm_state->get_inited() ) {
1121 if ( cur_fdm_state->get_Altitude() * SG_FEET_TO_METER <
1122 (acmodel_location->get_cur_elev_m() + alt_adjust_m - 3.0) ) {
1123 // now set aircraft altitude above ground
1124 printf("(*) Current Altitude = %.2f < %.2f forcing to %.2f\n",
1125 cur_fdm_state->get_Altitude() * SG_FEET_TO_METER,
1126 acmodel_location->get_cur_elev_m() + alt_adjust_m - 3.0,
1127 acmodel_location->get_cur_elev_m() + alt_adjust_m );
1128 cur_fdm_state->set_Altitude( (acmodel_location->get_cur_elev_m()
1129 + alt_adjust_m) * SG_METER_TO_FEET );
1130 SG_LOG( SG_ALL, SG_DEBUG,
1131 "<*> resetting altitude to "
1132 << cur_fdm_state->get_Altitude() * SG_FEET_TO_METER
1137 // End of code in question. (see Curt is this code used? above)
1139 /* printf("Adjustment - ground = %.2f runway = %.2f alt = %.2f\n",
1140 scenery.get_cur_elev(),
1141 cur_fdm_state->get_Runway_altitude() * SG_FEET_TO_METER,
1142 cur_fdm_state->get_Altitude() * SG_FEET_TO_METER); */
1144 // cout << "Warp = " << globals->get_warp() << endl;
1147 static bool last_clock_freeze = false;
1149 if ( clock_freeze->getBoolValue() ) {
1150 // clock freeze requested
1151 if ( cur_time_override->getLongValue() == 0 ) {
1152 fgSetLong( "/sim/time/cur-time-override", t->get_cur_time() );
1153 globals->set_warp( 0 );
1156 // no clock freeze requested
1157 if ( last_clock_freeze == true ) {
1158 // clock just unfroze, let's set warp as the difference
1159 // between frozen time and current time so we don't get a
1160 // time jump (and corresponding sky object and lighting
1162 globals->set_warp( cur_time_override->getLongValue() - time(NULL) );
1163 fgSetLong( "/sim/time/cur-time-override", 0 );
1165 if ( globals->get_warp_delta() != 0 ) {
1166 globals->inc_warp( globals->get_warp_delta() );
1170 last_clock_freeze = clock_freeze->getBoolValue();
1172 t->update( longitude->getDoubleValue() * SGD_DEGREES_TO_RADIANS,
1173 latitude->getDoubleValue() * SGD_DEGREES_TO_RADIANS,
1174 cur_time_override->getLongValue(),
1175 globals->get_warp() );
1177 if ( globals->get_warp_delta() != 0 ) {
1178 fgUpdateSkyAndLightingParams();
1181 // update magvar model
1182 globals->get_mag()->update( longitude->getDoubleValue()
1183 * SGD_DEGREES_TO_RADIANS,
1184 latitude->getDoubleValue()
1185 * SGD_DEGREES_TO_RADIANS,
1186 altitude->getDoubleValue() * SG_FEET_TO_METER,
1187 globals->get_time_params()->getJD() );
1189 // Get elapsed time (in usec) for this past frame
1190 elapsed = fgGetTimeInterval();
1191 SG_LOG( SG_ALL, SG_DEBUG,
1192 "Elapsed time interval is = " << elapsed
1193 << ", previous remainder is = " << remainder );
1195 // Calculate frame rate average
1196 #ifdef FANCY_FRAME_COUNTER
1197 /* old fps calculation */
1198 if ( elapsed > 0 ) {
1201 for ( i = FG_FRAME_RATE_HISTORY - 2; i >= 0; i-- ) {
1202 tmp = general.get_frame(i);
1204 // printf("frame[%d] = %.2f\n", i, g->frames[i]);
1205 general.set_frame(i+1,tmp);
1207 tmp = 1000000.0 / (float)elapsed;
1208 general.set_frame(0,tmp);
1209 // printf("frame[0] = %.2f\n", general.frames[0]);
1211 general.set_frame_rate(accum / (float)FG_FRAME_RATE_HISTORY);
1212 // printf("ave = %.2f\n", general.frame_rate);
1215 if ( (t->get_cur_time() != last_time) && (last_time > 0) ) {
1216 general.set_frame_rate( frames );
1217 fgSetInt("/sim/frame-rate", frames);
1218 SG_LOG( SG_ALL, SG_DEBUG,
1219 "--> Frame rate is = " << general.get_frame_rate() );
1222 last_time = t->get_cur_time();
1226 // Run ATC subsystem
1227 if (fgGetBool("/sim/ATC/enabled"))
1228 globals->get_ATC_mgr()->update(delta_time_sec);
1230 // Run the AI subsystem
1231 if (fgGetBool("/sim/ai-traffic/enabled"))
1232 globals->get_AI_mgr()->update(delta_time_sec);
1236 // Calculate model iterations needed for next frame
1237 elapsed += remainder;
1239 global_multi_loop = (long)(((double)elapsed * 0.000001) *
1240 fgGetInt("/sim/model-hz"));
1241 remainder = elapsed - ( (global_multi_loop*1000000) /
1242 fgGetInt("/sim/model-hz") );
1243 SG_LOG( SG_ALL, SG_DEBUG,
1244 "Model iterations needed = " << global_multi_loop
1245 << ", new remainder = " << remainder );
1247 // chop max interations to something reasonable if the sim was
1248 // delayed for an excesive amount of time
1249 if ( global_multi_loop > 2.0 * fgGetInt("/sim/model-hz") ) {
1250 global_multi_loop = (int)(2.0 * fgGetInt("/sim/model-hz") );
1255 if ( global_multi_loop > 0 ) {
1256 fgUpdateTimeDepCalcs();
1258 SG_LOG( SG_ALL, SG_DEBUG,
1259 "Elapsed time is zero ... we're zinging" );
1262 // Do any I/O channel work that might need to be done
1263 globals->get_io()->update( delta_time_sec );
1265 // see if we need to load any deferred-load textures
1266 material_lib.load_next_deferred();
1268 // Run audio scheduler
1269 #ifdef ENABLE_AUDIO_SUPPORT
1270 if ( fgGetBool("/sim/sound/audible")
1271 && globals->get_soundmgr()->is_working() ) {
1272 globals->get_soundmgr()->update( delta_time_sec );
1276 globals->get_subsystem_mgr()->update(delta_time_sec);
1279 // Tile Manager updates - see if we need to load any new scenery tiles.
1280 // this code ties together the fdm, viewer and scenery classes...
1281 // we may want to move this to it's own class at some point
1283 double visibility_meters = fgGetDouble("/environment/visibility-m");
1284 FGViewer *current_view = globals->get_current_view();
1286 // update tile manager for FDM...
1287 // ...only if location is different than the viewer (to avoid duplicating effort)
1288 if( acmodel_location != current_view->getFGLocation() ) {
1289 if( acmodel_location != 0 ) {
1290 globals->get_tile_mgr()->prep_ssg_nodes( acmodel_location,
1291 visibility_meters );
1292 globals->get_tile_mgr()->
1293 update( acmodel_location, visibility_meters,
1294 acmodel_location->get_absolute_view_pos() );
1295 // save results of update in FGLocation for fdm...
1296 if ( globals->get_scenery()->get_cur_elev() > -9990 ) {
1298 set_cur_elev_m( globals->get_scenery()->get_cur_elev() );
1301 set_tile_center( globals->get_scenery()->get_next_center() );
1305 globals->get_tile_mgr()->prep_ssg_nodes( current_view->getFGLocation(),
1306 visibility_meters );
1307 // update tile manager for view...
1308 // IMPORTANT!!! the tilemgr update for view location _must_ be done last
1309 // after the FDM's until all of Flight Gear code references the viewer's location
1310 // for elevation instead of the "scenery's" current elevation.
1311 FGLocation *view_location = globals->get_current_view()->getFGLocation();
1312 globals->get_tile_mgr()->update( view_location, visibility_meters,
1313 current_view->get_absolute_view_pos() );
1314 // save results of update in FGLocation for fdm...
1315 if ( globals->get_scenery()->get_cur_elev() > -9990 ) {
1316 current_view->getFGLocation()->set_cur_elev_m( globals->get_scenery()->get_cur_elev() );
1318 current_view->getFGLocation()->set_tile_center( globals->get_scenery()->get_next_center() );
1320 // If fdm location is same as viewer's then we didn't do the update for fdm location
1321 // above so we need to save the viewer results in the fdm FGLocation as well...
1322 if( acmodel_location == current_view->getFGLocation() ) {
1323 if( acmodel_location != 0 ) {
1324 if ( globals->get_scenery()->get_cur_elev() > -9990 ) {
1325 acmodel_location->set_cur_elev_m( globals->get_scenery()->get_cur_elev() );
1327 acmodel_location->set_tile_center( globals->get_scenery()->get_next_center() );
1331 // END Tile Manager udpates
1336 SG_LOG( SG_ALL, SG_DEBUG, "" );
1340 // This is the top level master main function that is registered as
1341 // our idle funciton
1343 // The first few passes take care of initialization things (a couple
1344 // per pass) and once everything has been initialized fgMainLoop from
1347 static void fgIdleFunction ( void ) {
1348 // printf("idle state == %d\n", idle_state);
1350 if ( idle_state == 0 ) {
1351 // Initialize the splash screen right away
1352 if ( fgGetBool("/sim/startup/splash-screen") ) {
1357 } else if ( idle_state == 1 ) {
1358 // Initialize audio support
1359 #ifdef ENABLE_AUDIO_SUPPORT
1361 // Start the intro music
1362 if ( fgGetBool("/sim/startup/intro-music") ) {
1363 SGPath mp3file( globals->get_fg_root() );
1364 mp3file.append( "Sounds/intro.mp3" );
1366 SG_LOG( SG_GENERAL, SG_INFO,
1367 "Starting intro music: " << mp3file.str() );
1369 #if defined( __CYGWIN__ )
1370 string command = "start /m `cygpath -w " + mp3file.str() + "`";
1371 #elif defined( WIN32 )
1372 string command = "start /m " + mp3file.str();
1374 string command = "mpg123 " + mp3file.str() + "> /dev/null 2>&1";
1377 system ( command.c_str() );
1382 } else if ( idle_state == 2 ) {
1383 // These are a few miscellaneous things that aren't really
1384 // "subsystems" but still need to be initialized.
1387 if ( strstr ( general.get_glRenderer(), "Glide" ) ) {
1388 grTexLodBiasValue ( GR_TMU0, 1.0 ) ;
1393 } else if ( idle_state == 3 ) {
1394 // This is the top level init routine which calls all the
1395 // other subsystem initialization routines. If you are adding
1396 // a subsystem to flightgear, its initialization call should
1397 // located in this routine.
1398 if( !fgInitSubsystems()) {
1399 SG_LOG( SG_GENERAL, SG_ALERT,
1400 "Subsystem initializations failed ..." );
1405 } else if ( idle_state == 4 ) {
1406 // setup OpenGL view parameters
1409 // Read the list of available aircrafts
1413 } else if ( idle_state == 5 ) {
1416 } else if ( idle_state == 6 ) {
1420 SG_LOG( SG_GENERAL, SG_INFO, "Panel visible = " << fgPanelVisible() );
1421 fgReshape( fgGetInt("/sim/startup/xsize"),
1422 fgGetInt("/sim/startup/ysize") );
1425 if ( idle_state == 1000 ) {
1426 // We've finished all our initialization steps, from now on we
1427 // run the main loop.
1429 glutIdleFunc(fgMainLoop);
1431 if ( fgGetBool("/sim/startup/splash-screen") ) {
1432 fgSplashUpdate(0.0, 1.0);
1437 // options.cxx needs to see this for toggle_panel()
1438 // Handle new window size or exposure
1439 void fgReshape( int width, int height ) {
1442 if ( (!fgGetBool("/sim/virtual-cockpit"))
1443 && fgPanelVisible() && idle_state == 1000 ) {
1444 view_h = (int)(height * (globals->get_current_panel()->getViewHeight() -
1445 globals->get_current_panel()->getYOffset()) / 768.0);
1451 FGViewMgr *viewmgr = globals->get_viewmgr();
1452 for ( int i = 0; i < viewmgr->size(); ++i ) {
1453 viewmgr->get_view(i)->
1454 set_aspect_ratio((float)view_h / (float)width);
1457 glViewport( 0, (GLint)(height - view_h), (GLint)(width), (GLint)(view_h) );
1459 fgSetInt("/sim/startup/xsize", width);
1460 fgSetInt("/sim/startup/ysize", height);
1461 guiInitMouse(width, height);
1463 ssgSetFOV( viewmgr->get_current_view()->get_h_fov(),
1464 viewmgr->get_current_view()->get_v_fov() );
1468 #ifdef FG_USE_CLOUDS_3D
1469 sgClouds3d->Resize( viewmgr->get_current_view()->get_h_fov(),
1470 viewmgr->get_current_view()->get_v_fov() );
1475 // Initialize GLUT and define a main window
1476 static bool fgGlutInit( int *argc, char **argv ) {
1478 #if !defined( macintosh )
1479 // GLUT will extract all glut specific options so later on we only
1480 // need wory about our own.
1481 glutInit(argc, argv);
1484 // Define Display Parameters. Clouds3d works best with --bpp32 option
1485 if ( fgGetBool("/sim/rendering/clouds3d") ) {
1486 glutInitDisplayMode( GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE | GLUT_ALPHA );
1488 glutInitDisplayMode( GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE );
1491 SG_LOG( SG_GENERAL, SG_INFO, "Opening a window: " <<
1492 fgGetInt("/sim/startup/xsize") << "x"
1493 << fgGetInt("/sim/startup/ysize") );
1495 // Define initial window size
1496 glutInitWindowSize( fgGetInt("/sim/startup/xsize"),
1497 fgGetInt("/sim/startup/ysize") );
1499 // Initialize windows
1500 if ( !fgGetBool("/sim/startup/game-mode")) {
1501 // Open the regular window
1502 glutCreateWindow("FlightGear");
1503 #ifndef GLUT_WRONG_VERSION
1505 // Open the cool new 'game mode' window
1506 char game_mode_str[256];
1507 //#define SYNC_OPENGL_WITH_DESKTOP_SETTINGS
1508 #if defined(WIN32) && defined(SYNC_OPENGL_WITH_DESKTOP_SETTINGS)
1509 #ifndef ENUM_CURRENT_SETTINGS
1510 #define ENUM_CURRENT_SETTINGS ((DWORD)-1)
1511 #define ENUM_REGISTRY_SETTINGS ((DWORD)-2)
1515 dm.dmSize = sizeof(DEVMODE);
1516 EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &dm);
1517 fgSetInt("/sim/startup/xsize", dm.dmPelsWidth);
1518 fgSetInt("/sim/startup/ysize", dm.dmPelsHeight);
1519 glutInitWindowSize( fgGetInt("/sim/startup/xsize"),
1520 fgGetInt("/sim/startup/ysize") );
1521 sprintf( game_mode_str, "%dx%d:%d@%d",
1525 dm.dmDisplayFrequency );
1527 // Open the cool new 'game mode' window
1528 sprintf( game_mode_str, "width=%d height=%d bpp=%d",
1529 fgGetInt("/sim/startup/xsize"),
1530 fgGetInt("/sim/startup/ysize"),
1531 fgGetInt("/sim/rendering/bits-per-pixel"));
1533 #endif // HAVE_WINDOWS_H
1534 SG_LOG( SG_GENERAL, SG_INFO,
1535 "game mode params = " << game_mode_str );
1536 glutGameModeString( game_mode_str );
1537 glutEnterGameMode();
1538 #endif // GLUT_WRONG_VERSION
1541 // This seems to be the absolute earliest in the init sequence
1542 // that these calls will return valid info. Too bad it's after
1543 // we've already created and sized out window. :-(
1544 general.set_glVendor( (char *)glGetString ( GL_VENDOR ) );
1545 general.set_glRenderer( (char *)glGetString ( GL_RENDERER ) );
1546 general.set_glVersion( (char *)glGetString ( GL_VERSION ) );
1547 SG_LOG( SG_GENERAL, SG_INFO, general.get_glRenderer() );
1550 glGetIntegerv( GL_MAX_TEXTURE_SIZE, &tmp );
1551 general.set_glMaxTexSize( tmp );
1552 SG_LOG ( SG_GENERAL, SG_INFO, "Max texture size = " << tmp );
1554 glGetIntegerv( GL_DEPTH_BITS, &tmp );
1555 general.set_glDepthBits( tmp );
1556 SG_LOG ( SG_GENERAL, SG_INFO, "Depth buffer bits = " << tmp );
1562 // Initialize GLUT event handlers
1563 static bool fgGlutInitEvents( void ) {
1564 // call fgReshape() on window resizes
1565 glutReshapeFunc( fgReshape );
1567 // keyboard and mouse callbacks are set in FGInput::init
1569 // call fgMainLoop() whenever there is
1570 // nothing else to do
1571 glutIdleFunc( fgIdleFunction );
1574 glutDisplayFunc( fgRenderFrame );
1579 // Main top level initialization
1580 static bool fgMainInit( int argc, char **argv ) {
1582 #if defined( macintosh )
1583 freopen ("stdout.txt", "w", stdout );
1584 freopen ("stderr.txt", "w", stderr );
1585 argc = ccommand( &argv );
1588 // set default log levels
1589 sglog().setLogLevels( SG_ALL, SG_INFO );
1592 #ifdef FLIGHTGEAR_VERSION
1593 version = FLIGHTGEAR_VERSION;
1595 version = "unknown version";
1597 SG_LOG( SG_GENERAL, SG_INFO, "FlightGear: Version "
1599 SG_LOG( SG_GENERAL, SG_INFO, "Built with " << SG_COMPILER_STR << endl );
1601 // Allocate global data structures. This needs to happen before
1602 // we parse command line options
1604 globals = new FGGlobals;
1606 #ifndef FG_WEATHERCM
1607 globals->set_environment_mgr(new FGEnvironmentMgr);
1610 // seed the random number generater
1613 SGRoute *route = new SGRoute;
1614 globals->set_route( route );
1616 FGControls *controls = new FGControls;
1617 globals->set_controls( controls );
1619 string_list *col = new string_list;
1620 globals->set_channel_options_list( col );
1622 // Scan the config file(s) and command line options to see if
1623 // fg_root was specified (ignore all other options for now)
1624 fgInitFGRoot(argc, argv);
1626 // Check for the correct base package version
1627 static char required_version[] = "0.9.1";
1628 string base_version = fgBasePackageVersion();
1629 if ( !(base_version == required_version) ) {
1630 // tell the operator how to use this application
1632 cerr << endl << "Base package check failed ... " \
1633 << "Found version " << base_version << " at: " \
1634 << globals->get_fg_root() << endl;
1635 cerr << "Please upgrade to version: " << required_version << endl;
1639 // Initialize the Aircraft directory to "" (UIUC)
1642 // Load the configuration parameters. (Command line options
1643 // overrides config file options. Config file options override
1645 if ( !fgInitConfig(argc, argv) ) {
1646 SG_LOG( SG_GENERAL, SG_ALERT, "Config option parsing failed ..." );
1650 // Initialize the Window/Graphics environment.
1651 if( !fgGlutInit(&argc, argv) ) {
1652 SG_LOG( SG_GENERAL, SG_ALERT, "GLUT initialization failed ..." );
1656 // Initialize the various GLUT Event Handlers.
1657 if( !fgGlutInitEvents() ) {
1658 SG_LOG( SG_GENERAL, SG_ALERT,
1659 "GLUT event handler initialization failed ..." );
1663 // Initialize plib net interface
1664 netInit( &argc, argv );
1666 // Initialize ssg (from plib). Needs to come before we do any
1667 // other ssg stuff, but after opengl/glut has been initialized.
1670 // Initialize the user interface (we need to do this before
1671 // passing off control to glut and before fgInitGeneral to get our
1675 // Read the list of available aircrafts
1678 #ifdef GL_EXT_texture_lod_bias
1679 glTexEnvf( GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, -0.5 ) ;
1682 #ifdef FG_EXPERIMENTAL_POINT_LIGHTING
1683 // get the address of our OpenGL extensions
1684 if ( fgGetBool("/sim/rendering/distance-attenuation") )
1687 glPointParameterfEXT = (PFNGLPOINTPARAMETERFEXTPROC)
1688 wglGetProcAddress("glPointParameterfEXT");
1689 glPointParameterfvEXT = (PFNGLPOINTPARAMETERFVEXTPROC)
1690 wglGetProcAddress("glPointParameterfvEXT");
1692 glPointParameterfEXT = (OpenGLFuncExt)
1693 glXGetProcAddressARB((GLubyte *)"glPointParameterfEXT");
1694 glPointParameterfvEXT = (OpenGLFuncExtv)
1695 glXGetProcAddressARB((GLubyte *)"glPointParameterfvEXT");
1700 // based on the requested presets, calculate the true starting
1705 SGTime *t = fgInitTime();
1706 globals->set_time_params( t );
1708 // Do some quick general initializations
1709 if( !fgInitGeneral()) {
1710 SG_LOG( SG_GENERAL, SG_ALERT,
1711 "General initializations failed ..." );
1715 SGPath modelpath( globals->get_fg_root() );
1716 ssgModelPath( (char *)modelpath.c_str() );
1718 // Initialize the global scenery manager
1719 globals->set_scenery( new FGScenery );
1720 globals->get_scenery()->init();
1721 globals->get_scenery()->bind();
1723 // Initialize the global tile manager
1724 globals->set_tile_mgr( new FGTileMgr );
1726 ////////////////////////////////////////////////////////////////////
1727 // Initialize the property-based built-in commands
1728 ////////////////////////////////////////////////////////////////////
1731 ////////////////////////////////////////////////////////////////////
1732 // Initialize the general model subsystem.
1733 ////////////////////////////////////////////////////////////////////
1735 globals->set_model_loader(new FGModelLoader);
1736 globals->set_texture_loader(new FGTextureLoader);
1737 globals->set_model_mgr(new FGModelMgr);
1738 globals->get_model_mgr()->init();
1739 globals->get_model_mgr()->bind();
1741 ////////////////////////////////////////////////////////////////////
1742 // Initialize the 3D aircraft model subsystem.
1743 ////////////////////////////////////////////////////////////////////
1745 globals->set_aircraft_model(new FGAircraftModel);
1746 globals->get_aircraft_model()->init();
1747 globals->get_aircraft_model()->bind();
1749 ////////////////////////////////////////////////////////////////////
1750 // Initialize the view manager subsystem.
1751 ////////////////////////////////////////////////////////////////////
1753 FGViewMgr *viewmgr = new FGViewMgr;
1754 globals->set_viewmgr( viewmgr );
1759 // Initialize the sky
1760 SGPath ephem_data_path( globals->get_fg_root() );
1761 ephem_data_path.append( "Astro" );
1762 SGEphemeris *ephem = new SGEphemeris( ephem_data_path.c_str() );
1763 ephem->update( globals->get_time_params()->getMjd(),
1764 globals->get_time_params()->getLst(),
1766 globals->set_ephem( ephem );
1768 // TODO: move to environment mgr
1770 SGPath texture_path(globals->get_fg_root());
1771 texture_path.append("Textures");
1772 texture_path.append("Sky");
1773 for (int i = 0; i < FGEnvironmentMgr::MAX_CLOUD_LAYERS; i++) {
1774 SGCloudLayer * layer = new SGCloudLayer(texture_path.str());
1775 thesky->add_cloud_layer(layer);
1779 SGPath sky_tex_path( globals->get_fg_root() );
1780 sky_tex_path.append( "Textures" );
1781 sky_tex_path.append( "Sky" );
1782 thesky->texture_path( sky_tex_path.str() );
1784 thesky->build( 550.0, 550.0,
1785 globals->get_ephem()->getNumPlanets(),
1786 globals->get_ephem()->getPlanets(), 60000.0,
1787 globals->get_ephem()->getNumStars(),
1788 globals->get_ephem()->getStars(), 60000.0 );
1790 // Initialize MagVar model
1791 SGMagVar *magvar = new SGMagVar();
1792 globals->set_mag( magvar );
1794 // airport = new ssgBranch;
1795 // airport->setName( "Airport Lighting" );
1796 // lighting->addKid( airport );
1802 #ifdef FG_NETWORK_OLK
1803 // Do the network intialization
1804 if ( fgGetBool("/sim/networking/network-olk") ) {
1805 printf("Multipilot mode %s\n",
1806 fg_net_init( globals->get_scenery()->get_scene_graph() ) );
1810 // build our custom render states
1811 fgBuildRenderStates();
1813 // pass control off to the master GLUT event handler
1816 // we never actually get here ... but to avoid compiler warnings,
1822 // $$$ end - added VS Renganathan, 15 Oct 2K
1823 // - added Venky , 12 Nov 2K
1825 #if defined(__linux__) && defined(__i386__)
1827 static void handleFPE (int);
1832 fpu_control_t fpe_flags = 0;
1833 _FPU_GETCW(fpe_flags);
1834 // fpe_flags &= ~_FPU_MASK_IM; // invalid operation
1835 // fpe_flags &= ~_FPU_MASK_DM; // denormalized operand
1836 // fpe_flags &= ~_FPU_MASK_ZM; // zero-divide
1837 // fpe_flags &= ~_FPU_MASK_OM; // overflow
1838 // fpe_flags &= ~_FPU_MASK_UM; // underflow
1839 // fpe_flags &= ~_FPU_MASK_PM; // precision (inexact result)
1840 _FPU_SETCW(fpe_flags);
1841 signal(SIGFPE, handleFPE);
1848 SG_LOG(SG_GENERAL, SG_ALERT, "Floating point interrupt (SIGFPE)");
1861 short CPSGetCurrentProcess(PSN *psn);
1862 short CPSSetProcessName (PSN *psn, char *processname);
1863 short CPSEnableForegroundOperation(PSN *psn, int _arg2, int _arg3, int _arg4, int _arg5);
1864 short CPSSetFrontProcess(PSN *psn);
1867 #define CPSEnableFG(psn) CPSEnableForegroundOperation(psn,0x03,0x3C,0x2C,0x1103)
1871 // Main entry point; catch any exceptions that have made it this far.
1872 int main ( int argc, char **argv ) {
1874 // Enable floating-point exceptions for Linux/x86
1875 #if defined(__linux__) && defined(__i386__)
1879 // Enable floating-point exceptions for Windows
1880 #if defined( _MSC_VER ) && defined( DEBUG )
1881 // Christian, we should document what this does
1882 _control87( _EM_INEXACT, _MCW_EM );
1885 #if defined( HAVE_BC5PLUS )
1886 _control87(MCW_EM, MCW_EM); /* defined in float.h */
1889 // Keyboard focus hack
1894 glutInit (&argc, argv);
1896 CPSGetCurrentProcess(&psn);
1897 CPSSetProcessName(&psn, "FlightGear");
1899 CPSSetFrontProcess(&psn);
1903 // FIXME: add other, more specific
1906 fgMainInit(argc, argv);
1907 } catch (sg_throwable &t) {
1908 // We must use cerr rather than
1909 // logging, since logging may be
1911 cerr << "Fatal error: " << t.getFormattedMessage()
1912 << "\n (received from " << t.getOrigin() << ')' << endl;
1920 void fgLoadDCS(void) {
1922 ssgEntity *ship_obj = NULL;
1924 char obj_filename[25];
1926 for ( int k = 0; k < 32; k++ ) {
1930 SGPath tile_path( globals->get_fg_root());
1931 tile_path.append( "Scenery" );
1932 tile_path.append( "Objects.txt" );
1933 sg_gzifstream in( tile_path.str() );
1934 if ( ! in.is_open() ) {
1935 SG_LOG( SG_TERRAIN, SG_ALERT, "Cannot open file: " << tile_path.str() );
1938 SGPath modelpath( globals->get_fg_root() );
1939 modelpath.append( "Models" );
1940 modelpath.append( "Geometry" );
1942 SGPath texturepath( globals->get_fg_root() );
1943 texturepath.append( "Models" );
1944 texturepath.append( "Textures" );
1946 ssgModelPath( (char *)modelpath.c_str() );
1947 ssgTexturePath( (char *)texturepath.c_str() );
1949 ship_sel = new ssgSelector;
1952 while ( ! in.eof() ) {
1954 if ( in.get( c ) && c == '#' ) {
1958 in >> obj_filename >> obj_lat[objc] >> obj_lon[objc] >> obj_alt[objc];
1959 /* cout << endl << obj_filename << " " << obj_lat[objc] << " " << obj_lon[objc] << " " << obj_alt[objc] << endl;
1960 int chj=getchar();*/
1962 obj_lon[objc] *=SGD_DEGREES_TO_RADIANS;
1963 obj_lat[objc] *=SGD_DEGREES_TO_RADIANS;
1965 ship_pos[objc] = new ssgTransform;
1967 // type "repeat" in objects.txt to load one more
1968 // instance of the last object.
1970 if ( strcmp(obj_filename,"repeat") != 0) {
1972 globals->get_model_loader()->load_model( obj_filename );
1975 if ( ship_obj != NULL ) {
1976 ship_obj->setName(obj_filename);
1978 ship_obj->clrTraversalMaskBits( SSGTRAV_HOT );
1980 ship_obj->setTraversalMaskBits( SSGTRAV_HOT );
1981 ship_pos[objc]->addKid( ship_obj ); // add object to transform node
1982 ship_sel->addKid( ship_pos[objc] ); // add transform node to selector
1983 SG_LOG( SG_TERRAIN, SG_ALERT, "Loaded file: "
1986 SG_LOG( SG_TERRAIN, SG_ALERT, "Cannot open file: "
1990 // temporary hack for deck lights - ultimately should move to PLib (when??)
1991 //const char *extn = file_extension ( obj_filename ) ;
1993 ssgVertexArray *lights = new ssgVertexArray( 100 );
1994 ssgVertexArray *lightpoints = new ssgVertexArray( 100 );
1995 ssgVertexArray *lightnormals = new ssgVertexArray( 100 );
1996 ssgVertexArray *lightdir = new ssgVertexArray( 100 );
1997 int ltype[500], light_type;
1998 static int ltcount = 0;
2000 sgVec3 rway_dir,rway_normal,lightpt;
2002 modelpath.append(obj_filename);
2003 sg_gzifstream in1( modelpath.str() );
2004 if ( ! in1.is_open() ) {
2005 SG_LOG( SG_TERRAIN, SG_ALERT, "Cannot open file: " << modelpath.str() );
2007 while ( ! in1.eof() ) {
2009 if ( in1.get( c ) && c == '#' ) {
2014 //cout << token << endl;
2015 if ( token == "runway" ) {
2017 sgSetVec3 (rway_dir, node[0], node[1], node[2] );
2018 } else if ( token == "edgelight" ) {
2020 sgSetVec3 (rway_normal, node[0], node[1], node[2] );
2022 } else if ( token == "taxi" ) {
2024 sgSetVec3 (rway_normal, node[0], node[1], node[2] );
2026 } else if ( token == "vasi" ) {
2028 sgSetVec3 (rway_normal, node[0], node[1], node[2] );
2030 } else if ( token == "threshold" ) {
2032 sgSetVec3 (rway_normal, node[0], node[1], node[2] );
2034 } else if ( token == "rabbit" ) {
2036 sgSetVec3 (rway_normal, node[0], node[1], node[2] );
2038 } else if ( token == "ols" ) {
2040 sgSetVec3 (rway_ols, node[0], node[1], node[2] );
2042 } else if ( token == "red" ) {
2044 sgSetVec3 (rway_normal, node[0], node[1], node[2] );
2046 } else if ( token == "green" ) {
2048 sgSetVec3 (rway_normal, node[0], node[1], node[2] );
2050 } else if ( token == "lp" ) {
2052 sgSetVec3 (lightpt, node[0], node[1], node[2] );
2053 lightpoints->add( lightpt );
2054 lightnormals->add( rway_normal );
2055 lightdir->add( rway_dir );
2056 ltype[ltcount]= light_type;
2059 if (in1.eof()) break;
2063 if ( lightpoints->getNum() ) {
2064 ssgBranch *lightpoints_branch;
2065 long int dummy = -999;
2066 dummy_tile = new FGTileEntry((SGBucket)dummy);
2067 dummy_tile->lightmaps_sequence = new ssgSelector;
2068 dummy_tile->ols_transform = new ssgTransform;
2070 // call function to generate the runway lights
2071 lightpoints_branch =
2072 dummy_tile->gen_runway_lights( lightpoints, lightnormals,
2074 lightpoints_brightness->addKid(lightpoints_branch);
2075 lightpoints_transform->addKid(lightpoints_brightness);
2076 //dummy_tile->lightmaps_sequence->setTraversalMaskBits( SSGTRAV_HOT );
2077 lightpoints_transform->addKid( dummy_tile->lightmaps_sequence );
2078 lightpoints_transform->ref();
2079 globals->get_scenery()->get_gnd_lights_root()->addKid( lightpoints_transform );
2083 // end hack for deck lights
2087 if (in.eof()) break;
2091 SG_LOG ( SG_TERRAIN, SG_ALERT, "Finished object processing." );
2093 globals->get_scenery()->get_terrain_branch()->addKid( ship_sel ); //add selector node to root node
2100 void fgUpdateDCS (void) {
2102 // double eye_lat,eye_lon,eye_alt;
2103 // static double obj_head;
2104 double sl_radius,obj_latgc;
2105 // float nresultmat[4][4];
2106 // sgMat4 Trans,rothead,rotlon,rot180,rotlat,resultmat1,resultmat2,resultmat3;
2109 // Instantaneous Geodetic Lat/Lon/Alt of moving object
2110 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
2112 // Deck should be the first object in objects.txt in case of fdm=ada
2114 if (!strcmp(fgGetString("/sim/flight-model"), "ada")) {
2115 if ((fdm->get_iaux(1))==1)
2117 obj_lat[1] = fdm->get_daux(1)*SGD_DEGREES_TO_RADIANS;
2118 obj_lon[1] = fdm->get_daux(2)*SGD_DEGREES_TO_RADIANS;
2119 obj_alt[1] = fdm->get_daux(3);
2120 obj_pitch[1] = fdm->get_faux(1);
2121 obj_roll[1] = fdm->get_faux(2);
2125 for ( int m = 0; m < objc; m++ ) {
2126 //cout << endl << obj_lat[m]*SGD_RADIANS_TO_DEGREES << " " << obj_lon[m]*SGD_RADIANS_TO_DEGREES << " " << obj_alt[m] << " " << objc << endl;
2129 //Geodetic to Geocentric angles for rotation
2130 sgGeodToGeoc(obj_lat[m],obj_alt[m],&sl_radius,&obj_latgc);
2132 //moving object gbs-posn in cartesian coords
2133 Point3D obj_posn = Point3D( obj_lon[m],obj_lat[m],obj_alt[m]);
2134 Point3D obj_pos = sgGeodToCart( obj_posn );
2136 // Translate moving object w.r.t eye
2137 Point3D Objtrans = obj_pos - globals->get_scenery()->get_center();
2142 // rotate dynamic objects for lat,lon & alt and other motion about its axes
2145 sgMakeTransMat4( sgTRANS, bz[0],bz[1],bz[2]);
2147 sgVec3 ship_fwd,ship_rt,ship_up;
2148 sgSetVec3( ship_fwd, 1.0, 0.0, 0.0);//east,roll
2149 sgSetVec3( ship_rt, 0.0, 1.0, 0.0);//up,pitch
2150 sgSetVec3( ship_up, 0.0, 0.0, 1.0); //north,yaw
2152 sgMat4 sgROT_lon, sgROT_lat, sgROT_hdg, sgROT_pitch, sgROT_roll;
2153 sgMakeRotMat4( sgROT_lon, obj_lon[m]*SGD_RADIANS_TO_DEGREES, ship_up );
2154 sgMakeRotMat4( sgROT_lat, 90-obj_latgc*SGD_RADIANS_TO_DEGREES, ship_rt );
2155 sgMakeRotMat4( sgROT_hdg, 180.0, ship_up );
2156 sgMakeRotMat4( sgROT_pitch, obj_pitch[m], ship_rt );
2157 sgMakeRotMat4( sgROT_roll, obj_roll[m], ship_fwd );
2160 sgCopyMat4( sgTUX, sgROT_hdg );
2161 sgPostMultMat4( sgTUX, sgROT_pitch );
2162 sgPostMultMat4( sgTUX, sgROT_roll );
2163 sgPostMultMat4( sgTUX, sgROT_lat );
2164 sgPostMultMat4( sgTUX, sgROT_lon );
2165 sgPostMultMat4( sgTUX, sgTRANS );
2168 sgSetCoord(&shippos, sgTUX );
2169 ship_pos[m]->setTransform( &shippos );
2170 // temporary hack for deck lights - ultimately should move to PLib (when ??)
2172 if (lightpoints_transform) {
2173 lightpoints_transform->setTransform( &shippos );
2174 float sun_angle = cur_light_params.sun_angle * SGD_RADIANS_TO_DEGREES;
2175 if ( sun_angle > 89 ) {
2176 lightpoints_brightness->select(0x01);
2178 lightpoints_brightness->select(0x00);
2187 sgXformPnt3( rp, rway_ols, sgTUX );
2188 vp = globals->get_current_view()->get_view_pos();
2189 to[0] = rp[0]-vp[0];
2190 to[1] = rp[1]-vp[1];
2191 to[2] = rp[2]-vp[2];
2192 float dist = sgLengthVec3( to );
2193 alt = (current_aircraft.fdm_state->get_Altitude() * SG_FEET_TO_METER)-rway_ols[2];
2195 elev = asin(alt/dist)*SGD_RADIANS_TO_DEGREES;
2197 ref_elev = elev - 3.75; // +ve above, -ve below
2201 // DO NOT DELETE THIS CODE - This is to compare a discrete FLOLS (without LOD) with analog FLOLS
2202 // if (ref_elev > 0.51) sel = 0x21;
2203 // if ((ref_elev <= 0.51) & (ref_elev > 0.17)) sel = 0x22;
2204 // if ((ref_elev <= 0.17) & (ref_elev >= -0.17)) sel = 0x24;
2205 // if ((ref_elev < -0.17) & (ref_elev >= -0.51)) sel = 0x28;
2206 // if (ref_elev < -0.51) sel = 0x30;
2207 // DO NOT DELETE THIS CODE - This is to compare a discrete FLOLS (without LOD) with analog FLOLS
2208 dummy_tile->lightmaps_sequence->select(sel);
2211 sgCopyVec3 (up, ship_up);
2213 sgScaleVec3 (up, 4.0*ref_elev*dist/750.0);
2215 sgScaleVec3 (up, 4.0*ref_elev);
2216 dummy_tile->ols_transform->setTransform(up);
2217 //cout << "ref_elev " << ref_elev << endl;
2219 // end hack for deck lights
2222 if ( ship_sel != NULL ) {
2223 ship_sel->select(0xFFFFFFFE); // first object is ownship, added to acmodel
2227 // $$$ end - added VS Renganathan, 15 Oct 2K
2228 // added Venky , 12 Nov 2K