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 #include <simgear/scene/model/animation.hxx>
81 #include <simgear/scene/model/location.hxx>
82 #ifdef FG_USE_CLOUDS_3D
83 # include <simgear/sky/clouds3d/SkySceneLoader.hpp>
84 # include <simgear/sky/clouds3d/SkyUtil.hpp>
86 #include <simgear/sky/sky.hxx>
87 #include <simgear/timing/sg_time.hxx>
89 #include <Include/general.hxx>
91 #include <Aircraft/aircraft.hxx>
93 #include <ATC/ATCmgr.hxx>
94 #include <ATC/ATCdisplay.hxx>
95 #include <ATC/AIMgr.hxx>
98 #include <Autopilot/newauto.hxx>
100 #include <Cockpit/hud.hxx>
101 #include <Cockpit/cockpit.hxx>
102 #include <Cockpit/radiostack.hxx>
104 #include <FDM/UIUCModel/uiuc_aircraftdir.h>
106 #include <Model/acmodel.hxx>
107 #include <Model/loader.hxx>
108 #include <Model/model.hxx>
109 #include <Model/modelmgr.hxx>
110 #include <Model/panelnode.hxx>
111 #ifdef FG_NETWORK_OLK
112 #include <NetworkOLK/network.h>
116 #include <MultiPlayer/multiplaytxmgr.hxx>
117 #include <MultiPlayer/multiplayrxmgr.hxx>
120 #include <Objects/matlib.hxx>
121 #include <Scenery/scenery.hxx>
122 #include <Scenery/tilemgr.hxx>
123 #ifdef ENABLE_AUDIO_SUPPORT
124 # include <Sound/soundmgr.hxx>
125 # include <Sound/fg_fx.hxx>
126 # include <Sound/morse.hxx>
128 #include <Systems/system_mgr.hxx>
129 #include <Instrumentation/instrument_mgr.hxx>
130 #include <Time/FGEventMgr.hxx>
131 #include <Time/fg_timer.hxx>
132 #include <Time/light.hxx>
133 #include <Time/sunpos.hxx>
134 #include <Time/tmp.hxx>
137 #include <simgear/misc/sgstream.hxx>
138 #include <simgear/math/point3d.hxx>
139 #include <FDM/flight.hxx>
140 #include <FDM/ADA.hxx>
141 #include <Scenery/tileentry.hxx>
143 #include "fg_commands.hxx"
145 #ifdef FG_EXPERIMENTAL_POINT_LIGHTING
147 typedef void (APIENTRY * PFNGLPOINTPARAMETERFEXTPROC)(GLenum pname,
149 typedef void (APIENTRY * PFNGLPOINTPARAMETERFVEXTPROC)(GLenum pname,
150 const GLfloat *params);
152 PFNGLPOINTPARAMETERFEXTPROC glPointParameterfEXT = 0;
153 PFNGLPOINTPARAMETERFVEXTPROC glPointParameterfvEXT = 0;
157 typedef void (* OpenGLFuncExt)(GLenum pname, GLfloat param);
158 typedef void (* OpenGLFuncExtv)(GLenum pname, const GLfloat *params);
160 OpenGLFuncExt glPointParameterfEXT = 0;
161 OpenGLFuncExtv glPointParameterfvEXT = 0;
165 float default_attenuation[3] = {1.0, 0.0, 0.0};
166 //Required for using GL_extensions
167 void fgLoadDCS (void);
168 void fgUpdateDCS (void);
169 ssgSelector *ship_sel=NULL;
170 // upto 32 instances of a same object can be loaded.
171 ssgTransform *ship_pos[32];
172 double obj_lat[32],obj_lon[32],obj_alt[32],obj_pitch[32],obj_roll[32];
174 ssgSelector *lightpoints_brightness = new ssgSelector;
175 ssgTransform *lightpoints_transform = new ssgTransform;
176 FGTileEntry *dummy_tile;
179 // Clip plane settings...
180 float scene_nearplane = 0.5f;
181 float scene_farplane = 120000.0f;
183 static double delta_time_sec = 0;
187 # include <WeatherCM/FGLocalWeatherDatabase.h>
189 # include <Environment/environment_mgr.hxx>
194 #include "fg_init.hxx"
196 #include "fg_props.hxx"
197 #include "globals.hxx"
198 #include "splash.hxx"
199 #include "viewmgr.hxx"
200 #include "options.hxx"
201 #include "logger.hxx"
204 # include <console.h> // -dw- for command line dialog
208 FGEventMgr global_events;
210 // This is a record containing a bit of global housekeeping information
213 // Specify our current idle function state. This is used to run all
214 // our initializations out of the glutIdleLoop() so that we can get a
215 // splash screen up and running right away.
216 static int idle_state = 0;
217 static long global_multi_loop;
219 // fog constants. I'm a little nervous about putting actual code out
220 // here but it seems to work (?)
221 static const double m_log01 = -log( 0.01 );
222 static const double sqrt_m_log01 = sqrt( m_log01 );
223 static GLfloat fog_exp_density;
224 static GLfloat fog_exp2_density;
225 static GLfloat rwy_exp2_punch_through;
226 static GLfloat taxi_exp2_punch_through;
227 static GLfloat ground_exp2_punch_through;
229 #ifdef FG_NETWORK_OLK
230 ssgSelector *fgd_sel = NULL;
231 ssgTransform *fgd_pos = NULL;
237 #ifdef FG_USE_CLOUDS_3D
238 SkySceneLoader *sgClouds3d;
239 bool _bcloud_orig = true;
243 sgMat4 copy_of_ssgOpenGLAxisSwapMatrix =
245 { 1.0f, 0.0f, 0.0f, 0.0f },
246 { 0.0f, 0.0f, -1.0f, 0.0f },
247 { 0.0f, 1.0f, 0.0f, 0.0f },
248 { 0.0f, 0.0f, 0.0f, 1.0f }
251 // The following defines flightgear options. Because glutlib will also
252 // want to parse its own options, those options must not be included here
253 // or they will get parsed by the main program option parser. Hence case
254 // is significant for any option added that might be in conflict with
257 // glutlib parses for:
259 // -direct (invalid in Win32)
263 // -indirect (invalid in Win32)
266 // Note that glutlib depends upon strings while this program's
267 // option parser wants only initial characters followed by numbers
272 ssgSimpleState *cloud3d_imposter_state;
273 ssgSimpleState *default_state;
274 ssgSimpleState *hud_and_panel;
275 ssgSimpleState *menus;
277 SGTimeStamp last_time_stamp;
278 SGTimeStamp current_time_stamp;
281 void fgBuildRenderStates( void ) {
282 default_state = new ssgSimpleState;
283 default_state->ref();
284 default_state->disable( GL_TEXTURE_2D );
285 default_state->enable( GL_CULL_FACE );
286 default_state->enable( GL_COLOR_MATERIAL );
287 default_state->setColourMaterial( GL_AMBIENT_AND_DIFFUSE );
288 default_state->setMaterial( GL_EMISSION, 0, 0, 0, 1 );
289 default_state->setMaterial( GL_SPECULAR, 0, 0, 0, 1 );
290 default_state->disable( GL_BLEND );
291 default_state->disable( GL_ALPHA_TEST );
292 default_state->disable( GL_LIGHTING );
294 cloud3d_imposter_state = new ssgSimpleState;
295 cloud3d_imposter_state->ref();
296 cloud3d_imposter_state->enable( GL_TEXTURE_2D );
297 cloud3d_imposter_state->enable( GL_CULL_FACE );
298 cloud3d_imposter_state->enable( GL_COLOR_MATERIAL );
299 cloud3d_imposter_state->setColourMaterial( GL_AMBIENT_AND_DIFFUSE );
300 cloud3d_imposter_state->setMaterial( GL_DIFFUSE, 1, 1, 1, 1 );
301 cloud3d_imposter_state->setMaterial( GL_AMBIENT, 1, 1, 1, 1 );
302 cloud3d_imposter_state->setMaterial( GL_EMISSION, 0, 0, 0, 1 );
303 cloud3d_imposter_state->setMaterial( GL_SPECULAR, 0, 0, 0, 1 );
304 cloud3d_imposter_state->enable( GL_BLEND );
305 cloud3d_imposter_state->enable( GL_ALPHA_TEST );
306 cloud3d_imposter_state->disable( GL_LIGHTING );
308 hud_and_panel = new ssgSimpleState;
309 hud_and_panel->ref();
310 hud_and_panel->disable( GL_CULL_FACE );
311 hud_and_panel->disable( GL_TEXTURE_2D );
312 hud_and_panel->disable( GL_LIGHTING );
313 hud_and_panel->enable( GL_BLEND );
315 menus = new ssgSimpleState;
317 menus->disable( GL_CULL_FACE );
318 menus->disable( GL_TEXTURE_2D );
319 menus->enable( GL_BLEND );
323 // fgInitVisuals() -- Initialize various GL/view parameters
324 void fgInitVisuals( void ) {
327 l = &cur_light_params;
329 #ifndef GLUT_WRONG_VERSION
330 // Go full screen if requested ...
331 if ( fgGetBool("/sim/startup/fullscreen") ) {
336 // If enabled, normal vectors specified with glNormal are scaled
337 // to unit length after transformation. Enabling this has
338 // performance implications. See the docs for glNormal.
339 // glEnable( GL_NORMALIZE );
341 glEnable( GL_LIGHTING );
342 glEnable( GL_LIGHT0 );
343 // glLightfv( GL_LIGHT0, GL_POSITION, l->sun_vec ); // done later with ssg
346 sgSetVec3( sunpos, l->sun_vec[0], l->sun_vec[1], l->sun_vec[2] );
347 ssgGetLight( 0 ) -> setPosition( sunpos );
349 glFogi (GL_FOG_MODE, GL_EXP2);
350 if ( (!strcmp(fgGetString("/sim/rendering/fog"), "disabled")) ||
351 (!fgGetBool("/sim/rendering/shading"))) {
352 // if fastest fog requested, or if flat shading force fastest
353 glHint ( GL_FOG_HINT, GL_FASTEST );
354 } else if ( !strcmp(fgGetString("/sim/rendering/fog"), "nicest") ) {
355 glHint ( GL_FOG_HINT, GL_NICEST );
357 if ( fgGetBool("/sim/rendering/wireframe") ) {
359 glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
362 // This is the default anyways, but it can't hurt
363 glFrontFace ( GL_CCW );
366 // glEnable(GL_POINT_SMOOTH);
367 // glEnable(GL_LINE_SMOOTH);
368 // glEnable(GL_POLYGON_SMOOTH);
372 // For HiRes screen Dumps using Brian Pauls TR Library
373 void trRenderFrame( void ) {
375 if ( fgPanelVisible() ) {
376 GLfloat height = fgGetInt("/sim/startup/ysize");
378 (globals->get_current_panel()->getViewHeight() - globals->get_current_panel()->getYOffset())
379 * (height / 768.0) + 1;
380 glTranslatef( 0.0, view_h, 0.0 );
383 static GLfloat black[4] = { 0.0, 0.0, 0.0, 1.0 };
384 static GLfloat white[4] = { 1.0, 1.0, 1.0, 1.0 };
386 fgLIGHT *l = &cur_light_params;
388 glClearColor(l->adj_fog_color[0], l->adj_fog_color[1],
389 l->adj_fog_color[2], l->adj_fog_color[3]);
391 glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
393 // set the opengl state to known default values
394 default_state->force();
397 glFogf ( GL_FOG_DENSITY, fog_exp2_density);
398 glFogi ( GL_FOG_MODE, GL_EXP2 );
399 glFogfv ( GL_FOG_COLOR, l->adj_fog_color );
401 // GL_LIGHT_MODEL_AMBIENT has a default non-zero value so if
402 // we only update GL_AMBIENT for our lights we will never get
403 // a completely dark scene. So, we set GL_LIGHT_MODEL_AMBIENT
404 // explicitely to black.
405 glLightModelfv( GL_LIGHT_MODEL_AMBIENT, black );
406 glLightModeli( GL_LIGHT_MODEL_LOCAL_VIEWER, GL_FALSE );
408 ssgGetLight( 0 ) -> setColour( GL_AMBIENT, l->scene_ambient );
410 // texture parameters
411 glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ) ;
412 glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST ) ;
414 // we need a white diffuse light for the phase of the moon
415 ssgGetLight( 0 ) -> setColour( GL_DIFFUSE, white );
418 // draw the ssg scene
419 // return to the desired diffuse color
420 ssgGetLight( 0 ) -> setColour( GL_DIFFUSE, l->scene_diffuse );
421 glEnable( GL_DEPTH_TEST );
422 ssgSetNearFar( scene_nearplane, scene_farplane );
423 ssgCullAndDraw( globals->get_scenery()->get_scene_graph() );
426 glFogf (GL_FOG_DENSITY, rwy_exp2_punch_through);
427 ssgSetNearFar( scene_nearplane, scene_farplane );
428 ssgCullAndDraw( globals->get_scenery()->get_rwy_lights_root() );
430 ssgCullAndDraw( globals->get_scenery()->get_gnd_lights_root() );
432 if (fgGetBool("/environment/clouds/status"))
433 thesky->postDraw( cur_fdm_state->get_Altitude() * SG_FEET_TO_METER );
435 globals->get_model_mgr()->draw();
436 globals->get_aircraft_model()->draw();
440 // Update all Visuals (redraws anything graphics related)
441 void fgRenderFrame() {
443 GLfloat black[4] = { 0.0, 0.0, 0.0, 1.0 };
444 GLfloat white[4] = { 1.0, 1.0, 1.0, 1.0 };
446 // Process/manage pending events
447 global_events.update( delta_time_sec );
449 // static const SGPropertyNode *longitude
450 // = fgGetNode("/position/longitude-deg");
451 // static const SGPropertyNode *latitude
452 // = fgGetNode("/position/latitude-deg");
453 // static const SGPropertyNode *altitude
454 // = fgGetNode("/position/altitude-ft");
455 static const SGPropertyNode *groundlevel_nearplane
456 = fgGetNode("/sim/current-view/ground-level-nearplane-m");
458 // Update the default (kludged) properties.
461 FGViewer *current__view = globals->get_current_view();
463 fgLIGHT *l = &cur_light_params;
464 static double last_visibility = -9999;
467 double actual_visibility;
468 if (fgGetBool("/environment/clouds/status"))
469 actual_visibility = thesky->get_visibility();
471 actual_visibility = fgGetDouble("/environment/visibility-m");
472 if ( actual_visibility != last_visibility ) {
473 last_visibility = actual_visibility;
475 fog_exp_density = m_log01 / actual_visibility;
476 fog_exp2_density = sqrt_m_log01 / actual_visibility;
477 ground_exp2_punch_through = sqrt_m_log01 / (actual_visibility * 1.5);
478 if ( actual_visibility < 8000 ) {
479 rwy_exp2_punch_through = sqrt_m_log01 / (actual_visibility * 2.5);
480 taxi_exp2_punch_through = sqrt_m_log01 / (actual_visibility * 1.5);
482 rwy_exp2_punch_through = sqrt_m_log01 / ( 8000 * 2.5 );
483 taxi_exp2_punch_through = sqrt_m_log01 / ( 8000 * 1.5 );
488 // GLfloat black[4] = { 0.0, 0.0, 0.0, 1.0 };
489 // GLfloat white[4] = { 1.0, 1.0, 1.0, 1.0 };
490 // GLfloat terrain_color[4] = { 0.54, 0.44, 0.29, 1.0 };
491 // GLfloat mat_shininess[] = { 10.0 };
492 GLbitfield clear_mask;
494 if ( idle_state != 1000 ) {
495 // still initializing, draw the splash screen
496 if ( fgGetBool("/sim/startup/splash-screen") ) {
497 fgSplashUpdate(0.0, 1.0);
499 // Keep resetting sim time while the sim is initializing
500 globals->set_sim_time_sec( 0.0 );
501 Animation::set_sim_time_sec( 0.0 );
503 // idle_state is now 1000 meaning we've finished all our
504 // initializations and are running the main loop, so this will
505 // now work without seg faulting the system.
507 // calculate our current position in cartesian space
508 globals->get_scenery()->set_center( globals->get_scenery()->get_next_center() );
511 fgReshape( fgGetInt("/sim/startup/xsize"),
512 fgGetInt("/sim/startup/ysize") );
514 if ( fgGetBool("/sim/rendering/clouds3d") ) {
515 glClear( GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT );
516 cloud3d_imposter_state->force();
518 glColor4f( 1.0, 1.0, 1.0, 1.0 );
519 glEnable(GL_DEPTH_TEST);
521 glBlendFunc( GL_ONE, GL_ONE_MINUS_SRC_ALPHA ) ;
523 #ifdef FG_USE_CLOUDS_3D
524 if ( _bcloud_orig ) {
525 Point3D c = globals->get_scenery()->get_center();
526 sgClouds3d->Set_Cloud_Orig( &c );
527 _bcloud_orig = false;
529 sgClouds3d->Update( current__view->get_absolute_view_pos() );
531 glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ) ;
532 glDisable(GL_DEPTH_TEST);
535 clear_mask = GL_DEPTH_BUFFER_BIT;
536 if ( fgGetBool("/sim/rendering/wireframe") ) {
537 clear_mask |= GL_COLOR_BUFFER_BIT;
540 if ( fgGetBool("/sim/rendering/skyblend") ) {
541 if ( fgGetBool("/sim/rendering/textures") ) {
542 // glClearColor(black[0], black[1], black[2], black[3]);
543 glClearColor(l->adj_fog_color[0], l->adj_fog_color[1],
544 l->adj_fog_color[2], l->adj_fog_color[3]);
545 clear_mask |= GL_COLOR_BUFFER_BIT;
548 glClearColor(l->sky_color[0], l->sky_color[1],
549 l->sky_color[2], l->sky_color[3]);
550 clear_mask |= GL_COLOR_BUFFER_BIT;
552 glClear( clear_mask );
554 // Tell GL we are switching to model view parameters
556 // I really should create a derived ssg node or use a call
557 // back or something so that I can draw the sky within the
558 // ssgCullAndDraw() function, but for now I just mimic what
559 // ssg does to set up the model view matrix
560 glMatrixMode(GL_MODELVIEW);
562 ssgSetCamera( (sgVec4 *)current__view->get_VIEW() );
564 // set the opengl state to known default values
565 default_state->force();
567 // update fog params if visibility has changed
568 double visibility_meters = fgGetDouble("/environment/visibility-m");
569 thesky->set_visibility(visibility_meters);
571 thesky->modify_vis( cur_fdm_state->get_Altitude() * SG_FEET_TO_METER,
572 ( global_multi_loop * fgGetInt("/sim/speed-up") )
573 / (double)fgGetInt("/sim/model-hz") );
575 // Set correct opengl fog density
576 glFogf (GL_FOG_DENSITY, fog_exp2_density);
578 // update the sky dome
579 if ( fgGetBool("/sim/rendering/skyblend") ) {
581 SG_LOG( SG_GENERAL, SG_BULK, "thesky->repaint() sky_color = "
582 << cur_light_params.sky_color[0] << " "
583 << cur_light_params.sky_color[1] << " "
584 << cur_light_params.sky_color[2] << " "
585 << cur_light_params.sky_color[3] );
586 SG_LOG( SG_GENERAL, SG_BULK, " fog = "
587 << cur_light_params.fog_color[0] << " "
588 << cur_light_params.fog_color[1] << " "
589 << cur_light_params.fog_color[2] << " "
590 << cur_light_params.fog_color[3] );
591 SG_LOG( SG_GENERAL, SG_BULK,
592 " sun_angle = " << cur_light_params.sun_angle
593 << " moon_angle = " << cur_light_params.moon_angle );
595 thesky->repaint( cur_light_params.sky_color,
596 cur_light_params.adj_fog_color,
597 cur_light_params.sun_angle,
598 cur_light_params.moon_angle,
599 globals->get_ephem()->getNumPlanets(),
600 globals->get_ephem()->getPlanets(),
601 globals->get_ephem()->getNumStars(),
602 globals->get_ephem()->getStars() );
605 SG_LOG( SG_GENERAL, SG_BULK,
606 "thesky->reposition( view_pos = " << view_pos[0] << " "
607 << view_pos[1] << " " << view_pos[2] );
608 SG_LOG( SG_GENERAL, SG_BULK,
609 " zero_elev = " << zero_elev[0] << " "
610 << zero_elev[1] << " " << zero_elev[2]
611 << " lon = " << cur_fdm_state->get_Longitude()
612 << " lat = " << cur_fdm_state->get_Latitude() );
613 SG_LOG( SG_GENERAL, SG_BULK,
614 " sun_rot = " << cur_light_params.sun_rotation
615 << " gst = " << SGTime::cur_time_params->getGst() );
616 SG_LOG( SG_GENERAL, SG_BULK,
617 " sun ra = " << globals->get_ephem()->getSunRightAscension()
618 << " sun dec = " << globals->get_ephem()->getSunDeclination()
619 << " moon ra = " << globals->get_ephem()->getMoonRightAscension()
620 << " moon dec = " << globals->get_ephem()->getMoonDeclination() );
623 thesky->reposition( current__view->get_view_pos(),
624 current__view->get_zero_elev(),
625 current__view->get_world_up(),
626 current__view->getLongitude_deg()
627 * SGD_DEGREES_TO_RADIANS,
628 current__view->getLatitude_deg()
629 * SGD_DEGREES_TO_RADIANS,
630 current__view->getAltitudeASL_ft()
632 cur_light_params.sun_rotation,
633 globals->get_time_params()->getGst(),
634 globals->get_ephem()->getSunRightAscension(),
635 globals->get_ephem()->getSunDeclination(),
637 globals->get_ephem()->getMoonRightAscension(),
638 globals->get_ephem()->getMoonDeclination(),
642 glEnable( GL_DEPTH_TEST );
643 if ( strcmp(fgGetString("/sim/rendering/fog"), "disabled") ) {
645 glFogi( GL_FOG_MODE, GL_EXP2 );
646 glFogfv( GL_FOG_COLOR, l->adj_fog_color );
649 // set sun/lighting parameters
650 ssgGetLight( 0 ) -> setPosition( l->sun_vec );
652 // GL_LIGHT_MODEL_AMBIENT has a default non-zero value so if
653 // we only update GL_AMBIENT for our lights we will never get
654 // a completely dark scene. So, we set GL_LIGHT_MODEL_AMBIENT
655 // explicitely to black.
656 glLightModelfv( GL_LIGHT_MODEL_AMBIENT, black );
658 ssgGetLight( 0 ) -> setColour( GL_AMBIENT, l->scene_ambient );
659 ssgGetLight( 0 ) -> setColour( GL_DIFFUSE, l->scene_diffuse );
660 ssgGetLight( 0 ) -> setColour( GL_SPECULAR, l->scene_specular );
662 // texture parameters
663 // glEnable( GL_TEXTURE_2D );
664 glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ) ;
665 glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST ) ;
667 // glMatrixMode( GL_PROJECTION );
669 ssgSetFOV( current__view->get_h_fov(),
670 current__view->get_v_fov() );
673 current_aircraft.fdm_state->get_Altitude() * SG_FEET_TO_METER
674 - globals->get_scenery()->get_cur_elev();
677 scene_nearplane = 10.0f;
678 scene_farplane = 120000.0f;
680 scene_nearplane = groundlevel_nearplane->getDoubleValue();
681 scene_farplane = 120000.0f;
684 ssgSetNearFar( scene_nearplane, scene_farplane );
686 // $$$ begin - added VS Renganthan 17 Oct 2K
689 // $$$ end - added VS Renganthan 17 Oct 2K
691 # ifdef FG_NETWORK_OLK
692 if ( fgGetBool("/sim/networking/network-olk") ) {
694 other = head->next; /* put listpointer to start */
695 while ( other != tail) { /* display all except myself */
696 if ( strcmp( other->ipadr, fgd_mcp_ip) != 0) {
697 other->fgd_sel->select(1);
698 sgSetCoord( &fgdpos, other->sgFGD_COORD );
699 other->fgd_pos->setTransform( &fgdpos );
704 // fgd_sel->select(1);
705 // sgCopyMat4( sgTUX, current_view.sgVIEW);
707 // sgSetCoord( &fgdpos, sgFGD_VIEW );
708 // fgd_pos->setTransform( &fgdpos);
713 // Update any multiplayer models
714 globals->get_multiplayer_rx_mgr()->Update();
717 if ( fgGetBool("/sim/rendering/skyblend") &&
718 fgGetBool("/sim/rendering/draw-otw") )
720 // draw the sky backdrop
722 // we need a white diffuse light for the phase of the moon
723 ssgGetLight( 0 ) -> setColour( GL_DIFFUSE, white );
727 // return to the desired diffuse color
728 ssgGetLight( 0 ) -> setColour( GL_DIFFUSE, l->scene_diffuse );
731 // draw the ssg scene
732 glEnable( GL_DEPTH_TEST );
734 ssgSetNearFar( scene_nearplane, scene_farplane );
736 if ( fgGetBool("/sim/rendering/wireframe") ) {
738 glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
740 if ( fgGetBool("/sim/rendering/draw-otw") ) {
741 ssgCullAndDraw( globals->get_scenery()->get_scene_graph() );
744 // This is a bit kludgy. Every 200 frames, do an extra
745 // traversal of the scene graph without drawing anything, but
746 // with the field-of-view set to 360x360 degrees. This
747 // ensures that out-of-range random objects that are not in
748 // the current view frustum will still be freed properly.
749 static int counter = 0;
751 if (counter == 200) {
754 // No need to put the near plane too close;
755 // this way, at least the aircraft can be
757 f.setNearFar(1000, 1000000);
759 ssgGetModelviewMatrix(m);
760 globals->get_scenery()->get_scene_graph()->cull(&f, m, true);
764 // change state for lighting here
766 // draw runway lighting
767 glFogf (GL_FOG_DENSITY, rwy_exp2_punch_through);
768 ssgSetNearFar( scene_nearplane, scene_farplane );
770 #ifdef FG_EXPERIMENTAL_POINT_LIGHTING
771 // Enable states for drawing points with GL_extension
772 glEnable(GL_POINT_SMOOTH);
774 if ( fgGetBool("/sim/rendering/distance-attenuation")
775 && glutExtensionSupported("GL_EXT_point_parameters") )
777 float quadratic[3] = {1.0, 0.001, 0.0000001};
778 // makes the points fade as they move away
779 glPointParameterfvEXT(GL_DISTANCE_ATTENUATION_EXT, quadratic);
780 glPointParameterfEXT(GL_POINT_SIZE_MIN_EXT, 1.0);
784 // blending function for runway lights
785 glBlendFunc ( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) ;
788 glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
789 glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
790 glEnable(GL_TEXTURE_GEN_S);
791 glEnable(GL_TEXTURE_GEN_T);
792 glPolygonMode(GL_FRONT, GL_POINT);
794 // draw runway lighting
795 if ( fgGetBool("/sim/rendering/draw-otw") ) {
796 ssgCullAndDraw( globals->get_scenery()->get_rwy_lights_root() );
799 // change punch through and then draw taxi lighting
800 glFogf ( GL_FOG_DENSITY, fog_exp2_density );
802 // sgSetVec3( taxi_fog, 0.0, 0.0, 0.0 );
803 // glFogfv ( GL_FOG_COLOR, taxi_fog );
804 if ( fgGetBool("/sim/rendering/draw-otw") ) {
805 ssgCullAndDraw( globals->get_scenery()->get_taxi_lights_root() );
809 glPolygonMode(GL_FRONT, GL_FILL);
810 glDisable(GL_TEXTURE_GEN_S);
811 glDisable(GL_TEXTURE_GEN_T);
813 //static int _frame_count = 0;
814 //if (_frame_count % 30 == 0) {
815 // printf("SSG: %s\n", ssgShowStats());
823 #ifdef FG_EXPERIMENTAL_POINT_LIGHTING
824 if ( fgGetBool("/sim/rendering/distance-attenuation")
825 && glutExtensionSupported("GL_EXT_point_parameters") )
827 glPointParameterfvEXT(GL_DISTANCE_ATTENUATION_EXT,
828 default_attenuation);
832 glDisable(GL_POINT_SMOOTH);
835 // draw ground lighting
836 glFogf (GL_FOG_DENSITY, ground_exp2_punch_through);
837 if ( fgGetBool("/sim/rendering/draw-otw") ) {
838 ssgCullAndDraw( globals->get_scenery()->get_gnd_lights_root() );
841 if ( fgGetBool("/sim/rendering/skyblend") ) {
842 // draw the sky cloud layers
843 if ( fgGetBool("/environment/clouds/status") &&
844 fgGetBool("/sim/rendering/draw-otw") )
846 thesky->postDraw( cur_fdm_state->get_Altitude()
847 * SG_FEET_TO_METER );
851 if ( fgGetBool("/sim/rendering/clouds3d") &&
852 fgGetBool("/sim/rendering/draw-otw") )
855 glDisable( GL_LIGHTING );
856 // cout << "drawing new clouds" << endl;
858 glEnable(GL_DEPTH_TEST);
860 glBlendFunc( GL_ONE, GL_ONE_MINUS_SRC_ALPHA ) ;
863 glEnable( GL_TEXTURE_2D );
864 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
865 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
866 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
867 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
870 #ifdef FG_USE_CLOUDS_3D
871 sgClouds3d->Draw((sgVec4 *)current__view->get_VIEW());
874 glEnable( GL_LIGHTING );
875 glEnable( GL_DEPTH_TEST );
876 glBlendFunc ( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ) ;
879 if ( fgGetBool("/sim/rendering/draw-otw") ) {
880 globals->get_model_mgr()->draw();
881 globals->get_aircraft_model()->draw();
884 // display HUD && Panel
886 glDisable( GL_DEPTH_TEST );
887 // glDisable( GL_CULL_FACE );
888 // glDisable( GL_TEXTURE_2D );
890 // update the controls subsystem
891 globals->get_controls()->update(delta_time_sec);
893 hud_and_panel->apply();
896 // Use the hud_and_panel ssgSimpleState for rendering the ATC output
897 // This only works properly if called before the panel call
898 if((fgGetBool("/sim/ATC/enabled")) || (fgGetBool("/sim/ai-traffic/enabled")))
899 globals->get_ATC_display()->update(delta_time_sec);
901 // update the panel subsystem
902 if ( globals->get_current_panel() != NULL ) {
903 globals->get_current_panel()->update(delta_time_sec);
907 // We can do translucent menus, so why not. :-)
909 glBlendFunc ( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ) ;
911 // glDisable ( GL_BLEND ) ;
913 glEnable( GL_DEPTH_TEST );
916 // Fade out the splash screen over the first three seconds.
917 double t = globals->get_sim_time_sec();
919 fgSplashUpdate(0.0, 1.0);
920 } else if ( t <= 3.0) {
921 fgSplashUpdate(0.0, (3.0 - t) / 2.0);
929 // Update internal time dependent calculations (i.e. flight model)
930 // FIXME: this distinction is obsolete; all subsystems now get delta
932 void fgUpdateTimeDepCalcs() {
933 static bool inited = false;
935 //SG_LOG(SG_FLIGHT,SG_INFO, "Updating time dep calcs()");
937 fgLIGHT *l = &cur_light_params;
939 // Initialize the FDM here if it hasn't been and if we have a
940 // scenery elevation hit.
942 // cout << "cur_fdm_state->get_inited() = " << cur_fdm_state->get_inited()
943 // << " cur_elev = " << scenery.get_cur_elev() << endl;
945 if ( !cur_fdm_state->get_inited() &&
946 globals->get_scenery()->get_cur_elev() > -9990 )
948 SG_LOG(SG_FLIGHT,SG_INFO, "Finally initializing fdm");
949 cur_fdm_state->init();
950 if ( cur_fdm_state->get_bound() ) {
951 cur_fdm_state->unbind();
953 cur_fdm_state->bind();
957 globals->get_environment_mgr()->update(delta_time_sec);
960 // conceptually, the following block could be done for each fdm
962 if ( !cur_fdm_state->get_inited() ) {
963 // do nothing, fdm isn't inited yet
965 // we have been inited, and we are good to go ...
971 globals->get_autopilot()->update(delta_time_sec);
972 cur_fdm_state->update(delta_time_sec);
975 globals->get_model_mgr()->update(delta_time_sec);
976 globals->get_aircraft_model()->update(delta_time_sec);
978 // update the view angle
979 globals->get_viewmgr()->update(delta_time_sec);
983 // Update solar system
984 globals->get_ephem()->update( globals->get_time_params()->getMjd(),
985 globals->get_time_params()->getLst(),
986 cur_fdm_state->get_Latitude() );
988 // Update radio stack model
989 current_radiostack->update(delta_time_sec);
993 void fgInitTimeDepCalcs( void ) {
998 static const double alt_adjust_ft = 3.758099;
999 static const double alt_adjust_m = alt_adjust_ft * SG_FEET_TO_METER;
1002 // What should we do when we have nothing else to do? Let's get ready
1003 // for the next move and update the display?
1004 static void fgMainLoop( void ) {
1006 static const SGPropertyNode *longitude
1007 = fgGetNode("/position/longitude-deg");
1008 static const SGPropertyNode *latitude
1009 = fgGetNode("/position/latitude-deg");
1010 static const SGPropertyNode *altitude
1011 = fgGetNode("/position/altitude-ft");
1012 static const SGPropertyNode *clock_freeze
1013 = fgGetNode("/sim/freeze/clock", true);
1014 static const SGPropertyNode *cur_time_override
1015 = fgGetNode("/sim/time/cur-time-override", true);
1017 // Update the elapsed time.
1018 static bool first_time = true;
1020 last_time_stamp.stamp();
1023 current_time_stamp.stamp();
1024 delta_time_sec = double(current_time_stamp - last_time_stamp) / 1000000.0;
1025 if (clock_freeze->getBoolValue())
1027 last_time_stamp = current_time_stamp;
1028 globals->inc_sim_time_sec( delta_time_sec );
1029 Animation::set_sim_time_sec( globals->get_sim_time_sec() );
1031 static long remainder = 0;
1033 #ifdef FANCY_FRAME_COUNTER
1037 static time_t last_time = 0;
1038 static int frames = 0;
1039 #endif // FANCY_FRAME_COUNTER
1041 SGTime *t = globals->get_time_params();
1043 sglog().setLogLevels( SG_ALL, (sgDebugPriority)fgGetInt("/sim/log-level") );
1044 sglog().setLogLevels( SG_ALL, SG_INFO );
1046 FGLocation * acmodel_location = 0;
1047 if(cur_fdm_state->getACModel() != 0) {
1048 acmodel_location = (FGLocation *) cur_fdm_state->getACModel()->get3DModel()->getFGLocation();
1051 SG_LOG( SG_ALL, SG_DEBUG, "Running Main Loop");
1052 SG_LOG( SG_ALL, SG_DEBUG, "======= ==== ====");
1054 #ifdef FG_NETWORK_OLK
1055 if ( fgGetBool("/sim/networking/network-olk") ) {
1056 if ( net_is_registered == 0 ) { // We first have to reg. to fgd
1057 // printf("FGD: Netupdate\n");
1058 fgd_send_com( "A", FGFS_host); // Send Mat4 data
1059 fgd_send_com( "B", FGFS_host); // Recv Mat4 data
1064 #if defined( ENABLE_PLIB_JOYSTICK )
1065 // Read joystick and update control settings
1066 // if ( fgGetString("/sim/control-mode") == "joystick" )
1068 // fgJoystickRead();
1070 #elif defined( ENABLE_GLUT_JOYSTICK )
1071 // Glut joystick support works by feeding a joystick handler
1072 // function to glut. This is taken care of once in the joystick
1073 // init routine and we don't have to worry about it again.
1076 // Fix elevation. I'm just sticking this here for now, it should
1077 // probably move eventually
1079 /* printf("Before - ground = %.2f runway = %.2f alt = %.2f\n",
1080 scenery.get_cur_elev(),
1081 cur_fdm_state->get_Runway_altitude() * SG_FEET_TO_METER,
1082 cur_fdm_state->get_Altitude() * SG_FEET_TO_METER); */
1084 // Curt is this code used? I don't see any problems when I comment it out.
1085 if ( acmodel_location != 0 ) {
1086 if ( acmodel_location->get_cur_elev_m() > -9990 && cur_fdm_state->get_inited() ) {
1087 if ( cur_fdm_state->get_Altitude() * SG_FEET_TO_METER <
1088 (acmodel_location->get_cur_elev_m() + alt_adjust_m - 3.0) ) {
1089 // now set aircraft altitude above ground
1090 printf("(*) Current Altitude = %.2f < %.2f forcing to %.2f\n",
1091 cur_fdm_state->get_Altitude() * SG_FEET_TO_METER,
1092 acmodel_location->get_cur_elev_m() + alt_adjust_m - 3.0,
1093 acmodel_location->get_cur_elev_m() + alt_adjust_m );
1094 cur_fdm_state->set_Altitude( (acmodel_location->get_cur_elev_m()
1095 + alt_adjust_m) * SG_METER_TO_FEET );
1096 SG_LOG( SG_ALL, SG_DEBUG,
1097 "<*> resetting altitude to "
1098 << cur_fdm_state->get_Altitude() * SG_FEET_TO_METER
1103 // End of code in question. (see Curt is this code used? above)
1105 /* printf("Adjustment - ground = %.2f runway = %.2f alt = %.2f\n",
1106 scenery.get_cur_elev(),
1107 cur_fdm_state->get_Runway_altitude() * SG_FEET_TO_METER,
1108 cur_fdm_state->get_Altitude() * SG_FEET_TO_METER); */
1110 // cout << "Warp = " << globals->get_warp() << endl;
1113 static bool last_clock_freeze = false;
1115 if ( clock_freeze->getBoolValue() ) {
1116 // clock freeze requested
1117 if ( cur_time_override->getLongValue() == 0 ) {
1118 fgSetLong( "/sim/time/cur-time-override", t->get_cur_time() );
1119 globals->set_warp( 0 );
1122 // no clock freeze requested
1123 if ( last_clock_freeze == true ) {
1124 // clock just unfroze, let's set warp as the difference
1125 // between frozen time and current time so we don't get a
1126 // time jump (and corresponding sky object and lighting
1128 globals->set_warp( cur_time_override->getLongValue() - time(NULL) );
1129 fgSetLong( "/sim/time/cur-time-override", 0 );
1131 if ( globals->get_warp_delta() != 0 ) {
1132 globals->inc_warp( globals->get_warp_delta() );
1136 last_clock_freeze = clock_freeze->getBoolValue();
1138 t->update( longitude->getDoubleValue() * SGD_DEGREES_TO_RADIANS,
1139 latitude->getDoubleValue() * SGD_DEGREES_TO_RADIANS,
1140 cur_time_override->getLongValue(),
1141 globals->get_warp() );
1143 if ( globals->get_warp_delta() != 0 ) {
1144 fgUpdateSkyAndLightingParams();
1147 // update magvar model
1148 globals->get_mag()->update( longitude->getDoubleValue()
1149 * SGD_DEGREES_TO_RADIANS,
1150 latitude->getDoubleValue()
1151 * SGD_DEGREES_TO_RADIANS,
1152 altitude->getDoubleValue() * SG_FEET_TO_METER,
1153 globals->get_time_params()->getJD() );
1155 // Get elapsed time (in usec) for this past frame
1156 elapsed = fgGetTimeInterval();
1157 SG_LOG( SG_ALL, SG_DEBUG,
1158 "Elapsed time interval is = " << elapsed
1159 << ", previous remainder is = " << remainder );
1161 // Calculate frame rate average
1162 #ifdef FANCY_FRAME_COUNTER
1163 /* old fps calculation */
1164 if ( elapsed > 0 ) {
1167 for ( i = FG_FRAME_RATE_HISTORY - 2; i >= 0; i-- ) {
1168 tmp = general.get_frame(i);
1170 // printf("frame[%d] = %.2f\n", i, g->frames[i]);
1171 general.set_frame(i+1,tmp);
1173 tmp = 1000000.0 / (float)elapsed;
1174 general.set_frame(0,tmp);
1175 // printf("frame[0] = %.2f\n", general.frames[0]);
1177 general.set_frame_rate(accum / (float)FG_FRAME_RATE_HISTORY);
1178 // printf("ave = %.2f\n", general.frame_rate);
1181 if ( (t->get_cur_time() != last_time) && (last_time > 0) ) {
1182 general.set_frame_rate( frames );
1183 fgSetInt("/sim/frame-rate", frames);
1184 SG_LOG( SG_ALL, SG_DEBUG,
1185 "--> Frame rate is = " << general.get_frame_rate() );
1188 last_time = t->get_cur_time();
1192 // Run ATC subsystem
1193 if (fgGetBool("/sim/ATC/enabled"))
1194 globals->get_ATC_mgr()->update(delta_time_sec);
1196 // Run the AI subsystem
1197 if (fgGetBool("/sim/ai-traffic/enabled"))
1198 globals->get_AI_mgr()->update(delta_time_sec);
1202 // Calculate model iterations needed for next frame
1203 elapsed += remainder;
1205 global_multi_loop = (long)(((double)elapsed * 0.000001) *
1206 fgGetInt("/sim/model-hz"));
1207 remainder = elapsed - ( (global_multi_loop*1000000) /
1208 fgGetInt("/sim/model-hz") );
1209 SG_LOG( SG_ALL, SG_DEBUG,
1210 "Model iterations needed = " << global_multi_loop
1211 << ", new remainder = " << remainder );
1213 // chop max interations to something reasonable if the sim was
1214 // delayed for an excesive amount of time
1215 if ( global_multi_loop > 2.0 * fgGetInt("/sim/model-hz") ) {
1216 global_multi_loop = (int)(2.0 * fgGetInt("/sim/model-hz") );
1221 if ( global_multi_loop > 0 ) {
1222 fgUpdateTimeDepCalcs();
1224 SG_LOG( SG_ALL, SG_DEBUG,
1225 "Elapsed time is zero ... we're zinging" );
1228 // Do any I/O channel work that might need to be done
1229 globals->get_io()->update( delta_time_sec );
1231 // see if we need to load any deferred-load textures
1232 material_lib.load_next_deferred();
1234 // Run audio scheduler
1235 #ifdef ENABLE_AUDIO_SUPPORT
1236 if ( fgGetBool("/sim/sound/audible")
1237 && globals->get_soundmgr()->is_working() ) {
1238 globals->get_soundmgr()->update( delta_time_sec );
1242 globals->get_subsystem_mgr()->update(delta_time_sec);
1245 // Tile Manager updates - see if we need to load any new scenery tiles.
1246 // this code ties together the fdm, viewer and scenery classes...
1247 // we may want to move this to it's own class at some point
1249 double visibility_meters = fgGetDouble("/environment/visibility-m");
1250 FGViewer *current_view = globals->get_current_view();
1252 // update tile manager for FDM...
1253 // ...only if location is different than the viewer (to avoid duplicating effort)
1254 if( acmodel_location != current_view->getFGLocation() ) {
1255 if( acmodel_location != 0 ) {
1256 globals->get_tile_mgr()->prep_ssg_nodes( acmodel_location,
1257 visibility_meters );
1258 globals->get_tile_mgr()->
1259 update( acmodel_location, visibility_meters,
1260 acmodel_location->get_absolute_view_pos(globals->get_scenery()->get_center()) );
1261 // save results of update in FGLocation for fdm...
1262 if ( globals->get_scenery()->get_cur_elev() > -9990 ) {
1264 set_cur_elev_m( globals->get_scenery()->get_cur_elev() );
1267 set_tile_center( globals->get_scenery()->get_next_center() );
1271 globals->get_tile_mgr()->prep_ssg_nodes( current_view->getFGLocation(),
1272 visibility_meters );
1273 // update tile manager for view...
1274 // IMPORTANT!!! the tilemgr update for view location _must_ be done last
1275 // after the FDM's until all of Flight Gear code references the viewer's location
1276 // for elevation instead of the "scenery's" current elevation.
1277 FGLocation *view_location = globals->get_current_view()->getFGLocation();
1278 globals->get_tile_mgr()->update( view_location, visibility_meters,
1279 current_view->get_absolute_view_pos() );
1280 // save results of update in FGLocation for fdm...
1281 if ( globals->get_scenery()->get_cur_elev() > -9990 ) {
1282 current_view->getFGLocation()->set_cur_elev_m( globals->get_scenery()->get_cur_elev() );
1284 current_view->getFGLocation()->set_tile_center( globals->get_scenery()->get_next_center() );
1286 // If fdm location is same as viewer's then we didn't do the update for fdm location
1287 // above so we need to save the viewer results in the fdm FGLocation as well...
1288 if( acmodel_location == current_view->getFGLocation() ) {
1289 if( acmodel_location != 0 ) {
1290 if ( globals->get_scenery()->get_cur_elev() > -9990 ) {
1291 acmodel_location->set_cur_elev_m( globals->get_scenery()->get_cur_elev() );
1293 acmodel_location->set_tile_center( globals->get_scenery()->get_next_center() );
1297 // END Tile Manager udpates
1302 SG_LOG( SG_ALL, SG_DEBUG, "" );
1306 // This is the top level master main function that is registered as
1307 // our idle funciton
1309 // The first few passes take care of initialization things (a couple
1310 // per pass) and once everything has been initialized fgMainLoop from
1313 static void fgIdleFunction ( void ) {
1314 // printf("idle state == %d\n", idle_state);
1316 if ( idle_state == 0 ) {
1317 // Initialize the splash screen right away
1318 if ( fgGetBool("/sim/startup/splash-screen") ) {
1323 } else if ( idle_state == 1 ) {
1324 // Initialize audio support
1325 #ifdef ENABLE_AUDIO_SUPPORT
1327 // Start the intro music
1328 if ( fgGetBool("/sim/startup/intro-music") ) {
1329 SGPath mp3file( globals->get_fg_root() );
1330 mp3file.append( "Sounds/intro.mp3" );
1332 SG_LOG( SG_GENERAL, SG_INFO,
1333 "Starting intro music: " << mp3file.str() );
1335 #if defined( __CYGWIN__ )
1336 string command = "start /m `cygpath -w " + mp3file.str() + "`";
1337 #elif defined( WIN32 )
1338 string command = "start /m " + mp3file.str();
1340 string command = "mpg123 " + mp3file.str() + "> /dev/null 2>&1";
1343 system ( command.c_str() );
1348 } else if ( idle_state == 2 ) {
1349 // These are a few miscellaneous things that aren't really
1350 // "subsystems" but still need to be initialized.
1353 if ( strstr ( general.get_glRenderer(), "Glide" ) ) {
1354 grTexLodBiasValue ( GR_TMU0, 1.0 ) ;
1359 } else if ( idle_state == 3 ) {
1360 // This is the top level init routine which calls all the
1361 // other subsystem initialization routines. If you are adding
1362 // a subsystem to flightgear, its initialization call should
1363 // located in this routine.
1364 if( !fgInitSubsystems()) {
1365 SG_LOG( SG_GENERAL, SG_ALERT,
1366 "Subsystem initializations failed ..." );
1371 } else if ( idle_state == 4 ) {
1372 // setup OpenGL view parameters
1375 // Read the list of available aircrafts
1379 } else if ( idle_state == 5 ) {
1382 } else if ( idle_state == 6 ) {
1386 SG_LOG( SG_GENERAL, SG_INFO, "Panel visible = " << fgPanelVisible() );
1387 fgReshape( fgGetInt("/sim/startup/xsize"),
1388 fgGetInt("/sim/startup/ysize") );
1391 if ( idle_state == 1000 ) {
1392 // We've finished all our initialization steps, from now on we
1393 // run the main loop.
1395 glutIdleFunc(fgMainLoop);
1397 if ( fgGetBool("/sim/startup/splash-screen") ) {
1398 fgSplashUpdate(0.0, 1.0);
1403 // options.cxx needs to see this for toggle_panel()
1404 // Handle new window size or exposure
1405 void fgReshape( int width, int height ) {
1408 if ( (!fgGetBool("/sim/virtual-cockpit"))
1409 && fgPanelVisible() && idle_state == 1000 ) {
1410 view_h = (int)(height * (globals->get_current_panel()->getViewHeight() -
1411 globals->get_current_panel()->getYOffset()) / 768.0);
1417 FGViewMgr *viewmgr = globals->get_viewmgr();
1418 for ( int i = 0; i < viewmgr->size(); ++i ) {
1419 viewmgr->get_view(i)->
1420 set_aspect_ratio((float)view_h / (float)width);
1423 glViewport( 0, (GLint)(height - view_h), (GLint)(width), (GLint)(view_h) );
1425 fgSetInt("/sim/startup/xsize", width);
1426 fgSetInt("/sim/startup/ysize", height);
1427 guiInitMouse(width, height);
1429 ssgSetFOV( viewmgr->get_current_view()->get_h_fov(),
1430 viewmgr->get_current_view()->get_v_fov() );
1434 #ifdef FG_USE_CLOUDS_3D
1435 sgClouds3d->Resize( viewmgr->get_current_view()->get_h_fov(),
1436 viewmgr->get_current_view()->get_v_fov() );
1441 // Initialize GLUT and define a main window
1442 static bool fgGlutInit( int *argc, char **argv ) {
1444 #if !defined( macintosh )
1445 // GLUT will extract all glut specific options so later on we only
1446 // need wory about our own.
1447 glutInit(argc, argv);
1450 // Define Display Parameters. Clouds3d works best with --bpp32 option
1451 if ( fgGetBool("/sim/rendering/clouds3d") ) {
1452 glutInitDisplayMode( GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE | GLUT_ALPHA );
1454 glutInitDisplayMode( GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE );
1457 SG_LOG( SG_GENERAL, SG_INFO, "Opening a window: " <<
1458 fgGetInt("/sim/startup/xsize") << "x"
1459 << fgGetInt("/sim/startup/ysize") );
1461 // Define initial window size
1462 glutInitWindowSize( fgGetInt("/sim/startup/xsize"),
1463 fgGetInt("/sim/startup/ysize") );
1465 // Initialize windows
1466 if ( !fgGetBool("/sim/startup/game-mode")) {
1467 // Open the regular window
1468 glutCreateWindow("FlightGear");
1469 #ifndef GLUT_WRONG_VERSION
1471 // Open the cool new 'game mode' window
1472 char game_mode_str[256];
1473 //#define SYNC_OPENGL_WITH_DESKTOP_SETTINGS
1474 #if defined(WIN32) && defined(SYNC_OPENGL_WITH_DESKTOP_SETTINGS)
1475 #ifndef ENUM_CURRENT_SETTINGS
1476 #define ENUM_CURRENT_SETTINGS ((DWORD)-1)
1477 #define ENUM_REGISTRY_SETTINGS ((DWORD)-2)
1481 dm.dmSize = sizeof(DEVMODE);
1482 EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &dm);
1483 fgSetInt("/sim/startup/xsize", dm.dmPelsWidth);
1484 fgSetInt("/sim/startup/ysize", dm.dmPelsHeight);
1485 glutInitWindowSize( fgGetInt("/sim/startup/xsize"),
1486 fgGetInt("/sim/startup/ysize") );
1487 sprintf( game_mode_str, "%dx%d:%d@%d",
1491 dm.dmDisplayFrequency );
1493 // Open the cool new 'game mode' window
1494 sprintf( game_mode_str, "width=%d height=%d bpp=%d",
1495 fgGetInt("/sim/startup/xsize"),
1496 fgGetInt("/sim/startup/ysize"),
1497 fgGetInt("/sim/rendering/bits-per-pixel"));
1499 #endif // HAVE_WINDOWS_H
1500 SG_LOG( SG_GENERAL, SG_INFO,
1501 "game mode params = " << game_mode_str );
1502 glutGameModeString( game_mode_str );
1503 glutEnterGameMode();
1504 #endif // GLUT_WRONG_VERSION
1507 // This seems to be the absolute earliest in the init sequence
1508 // that these calls will return valid info. Too bad it's after
1509 // we've already created and sized out window. :-(
1510 general.set_glVendor( (char *)glGetString ( GL_VENDOR ) );
1511 general.set_glRenderer( (char *)glGetString ( GL_RENDERER ) );
1512 general.set_glVersion( (char *)glGetString ( GL_VERSION ) );
1513 SG_LOG( SG_GENERAL, SG_INFO, general.get_glRenderer() );
1516 glGetIntegerv( GL_MAX_TEXTURE_SIZE, &tmp );
1517 general.set_glMaxTexSize( tmp );
1518 SG_LOG ( SG_GENERAL, SG_INFO, "Max texture size = " << tmp );
1520 glGetIntegerv( GL_DEPTH_BITS, &tmp );
1521 general.set_glDepthBits( tmp );
1522 SG_LOG ( SG_GENERAL, SG_INFO, "Depth buffer bits = " << tmp );
1528 // Initialize GLUT event handlers
1529 static bool fgGlutInitEvents( void ) {
1530 // call fgReshape() on window resizes
1531 glutReshapeFunc( fgReshape );
1533 // keyboard and mouse callbacks are set in FGInput::init
1535 // call fgMainLoop() whenever there is
1536 // nothing else to do
1537 glutIdleFunc( fgIdleFunction );
1540 glutDisplayFunc( fgRenderFrame );
1545 // Main top level initialization
1546 static bool fgMainInit( int argc, char **argv ) {
1548 #if defined( macintosh )
1549 freopen ("stdout.txt", "w", stdout );
1550 freopen ("stderr.txt", "w", stderr );
1551 argc = ccommand( &argv );
1554 // set default log levels
1555 sglog().setLogLevels( SG_ALL, SG_INFO );
1558 #ifdef FLIGHTGEAR_VERSION
1559 version = FLIGHTGEAR_VERSION;
1561 version = "unknown version";
1563 SG_LOG( SG_GENERAL, SG_INFO, "FlightGear: Version "
1565 SG_LOG( SG_GENERAL, SG_INFO, "Built with " << SG_COMPILER_STR << endl );
1567 // Allocate global data structures. This needs to happen before
1568 // we parse command line options
1570 globals = new FGGlobals;
1572 #ifndef FG_WEATHERCM
1573 globals->set_environment_mgr(new FGEnvironmentMgr);
1576 // seed the random number generater
1579 SGRoute *route = new SGRoute;
1580 globals->set_route( route );
1582 FGControls *controls = new FGControls;
1583 globals->set_controls( controls );
1585 string_list *col = new string_list;
1586 globals->set_channel_options_list( col );
1588 // Scan the config file(s) and command line options to see if
1589 // fg_root was specified (ignore all other options for now)
1590 fgInitFGRoot(argc, argv);
1592 // Check for the correct base package version
1593 static char required_version[] = "0.9.1";
1594 string base_version = fgBasePackageVersion();
1595 if ( !(base_version == required_version) ) {
1596 // tell the operator how to use this application
1598 cerr << endl << "Base package check failed ... " \
1599 << "Found version " << base_version << " at: " \
1600 << globals->get_fg_root() << endl;
1601 cerr << "Please upgrade to version: " << required_version << endl;
1605 // Initialize the Aircraft directory to "" (UIUC)
1608 // Load the configuration parameters. (Command line options
1609 // overrides config file options. Config file options override
1611 if ( !fgInitConfig(argc, argv) ) {
1612 SG_LOG( SG_GENERAL, SG_ALERT, "Config option parsing failed ..." );
1616 // Initialize the Window/Graphics environment.
1617 if( !fgGlutInit(&argc, argv) ) {
1618 SG_LOG( SG_GENERAL, SG_ALERT, "GLUT initialization failed ..." );
1622 // Initialize the various GLUT Event Handlers.
1623 if( !fgGlutInitEvents() ) {
1624 SG_LOG( SG_GENERAL, SG_ALERT,
1625 "GLUT event handler initialization failed ..." );
1629 // Initialize plib net interface
1630 netInit( &argc, argv );
1632 // Initialize ssg (from plib). Needs to come before we do any
1633 // other ssg stuff, but after opengl/glut has been initialized.
1636 // Initialize the user interface (we need to do this before
1637 // passing off control to glut and before fgInitGeneral to get our
1641 // Read the list of available aircrafts
1644 #ifdef GL_EXT_texture_lod_bias
1645 glTexEnvf( GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, -0.5 ) ;
1648 #ifdef FG_EXPERIMENTAL_POINT_LIGHTING
1649 // get the address of our OpenGL extensions
1650 if ( fgGetBool("/sim/rendering/distance-attenuation") )
1653 glPointParameterfEXT = (PFNGLPOINTPARAMETERFEXTPROC)
1654 wglGetProcAddress("glPointParameterfEXT");
1655 glPointParameterfvEXT = (PFNGLPOINTPARAMETERFVEXTPROC)
1656 wglGetProcAddress("glPointParameterfvEXT");
1658 glPointParameterfEXT = (OpenGLFuncExt)
1659 glXGetProcAddressARB((GLubyte *)"glPointParameterfEXT");
1660 glPointParameterfvEXT = (OpenGLFuncExtv)
1661 glXGetProcAddressARB((GLubyte *)"glPointParameterfvEXT");
1666 // based on the requested presets, calculate the true starting
1671 SGTime *t = fgInitTime();
1672 globals->set_time_params( t );
1674 // Do some quick general initializations
1675 if( !fgInitGeneral()) {
1676 SG_LOG( SG_GENERAL, SG_ALERT,
1677 "General initializations failed ..." );
1681 SGPath modelpath( globals->get_fg_root() );
1682 ssgModelPath( (char *)modelpath.c_str() );
1684 // Initialize the global scenery manager
1685 globals->set_scenery( new FGScenery );
1686 globals->get_scenery()->init();
1687 globals->get_scenery()->bind();
1689 // Initialize the global tile manager
1690 globals->set_tile_mgr( new FGTileMgr );
1692 ////////////////////////////////////////////////////////////////////
1693 // Initialize the property-based built-in commands
1694 ////////////////////////////////////////////////////////////////////
1697 ////////////////////////////////////////////////////////////////////
1698 // Initialize the general model subsystem.
1699 ////////////////////////////////////////////////////////////////////
1701 globals->set_model_loader(new FGModelLoader);
1702 globals->set_model_mgr(new FGModelMgr);
1703 globals->get_model_mgr()->init();
1704 globals->get_model_mgr()->bind();
1706 ////////////////////////////////////////////////////////////////////
1707 // Initialize the 3D aircraft model subsystem.
1708 ////////////////////////////////////////////////////////////////////
1710 globals->set_aircraft_model(new FGAircraftModel);
1711 globals->get_aircraft_model()->init();
1712 globals->get_aircraft_model()->bind();
1714 ////////////////////////////////////////////////////////////////////
1715 // Initialize the view manager subsystem.
1716 ////////////////////////////////////////////////////////////////////
1718 FGViewMgr *viewmgr = new FGViewMgr;
1719 globals->set_viewmgr( viewmgr );
1724 // Initialize the sky
1725 SGPath ephem_data_path( globals->get_fg_root() );
1726 ephem_data_path.append( "Astro" );
1727 SGEphemeris *ephem = new SGEphemeris( ephem_data_path.c_str() );
1728 ephem->update( globals->get_time_params()->getMjd(),
1729 globals->get_time_params()->getLst(),
1731 globals->set_ephem( ephem );
1733 // TODO: move to environment mgr
1735 SGPath texture_path(globals->get_fg_root());
1736 texture_path.append("Textures");
1737 texture_path.append("Sky");
1738 for (int i = 0; i < FGEnvironmentMgr::MAX_CLOUD_LAYERS; i++) {
1739 SGCloudLayer * layer = new SGCloudLayer(texture_path.str());
1740 thesky->add_cloud_layer(layer);
1744 SGPath sky_tex_path( globals->get_fg_root() );
1745 sky_tex_path.append( "Textures" );
1746 sky_tex_path.append( "Sky" );
1747 thesky->texture_path( sky_tex_path.str() );
1749 thesky->build( 550.0, 550.0,
1750 globals->get_ephem()->getNumPlanets(),
1751 globals->get_ephem()->getPlanets(), 60000.0,
1752 globals->get_ephem()->getNumStars(),
1753 globals->get_ephem()->getStars(), 60000.0 );
1755 // Initialize MagVar model
1756 SGMagVar *magvar = new SGMagVar();
1757 globals->set_mag( magvar );
1759 // airport = new ssgBranch;
1760 // airport->setName( "Airport Lighting" );
1761 // lighting->addKid( airport );
1767 #ifdef FG_NETWORK_OLK
1768 // Do the network intialization
1769 if ( fgGetBool("/sim/networking/network-olk") ) {
1770 printf("Multipilot mode %s\n",
1771 fg_net_init( globals->get_scenery()->get_scene_graph() ) );
1775 // build our custom render states
1776 fgBuildRenderStates();
1778 // pass control off to the master GLUT event handler
1781 // we never actually get here ... but to avoid compiler warnings,
1787 // $$$ end - added VS Renganathan, 15 Oct 2K
1788 // - added Venky , 12 Nov 2K
1790 #if defined(__linux__) && defined(__i386__)
1792 static void handleFPE (int);
1797 fpu_control_t fpe_flags = 0;
1798 _FPU_GETCW(fpe_flags);
1799 // fpe_flags &= ~_FPU_MASK_IM; // invalid operation
1800 // fpe_flags &= ~_FPU_MASK_DM; // denormalized operand
1801 // fpe_flags &= ~_FPU_MASK_ZM; // zero-divide
1802 // fpe_flags &= ~_FPU_MASK_OM; // overflow
1803 // fpe_flags &= ~_FPU_MASK_UM; // underflow
1804 // fpe_flags &= ~_FPU_MASK_PM; // precision (inexact result)
1805 _FPU_SETCW(fpe_flags);
1806 signal(SIGFPE, handleFPE);
1813 SG_LOG(SG_GENERAL, SG_ALERT, "Floating point interrupt (SIGFPE)");
1826 short CPSGetCurrentProcess(PSN *psn);
1827 short CPSSetProcessName (PSN *psn, char *processname);
1828 short CPSEnableForegroundOperation(PSN *psn, int _arg2, int _arg3, int _arg4, int _arg5);
1829 short CPSSetFrontProcess(PSN *psn);
1832 #define CPSEnableFG(psn) CPSEnableForegroundOperation(psn,0x03,0x3C,0x2C,0x1103)
1836 // Main entry point; catch any exceptions that have made it this far.
1837 int main ( int argc, char **argv ) {
1839 // Enable floating-point exceptions for Linux/x86
1840 #if defined(__linux__) && defined(__i386__)
1844 // Enable floating-point exceptions for Windows
1845 #if defined( _MSC_VER ) && defined( DEBUG )
1846 // Christian, we should document what this does
1847 _control87( _EM_INEXACT, _MCW_EM );
1850 #if defined( HAVE_BC5PLUS )
1851 _control87(MCW_EM, MCW_EM); /* defined in float.h */
1854 // Keyboard focus hack
1859 glutInit (&argc, argv);
1861 CPSGetCurrentProcess(&psn);
1862 CPSSetProcessName(&psn, "FlightGear");
1864 CPSSetFrontProcess(&psn);
1868 // FIXME: add other, more specific
1871 fgMainInit(argc, argv);
1872 } catch (sg_throwable &t) {
1873 // We must use cerr rather than
1874 // logging, since logging may be
1876 cerr << "Fatal error: " << t.getFormattedMessage()
1877 << "\n (received from " << t.getOrigin() << ')' << endl;
1885 void fgLoadDCS(void) {
1887 ssgEntity *ship_obj = NULL;
1889 char obj_filename[25];
1891 for ( int k = 0; k < 32; k++ ) {
1895 SGPath tile_path( globals->get_fg_root());
1896 tile_path.append( "Scenery" );
1897 tile_path.append( "Objects.txt" );
1898 sg_gzifstream in( tile_path.str() );
1899 if ( ! in.is_open() ) {
1900 SG_LOG( SG_TERRAIN, SG_ALERT, "Cannot open file: " << tile_path.str() );
1903 SGPath modelpath( globals->get_fg_root() );
1904 modelpath.append( "Models" );
1905 modelpath.append( "Geometry" );
1907 SGPath texturepath( globals->get_fg_root() );
1908 texturepath.append( "Models" );
1909 texturepath.append( "Textures" );
1911 ssgModelPath( (char *)modelpath.c_str() );
1912 ssgTexturePath( (char *)texturepath.c_str() );
1914 ship_sel = new ssgSelector;
1917 while ( ! in.eof() ) {
1919 if ( in.get( c ) && c == '#' ) {
1923 in >> obj_filename >> obj_lat[objc] >> obj_lon[objc] >> obj_alt[objc];
1924 /* cout << endl << obj_filename << " " << obj_lat[objc] << " " << obj_lon[objc] << " " << obj_alt[objc] << endl;
1925 int chj=getchar();*/
1927 obj_lon[objc] *=SGD_DEGREES_TO_RADIANS;
1928 obj_lat[objc] *=SGD_DEGREES_TO_RADIANS;
1930 ship_pos[objc] = new ssgTransform;
1932 // type "repeat" in objects.txt to load one more
1933 // instance of the last object.
1935 if ( strcmp(obj_filename,"repeat") != 0) {
1937 globals->get_model_loader()->load_model( globals->get_fg_root(), obj_filename, globals->get_props(), globals->get_sim_time_sec() );
1940 if ( ship_obj != NULL ) {
1941 ship_obj->setName(obj_filename);
1943 ship_obj->clrTraversalMaskBits( SSGTRAV_HOT );
1945 ship_obj->setTraversalMaskBits( SSGTRAV_HOT );
1946 ship_pos[objc]->addKid( ship_obj ); // add object to transform node
1947 ship_sel->addKid( ship_pos[objc] ); // add transform node to selector
1948 SG_LOG( SG_TERRAIN, SG_ALERT, "Loaded file: "
1951 SG_LOG( SG_TERRAIN, SG_ALERT, "Cannot open file: "
1955 // temporary hack for deck lights - ultimately should move to PLib (when??)
1956 //const char *extn = file_extension ( obj_filename ) ;
1958 // ssgVertexArray *lights = new ssgVertexArray( 100 );
1959 ssgVertexArray *lightpoints = new ssgVertexArray( 100 );
1960 ssgVertexArray *lightnormals = new ssgVertexArray( 100 );
1961 ssgVertexArray *lightdir = new ssgVertexArray( 100 );
1962 int ltype[500], light_type = 0;
1963 static int ltcount = 0;
1965 sgVec3 rway_dir,rway_normal,lightpt;
1967 modelpath.append(obj_filename);
1968 sg_gzifstream in1( modelpath.str() );
1969 if ( ! in1.is_open() ) {
1970 SG_LOG( SG_TERRAIN, SG_ALERT, "Cannot open file: " << modelpath.str() );
1972 while ( ! in1.eof() ) {
1974 if ( in1.get( c ) && c == '#' ) {
1979 //cout << token << endl;
1980 if ( token == "runway" ) {
1982 sgSetVec3 (rway_dir, node[0], node[1], node[2] );
1983 } else if ( token == "edgelight" ) {
1985 sgSetVec3 (rway_normal, node[0], node[1], node[2] );
1987 } else if ( token == "taxi" ) {
1989 sgSetVec3 (rway_normal, node[0], node[1], node[2] );
1991 } else if ( token == "vasi" ) {
1993 sgSetVec3 (rway_normal, node[0], node[1], node[2] );
1995 } else if ( token == "threshold" ) {
1997 sgSetVec3 (rway_normal, node[0], node[1], node[2] );
1999 } else if ( token == "rabbit" ) {
2001 sgSetVec3 (rway_normal, node[0], node[1], node[2] );
2003 } else if ( token == "ols" ) {
2005 sgSetVec3 (rway_ols, node[0], node[1], node[2] );
2007 } else if ( token == "red" ) {
2009 sgSetVec3 (rway_normal, node[0], node[1], node[2] );
2011 } else if ( token == "green" ) {
2013 sgSetVec3 (rway_normal, node[0], node[1], node[2] );
2015 } else if ( token == "lp" ) {
2017 sgSetVec3 (lightpt, node[0], node[1], node[2] );
2018 lightpoints->add( lightpt );
2019 lightnormals->add( rway_normal );
2020 lightdir->add( rway_dir );
2021 ltype[ltcount]= light_type;
2024 if (in1.eof()) break;
2029 if ( lightpoints->getNum() ) {
2030 ssgBranch *lightpoints_branch;
2031 long int dummy = -999;
2032 dummy_tile = new FGTileEntry((SGBucket)dummy);
2033 dummy_tile->lightmaps_sequence = new ssgSelector;
2034 dummy_tile->ols_transform = new ssgTransform;
2036 // call function to generate the runway lights
2037 lightpoints_branch =
2038 dummy_tile->gen_runway_lights( lightpoints, lightnormals,
2040 lightpoints_brightness->addKid(lightpoints_branch);
2041 lightpoints_transform->addKid(lightpoints_brightness);
2042 //dummy_tile->lightmaps_sequence->setTraversalMaskBits( SSGTRAV_HOT );
2043 lightpoints_transform->addKid( dummy_tile->lightmaps_sequence );
2044 lightpoints_transform->ref();
2045 globals->get_scenery()->get_gnd_lights_root()->addKid( lightpoints_transform );
2050 // end hack for deck lights
2054 if (in.eof()) break;
2058 SG_LOG ( SG_TERRAIN, SG_ALERT, "Finished object processing." );
2060 globals->get_scenery()->get_terrain_branch()->addKid( ship_sel ); //add selector node to root node
2067 void fgUpdateDCS (void) {
2069 // double eye_lat,eye_lon,eye_alt;
2070 // static double obj_head;
2071 double sl_radius,obj_latgc;
2072 // float nresultmat[4][4];
2073 // sgMat4 Trans,rothead,rotlon,rot180,rotlat,resultmat1,resultmat2,resultmat3;
2076 // Instantaneous Geodetic Lat/Lon/Alt of moving object
2077 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
2079 // Deck should be the first object in objects.txt in case of fdm=ada
2081 if (!strcmp(fgGetString("/sim/flight-model"), "ada")) {
2082 if ((fdm->get_iaux(1))==1)
2084 obj_lat[1] = fdm->get_daux(1)*SGD_DEGREES_TO_RADIANS;
2085 obj_lon[1] = fdm->get_daux(2)*SGD_DEGREES_TO_RADIANS;
2086 obj_alt[1] = fdm->get_daux(3);
2087 obj_pitch[1] = fdm->get_faux(1);
2088 obj_roll[1] = fdm->get_faux(2);
2092 for ( int m = 0; m < objc; m++ ) {
2093 //cout << endl << obj_lat[m]*SGD_RADIANS_TO_DEGREES << " " << obj_lon[m]*SGD_RADIANS_TO_DEGREES << " " << obj_alt[m] << " " << objc << endl;
2096 //Geodetic to Geocentric angles for rotation
2097 sgGeodToGeoc(obj_lat[m],obj_alt[m],&sl_radius,&obj_latgc);
2099 //moving object gbs-posn in cartesian coords
2100 Point3D obj_posn = Point3D( obj_lon[m],obj_lat[m],obj_alt[m]);
2101 Point3D obj_pos = sgGeodToCart( obj_posn );
2103 // Translate moving object w.r.t eye
2104 Point3D Objtrans = obj_pos - globals->get_scenery()->get_center();
2109 // rotate dynamic objects for lat,lon & alt and other motion about its axes
2112 sgMakeTransMat4( sgTRANS, bz[0],bz[1],bz[2]);
2114 sgVec3 ship_fwd,ship_rt,ship_up;
2115 sgSetVec3( ship_fwd, 1.0, 0.0, 0.0);//east,roll
2116 sgSetVec3( ship_rt, 0.0, 1.0, 0.0);//up,pitch
2117 sgSetVec3( ship_up, 0.0, 0.0, 1.0); //north,yaw
2119 sgMat4 sgROT_lon, sgROT_lat, sgROT_hdg, sgROT_pitch, sgROT_roll;
2120 sgMakeRotMat4( sgROT_lon, obj_lon[m]*SGD_RADIANS_TO_DEGREES, ship_up );
2121 sgMakeRotMat4( sgROT_lat, 90-obj_latgc*SGD_RADIANS_TO_DEGREES, ship_rt );
2122 sgMakeRotMat4( sgROT_hdg, 180.0, ship_up );
2123 sgMakeRotMat4( sgROT_pitch, obj_pitch[m], ship_rt );
2124 sgMakeRotMat4( sgROT_roll, obj_roll[m], ship_fwd );
2127 sgCopyMat4( sgTUX, sgROT_hdg );
2128 sgPostMultMat4( sgTUX, sgROT_pitch );
2129 sgPostMultMat4( sgTUX, sgROT_roll );
2130 sgPostMultMat4( sgTUX, sgROT_lat );
2131 sgPostMultMat4( sgTUX, sgROT_lon );
2132 sgPostMultMat4( sgTUX, sgTRANS );
2135 sgSetCoord(&shippos, sgTUX );
2136 ship_pos[m]->setTransform( &shippos );
2137 // temporary hack for deck lights - ultimately should move to PLib (when ??)
2139 if (lightpoints_transform) {
2140 lightpoints_transform->setTransform( &shippos );
2141 float sun_angle = cur_light_params.sun_angle * SGD_RADIANS_TO_DEGREES;
2142 if ( sun_angle > 89 ) {
2143 lightpoints_brightness->select(0x01);
2145 lightpoints_brightness->select(0x00);
2154 sgXformPnt3( rp, rway_ols, sgTUX );
2155 vp = globals->get_current_view()->get_view_pos();
2156 to[0] = rp[0]-vp[0];
2157 to[1] = rp[1]-vp[1];
2158 to[2] = rp[2]-vp[2];
2159 float dist = sgLengthVec3( to );
2160 alt = (current_aircraft.fdm_state->get_Altitude() * SG_FEET_TO_METER)-rway_ols[2];
2162 elev = asin(alt/dist)*SGD_RADIANS_TO_DEGREES;
2164 ref_elev = elev - 3.75; // +ve above, -ve below
2168 // DO NOT DELETE THIS CODE - This is to compare a discrete FLOLS (without LOD) with analog FLOLS
2169 // if (ref_elev > 0.51) sel = 0x21;
2170 // if ((ref_elev <= 0.51) & (ref_elev > 0.17)) sel = 0x22;
2171 // if ((ref_elev <= 0.17) & (ref_elev >= -0.17)) sel = 0x24;
2172 // if ((ref_elev < -0.17) & (ref_elev >= -0.51)) sel = 0x28;
2173 // if (ref_elev < -0.51) sel = 0x30;
2174 // DO NOT DELETE THIS CODE - This is to compare a discrete FLOLS (without LOD) with analog FLOLS
2175 // dummy_tile->lightmaps_sequence->select(sel);
2178 sgCopyVec3 (up, ship_up);
2180 sgScaleVec3 (up, 4.0*ref_elev*dist/750.0);
2182 sgScaleVec3 (up, 4.0*ref_elev);
2183 // dummy_tile->ols_transform->setTransform(up);
2184 //cout << "ref_elev " << ref_elev << endl;
2186 // end hack for deck lights
2189 if ( ship_sel != NULL ) {
2190 ship_sel->select(0xFFFFFFFE); // first object is ownship, added to acmodel
2194 // $$$ end - added VS Renganathan, 15 Oct 2K
2195 // added Venky , 12 Nov 2K