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 // forward declaration
219 void fgReshape( int width, int height );
221 // fog constants. I'm a little nervous about putting actual code out
222 // here but it seems to work (?)
223 static const double m_log01 = -log( 0.01 );
224 static const double sqrt_m_log01 = sqrt( m_log01 );
225 static GLfloat fog_exp_density;
226 static GLfloat fog_exp2_density;
227 static GLfloat rwy_exp2_punch_through;
228 static GLfloat taxi_exp2_punch_through;
229 static GLfloat ground_exp2_punch_through;
231 #ifdef FG_NETWORK_OLK
232 ssgSelector *fgd_sel = NULL;
233 ssgTransform *fgd_pos = NULL;
239 #ifdef FG_USE_CLOUDS_3D
240 SkySceneLoader *sgClouds3d;
241 bool _bcloud_orig = true;
245 sgMat4 copy_of_ssgOpenGLAxisSwapMatrix =
247 { 1.0f, 0.0f, 0.0f, 0.0f },
248 { 0.0f, 0.0f, -1.0f, 0.0f },
249 { 0.0f, 1.0f, 0.0f, 0.0f },
250 { 0.0f, 0.0f, 0.0f, 1.0f }
253 // The following defines flightgear options. Because glutlib will also
254 // want to parse its own options, those options must not be included here
255 // or they will get parsed by the main program option parser. Hence case
256 // is significant for any option added that might be in conflict with
259 // glutlib parses for:
261 // -direct (invalid in Win32)
265 // -indirect (invalid in Win32)
268 // Note that glutlib depends upon strings while this program's
269 // option parser wants only initial characters followed by numbers
274 ssgSimpleState *cloud3d_imposter_state;
275 ssgSimpleState *default_state;
276 ssgSimpleState *hud_and_panel;
277 ssgSimpleState *menus;
279 SGTimeStamp last_time_stamp;
280 SGTimeStamp current_time_stamp;
283 void fgBuildRenderStates( void ) {
284 default_state = new ssgSimpleState;
285 default_state->ref();
286 default_state->disable( GL_TEXTURE_2D );
287 default_state->enable( GL_CULL_FACE );
288 default_state->enable( GL_COLOR_MATERIAL );
289 default_state->setColourMaterial( GL_AMBIENT_AND_DIFFUSE );
290 default_state->setMaterial( GL_EMISSION, 0, 0, 0, 1 );
291 default_state->setMaterial( GL_SPECULAR, 0, 0, 0, 1 );
292 default_state->disable( GL_BLEND );
293 default_state->disable( GL_ALPHA_TEST );
294 default_state->disable( GL_LIGHTING );
296 cloud3d_imposter_state = new ssgSimpleState;
297 cloud3d_imposter_state->ref();
298 cloud3d_imposter_state->enable( GL_TEXTURE_2D );
299 cloud3d_imposter_state->enable( GL_CULL_FACE );
300 cloud3d_imposter_state->enable( GL_COLOR_MATERIAL );
301 cloud3d_imposter_state->setColourMaterial( GL_AMBIENT_AND_DIFFUSE );
302 cloud3d_imposter_state->setMaterial( GL_DIFFUSE, 1, 1, 1, 1 );
303 cloud3d_imposter_state->setMaterial( GL_AMBIENT, 1, 1, 1, 1 );
304 cloud3d_imposter_state->setMaterial( GL_EMISSION, 0, 0, 0, 1 );
305 cloud3d_imposter_state->setMaterial( GL_SPECULAR, 0, 0, 0, 1 );
306 cloud3d_imposter_state->enable( GL_BLEND );
307 cloud3d_imposter_state->enable( GL_ALPHA_TEST );
308 cloud3d_imposter_state->disable( GL_LIGHTING );
310 hud_and_panel = new ssgSimpleState;
311 hud_and_panel->ref();
312 hud_and_panel->disable( GL_CULL_FACE );
313 hud_and_panel->disable( GL_TEXTURE_2D );
314 hud_and_panel->disable( GL_LIGHTING );
315 hud_and_panel->enable( GL_BLEND );
317 menus = new ssgSimpleState;
319 menus->disable( GL_CULL_FACE );
320 menus->disable( GL_TEXTURE_2D );
321 menus->enable( GL_BLEND );
325 // fgInitVisuals() -- Initialize various GL/view parameters
326 void fgInitVisuals( void ) {
329 l = &cur_light_params;
331 #ifndef GLUT_WRONG_VERSION
332 // Go full screen if requested ...
333 if ( fgGetBool("/sim/startup/fullscreen") ) {
338 // If enabled, normal vectors specified with glNormal are scaled
339 // to unit length after transformation. Enabling this has
340 // performance implications. See the docs for glNormal.
341 // glEnable( GL_NORMALIZE );
343 glEnable( GL_LIGHTING );
344 glEnable( GL_LIGHT0 );
345 // glLightfv( GL_LIGHT0, GL_POSITION, l->sun_vec ); // done later with ssg
348 sgSetVec3( sunpos, l->sun_vec[0], l->sun_vec[1], l->sun_vec[2] );
349 ssgGetLight( 0 ) -> setPosition( sunpos );
351 glFogi (GL_FOG_MODE, GL_EXP2);
352 if ( (!strcmp(fgGetString("/sim/rendering/fog"), "disabled")) ||
353 (!fgGetBool("/sim/rendering/shading"))) {
354 // if fastest fog requested, or if flat shading force fastest
355 glHint ( GL_FOG_HINT, GL_FASTEST );
356 } else if ( !strcmp(fgGetString("/sim/rendering/fog"), "nicest") ) {
357 glHint ( GL_FOG_HINT, GL_NICEST );
359 if ( fgGetBool("/sim/rendering/wireframe") ) {
361 glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
364 // This is the default anyways, but it can't hurt
365 glFrontFace ( GL_CCW );
368 // glEnable(GL_POINT_SMOOTH);
369 // glEnable(GL_LINE_SMOOTH);
370 // glEnable(GL_POLYGON_SMOOTH);
374 // For HiRes screen Dumps using Brian Pauls TR Library
375 void trRenderFrame( void ) {
377 if ( fgPanelVisible() ) {
378 GLfloat height = fgGetInt("/sim/startup/ysize");
380 (globals->get_current_panel()->getViewHeight() - globals->get_current_panel()->getYOffset())
381 * (height / 768.0) + 1;
382 glTranslatef( 0.0, view_h, 0.0 );
385 static GLfloat black[4] = { 0.0, 0.0, 0.0, 1.0 };
386 static GLfloat white[4] = { 1.0, 1.0, 1.0, 1.0 };
388 fgLIGHT *l = &cur_light_params;
390 glClearColor(l->adj_fog_color[0], l->adj_fog_color[1],
391 l->adj_fog_color[2], l->adj_fog_color[3]);
393 glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
395 // set the opengl state to known default values
396 default_state->force();
399 glFogf ( GL_FOG_DENSITY, fog_exp2_density);
400 glFogi ( GL_FOG_MODE, GL_EXP2 );
401 glFogfv ( GL_FOG_COLOR, l->adj_fog_color );
403 // GL_LIGHT_MODEL_AMBIENT has a default non-zero value so if
404 // we only update GL_AMBIENT for our lights we will never get
405 // a completely dark scene. So, we set GL_LIGHT_MODEL_AMBIENT
406 // explicitely to black.
407 glLightModelfv( GL_LIGHT_MODEL_AMBIENT, black );
408 glLightModeli( GL_LIGHT_MODEL_LOCAL_VIEWER, GL_FALSE );
410 ssgGetLight( 0 ) -> setColour( GL_AMBIENT, l->scene_ambient );
412 // texture parameters
413 glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ) ;
414 glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST ) ;
416 // we need a white diffuse light for the phase of the moon
417 ssgGetLight( 0 ) -> setColour( GL_DIFFUSE, white );
420 // draw the ssg scene
421 // return to the desired diffuse color
422 ssgGetLight( 0 ) -> setColour( GL_DIFFUSE, l->scene_diffuse );
423 glEnable( GL_DEPTH_TEST );
424 ssgSetNearFar( scene_nearplane, scene_farplane );
425 ssgCullAndDraw( globals->get_scenery()->get_scene_graph() );
428 glFogf (GL_FOG_DENSITY, rwy_exp2_punch_through);
429 ssgSetNearFar( scene_nearplane, scene_farplane );
430 ssgCullAndDraw( globals->get_scenery()->get_rwy_lights_root() );
432 ssgCullAndDraw( globals->get_scenery()->get_gnd_lights_root() );
434 if (fgGetBool("/environment/clouds/status"))
435 thesky->postDraw( cur_fdm_state->get_Altitude() * SG_FEET_TO_METER );
437 globals->get_model_mgr()->draw();
438 globals->get_aircraft_model()->draw();
442 // Update all Visuals (redraws anything graphics related)
443 void fgRenderFrame() {
445 GLfloat black[4] = { 0.0, 0.0, 0.0, 1.0 };
446 GLfloat white[4] = { 1.0, 1.0, 1.0, 1.0 };
448 // Process/manage pending events
449 global_events.update( delta_time_sec );
451 static const SGPropertyNode *longitude
452 = fgGetNode("/position/longitude-deg");
453 static const SGPropertyNode *latitude
454 = fgGetNode("/position/latitude-deg");
455 static const SGPropertyNode *altitude
456 = fgGetNode("/position/altitude-ft");
457 static const SGPropertyNode *groundlevel_nearplane
458 = fgGetNode("/sim/current-view/ground-level-nearplane-m");
460 // Update the default (kludged) properties.
463 FGViewer *current__view = globals->get_current_view();
465 fgLIGHT *l = &cur_light_params;
466 static double last_visibility = -9999;
469 double actual_visibility;
470 if (fgGetBool("/environment/clouds/status"))
471 actual_visibility = thesky->get_visibility();
473 actual_visibility = fgGetDouble("/environment/visibility-m");
474 if ( actual_visibility != last_visibility ) {
475 last_visibility = actual_visibility;
477 fog_exp_density = m_log01 / actual_visibility;
478 fog_exp2_density = sqrt_m_log01 / actual_visibility;
479 ground_exp2_punch_through = sqrt_m_log01 / (actual_visibility * 1.5);
480 if ( actual_visibility < 8000 ) {
481 rwy_exp2_punch_through = sqrt_m_log01 / (actual_visibility * 2.5);
482 taxi_exp2_punch_through = sqrt_m_log01 / (actual_visibility * 1.5);
484 rwy_exp2_punch_through = sqrt_m_log01 / ( 8000 * 2.5 );
485 taxi_exp2_punch_through = sqrt_m_log01 / ( 8000 * 1.5 );
490 // GLfloat black[4] = { 0.0, 0.0, 0.0, 1.0 };
491 // GLfloat white[4] = { 1.0, 1.0, 1.0, 1.0 };
492 // GLfloat terrain_color[4] = { 0.54, 0.44, 0.29, 1.0 };
493 // GLfloat mat_shininess[] = { 10.0 };
494 GLbitfield clear_mask;
496 if ( idle_state != 1000 ) {
497 // still initializing, draw the splash screen
498 if ( fgGetBool("/sim/startup/splash-screen") ) {
499 fgSplashUpdate(0.0, 1.0);
501 // Keep resetting sim time while the sim is initializing
502 globals->set_sim_time_sec( 0.0 );
504 // idle_state is now 1000 meaning we've finished all our
505 // initializations and are running the main loop, so this will
506 // now work without seg faulting the system.
508 // calculate our current position in cartesian space
509 globals->get_scenery()->set_center( globals->get_scenery()->get_next_center() );
512 fgReshape( fgGetInt("/sim/startup/xsize"),
513 fgGetInt("/sim/startup/ysize") );
515 if ( fgGetBool("/sim/rendering/clouds3d") ) {
516 glClear( GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT );
517 cloud3d_imposter_state->force();
519 glColor4f( 1.0, 1.0, 1.0, 1.0 );
520 glEnable(GL_DEPTH_TEST);
522 glBlendFunc( GL_ONE, GL_ONE_MINUS_SRC_ALPHA ) ;
524 #ifdef FG_USE_CLOUDS_3D
525 if ( _bcloud_orig ) {
526 Point3D c = globals->get_scenery()->get_center();
527 sgClouds3d->Set_Cloud_Orig( &c );
528 _bcloud_orig = false;
530 sgClouds3d->Update( current__view->get_absolute_view_pos() );
532 glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ) ;
533 glDisable(GL_DEPTH_TEST);
536 clear_mask = GL_DEPTH_BUFFER_BIT;
537 if ( fgGetBool("/sim/rendering/wireframe") ) {
538 clear_mask |= GL_COLOR_BUFFER_BIT;
541 if ( fgGetBool("/sim/rendering/skyblend") ) {
542 if ( fgGetBool("/sim/rendering/textures") ) {
543 // glClearColor(black[0], black[1], black[2], black[3]);
544 glClearColor(l->adj_fog_color[0], l->adj_fog_color[1],
545 l->adj_fog_color[2], l->adj_fog_color[3]);
546 clear_mask |= GL_COLOR_BUFFER_BIT;
549 glClearColor(l->sky_color[0], l->sky_color[1],
550 l->sky_color[2], l->sky_color[3]);
551 clear_mask |= GL_COLOR_BUFFER_BIT;
553 glClear( clear_mask );
555 // Tell GL we are switching to model view parameters
557 // I really should create a derived ssg node or use a call
558 // back or something so that I can draw the sky within the
559 // ssgCullAndDraw() function, but for now I just mimic what
560 // ssg does to set up the model view matrix
561 glMatrixMode(GL_MODELVIEW);
563 ssgSetCamera( (sgVec4 *)current__view->get_VIEW() );
565 // set the opengl state to known default values
566 default_state->force();
568 // update fog params if visibility has changed
569 double visibility_meters = fgGetDouble("/environment/visibility-m");
570 thesky->set_visibility(visibility_meters);
572 thesky->modify_vis( cur_fdm_state->get_Altitude() * SG_FEET_TO_METER,
573 ( global_multi_loop * fgGetInt("/sim/speed-up") )
574 / (double)fgGetInt("/sim/model-hz") );
576 // Set correct opengl fog density
577 glFogf (GL_FOG_DENSITY, fog_exp2_density);
579 // update the sky dome
580 if ( fgGetBool("/sim/rendering/skyblend") ) {
582 SG_LOG( SG_GENERAL, SG_BULK, "thesky->repaint() sky_color = "
583 << cur_light_params.sky_color[0] << " "
584 << cur_light_params.sky_color[1] << " "
585 << cur_light_params.sky_color[2] << " "
586 << cur_light_params.sky_color[3] );
587 SG_LOG( SG_GENERAL, SG_BULK, " fog = "
588 << cur_light_params.fog_color[0] << " "
589 << cur_light_params.fog_color[1] << " "
590 << cur_light_params.fog_color[2] << " "
591 << cur_light_params.fog_color[3] );
592 SG_LOG( SG_GENERAL, SG_BULK,
593 " sun_angle = " << cur_light_params.sun_angle
594 << " moon_angle = " << cur_light_params.moon_angle );
596 thesky->repaint( cur_light_params.sky_color,
597 cur_light_params.adj_fog_color,
598 cur_light_params.sun_angle,
599 cur_light_params.moon_angle,
600 globals->get_ephem()->getNumPlanets(),
601 globals->get_ephem()->getPlanets(),
602 globals->get_ephem()->getNumStars(),
603 globals->get_ephem()->getStars() );
606 SG_LOG( SG_GENERAL, SG_BULK,
607 "thesky->reposition( view_pos = " << view_pos[0] << " "
608 << view_pos[1] << " " << view_pos[2] );
609 SG_LOG( SG_GENERAL, SG_BULK,
610 " zero_elev = " << zero_elev[0] << " "
611 << zero_elev[1] << " " << zero_elev[2]
612 << " lon = " << cur_fdm_state->get_Longitude()
613 << " lat = " << cur_fdm_state->get_Latitude() );
614 SG_LOG( SG_GENERAL, SG_BULK,
615 " sun_rot = " << cur_light_params.sun_rotation
616 << " gst = " << SGTime::cur_time_params->getGst() );
617 SG_LOG( SG_GENERAL, SG_BULK,
618 " sun ra = " << globals->get_ephem()->getSunRightAscension()
619 << " sun dec = " << globals->get_ephem()->getSunDeclination()
620 << " moon ra = " << globals->get_ephem()->getMoonRightAscension()
621 << " moon dec = " << globals->get_ephem()->getMoonDeclination() );
624 thesky->reposition( current__view->get_view_pos(),
625 current__view->get_zero_elev(),
626 current__view->get_world_up(),
627 current__view->getLongitude_deg()
628 * SGD_DEGREES_TO_RADIANS,
629 current__view->getLatitude_deg()
630 * SGD_DEGREES_TO_RADIANS,
631 current__view->getAltitudeASL_ft() * SG_FEET_TO_METER,
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 globals->get_ATC_display()->update(delta_time_sec);
900 // update the panel subsystem
901 if ( globals->get_current_panel() != NULL ) {
902 globals->get_current_panel()->update(delta_time_sec);
906 // We can do translucent menus, so why not. :-)
908 glBlendFunc ( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ) ;
910 // glDisable ( GL_BLEND ) ;
912 glEnable( GL_DEPTH_TEST );
915 // Fade out the splash screen over the first three seconds.
916 double t = globals->get_sim_time_sec();
918 fgSplashUpdate(0.0, 1.0);
919 } else if ( t <= 3.0) {
920 fgSplashUpdate(0.0, (3.0 - t) / 2.0);
928 // Update internal time dependent calculations (i.e. flight model)
929 // FIXME: this distinction is obsolete; all subsystems now get delta
931 void fgUpdateTimeDepCalcs() {
932 static bool inited = false;
934 //SG_LOG(SG_FLIGHT,SG_INFO, "Updating time dep calcs()");
936 fgLIGHT *l = &cur_light_params;
938 // Initialize the FDM here if it hasn't been and if we have a
939 // scenery elevation hit.
941 // cout << "cur_fdm_state->get_inited() = " << cur_fdm_state->get_inited()
942 // << " cur_elev = " << scenery.get_cur_elev() << endl;
944 if ( !cur_fdm_state->get_inited() &&
945 globals->get_scenery()->get_cur_elev() > -9990 )
947 SG_LOG(SG_FLIGHT,SG_INFO, "Finally initializing fdm");
948 cur_fdm_state->init();
949 if ( cur_fdm_state->get_bound() ) {
950 cur_fdm_state->unbind();
952 cur_fdm_state->bind();
956 globals->get_environment_mgr()->update(delta_time_sec);
959 // conceptually, the following block could be done for each fdm
961 if ( !cur_fdm_state->get_inited() ) {
962 // do nothing, fdm isn't inited yet
964 // we have been inited, and we are good to go ...
970 globals->get_autopilot()->update(delta_time_sec);
971 cur_fdm_state->update(delta_time_sec);
974 globals->get_model_mgr()->update(delta_time_sec);
975 globals->get_aircraft_model()->update(delta_time_sec);
977 // update the view angle
978 globals->get_viewmgr()->update(delta_time_sec);
982 // Update solar system
983 globals->get_ephem()->update( globals->get_time_params()->getMjd(),
984 globals->get_time_params()->getLst(),
985 cur_fdm_state->get_Latitude() );
987 // Update radio stack model
988 current_radiostack->update(delta_time_sec);
992 void fgInitTimeDepCalcs( void ) {
997 static const double alt_adjust_ft = 3.758099;
998 static const double alt_adjust_m = alt_adjust_ft * SG_FEET_TO_METER;
1001 // What should we do when we have nothing else to do? Let's get ready
1002 // for the next move and update the display?
1003 static void fgMainLoop( void ) {
1005 static const SGPropertyNode *longitude
1006 = fgGetNode("/position/longitude-deg");
1007 static const SGPropertyNode *latitude
1008 = fgGetNode("/position/latitude-deg");
1009 static const SGPropertyNode *altitude
1010 = fgGetNode("/position/altitude-ft");
1011 static const SGPropertyNode *clock_freeze
1012 = fgGetNode("/sim/freeze/clock", true);
1013 static const SGPropertyNode *cur_time_override
1014 = fgGetNode("/sim/time/cur-time-override", true);
1016 // Update the elapsed time.
1017 static bool first_time = true;
1019 last_time_stamp.stamp();
1022 current_time_stamp.stamp();
1023 delta_time_sec = double(current_time_stamp - last_time_stamp) / 1000000.0;
1024 if (clock_freeze->getBoolValue())
1026 last_time_stamp = current_time_stamp;
1027 globals->inc_sim_time_sec( delta_time_sec );
1029 static long remainder = 0;
1031 #ifdef FANCY_FRAME_COUNTER
1035 static time_t last_time = 0;
1036 static int frames = 0;
1037 #endif // FANCY_FRAME_COUNTER
1039 SGTime *t = globals->get_time_params();
1041 sglog().setLogLevels( SG_ALL, (sgDebugPriority)fgGetInt("/sim/log-level") );
1043 FGLocation * acmodel_location = 0;
1044 if(cur_fdm_state->getACModel() != 0) {
1045 acmodel_location = (FGLocation *) cur_fdm_state->getACModel()->get3DModel()->getFGLocation();
1048 SG_LOG( SG_ALL, SG_DEBUG, "Running Main Loop");
1049 SG_LOG( SG_ALL, SG_DEBUG, "======= ==== ====");
1051 #ifdef FG_NETWORK_OLK
1052 if ( fgGetBool("/sim/networking/network-olk") ) {
1053 if ( net_is_registered == 0 ) { // We first have to reg. to fgd
1054 // printf("FGD: Netupdate\n");
1055 fgd_send_com( "A", FGFS_host); // Send Mat4 data
1056 fgd_send_com( "B", FGFS_host); // Recv Mat4 data
1061 #if defined( ENABLE_PLIB_JOYSTICK )
1062 // Read joystick and update control settings
1063 // if ( fgGetString("/sim/control-mode") == "joystick" )
1065 // fgJoystickRead();
1067 #elif defined( ENABLE_GLUT_JOYSTICK )
1068 // Glut joystick support works by feeding a joystick handler
1069 // function to glut. This is taken care of once in the joystick
1070 // init routine and we don't have to worry about it again.
1073 // Fix elevation. I'm just sticking this here for now, it should
1074 // probably move eventually
1076 /* printf("Before - ground = %.2f runway = %.2f alt = %.2f\n",
1077 scenery.get_cur_elev(),
1078 cur_fdm_state->get_Runway_altitude() * SG_FEET_TO_METER,
1079 cur_fdm_state->get_Altitude() * SG_FEET_TO_METER); */
1081 // Curt is this code used? I don't see any problems when I comment it out.
1082 if ( acmodel_location != 0 ) {
1083 if ( acmodel_location->get_cur_elev_m() > -9990 && cur_fdm_state->get_inited() ) {
1084 if ( cur_fdm_state->get_Altitude() * SG_FEET_TO_METER <
1085 (acmodel_location->get_cur_elev_m() + alt_adjust_m - 3.0) ) {
1086 // now set aircraft altitude above ground
1087 printf("(*) Current Altitude = %.2f < %.2f forcing to %.2f\n",
1088 cur_fdm_state->get_Altitude() * SG_FEET_TO_METER,
1089 acmodel_location->get_cur_elev_m() + alt_adjust_m - 3.0,
1090 acmodel_location->get_cur_elev_m() + alt_adjust_m );
1091 cur_fdm_state->set_Altitude( (acmodel_location->get_cur_elev_m()
1092 + alt_adjust_m) * SG_METER_TO_FEET );
1093 SG_LOG( SG_ALL, SG_DEBUG,
1094 "<*> resetting altitude to "
1095 << cur_fdm_state->get_Altitude() * SG_FEET_TO_METER
1100 // End of code in question. (see Curt is this code used? above)
1102 /* printf("Adjustment - ground = %.2f runway = %.2f alt = %.2f\n",
1103 scenery.get_cur_elev(),
1104 cur_fdm_state->get_Runway_altitude() * SG_FEET_TO_METER,
1105 cur_fdm_state->get_Altitude() * SG_FEET_TO_METER); */
1107 // cout << "Warp = " << globals->get_warp() << endl;
1110 static bool last_clock_freeze = false;
1112 if ( clock_freeze->getBoolValue() ) {
1113 // clock freeze requested
1114 if ( cur_time_override->getLongValue() == 0 ) {
1115 fgSetLong( "/sim/time/cur-time-override", t->get_cur_time() );
1116 globals->set_warp( 0 );
1119 // no clock freeze requested
1120 if ( last_clock_freeze == true ) {
1121 // clock just unfroze, let's set warp as the difference
1122 // between frozen time and current time so we don't get a
1123 // time jump (and corresponding sky object and lighting
1125 globals->set_warp( cur_time_override->getLongValue() - time(NULL) );
1126 fgSetLong( "/sim/time/cur-time-override", 0 );
1128 if ( globals->get_warp_delta() != 0 ) {
1129 globals->inc_warp( globals->get_warp_delta() );
1133 last_clock_freeze = clock_freeze->getBoolValue();
1135 t->update( longitude->getDoubleValue() * SGD_DEGREES_TO_RADIANS,
1136 latitude->getDoubleValue() * SGD_DEGREES_TO_RADIANS,
1137 cur_time_override->getLongValue(),
1138 globals->get_warp() );
1140 if ( globals->get_warp_delta() != 0 ) {
1141 fgUpdateSkyAndLightingParams();
1144 // update magvar model
1145 globals->get_mag()->update( longitude->getDoubleValue()
1146 * SGD_DEGREES_TO_RADIANS,
1147 latitude->getDoubleValue()
1148 * SGD_DEGREES_TO_RADIANS,
1149 altitude->getDoubleValue() * SG_FEET_TO_METER,
1150 globals->get_time_params()->getJD() );
1152 // Get elapsed time (in usec) for this past frame
1153 elapsed = fgGetTimeInterval();
1154 SG_LOG( SG_ALL, SG_DEBUG,
1155 "Elapsed time interval is = " << elapsed
1156 << ", previous remainder is = " << remainder );
1158 // Calculate frame rate average
1159 #ifdef FANCY_FRAME_COUNTER
1160 /* old fps calculation */
1161 if ( elapsed > 0 ) {
1164 for ( i = FG_FRAME_RATE_HISTORY - 2; i >= 0; i-- ) {
1165 tmp = general.get_frame(i);
1167 // printf("frame[%d] = %.2f\n", i, g->frames[i]);
1168 general.set_frame(i+1,tmp);
1170 tmp = 1000000.0 / (float)elapsed;
1171 general.set_frame(0,tmp);
1172 // printf("frame[0] = %.2f\n", general.frames[0]);
1174 general.set_frame_rate(accum / (float)FG_FRAME_RATE_HISTORY);
1175 // printf("ave = %.2f\n", general.frame_rate);
1178 if ( (t->get_cur_time() != last_time) && (last_time > 0) ) {
1179 general.set_frame_rate( frames );
1180 fgSetInt("/sim/frame-rate", frames);
1181 SG_LOG( SG_ALL, SG_DEBUG,
1182 "--> Frame rate is = " << general.get_frame_rate() );
1185 last_time = t->get_cur_time();
1189 // Run ATC subsystem
1190 globals->get_ATC_mgr()->update(delta_time_sec);
1192 // Run the AI subsystem
1193 if (fgGetBool("/sim/ai-traffic/enabled"))
1194 globals->get_AI_mgr()->update(delta_time_sec);
1198 // Calculate model iterations needed for next frame
1199 elapsed += remainder;
1201 global_multi_loop = (long)(((double)elapsed * 0.000001) *
1202 fgGetInt("/sim/model-hz"));
1203 remainder = elapsed - ( (global_multi_loop*1000000) /
1204 fgGetInt("/sim/model-hz") );
1205 SG_LOG( SG_ALL, SG_DEBUG,
1206 "Model iterations needed = " << global_multi_loop
1207 << ", new remainder = " << remainder );
1209 // chop max interations to something reasonable if the sim was
1210 // delayed for an excesive amount of time
1211 if ( global_multi_loop > 2.0 * fgGetInt("/sim/model-hz") ) {
1212 global_multi_loop = (int)(2.0 * fgGetInt("/sim/model-hz") );
1217 if ( global_multi_loop > 0 ) {
1218 fgUpdateTimeDepCalcs();
1220 SG_LOG( SG_ALL, SG_DEBUG,
1221 "Elapsed time is zero ... we're zinging" );
1224 // Do any I/O channel work that might need to be done
1225 globals->get_io()->update( delta_time_sec );
1227 // see if we need to load any deferred-load textures
1228 material_lib.load_next_deferred();
1230 // Run audio scheduler
1231 #ifdef ENABLE_AUDIO_SUPPORT
1232 if ( fgGetBool("/sim/sound/audible")
1233 && globals->get_soundmgr()->is_working() ) {
1234 globals->get_soundmgr()->update( delta_time_sec );
1238 globals->get_subsystem_mgr()->update(delta_time_sec);
1241 // Tile Manager updates - see if we need to load any new scenery tiles.
1242 // this code ties together the fdm, viewer and scenery classes...
1243 // we may want to move this to it's own class at some point
1245 double visibility_meters = fgGetDouble("/environment/visibility-m");
1246 FGViewer *current_view = globals->get_current_view();
1248 // update tile manager for FDM...
1249 // ...only if location is different than the viewer (to avoid duplicating effort)
1250 if( acmodel_location != current_view->getFGLocation() ) {
1251 if( acmodel_location != 0 ) {
1252 globals->get_tile_mgr()->prep_ssg_nodes( acmodel_location,
1253 visibility_meters );
1254 globals->get_tile_mgr()->
1255 update( acmodel_location, visibility_meters,
1256 acmodel_location->get_absolute_view_pos() );
1257 // save results of update in FGLocation for fdm...
1258 if ( globals->get_scenery()->get_cur_elev() > -9990 ) {
1260 set_cur_elev_m( globals->get_scenery()->get_cur_elev() );
1263 set_tile_center( globals->get_scenery()->get_next_center() );
1267 globals->get_tile_mgr()->prep_ssg_nodes( current_view->getFGLocation(),
1268 visibility_meters );
1269 // update tile manager for view...
1270 // IMPORTANT!!! the tilemgr update for view location _must_ be done last
1271 // after the FDM's until all of Flight Gear code references the viewer's location
1272 // for elevation instead of the "scenery's" current elevation.
1273 FGLocation *view_location = globals->get_current_view()->getFGLocation();
1274 globals->get_tile_mgr()->update( view_location, visibility_meters,
1275 current_view->get_absolute_view_pos() );
1276 // save results of update in FGLocation for fdm...
1277 if ( globals->get_scenery()->get_cur_elev() > -9990 ) {
1278 current_view->getFGLocation()->set_cur_elev_m( globals->get_scenery()->get_cur_elev() );
1280 current_view->getFGLocation()->set_tile_center( globals->get_scenery()->get_next_center() );
1282 // If fdm location is same as viewer's then we didn't do the update for fdm location
1283 // above so we need to save the viewer results in the fdm FGLocation as well...
1284 if( acmodel_location == current_view->getFGLocation() ) {
1285 if( acmodel_location != 0 ) {
1286 if ( globals->get_scenery()->get_cur_elev() > -9990 ) {
1287 acmodel_location->set_cur_elev_m( globals->get_scenery()->get_cur_elev() );
1289 acmodel_location->set_tile_center( globals->get_scenery()->get_next_center() );
1293 // END Tile Manager udpates
1298 SG_LOG( SG_ALL, SG_DEBUG, "" );
1302 // This is the top level master main function that is registered as
1303 // our idle funciton
1305 // The first few passes take care of initialization things (a couple
1306 // per pass) and once everything has been initialized fgMainLoop from
1309 static void fgIdleFunction ( void ) {
1310 // printf("idle state == %d\n", idle_state);
1312 if ( idle_state == 0 ) {
1313 // Initialize the splash screen right away
1314 if ( fgGetBool("/sim/startup/splash-screen") ) {
1319 } else if ( idle_state == 1 ) {
1320 // Initialize audio support
1321 #ifdef ENABLE_AUDIO_SUPPORT
1323 // Start the intro music
1324 if ( fgGetBool("/sim/startup/intro-music") ) {
1325 SGPath mp3file( globals->get_fg_root() );
1326 mp3file.append( "Sounds/intro.mp3" );
1328 SG_LOG( SG_GENERAL, SG_INFO,
1329 "Starting intro music: " << mp3file.str() );
1331 #if defined( __CYGWIN__ )
1332 string command = "start /m `cygpath -w " + mp3file.str() + "`";
1333 #elif defined( WIN32 )
1334 string command = "start /m " + mp3file.str();
1336 string command = "mpg123 " + mp3file.str() + "> /dev/null 2>&1";
1339 system ( command.c_str() );
1344 } else if ( idle_state == 2 ) {
1345 // These are a few miscellaneous things that aren't really
1346 // "subsystems" but still need to be initialized.
1349 if ( strstr ( general.get_glRenderer(), "Glide" ) ) {
1350 grTexLodBiasValue ( GR_TMU0, 1.0 ) ;
1355 } else if ( idle_state == 3 ) {
1356 // This is the top level init routine which calls all the
1357 // other subsystem initialization routines. If you are adding
1358 // a subsystem to flightgear, its initialization call should
1359 // located in this routine.
1360 if( !fgInitSubsystems()) {
1361 SG_LOG( SG_GENERAL, SG_ALERT,
1362 "Subsystem initializations failed ..." );
1367 } else if ( idle_state == 4 ) {
1368 // setup OpenGL view parameters
1371 // Read the list of available aircrafts
1375 } else if ( idle_state == 5 ) {
1378 } else if ( idle_state == 6 ) {
1382 SG_LOG( SG_GENERAL, SG_INFO, "Panel visible = " << fgPanelVisible() );
1383 fgReshape( fgGetInt("/sim/startup/xsize"),
1384 fgGetInt("/sim/startup/ysize") );
1387 if ( idle_state == 1000 ) {
1388 // We've finished all our initialization steps, from now on we
1389 // run the main loop.
1391 glutIdleFunc(fgMainLoop);
1393 if ( fgGetBool("/sim/startup/splash-screen") ) {
1394 fgSplashUpdate(0.0, 1.0);
1399 // options.cxx needs to see this for toggle_panel()
1400 // Handle new window size or exposure
1401 void fgReshape( int width, int height ) {
1404 if ( (!fgGetBool("/sim/virtual-cockpit"))
1405 && fgPanelVisible() && idle_state == 1000 ) {
1406 view_h = (int)(height * (globals->get_current_panel()->getViewHeight() -
1407 globals->get_current_panel()->getYOffset()) / 768.0);
1413 FGViewMgr *viewmgr = globals->get_viewmgr();
1414 for ( int i = 0; i < viewmgr->size(); ++i ) {
1415 viewmgr->get_view(i)->
1416 set_aspect_ratio((float)view_h / (float)width);
1419 glViewport( 0, (GLint)(height - view_h), (GLint)(width), (GLint)(view_h) );
1421 fgSetInt("/sim/startup/xsize", width);
1422 fgSetInt("/sim/startup/ysize", height);
1423 guiInitMouse(width, height);
1425 ssgSetFOV( viewmgr->get_current_view()->get_h_fov(),
1426 viewmgr->get_current_view()->get_v_fov() );
1430 #ifdef FG_USE_CLOUDS_3D
1431 sgClouds3d->Resize( viewmgr->get_current_view()->get_h_fov(),
1432 viewmgr->get_current_view()->get_v_fov() );
1437 // Initialize GLUT and define a main window
1438 static bool fgGlutInit( int *argc, char **argv ) {
1440 #if !defined( macintosh )
1441 // GLUT will extract all glut specific options so later on we only
1442 // need wory about our own.
1443 glutInit(argc, argv);
1446 // Define Display Parameters. Clouds3d works best with --bpp32 option
1447 if ( fgGetBool("/sim/rendering/clouds3d") ) {
1448 glutInitDisplayMode( GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE | GLUT_ALPHA );
1450 glutInitDisplayMode( GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE );
1453 SG_LOG( SG_GENERAL, SG_INFO, "Opening a window: " <<
1454 fgGetInt("/sim/startup/xsize") << "x"
1455 << fgGetInt("/sim/startup/ysize") );
1457 // Define initial window size
1458 glutInitWindowSize( fgGetInt("/sim/startup/xsize"),
1459 fgGetInt("/sim/startup/ysize") );
1461 // Initialize windows
1462 if ( !fgGetBool("/sim/startup/game-mode")) {
1463 // Open the regular window
1464 glutCreateWindow("FlightGear");
1465 #ifndef GLUT_WRONG_VERSION
1467 // Open the cool new 'game mode' window
1468 char game_mode_str[256];
1469 //#define SYNC_OPENGL_WITH_DESKTOP_SETTINGS
1470 #if defined(WIN32) && defined(SYNC_OPENGL_WITH_DESKTOP_SETTINGS)
1471 #ifndef ENUM_CURRENT_SETTINGS
1472 #define ENUM_CURRENT_SETTINGS ((DWORD)-1)
1473 #define ENUM_REGISTRY_SETTINGS ((DWORD)-2)
1477 dm.dmSize = sizeof(DEVMODE);
1478 EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &dm);
1479 fgSetInt("/sim/startup/xsize", dm.dmPelsWidth);
1480 fgSetInt("/sim/startup/ysize", dm.dmPelsHeight);
1481 glutInitWindowSize( fgGetInt("/sim/startup/xsize"),
1482 fgGetInt("/sim/startup/ysize") );
1483 sprintf( game_mode_str, "%dx%d:%d@%d",
1487 dm.dmDisplayFrequency );
1489 // Open the cool new 'game mode' window
1490 sprintf( game_mode_str, "width=%d height=%d bpp=%d",
1491 fgGetInt("/sim/startup/xsize"),
1492 fgGetInt("/sim/startup/ysize"),
1493 fgGetInt("/sim/rendering/bits-per-pixel"));
1495 #endif // HAVE_WINDOWS_H
1496 SG_LOG( SG_GENERAL, SG_INFO,
1497 "game mode params = " << game_mode_str );
1498 glutGameModeString( game_mode_str );
1499 glutEnterGameMode();
1500 #endif // GLUT_WRONG_VERSION
1503 // This seems to be the absolute earliest in the init sequence
1504 // that these calls will return valid info. Too bad it's after
1505 // we've already created and sized out window. :-(
1506 general.set_glVendor( (char *)glGetString ( GL_VENDOR ) );
1507 general.set_glRenderer( (char *)glGetString ( GL_RENDERER ) );
1508 general.set_glVersion( (char *)glGetString ( GL_VERSION ) );
1509 SG_LOG( SG_GENERAL, SG_INFO, general.get_glRenderer() );
1512 glGetIntegerv( GL_MAX_TEXTURE_SIZE, &tmp );
1513 general.set_glMaxTexSize( tmp );
1514 SG_LOG ( SG_GENERAL, SG_INFO, "Max texture size = " << tmp );
1516 glGetIntegerv( GL_DEPTH_BITS, &tmp );
1517 general.set_glDepthBits( tmp );
1518 SG_LOG ( SG_GENERAL, SG_INFO, "Depth buffer bits = " << tmp );
1524 // Initialize GLUT event handlers
1525 static bool fgGlutInitEvents( void ) {
1526 // call fgReshape() on window resizes
1527 glutReshapeFunc( fgReshape );
1529 // keyboard and mouse callbacks are set in FGInput::init
1531 // call fgMainLoop() whenever there is
1532 // nothing else to do
1533 glutIdleFunc( fgIdleFunction );
1536 glutDisplayFunc( fgRenderFrame );
1541 // Main top level initialization
1542 static bool fgMainInit( int argc, char **argv ) {
1544 #if defined( macintosh )
1545 freopen ("stdout.txt", "w", stdout );
1546 freopen ("stderr.txt", "w", stderr );
1547 argc = ccommand( &argv );
1550 // set default log levels
1551 sglog().setLogLevels( SG_ALL, SG_WARN );
1554 #ifdef FLIGHTGEAR_VERSION
1555 version = FLIGHTGEAR_VERSION;
1557 version = "unknown version";
1559 SG_LOG( SG_GENERAL, SG_INFO, "FlightGear: Version "
1561 SG_LOG( SG_GENERAL, SG_INFO, "Built with " << SG_COMPILER_STR << endl );
1563 // Allocate global data structures. This needs to happen before
1564 // we parse command line options
1566 globals = new FGGlobals;
1568 #ifndef FG_WEATHERCM
1569 globals->set_environment_mgr(new FGEnvironmentMgr);
1572 // seed the random number generater
1575 SGRoute *route = new SGRoute;
1576 globals->set_route( route );
1578 FGControls *controls = new FGControls;
1579 globals->set_controls( controls );
1581 string_list *col = new string_list;
1582 globals->set_channel_options_list( col );
1584 // Scan the config file(s) and command line options to see if
1585 // fg_root was specified (ignore all other options for now)
1586 fgInitFGRoot(argc, argv);
1588 // Check for the correct base package version
1589 static char required_version[] = "0.9.1";
1590 string base_version = fgBasePackageVersion();
1591 if ( !(base_version == required_version) ) {
1592 // tell the operator how to use this application
1594 cerr << endl << "Base package check failed ... " \
1595 << "Found version " << base_version << " at: " \
1596 << globals->get_fg_root() << endl;
1597 cerr << "Please upgrade to version: " << required_version << endl;
1601 // Initialize the Aircraft directory to "" (UIUC)
1604 // Load the configuration parameters. (Command line options
1605 // overrides config file options. Config file options override
1607 if ( !fgInitConfig(argc, argv) ) {
1608 SG_LOG( SG_GENERAL, SG_ALERT, "Config option parsing failed ..." );
1612 // Initialize the Window/Graphics environment.
1613 if( !fgGlutInit(&argc, argv) ) {
1614 SG_LOG( SG_GENERAL, SG_ALERT, "GLUT initialization failed ..." );
1618 // Initialize the various GLUT Event Handlers.
1619 if( !fgGlutInitEvents() ) {
1620 SG_LOG( SG_GENERAL, SG_ALERT,
1621 "GLUT event handler initialization failed ..." );
1625 // Initialize plib net interface
1626 netInit( &argc, argv );
1628 // Initialize ssg (from plib). Needs to come before we do any
1629 // other ssg stuff, but after opengl/glut has been initialized.
1632 // Initialize the user interface (we need to do this before
1633 // passing off control to glut and before fgInitGeneral to get our
1637 // Read the list of available aircrafts
1640 #ifdef GL_EXT_texture_lod_bias
1641 glTexEnvf( GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, -0.5 ) ;
1644 #ifdef FG_EXPERIMENTAL_POINT_LIGHTING
1645 // get the address of our OpenGL extensions
1646 if ( fgGetBool("/sim/rendering/distance-attenuation") )
1649 glPointParameterfEXT = (PFNGLPOINTPARAMETERFEXTPROC)
1650 wglGetProcAddress("glPointParameterfEXT");
1651 glPointParameterfvEXT = (PFNGLPOINTPARAMETERFVEXTPROC)
1652 wglGetProcAddress("glPointParameterfvEXT");
1654 glPointParameterfEXT = (OpenGLFuncExt)
1655 glXGetProcAddressARB((GLubyte *)"glPointParameterfEXT");
1656 glPointParameterfvEXT = (OpenGLFuncExtv)
1657 glXGetProcAddressARB((GLubyte *)"glPointParameterfvEXT");
1662 // based on the requested presets, calculate the true starting
1667 SGTime *t = fgInitTime();
1668 globals->set_time_params( t );
1670 // Do some quick general initializations
1671 if( !fgInitGeneral()) {
1672 SG_LOG( SG_GENERAL, SG_ALERT,
1673 "General initializations failed ..." );
1677 SGPath modelpath( globals->get_fg_root() );
1678 ssgModelPath( (char *)modelpath.c_str() );
1680 // Initialize the global scenery manager
1681 globals->set_scenery( new FGScenery );
1682 globals->get_scenery()->init();
1683 globals->get_scenery()->bind();
1685 // Initialize the global tile manager
1686 globals->set_tile_mgr( new FGTileMgr );
1688 ////////////////////////////////////////////////////////////////////
1689 // Initialize the property-based built-in commands
1690 ////////////////////////////////////////////////////////////////////
1693 ////////////////////////////////////////////////////////////////////
1694 // Initialize the general model subsystem.
1695 ////////////////////////////////////////////////////////////////////
1697 globals->set_model_loader(new FGModelLoader);
1698 globals->set_texture_loader(new FGTextureLoader);
1699 globals->set_model_mgr(new FGModelMgr);
1700 globals->get_model_mgr()->init();
1701 globals->get_model_mgr()->bind();
1703 ////////////////////////////////////////////////////////////////////
1704 // Initialize the 3D aircraft model subsystem.
1705 ////////////////////////////////////////////////////////////////////
1707 globals->set_aircraft_model(new FGAircraftModel);
1708 globals->get_aircraft_model()->init();
1709 globals->get_aircraft_model()->bind();
1711 ////////////////////////////////////////////////////////////////////
1712 // Initialize the view manager subsystem.
1713 ////////////////////////////////////////////////////////////////////
1715 FGViewMgr *viewmgr = new FGViewMgr;
1716 globals->set_viewmgr( viewmgr );
1721 // Initialize the sky
1722 SGPath ephem_data_path( globals->get_fg_root() );
1723 ephem_data_path.append( "Astro" );
1724 SGEphemeris *ephem = new SGEphemeris( ephem_data_path.c_str() );
1725 ephem->update( globals->get_time_params()->getMjd(),
1726 globals->get_time_params()->getLst(),
1728 globals->set_ephem( ephem );
1730 // TODO: move to environment mgr
1732 SGPath texture_path(globals->get_fg_root());
1733 texture_path.append("Textures");
1734 texture_path.append("Sky");
1735 for (int i = 0; i < FGEnvironmentMgr::MAX_CLOUD_LAYERS; i++) {
1736 SGCloudLayer * layer = new SGCloudLayer(texture_path.str());
1737 thesky->add_cloud_layer(layer);
1741 SGPath sky_tex_path( globals->get_fg_root() );
1742 sky_tex_path.append( "Textures" );
1743 sky_tex_path.append( "Sky" );
1744 thesky->texture_path( sky_tex_path.str() );
1746 thesky->build( 550.0, 550.0,
1747 globals->get_ephem()->getNumPlanets(),
1748 globals->get_ephem()->getPlanets(), 60000.0,
1749 globals->get_ephem()->getNumStars(),
1750 globals->get_ephem()->getStars(), 60000.0 );
1752 // Initialize MagVar model
1753 SGMagVar *magvar = new SGMagVar();
1754 globals->set_mag( magvar );
1756 // airport = new ssgBranch;
1757 // airport->setName( "Airport Lighting" );
1758 // lighting->addKid( airport );
1764 #ifdef FG_NETWORK_OLK
1765 // Do the network intialization
1766 if ( fgGetBool("/sim/networking/network-olk") ) {
1767 printf("Multipilot mode %s\n",
1768 fg_net_init( globals->get_scenery()->get_scene_graph() ) );
1772 // build our custom render states
1773 fgBuildRenderStates();
1775 // pass control off to the master GLUT event handler
1778 // we never actually get here ... but to avoid compiler warnings,
1784 // $$$ end - added VS Renganathan, 15 Oct 2K
1785 // - added Venky , 12 Nov 2K
1787 #if defined(__linux__) && defined(__i386__)
1789 static void handleFPE (int);
1794 fpu_control_t fpe_flags = 0;
1795 _FPU_GETCW(fpe_flags);
1796 // fpe_flags &= ~_FPU_MASK_IM; // invalid operation
1797 // fpe_flags &= ~_FPU_MASK_DM; // denormalized operand
1798 // fpe_flags &= ~_FPU_MASK_ZM; // zero-divide
1799 // fpe_flags &= ~_FPU_MASK_OM; // overflow
1800 // fpe_flags &= ~_FPU_MASK_UM; // underflow
1801 // fpe_flags &= ~_FPU_MASK_PM; // precision (inexact result)
1802 _FPU_SETCW(fpe_flags);
1803 signal(SIGFPE, handleFPE);
1810 SG_LOG(SG_GENERAL, SG_ALERT, "Floating point interrupt (SIGFPE)");
1823 short CPSGetCurrentProcess(PSN *psn);
1824 short CPSSetProcessName (PSN *psn, char *processname);
1825 short CPSEnableForegroundOperation(PSN *psn, int _arg2, int _arg3, int _arg4, int _arg5);
1826 short CPSSetFrontProcess(PSN *psn);
1829 #define CPSEnableFG(psn) CPSEnableForegroundOperation(psn,0x03,0x3C,0x2C,0x1103)
1833 // Main entry point; catch any exceptions that have made it this far.
1834 int main ( int argc, char **argv ) {
1836 // Enable floating-point exceptions for Linux/x86
1837 #if defined(__linux__) && defined(__i386__)
1841 // Enable floating-point exceptions for Windows
1842 #if defined( _MSC_VER ) && defined( DEBUG )
1843 // Christian, we should document what this does
1844 _control87( _EM_INEXACT, _MCW_EM );
1847 #if defined( HAVE_BC5PLUS )
1848 _control87(MCW_EM, MCW_EM); /* defined in float.h */
1851 // Keyboard focus hack
1856 glutInit (&argc, argv);
1858 CPSGetCurrentProcess(&psn);
1859 CPSSetProcessName(&psn, "FlightGear");
1861 CPSSetFrontProcess(&psn);
1865 // FIXME: add other, more specific
1868 fgMainInit(argc, argv);
1869 } catch (sg_throwable &t) {
1870 // We must use cerr rather than
1871 // logging, since logging may be
1873 cerr << "Fatal error: " << t.getFormattedMessage()
1874 << "\n (received from " << t.getOrigin() << ')' << endl;
1882 void fgLoadDCS(void) {
1884 ssgEntity *ship_obj = NULL;
1886 char obj_filename[25];
1888 for ( int k = 0; k < 32; k++ ) {
1892 SGPath tile_path( globals->get_fg_root());
1893 tile_path.append( "Scenery" );
1894 tile_path.append( "Objects.txt" );
1895 sg_gzifstream in( tile_path.str() );
1896 if ( ! in.is_open() ) {
1897 SG_LOG( SG_TERRAIN, SG_ALERT, "Cannot open file: " << tile_path.str() );
1900 SGPath modelpath( globals->get_fg_root() );
1901 modelpath.append( "Models" );
1902 modelpath.append( "Geometry" );
1904 SGPath texturepath( globals->get_fg_root() );
1905 texturepath.append( "Models" );
1906 texturepath.append( "Textures" );
1908 ssgModelPath( (char *)modelpath.c_str() );
1909 ssgTexturePath( (char *)texturepath.c_str() );
1911 ship_sel = new ssgSelector;
1914 while ( ! in.eof() ) {
1916 if ( in.get( c ) && c == '#' ) {
1920 in >> obj_filename >> obj_lat[objc] >> obj_lon[objc] >> obj_alt[objc];
1921 /* cout << endl << obj_filename << " " << obj_lat[objc] << " " << obj_lon[objc] << " " << obj_alt[objc] << endl;
1922 int chj=getchar();*/
1924 obj_lon[objc] *=SGD_DEGREES_TO_RADIANS;
1925 obj_lat[objc] *=SGD_DEGREES_TO_RADIANS;
1927 ship_pos[objc] = new ssgTransform;
1929 // type "repeat" in objects.txt to load one more
1930 // instance of the last object.
1932 if ( strcmp(obj_filename,"repeat") != 0) {
1934 globals->get_model_loader()->load_model( obj_filename );
1937 if ( ship_obj != NULL ) {
1938 ship_obj->setName(obj_filename);
1940 ship_obj->clrTraversalMaskBits( SSGTRAV_HOT );
1942 ship_obj->setTraversalMaskBits( SSGTRAV_HOT );
1943 ship_pos[objc]->addKid( ship_obj ); // add object to transform node
1944 ship_sel->addKid( ship_pos[objc] ); // add transform node to selector
1945 SG_LOG( SG_TERRAIN, SG_ALERT, "Loaded file: "
1948 SG_LOG( SG_TERRAIN, SG_ALERT, "Cannot open file: "
1952 // temporary hack for deck lights - ultimately should move to PLib (when??)
1953 //const char *extn = file_extension ( obj_filename ) ;
1955 ssgVertexArray *lights = new ssgVertexArray( 100 );
1956 ssgVertexArray *lightpoints = new ssgVertexArray( 100 );
1957 ssgVertexArray *lightnormals = new ssgVertexArray( 100 );
1958 ssgVertexArray *lightdir = new ssgVertexArray( 100 );
1959 int ltype[500], light_type;
1960 static int ltcount = 0;
1962 sgVec3 rway_dir,rway_normal,lightpt;
1964 modelpath.append(obj_filename);
1965 sg_gzifstream in1( modelpath.str() );
1966 if ( ! in1.is_open() ) {
1967 SG_LOG( SG_TERRAIN, SG_ALERT, "Cannot open file: " << modelpath.str() );
1969 while ( ! in1.eof() ) {
1971 if ( in1.get( c ) && c == '#' ) {
1976 //cout << token << endl;
1977 if ( token == "runway" ) {
1979 sgSetVec3 (rway_dir, node[0], node[1], node[2] );
1980 } else if ( token == "edgelight" ) {
1982 sgSetVec3 (rway_normal, node[0], node[1], node[2] );
1984 } else if ( token == "taxi" ) {
1986 sgSetVec3 (rway_normal, node[0], node[1], node[2] );
1988 } else if ( token == "vasi" ) {
1990 sgSetVec3 (rway_normal, node[0], node[1], node[2] );
1992 } else if ( token == "threshold" ) {
1994 sgSetVec3 (rway_normal, node[0], node[1], node[2] );
1996 } else if ( token == "rabbit" ) {
1998 sgSetVec3 (rway_normal, node[0], node[1], node[2] );
2000 } else if ( token == "ols" ) {
2002 sgSetVec3 (rway_ols, node[0], node[1], node[2] );
2004 } else if ( token == "red" ) {
2006 sgSetVec3 (rway_normal, node[0], node[1], node[2] );
2008 } else if ( token == "green" ) {
2010 sgSetVec3 (rway_normal, node[0], node[1], node[2] );
2012 } else if ( token == "lp" ) {
2014 sgSetVec3 (lightpt, node[0], node[1], node[2] );
2015 lightpoints->add( lightpt );
2016 lightnormals->add( rway_normal );
2017 lightdir->add( rway_dir );
2018 ltype[ltcount]= light_type;
2021 if (in1.eof()) break;
2025 if ( lightpoints->getNum() ) {
2026 ssgBranch *lightpoints_branch;
2027 long int dummy = -999;
2028 dummy_tile = new FGTileEntry((SGBucket)dummy);
2029 dummy_tile->lightmaps_sequence = new ssgSelector;
2030 dummy_tile->ols_transform = new ssgTransform;
2032 // call function to generate the runway lights
2033 lightpoints_branch =
2034 dummy_tile->gen_runway_lights( lightpoints, lightnormals,
2036 lightpoints_brightness->addKid(lightpoints_branch);
2037 lightpoints_transform->addKid(lightpoints_brightness);
2038 //dummy_tile->lightmaps_sequence->setTraversalMaskBits( SSGTRAV_HOT );
2039 lightpoints_transform->addKid( dummy_tile->lightmaps_sequence );
2040 lightpoints_transform->ref();
2041 globals->get_scenery()->get_gnd_lights_root()->addKid( lightpoints_transform );
2045 // end hack for deck lights
2049 if (in.eof()) break;
2053 SG_LOG ( SG_TERRAIN, SG_ALERT, "Finished object processing." );
2055 globals->get_scenery()->get_terrain_branch()->addKid( ship_sel ); //add selector node to root node
2062 void fgUpdateDCS (void) {
2064 // double eye_lat,eye_lon,eye_alt;
2065 // static double obj_head;
2066 double sl_radius,obj_latgc;
2067 // float nresultmat[4][4];
2068 // sgMat4 Trans,rothead,rotlon,rot180,rotlat,resultmat1,resultmat2,resultmat3;
2071 // Instantaneous Geodetic Lat/Lon/Alt of moving object
2072 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
2074 // Deck should be the first object in objects.txt in case of fdm=ada
2076 if (!strcmp(fgGetString("/sim/flight-model"), "ada")) {
2077 if ((fdm->get_iaux(1))==1)
2079 obj_lat[1] = fdm->get_daux(1)*SGD_DEGREES_TO_RADIANS;
2080 obj_lon[1] = fdm->get_daux(2)*SGD_DEGREES_TO_RADIANS;
2081 obj_alt[1] = fdm->get_daux(3);
2082 obj_pitch[1] = fdm->get_faux(1);
2083 obj_roll[1] = fdm->get_faux(2);
2087 for ( int m = 0; m < objc; m++ ) {
2088 //cout << endl << obj_lat[m]*SGD_RADIANS_TO_DEGREES << " " << obj_lon[m]*SGD_RADIANS_TO_DEGREES << " " << obj_alt[m] << " " << objc << endl;
2091 //Geodetic to Geocentric angles for rotation
2092 sgGeodToGeoc(obj_lat[m],obj_alt[m],&sl_radius,&obj_latgc);
2094 //moving object gbs-posn in cartesian coords
2095 Point3D obj_posn = Point3D( obj_lon[m],obj_lat[m],obj_alt[m]);
2096 Point3D obj_pos = sgGeodToCart( obj_posn );
2098 // Translate moving object w.r.t eye
2099 Point3D Objtrans = obj_pos - globals->get_scenery()->get_center();
2104 // rotate dynamic objects for lat,lon & alt and other motion about its axes
2107 sgMakeTransMat4( sgTRANS, bz[0],bz[1],bz[2]);
2109 sgVec3 ship_fwd,ship_rt,ship_up;
2110 sgSetVec3( ship_fwd, 1.0, 0.0, 0.0);//east,roll
2111 sgSetVec3( ship_rt, 0.0, 1.0, 0.0);//up,pitch
2112 sgSetVec3( ship_up, 0.0, 0.0, 1.0); //north,yaw
2114 sgMat4 sgROT_lon, sgROT_lat, sgROT_hdg, sgROT_pitch, sgROT_roll;
2115 sgMakeRotMat4( sgROT_lon, obj_lon[m]*SGD_RADIANS_TO_DEGREES, ship_up );
2116 sgMakeRotMat4( sgROT_lat, 90-obj_latgc*SGD_RADIANS_TO_DEGREES, ship_rt );
2117 sgMakeRotMat4( sgROT_hdg, 180.0, ship_up );
2118 sgMakeRotMat4( sgROT_pitch, obj_pitch[m], ship_rt );
2119 sgMakeRotMat4( sgROT_roll, obj_roll[m], ship_fwd );
2122 sgCopyMat4( sgTUX, sgROT_hdg );
2123 sgPostMultMat4( sgTUX, sgROT_pitch );
2124 sgPostMultMat4( sgTUX, sgROT_roll );
2125 sgPostMultMat4( sgTUX, sgROT_lat );
2126 sgPostMultMat4( sgTUX, sgROT_lon );
2127 sgPostMultMat4( sgTUX, sgTRANS );
2130 sgSetCoord(&shippos, sgTUX );
2131 ship_pos[m]->setTransform( &shippos );
2132 // temporary hack for deck lights - ultimately should move to PLib (when ??)
2134 if (lightpoints_transform) {
2135 lightpoints_transform->setTransform( &shippos );
2136 float sun_angle = cur_light_params.sun_angle * SGD_RADIANS_TO_DEGREES;
2137 if ( sun_angle > 89 ) {
2138 lightpoints_brightness->select(0x01);
2140 lightpoints_brightness->select(0x00);
2149 sgXformPnt3( rp, rway_ols, sgTUX );
2150 vp = globals->get_current_view()->get_view_pos();
2151 to[0] = rp[0]-vp[0];
2152 to[1] = rp[1]-vp[1];
2153 to[2] = rp[2]-vp[2];
2154 float dist = sgLengthVec3( to );
2155 alt = (current_aircraft.fdm_state->get_Altitude() * SG_FEET_TO_METER)-rway_ols[2];
2157 elev = asin(alt/dist)*SGD_RADIANS_TO_DEGREES;
2159 ref_elev = elev - 3.75; // +ve above, -ve below
2163 // DO NOT DELETE THIS CODE - This is to compare a discrete FLOLS (without LOD) with analog FLOLS
2164 // if (ref_elev > 0.51) sel = 0x21;
2165 // if ((ref_elev <= 0.51) & (ref_elev > 0.17)) sel = 0x22;
2166 // if ((ref_elev <= 0.17) & (ref_elev >= -0.17)) sel = 0x24;
2167 // if ((ref_elev < -0.17) & (ref_elev >= -0.51)) sel = 0x28;
2168 // if (ref_elev < -0.51) sel = 0x30;
2169 // DO NOT DELETE THIS CODE - This is to compare a discrete FLOLS (without LOD) with analog FLOLS
2170 dummy_tile->lightmaps_sequence->select(sel);
2173 sgCopyVec3 (up, ship_up);
2175 sgScaleVec3 (up, 4.0*ref_elev*dist/750.0);
2177 sgScaleVec3 (up, 4.0*ref_elev);
2178 dummy_tile->ols_transform->setTransform(up);
2179 //cout << "ref_elev " << ref_elev << endl;
2181 // end hack for deck lights
2184 if ( ship_sel != NULL ) {
2185 ship_sel->select(0xFFFFFFFE); // first object is ownship, added to acmodel
2189 // $$$ end - added VS Renganathan, 15 Oct 2K
2190 // added Venky , 12 Nov 2K