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>
36 #ifndef SG_HAVE_NATIVE_SGI_COMPILERS
41 #include <simgear/misc/exception.hxx>
42 #include <simgear/ephemeris/ephemeris.hxx>
43 #include <simgear/route/route.hxx>
45 #ifdef SG_MATH_EXCEPTION_CLASH
57 #include <string.h> // for strcmp()
64 #ifdef HAVE_SYS_STAT_H
65 # include <sys/stat.h> // for stat()
69 # include <unistd.h> // for stat()
72 #include <plib/netChat.h>
77 #include <simgear/constants.h> // for VERSION
78 #include <simgear/debug/logstream.hxx>
79 #include <simgear/math/polar3d.hxx>
80 #include <simgear/math/sg_random.h>
81 #include <simgear/misc/sg_path.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/cockpit.hxx>
101 #include <Cockpit/radiostack.hxx>
102 #include <Cockpit/steam.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 <Main/location.hxx>
111 #include <Model/panelnode.hxx>
112 #ifdef FG_NETWORK_OLK
113 #include <NetworkOLK/network.h>
115 #include <Objects/matlib.hxx>
116 #include <Scenery/scenery.hxx>
117 #include <Scenery/tilemgr.hxx>
118 #ifdef ENABLE_AUDIO_SUPPORT
119 # include <Sound/soundmgr.hxx>
120 # include <Sound/fg_fx.hxx>
121 # include <Sound/morse.hxx>
123 #include <Systems/system_mgr.hxx>
124 #include <Instrumentation/instrument_mgr.hxx>
125 #include <Time/FGEventMgr.hxx>
126 #include <Time/fg_timer.hxx>
127 #include <Time/light.hxx>
128 #include <Time/sunpos.hxx>
129 #include <Time/tmp.hxx>
132 #include <simgear/misc/sgstream.hxx>
133 #include <simgear/math/point3d.hxx>
134 #include <FDM/flight.hxx>
135 #include <FDM/ADA.hxx>
136 #include <Scenery/tileentry.hxx>
138 #include "fg_commands.hxx"
141 typedef void (APIENTRY * PFNGLPOINTPARAMETERFEXTPROC)(GLenum pname,
143 typedef void (APIENTRY * PFNGLPOINTPARAMETERFVEXTPROC)(GLenum pname,
144 const GLfloat *params);
146 PFNGLPOINTPARAMETERFEXTPROC glPointParameterfEXT = 0;
147 PFNGLPOINTPARAMETERFVEXTPROC glPointParameterfvEXT = 0;
151 typedef void (* OpenGLFuncExt)(GLenum pname, GLfloat param);
152 typedef void (* OpenGLFuncExtv)(GLenum pname, const GLfloat *params);
154 OpenGLFuncExt glPointParameterfEXT = 0;
155 OpenGLFuncExtv glPointParameterfvEXT = 0;
158 float default_attenuation[3] = {1.0, 0.0, 0.0};
159 //Required for using GL_extensions
160 void fgLoadDCS (void);
161 void fgUpdateDCS (void);
162 ssgSelector *ship_sel=NULL;
163 // upto 32 instances of a same object can be loaded.
164 ssgTransform *ship_pos[32];
165 double obj_lat[32],obj_lon[32],obj_alt[32],obj_pitch[32],obj_roll[32];
167 ssgSelector *lightpoints_brightness = new ssgSelector;
168 ssgTransform *lightpoints_transform = new ssgTransform;
169 FGTileEntry *dummy_tile;
172 // Clip plane settings...
173 float scene_nearplane = 0.5f;
174 float scene_farplane = 120000.0f;
176 static double delta_time_sec = 0;
180 # include <WeatherCM/FGLocalWeatherDatabase.h>
182 # include <Environment/environment_mgr.hxx>
187 #include "fg_init.hxx"
189 #include "fg_props.hxx"
190 #include "globals.hxx"
191 #include "splash.hxx"
192 #include "viewmgr.hxx"
193 #include "options.hxx"
194 #include "logger.hxx"
197 # include <console.h> // -dw- for command line dialog
201 FGEventMgr global_events;
203 // This is a record containing a bit of global housekeeping information
206 // Specify our current idle function state. This is used to run all
207 // our initializations out of the glutIdleLoop() so that we can get a
208 // splash screen up and running right away.
209 static int idle_state = 0;
210 static long global_multi_loop;
212 // forward declaration
213 void fgReshape( int width, int height );
215 // fog constants. I'm a little nervous about putting actual code out
216 // here but it seems to work (?)
217 static const double m_log01 = -log( 0.01 );
218 static const double sqrt_m_log01 = sqrt( m_log01 );
219 static GLfloat fog_exp_density;
220 static GLfloat fog_exp2_density;
221 static GLfloat rwy_exp2_punch_through;
222 static GLfloat taxi_exp2_punch_through;
223 static GLfloat ground_exp2_punch_through;
225 #ifdef FG_NETWORK_OLK
226 ssgSelector *fgd_sel = NULL;
227 ssgTransform *fgd_pos = NULL;
233 #ifdef FG_USE_CLOUDS_3D
234 SkySceneLoader *sgClouds3d;
235 bool _bcloud_orig = true;
239 sgMat4 copy_of_ssgOpenGLAxisSwapMatrix =
241 { 1.0f, 0.0f, 0.0f, 0.0f },
242 { 0.0f, 0.0f, -1.0f, 0.0f },
243 { 0.0f, 1.0f, 0.0f, 0.0f },
244 { 0.0f, 0.0f, 0.0f, 1.0f }
247 // The following defines flightgear options. Because glutlib will also
248 // want to parse its own options, those options must not be included here
249 // or they will get parsed by the main program option parser. Hence case
250 // is significant for any option added that might be in conflict with
253 // glutlib parses for:
255 // -direct (invalid in Win32)
259 // -indirect (invalid in Win32)
262 // Note that glutlib depends upon strings while this program's
263 // option parser wants only initial characters followed by numbers
268 ssgSimpleState *cloud3d_imposter_state;
269 ssgSimpleState *default_state;
270 ssgSimpleState *hud_and_panel;
271 ssgSimpleState *menus;
273 SGTimeStamp last_time_stamp;
274 SGTimeStamp current_time_stamp;
276 void fgBuildRenderStates( void ) {
277 default_state = new ssgSimpleState;
278 default_state->ref();
279 default_state->disable( GL_TEXTURE_2D );
280 default_state->enable( GL_CULL_FACE );
281 default_state->enable( GL_COLOR_MATERIAL );
282 default_state->setColourMaterial( GL_AMBIENT_AND_DIFFUSE );
283 default_state->setMaterial( GL_EMISSION, 0, 0, 0, 1 );
284 default_state->setMaterial( GL_SPECULAR, 0, 0, 0, 1 );
285 default_state->disable( GL_BLEND );
286 default_state->disable( GL_ALPHA_TEST );
287 default_state->disable( GL_LIGHTING );
289 cloud3d_imposter_state = new ssgSimpleState;
290 cloud3d_imposter_state->ref();
291 cloud3d_imposter_state->enable( GL_TEXTURE_2D );
292 cloud3d_imposter_state->enable( GL_CULL_FACE );
293 cloud3d_imposter_state->enable( GL_COLOR_MATERIAL );
294 cloud3d_imposter_state->setColourMaterial( GL_AMBIENT_AND_DIFFUSE );
295 cloud3d_imposter_state->setMaterial( GL_DIFFUSE, 1, 1, 1, 1 );
296 cloud3d_imposter_state->setMaterial( GL_AMBIENT, 1, 1, 1, 1 );
297 cloud3d_imposter_state->setMaterial( GL_EMISSION, 0, 0, 0, 1 );
298 cloud3d_imposter_state->setMaterial( GL_SPECULAR, 0, 0, 0, 1 );
299 cloud3d_imposter_state->enable( GL_BLEND );
300 cloud3d_imposter_state->enable( GL_ALPHA_TEST );
301 cloud3d_imposter_state->disable( GL_LIGHTING );
303 hud_and_panel = new ssgSimpleState;
304 hud_and_panel->ref();
305 hud_and_panel->disable( GL_CULL_FACE );
306 hud_and_panel->disable( GL_TEXTURE_2D );
307 hud_and_panel->disable( GL_LIGHTING );
308 hud_and_panel->enable( GL_BLEND );
310 menus = new ssgSimpleState;
312 menus->disable( GL_CULL_FACE );
313 menus->disable( GL_TEXTURE_2D );
314 menus->enable( GL_BLEND );
318 // fgInitVisuals() -- Initialize various GL/view parameters
319 void fgInitVisuals( void ) {
322 l = &cur_light_params;
324 #ifndef GLUT_WRONG_VERSION
325 // Go full screen if requested ...
326 if ( fgGetBool("/sim/startup/fullscreen") ) {
331 // If enabled, normal vectors specified with glNormal are scaled
332 // to unit length after transformation. Enabling this has
333 // performance implications. See the docs for glNormal.
334 // glEnable( GL_NORMALIZE );
336 glEnable( GL_LIGHTING );
337 glEnable( GL_LIGHT0 );
338 // glLightfv( GL_LIGHT0, GL_POSITION, l->sun_vec ); // done later with ssg
341 sgSetVec3( sunpos, l->sun_vec[0], l->sun_vec[1], l->sun_vec[2] );
342 ssgGetLight( 0 ) -> setPosition( sunpos );
344 glFogi (GL_FOG_MODE, GL_EXP2);
345 if ( (!strcmp(fgGetString("/sim/rendering/fog"), "disabled")) ||
346 (!fgGetBool("/sim/rendering/shading"))) {
347 // if fastest fog requested, or if flat shading force fastest
348 glHint ( GL_FOG_HINT, GL_FASTEST );
349 } else if ( !strcmp(fgGetString("/sim/rendering/fog"), "nicest") ) {
350 glHint ( GL_FOG_HINT, GL_NICEST );
352 if ( fgGetBool("/sim/rendering/wireframe") ) {
354 glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
357 // This is the default anyways, but it can't hurt
358 glFrontFace ( GL_CCW );
361 // glEnable(GL_POINT_SMOOTH);
362 // glEnable(GL_LINE_SMOOTH);
363 // glEnable(GL_POLYGON_SMOOTH);
367 // For HiRes screen Dumps using Brian Pauls TR Library
368 void trRenderFrame( void ) {
370 if ( fgPanelVisible() ) {
371 GLfloat height = fgGetInt("/sim/startup/ysize");
373 (current_panel->getViewHeight() - current_panel->getYOffset())
374 * (height / 768.0) + 1;
375 glTranslatef( 0.0, view_h, 0.0 );
378 static GLfloat black[4] = { 0.0, 0.0, 0.0, 1.0 };
379 static GLfloat white[4] = { 1.0, 1.0, 1.0, 1.0 };
381 fgLIGHT *l = &cur_light_params;
383 glClearColor(l->adj_fog_color[0], l->adj_fog_color[1],
384 l->adj_fog_color[2], l->adj_fog_color[3]);
386 glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
388 // set the opengl state to known default values
389 default_state->force();
392 glFogf ( GL_FOG_DENSITY, fog_exp2_density);
393 glFogi ( GL_FOG_MODE, GL_EXP2 );
394 glFogfv ( GL_FOG_COLOR, l->adj_fog_color );
396 // GL_LIGHT_MODEL_AMBIENT has a default non-zero value so if
397 // we only update GL_AMBIENT for our lights we will never get
398 // a completely dark scene. So, we set GL_LIGHT_MODEL_AMBIENT
399 // explicitely to black.
400 glLightModelfv( GL_LIGHT_MODEL_AMBIENT, black );
401 glLightModeli( GL_LIGHT_MODEL_LOCAL_VIEWER, GL_FALSE );
403 ssgGetLight( 0 ) -> setColour( GL_AMBIENT, l->scene_ambient );
405 // texture parameters
406 glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ) ;
407 glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST ) ;
409 // we need a white diffuse light for the phase of the moon
410 ssgGetLight( 0 ) -> setColour( GL_DIFFUSE, white );
413 // draw the ssg scene
414 // return to the desired diffuse color
415 ssgGetLight( 0 ) -> setColour( GL_DIFFUSE, l->scene_diffuse );
416 glEnable( GL_DEPTH_TEST );
417 ssgSetNearFar( scene_nearplane, scene_farplane );
418 ssgCullAndDraw( globals->get_scenery()->get_scene_graph() );
421 glFogf (GL_FOG_DENSITY, rwy_exp2_punch_through);
422 ssgSetNearFar( scene_nearplane, scene_farplane );
423 ssgCullAndDraw( globals->get_scenery()->get_rwy_lights_root() );
425 ssgCullAndDraw( globals->get_scenery()->get_gnd_lights_root() );
427 if (fgGetBool("/environment/clouds/status"))
428 thesky->postDraw( cur_fdm_state->get_Altitude() * SG_FEET_TO_METER );
430 globals->get_model_mgr()->draw();
431 globals->get_aircraft_model()->draw();
435 // Update all Visuals (redraws anything graphics related)
436 void fgRenderFrame() {
438 GLfloat black[4] = { 0.0, 0.0, 0.0, 1.0 };
439 GLfloat white[4] = { 1.0, 1.0, 1.0, 1.0 };
441 // Process/manage pending events
442 global_events.update( delta_time_sec );
444 static const SGPropertyNode *longitude
445 = fgGetNode("/position/longitude-deg");
446 static const SGPropertyNode *latitude
447 = fgGetNode("/position/latitude-deg");
448 static const SGPropertyNode *altitude
449 = fgGetNode("/position/altitude-ft");
450 static const SGPropertyNode *groundlevel_nearplane
451 = fgGetNode("/sim/current-view/ground-level-nearplane-m");
453 // Update the default (kludged) properties.
456 FGViewer *current__view = globals->get_current_view();
458 fgLIGHT *l = &cur_light_params;
459 static double last_visibility = -9999;
462 double actual_visibility;
463 if (fgGetBool("/environment/clouds/status"))
464 actual_visibility = thesky->get_visibility();
466 actual_visibility = fgGetDouble("/environment/visibility-m");
467 if ( actual_visibility != last_visibility ) {
468 last_visibility = actual_visibility;
470 fog_exp_density = m_log01 / actual_visibility;
471 fog_exp2_density = sqrt_m_log01 / actual_visibility;
472 ground_exp2_punch_through = sqrt_m_log01 / (actual_visibility * 1.5);
473 if ( actual_visibility < 8000 ) {
474 rwy_exp2_punch_through = sqrt_m_log01 / (actual_visibility * 2.5);
475 taxi_exp2_punch_through = sqrt_m_log01 / (actual_visibility * 1.5);
477 rwy_exp2_punch_through = sqrt_m_log01 / ( 8000 * 2.5 );
478 taxi_exp2_punch_through = sqrt_m_log01 / ( 8000 * 1.5 );
483 // GLfloat black[4] = { 0.0, 0.0, 0.0, 1.0 };
484 // GLfloat white[4] = { 1.0, 1.0, 1.0, 1.0 };
485 // GLfloat terrain_color[4] = { 0.54, 0.44, 0.29, 1.0 };
486 // GLfloat mat_shininess[] = { 10.0 };
487 GLbitfield clear_mask;
489 if ( idle_state != 1000 ) {
490 // still initializing, draw the splash screen
491 if ( fgGetBool("/sim/startup/splash-screen") ) {
492 fgSplashUpdate(0.0, 1.0);
494 // Keep resetting sim time while the sim is initializing
495 globals->set_sim_time_sec( 0.0 );
497 // idle_state is now 1000 meaning we've finished all our
498 // initializations and are running the main loop, so this will
499 // now work without seg faulting the system.
501 // calculate our current position in cartesian space
502 globals->get_scenery()->set_center( globals->get_scenery()->get_next_center() );
505 fgReshape( fgGetInt("/sim/startup/xsize"),
506 fgGetInt("/sim/startup/ysize") );
508 if ( fgGetBool("/sim/rendering/clouds3d") ) {
509 glClear( GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT );
510 cloud3d_imposter_state->force();
512 glColor4f( 1.0, 1.0, 1.0, 1.0 );
513 glEnable(GL_DEPTH_TEST);
515 glBlendFunc( GL_ONE, GL_ONE_MINUS_SRC_ALPHA ) ;
517 #ifdef FG_USE_CLOUDS_3D
518 if ( _bcloud_orig ) {
519 Point3D c = globals->get_scenery()->get_center();
520 sgClouds3d->Set_Cloud_Orig( &c );
521 _bcloud_orig = false;
523 sgClouds3d->Update( current__view->get_absolute_view_pos() );
525 glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ) ;
526 glDisable(GL_DEPTH_TEST);
529 clear_mask = GL_DEPTH_BUFFER_BIT;
530 if ( fgGetBool("/sim/rendering/wireframe") ) {
531 clear_mask |= GL_COLOR_BUFFER_BIT;
534 if ( fgGetBool("/sim/rendering/skyblend") ) {
535 if ( fgGetBool("/sim/rendering/textures") ) {
536 // glClearColor(black[0], black[1], black[2], black[3]);
537 glClearColor(l->adj_fog_color[0], l->adj_fog_color[1],
538 l->adj_fog_color[2], l->adj_fog_color[3]);
539 clear_mask |= GL_COLOR_BUFFER_BIT;
542 glClearColor(l->sky_color[0], l->sky_color[1],
543 l->sky_color[2], l->sky_color[3]);
544 clear_mask |= GL_COLOR_BUFFER_BIT;
546 glClear( clear_mask );
548 // Tell GL we are switching to model view parameters
550 // I really should create a derived ssg node or use a call
551 // back or something so that I can draw the sky within the
552 // ssgCullAndDraw() function, but for now I just mimic what
553 // ssg does to set up the model view matrix
554 glMatrixMode(GL_MODELVIEW);
556 ssgSetCamera( (sgVec4 *)current__view->get_VIEW() );
558 // set the opengl state to known default values
559 default_state->force();
561 // update fog params if visibility has changed
562 double visibility_meters = fgGetDouble("/environment/visibility-m");
563 thesky->set_visibility(visibility_meters);
565 thesky->modify_vis( cur_fdm_state->get_Altitude() * SG_FEET_TO_METER,
566 ( global_multi_loop * fgGetInt("/sim/speed-up") )
567 / (double)fgGetInt("/sim/model-hz") );
569 // Set correct opengl fog density
570 glFogf (GL_FOG_DENSITY, fog_exp2_density);
572 // update the sky dome
573 if ( fgGetBool("/sim/rendering/skyblend") ) {
574 /* cout << "thesky->repaint() sky_color = "
575 << cur_light_params.sky_color[0] << " "
576 << cur_light_params.sky_color[1] << " "
577 << cur_light_params.sky_color[2] << " "
578 << cur_light_params.sky_color[3] << endl;
580 << cur_light_params.fog_color[0] << " "
581 << cur_light_params.fog_color[1] << " "
582 << cur_light_params.fog_color[2] << " "
583 << cur_light_params.fog_color[3] << endl;
584 cout << " sun_angle = " << cur_light_params.sun_angle
585 << " moon_angle = " << cur_light_params.moon_angle
587 thesky->repaint( cur_light_params.sky_color,
588 cur_light_params.adj_fog_color,
589 cur_light_params.sun_angle,
590 cur_light_params.moon_angle,
591 globals->get_ephem()->getNumPlanets(),
592 globals->get_ephem()->getPlanets(),
593 globals->get_ephem()->getNumStars(),
594 globals->get_ephem()->getStars() );
596 /* cout << "thesky->reposition( view_pos = " << view_pos[0] << " "
597 << view_pos[1] << " " << view_pos[2] << endl;
598 cout << " zero_elev = " << zero_elev[0] << " "
599 << zero_elev[1] << " " << zero_elev[2]
600 << " lon = " << cur_fdm_state->get_Longitude()
601 << " lat = " << cur_fdm_state->get_Latitude() << endl;
602 cout << " sun_rot = " << cur_light_params.sun_rotation
603 << " gst = " << SGTime::cur_time_params->getGst() << endl;
604 cout << " sun ra = " << globals->get_ephem()->getSunRightAscension()
605 << " sun dec = " << globals->get_ephem()->getSunDeclination()
606 << " moon ra = " << globals->get_ephem()->getMoonRightAscension()
607 << " moon dec = " << globals->get_ephem()->getMoonDeclination() << endl; */
609 thesky->reposition( current__view->get_view_pos(),
610 current__view->get_zero_elev(),
611 current__view->get_world_up(),
612 current__view->getLongitude_deg()
613 * SGD_DEGREES_TO_RADIANS,
614 current__view->getLatitude_deg()
615 * SGD_DEGREES_TO_RADIANS,
616 current__view->getAltitudeASL_ft() * SG_FEET_TO_METER,
617 cur_light_params.sun_rotation,
618 globals->get_time_params()->getGst(),
619 globals->get_ephem()->getSunRightAscension(),
620 globals->get_ephem()->getSunDeclination(),
622 globals->get_ephem()->getMoonRightAscension(),
623 globals->get_ephem()->getMoonDeclination(),
627 glEnable( GL_DEPTH_TEST );
628 if ( strcmp(fgGetString("/sim/rendering/fog"), "disabled") ) {
630 glFogi( GL_FOG_MODE, GL_EXP2 );
631 glFogfv( GL_FOG_COLOR, l->adj_fog_color );
634 // set sun/lighting parameters
635 ssgGetLight( 0 ) -> setPosition( l->sun_vec );
637 // GL_LIGHT_MODEL_AMBIENT has a default non-zero value so if
638 // we only update GL_AMBIENT for our lights we will never get
639 // a completely dark scene. So, we set GL_LIGHT_MODEL_AMBIENT
640 // explicitely to black.
641 glLightModelfv( GL_LIGHT_MODEL_AMBIENT, black );
643 ssgGetLight( 0 ) -> setColour( GL_AMBIENT, l->scene_ambient );
644 ssgGetLight( 0 ) -> setColour( GL_DIFFUSE, l->scene_diffuse );
645 ssgGetLight( 0 ) -> setColour( GL_SPECULAR, l->scene_specular );
647 // texture parameters
648 // glEnable( GL_TEXTURE_2D );
649 glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ) ;
650 glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST ) ;
652 // glMatrixMode( GL_PROJECTION );
654 ssgSetFOV( current__view->get_h_fov(),
655 current__view->get_v_fov() );
658 current_aircraft.fdm_state->get_Altitude() * SG_FEET_TO_METER
659 - globals->get_scenery()->get_cur_elev();
662 scene_nearplane = 10.0f;
663 scene_farplane = 120000.0f;
665 scene_nearplane = groundlevel_nearplane->getDoubleValue();
666 scene_farplane = 120000.0f;
669 ssgSetNearFar( scene_nearplane, scene_farplane );
671 // $$$ begin - added VS Renganthan 17 Oct 2K
674 // $$$ end - added VS Renganthan 17 Oct 2K
676 # ifdef FG_NETWORK_OLK
677 if ( fgGetBool("/sim/networking/network-olk") ) {
679 other = head->next; /* put listpointer to start */
680 while ( other != tail) { /* display all except myself */
681 if ( strcmp( other->ipadr, fgd_mcp_ip) != 0) {
682 other->fgd_sel->select(1);
683 sgSetCoord( &fgdpos, other->sgFGD_COORD );
684 other->fgd_pos->setTransform( &fgdpos );
689 // fgd_sel->select(1);
690 // sgCopyMat4( sgTUX, current_view.sgVIEW);
692 // sgSetCoord( &fgdpos, sgFGD_VIEW );
693 // fgd_pos->setTransform( &fgdpos);
697 if ( fgGetBool("/sim/rendering/skyblend") ) {
698 // draw the sky backdrop
700 // we need a white diffuse light for the phase of the moon
701 ssgGetLight( 0 ) -> setColour( GL_DIFFUSE, white );
705 // return to the desired diffuse color
706 ssgGetLight( 0 ) -> setColour( GL_DIFFUSE, l->scene_diffuse );
709 // draw the ssg scene
710 glEnable( GL_DEPTH_TEST );
712 ssgSetNearFar( scene_nearplane, scene_farplane );
713 ssgCullAndDraw( globals->get_scenery()->get_scene_graph() );
715 // This is a bit kludgy. Every 200 frames, do an extra
716 // traversal of the scene graph without drawing anything, but
717 // with the field-of-view set to 360x360 degrees. This
718 // ensures that out-of-range random objects that are not in
719 // the current view frustum will still be freed properly.
720 static int counter = 0;
722 if (counter == 200) {
725 // No need to put the near plane too close;
726 // this way, at least the aircraft can be
728 f.setNearFar(1000, 1000000);
730 ssgGetModelviewMatrix(m);
731 globals->get_scenery()->get_scene_graph()->cull(&f, m, true);
735 // change state for lighting here
737 // draw runway lighting
738 glFogf (GL_FOG_DENSITY, rwy_exp2_punch_through);
739 ssgSetNearFar( scene_nearplane, scene_farplane );
741 if (fgGetBool("/sim/rendering/experimental-lighting")) {
743 // Enable states for drawing points with GL_extension
744 glEnable(GL_POINT_SMOOTH);
746 if ( fgGetBool("/sim/rendering/distance-attenuation")
747 && glutExtensionSupported("GL_EXT_point_parameters") )
749 float quadratic[3] = {1.0, 0.001, 0.0000001};
750 // makes the points fade as they move away
751 glPointParameterfvEXT(GL_DISTANCE_ATTENUATION_EXT, quadratic);
752 glPointParameterfEXT(GL_POINT_SIZE_MIN_EXT, 1.0);
756 // blending function for runway lights
757 glBlendFunc ( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) ;
760 glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
761 glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
762 glEnable(GL_TEXTURE_GEN_S);
763 glEnable(GL_TEXTURE_GEN_T);
764 glPolygonMode(GL_FRONT, GL_POINT);
766 // draw runway lighting
767 ssgCullAndDraw( globals->get_scenery()->get_rwy_lights_root() );
769 // change punch through and then draw taxi lighting
770 glFogf ( GL_FOG_DENSITY, fog_exp2_density );
772 // sgSetVec3( taxi_fog, 0.0, 0.0, 0.0 );
773 // glFogfv ( GL_FOG_COLOR, taxi_fog );
774 ssgCullAndDraw( globals->get_scenery()->get_taxi_lights_root() );
777 glPolygonMode(GL_FRONT, GL_FILL);
778 glDisable(GL_TEXTURE_GEN_S);
779 glDisable(GL_TEXTURE_GEN_T);
781 //static int _frame_count = 0;
782 //if (_frame_count % 30 == 0) {
783 // printf("SSG: %s\n", ssgShowStats());
791 if (fgGetBool("/sim/rendering/experimental-lighting")) {
792 if ( fgGetBool("/sim/rendering/distance-attenuation")
793 && glutExtensionSupported("GL_EXT_point_parameters") )
795 glPointParameterfvEXT(GL_DISTANCE_ATTENUATION_EXT,
796 default_attenuation);
800 glDisable(GL_POINT_SMOOTH);
803 // draw ground lighting
804 glFogf (GL_FOG_DENSITY, ground_exp2_punch_through);
805 ssgCullAndDraw( globals->get_scenery()->get_gnd_lights_root() );
807 if ( fgGetBool("/sim/rendering/skyblend") ) {
808 // draw the sky cloud layers
809 if (fgGetBool("/environment/clouds/status")) {
810 thesky->postDraw( cur_fdm_state->get_Altitude()
811 * SG_FEET_TO_METER );
815 if ( fgGetBool("/sim/rendering/clouds3d") ) {
817 glDisable( GL_LIGHTING );
818 // cout << "drawing new clouds" << endl;
820 glEnable(GL_DEPTH_TEST);
822 glBlendFunc( GL_ONE, GL_ONE_MINUS_SRC_ALPHA ) ;
825 glEnable( GL_TEXTURE_2D );
826 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
827 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
828 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
829 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
832 #ifdef FG_USE_CLOUDS_3D
833 sgClouds3d->Draw((sgVec4 *)current__view->get_VIEW());
836 glEnable( GL_LIGHTING );
837 glEnable( GL_DEPTH_TEST );
838 glBlendFunc ( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ) ;
841 globals->get_model_mgr()->draw();
842 globals->get_aircraft_model()->draw();
844 // display HUD && Panel
846 glDisable( GL_DEPTH_TEST );
847 // glDisable( GL_CULL_FACE );
848 // glDisable( GL_TEXTURE_2D );
850 // update the controls subsystem
851 globals->get_controls()->update(delta_time_sec);
853 hud_and_panel->apply();
856 // Use the hud_and_panel ssgSimpleState for rendering the ATC output
857 // This only works properly if called before the panel call
858 globals->get_ATC_display()->update(delta_time_sec);
860 // update the panel subsystem
861 if ( current_panel != NULL ) {
862 current_panel->update(delta_time_sec);
866 // We can do translucent menus, so why not. :-)
868 glBlendFunc ( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ) ;
870 // glDisable ( GL_BLEND ) ;
872 glEnable( GL_DEPTH_TEST );
875 // Fade out the splash screen over the first three seconds.
876 double t = globals->get_sim_time_sec();
878 fgSplashUpdate(0.0, 1.0);
879 } else if ( t <= 3.0) {
880 fgSplashUpdate(0.0, (3.0 - t) / 2.0);
888 // Update internal time dependent calculations (i.e. flight model)
889 // FIXME: this distinction is obsolete; all subsystems now get delta
891 void fgUpdateTimeDepCalcs() {
892 static bool inited = false;
894 //SG_LOG(SG_FLIGHT,SG_INFO, "Updating time dep calcs()");
896 fgLIGHT *l = &cur_light_params;
898 // Initialize the FDM here if it hasn't been and if we have a
899 // scenery elevation hit.
901 // cout << "cur_fdm_state->get_inited() = " << cur_fdm_state->get_inited()
902 // << " cur_elev = " << scenery.get_cur_elev() << endl;
904 if ( !cur_fdm_state->get_inited() &&
905 globals->get_scenery()->get_cur_elev() > -9990 )
907 SG_LOG(SG_FLIGHT,SG_INFO, "Finally initializing fdm");
909 cur_fdm_state->init();
910 if ( cur_fdm_state->get_bound() ) {
911 cur_fdm_state->unbind();
913 cur_fdm_state->bind();
916 // conceptually, the following block could be done for each fdm
918 if ( !cur_fdm_state->get_inited() ) {
919 // do nothing, fdm isn't inited yet
921 // we have been inited, and we are good to go ...
927 globals->get_autopilot()->update(delta_time_sec);
928 cur_fdm_state->update(delta_time_sec);
929 globals->get_steam()->update(delta_time_sec);
932 globals->get_model_mgr()->update(delta_time_sec);
933 globals->get_aircraft_model()->update(delta_time_sec);
935 // update the view angle
936 globals->get_viewmgr()->update(delta_time_sec);
940 // Update solar system
941 globals->get_ephem()->update( globals->get_time_params()->getMjd(),
942 globals->get_time_params()->getLst(),
943 cur_fdm_state->get_Latitude() );
945 // Update radio stack model
946 current_radiostack->update(delta_time_sec);
950 void fgInitTimeDepCalcs( void ) {
955 static const double alt_adjust_ft = 3.758099;
956 static const double alt_adjust_m = alt_adjust_ft * SG_FEET_TO_METER;
959 // What should we do when we have nothing else to do? Let's get ready
960 // for the next move and update the display?
961 static void fgMainLoop( void ) {
963 static const SGPropertyNode *longitude
964 = fgGetNode("/position/longitude-deg");
965 static const SGPropertyNode *latitude
966 = fgGetNode("/position/latitude-deg");
967 static const SGPropertyNode *altitude
968 = fgGetNode("/position/altitude-ft");
969 static const SGPropertyNode *clock_freeze
970 = fgGetNode("/sim/freeze/clock", true);
971 static const SGPropertyNode *cur_time_override
972 = fgGetNode("/sim/time/cur-time-override", true);
974 // Update the elapsed time.
975 static bool first_time = true;
977 last_time_stamp.stamp();
980 current_time_stamp.stamp();
981 delta_time_sec = double(current_time_stamp - last_time_stamp) / 1000000.0;
982 if (clock_freeze->getBoolValue())
984 last_time_stamp = current_time_stamp;
985 globals->inc_sim_time_sec( delta_time_sec );
987 static long remainder = 0;
989 #ifdef FANCY_FRAME_COUNTER
993 static time_t last_time = 0;
994 static int frames = 0;
995 #endif // FANCY_FRAME_COUNTER
997 SGTime *t = globals->get_time_params();
999 FGLocation * acmodel_location = 0;
1000 if(cur_fdm_state->getACModel() != 0) {
1001 acmodel_location = (FGLocation *) cur_fdm_state->getACModel()->get3DModel()->getFGLocation();
1004 SG_LOG( SG_ALL, SG_DEBUG, "Running Main Loop");
1005 SG_LOG( SG_ALL, SG_DEBUG, "======= ==== ====");
1007 #ifdef FG_NETWORK_OLK
1008 if ( fgGetBool("/sim/networking/network-olk") ) {
1009 if ( net_is_registered == 0 ) { // We first have to reg. to fgd
1010 // printf("FGD: Netupdate\n");
1011 fgd_send_com( "A", FGFS_host); // Send Mat4 data
1012 fgd_send_com( "B", FGFS_host); // Recv Mat4 data
1017 #if defined( ENABLE_PLIB_JOYSTICK )
1018 // Read joystick and update control settings
1019 // if ( fgGetString("/sim/control-mode") == "joystick" )
1021 // fgJoystickRead();
1023 #elif defined( ENABLE_GLUT_JOYSTICK )
1024 // Glut joystick support works by feeding a joystick handler
1025 // function to glut. This is taken care of once in the joystick
1026 // init routine and we don't have to worry about it again.
1029 #ifndef FG_WEATHERCM
1030 globals->get_environment_mgr()->update(delta_time_sec);
1033 // Fix elevation. I'm just sticking this here for now, it should
1034 // probably move eventually
1036 /* printf("Before - ground = %.2f runway = %.2f alt = %.2f\n",
1037 scenery.get_cur_elev(),
1038 cur_fdm_state->get_Runway_altitude() * SG_FEET_TO_METER,
1039 cur_fdm_state->get_Altitude() * SG_FEET_TO_METER); */
1041 // Curt is this code used? I don't see any problems when I comment it out.
1042 if ( acmodel_location != 0 ) {
1043 if ( acmodel_location->get_cur_elev_m() > -9990 && cur_fdm_state->get_inited() ) {
1044 if ( cur_fdm_state->get_Altitude() * SG_FEET_TO_METER <
1045 (acmodel_location->get_cur_elev_m() + alt_adjust_m - 3.0) ) {
1046 // now set aircraft altitude above ground
1047 printf("(*) Current Altitude = %.2f < %.2f forcing to %.2f\n",
1048 cur_fdm_state->get_Altitude() * SG_FEET_TO_METER,
1049 acmodel_location->get_cur_elev_m() + alt_adjust_m - 3.0,
1050 acmodel_location->get_cur_elev_m() + alt_adjust_m );
1051 cur_fdm_state->set_Altitude( (acmodel_location->get_cur_elev_m()
1052 + alt_adjust_m) * SG_METER_TO_FEET );
1053 SG_LOG( SG_ALL, SG_DEBUG,
1054 "<*> resetting altitude to "
1055 << cur_fdm_state->get_Altitude() * SG_FEET_TO_METER
1060 // End of code in question. (see Curt is this code used? above)
1062 /* printf("Adjustment - ground = %.2f runway = %.2f alt = %.2f\n",
1063 scenery.get_cur_elev(),
1064 cur_fdm_state->get_Runway_altitude() * SG_FEET_TO_METER,
1065 cur_fdm_state->get_Altitude() * SG_FEET_TO_METER); */
1067 // cout << "Warp = " << globals->get_warp() << endl;
1070 static bool last_clock_freeze = false;
1072 if ( clock_freeze->getBoolValue() ) {
1073 // clock freeze requested
1074 if ( cur_time_override->getLongValue() == 0 ) {
1075 fgSetLong( "/sim/time/cur-time-override", t->get_cur_time() );
1076 globals->set_warp( 0 );
1079 // no clock freeze requested
1080 if ( last_clock_freeze == true ) {
1081 // clock just unfroze, let's set warp as the difference
1082 // between frozen time and current time so we don't get a
1083 // time jump (and corresponding sky object and lighting
1085 globals->set_warp( cur_time_override->getLongValue() - time(NULL) );
1086 fgSetLong( "/sim/time/cur-time-override", 0 );
1088 if ( globals->get_warp_delta() != 0 ) {
1089 globals->inc_warp( globals->get_warp_delta() );
1093 last_clock_freeze = clock_freeze->getBoolValue();
1095 t->update( longitude->getDoubleValue() * SGD_DEGREES_TO_RADIANS,
1096 latitude->getDoubleValue() * SGD_DEGREES_TO_RADIANS,
1097 cur_time_override->getLongValue(),
1098 globals->get_warp() );
1100 if ( globals->get_warp_delta() != 0 ) {
1101 fgUpdateSkyAndLightingParams();
1104 // update magvar model
1105 globals->get_mag()->update( longitude->getDoubleValue()
1106 * SGD_DEGREES_TO_RADIANS,
1107 latitude->getDoubleValue()
1108 * SGD_DEGREES_TO_RADIANS,
1109 altitude->getDoubleValue() * SG_FEET_TO_METER,
1110 globals->get_time_params()->getJD() );
1112 // Get elapsed time (in usec) for this past frame
1113 elapsed = fgGetTimeInterval();
1114 SG_LOG( SG_ALL, SG_DEBUG,
1115 "Elapsed time interval is = " << elapsed
1116 << ", previous remainder is = " << remainder );
1118 // Calculate frame rate average
1119 #ifdef FANCY_FRAME_COUNTER
1120 /* old fps calculation */
1121 if ( elapsed > 0 ) {
1124 for ( i = FG_FRAME_RATE_HISTORY - 2; i >= 0; i-- ) {
1125 tmp = general.get_frame(i);
1127 // printf("frame[%d] = %.2f\n", i, g->frames[i]);
1128 general.set_frame(i+1,tmp);
1130 tmp = 1000000.0 / (float)elapsed;
1131 general.set_frame(0,tmp);
1132 // printf("frame[0] = %.2f\n", general.frames[0]);
1134 general.set_frame_rate(accum / (float)FG_FRAME_RATE_HISTORY);
1135 // printf("ave = %.2f\n", general.frame_rate);
1138 if ( (t->get_cur_time() != last_time) && (last_time > 0) ) {
1139 general.set_frame_rate( frames );
1140 SG_LOG( SG_ALL, SG_DEBUG,
1141 "--> Frame rate is = " << general.get_frame_rate() );
1144 last_time = t->get_cur_time();
1148 // Run ATC subsystem
1149 globals->get_ATC_mgr()->update(delta_time_sec);
1151 // Run the AI subsystem
1152 if (fgGetBool("/sim/ai-traffic/enabled"))
1153 globals->get_AI_mgr()->update(delta_time_sec);
1157 // Calculate model iterations needed for next frame
1158 elapsed += remainder;
1160 global_multi_loop = (long)(((double)elapsed * 0.000001) *
1161 fgGetInt("/sim/model-hz"));
1162 remainder = elapsed - ( (global_multi_loop*1000000) /
1163 fgGetInt("/sim/model-hz") );
1164 SG_LOG( SG_ALL, SG_DEBUG,
1165 "Model iterations needed = " << global_multi_loop
1166 << ", new remainder = " << remainder );
1168 // chop max interations to something reasonable if the sim was
1169 // delayed for an excesive amount of time
1170 if ( global_multi_loop > 2.0 * fgGetInt("/sim/model-hz") ) {
1171 global_multi_loop = (int)(2.0 * fgGetInt("/sim/model-hz") );
1176 if ( global_multi_loop > 0 ) {
1177 fgUpdateTimeDepCalcs();
1179 SG_LOG( SG_ALL, SG_DEBUG,
1180 "Elapsed time is zero ... we're zinging" );
1183 // Do any I/O channel work that might need to be done
1184 globals->get_io()->update( delta_time_sec );
1186 // see if we need to load any deferred-load textures
1187 material_lib.load_next_deferred();
1189 // Run audio scheduler
1190 #ifdef ENABLE_AUDIO_SUPPORT
1191 if ( fgGetBool("/sim/sound/audible")
1192 && globals->get_soundmgr()->is_working() ) {
1193 globals->get_soundmgr()->update( delta_time_sec );
1197 globals->get_subsystem_mgr()->update(delta_time_sec);
1200 // Tile Manager updates - see if we need to load any new scenery tiles.
1201 // this code ties together the fdm, viewer and scenery classes...
1202 // we may want to move this to it's own class at some point
1204 double visibility_meters = fgGetDouble("/environment/visibility-m");
1205 FGViewer *current_view = globals->get_current_view();
1207 // update tile manager for FDM...
1208 // ...only if location is different than the viewer (to avoid duplicating effort)
1209 if( acmodel_location != current_view->getFGLocation() ) {
1210 if( acmodel_location != 0 ) {
1211 globals->get_tile_mgr()->prep_ssg_nodes( acmodel_location,
1212 visibility_meters );
1213 globals->get_tile_mgr()->
1214 update( acmodel_location, visibility_meters,
1215 acmodel_location->get_absolute_view_pos() );
1216 // save results of update in FGLocation for fdm...
1217 if ( globals->get_scenery()->get_cur_elev() > -9990 ) {
1219 set_cur_elev_m( globals->get_scenery()->get_cur_elev() );
1222 set_tile_center( globals->get_scenery()->get_next_center() );
1226 globals->get_tile_mgr()->prep_ssg_nodes( current_view->getFGLocation(),
1227 visibility_meters );
1228 // update tile manager for view...
1229 // IMPORTANT!!! the tilemgr update for view location _must_ be done last
1230 // after the FDM's until all of Flight Gear code references the viewer's location
1231 // for elevation instead of the "scenery's" current elevation.
1232 FGLocation *view_location = globals->get_current_view()->getFGLocation();
1233 globals->get_tile_mgr()->update( view_location, visibility_meters,
1234 current_view->get_absolute_view_pos() );
1235 // save results of update in FGLocation for fdm...
1236 if ( globals->get_scenery()->get_cur_elev() > -9990 ) {
1237 current_view->getFGLocation()->set_cur_elev_m( globals->get_scenery()->get_cur_elev() );
1239 current_view->getFGLocation()->set_tile_center( globals->get_scenery()->get_next_center() );
1241 // If fdm location is same as viewer's then we didn't do the update for fdm location
1242 // above so we need to save the viewer results in the fdm FGLocation as well...
1243 if( acmodel_location == current_view->getFGLocation() ) {
1244 if( acmodel_location != 0 ) {
1245 if ( globals->get_scenery()->get_cur_elev() > -9990 ) {
1246 acmodel_location->set_cur_elev_m( globals->get_scenery()->get_cur_elev() );
1248 acmodel_location->set_tile_center( globals->get_scenery()->get_next_center() );
1252 // END Tile Manager udpates
1257 SG_LOG( SG_ALL, SG_DEBUG, "" );
1261 // This is the top level master main function that is registered as
1262 // our idle funciton
1264 // The first few passes take care of initialization things (a couple
1265 // per pass) and once everything has been initialized fgMainLoop from
1268 static void fgIdleFunction ( void ) {
1269 // printf("idle state == %d\n", idle_state);
1271 if ( idle_state == 0 ) {
1272 // Initialize the splash screen right away
1273 if ( fgGetBool("/sim/startup/splash-screen") ) {
1278 } else if ( idle_state == 1 ) {
1279 // Initialize audio support
1280 #ifdef ENABLE_AUDIO_SUPPORT
1282 // Start the intro music
1283 if ( fgGetBool("/sim/startup/intro-music") ) {
1284 SGPath mp3file( globals->get_fg_root() );
1285 mp3file.append( "Sounds/intro.mp3" );
1287 SG_LOG( SG_GENERAL, SG_INFO,
1288 "Starting intro music: " << mp3file.str() );
1290 #if defined( __CYGWIN__ )
1291 string command = "start /m `cygpath -w " + mp3file.str() + "`";
1292 #elif defined( WIN32 )
1293 string command = "start /m " + mp3file.str();
1295 string command = "mpg123 " + mp3file.str() + "> /dev/null 2>&1";
1298 system ( command.c_str() );
1303 } else if ( idle_state == 2 ) {
1304 // These are a few miscellaneous things that aren't really
1305 // "subsystems" but still need to be initialized.
1308 if ( strstr ( general.get_glRenderer(), "Glide" ) ) {
1309 grTexLodBiasValue ( GR_TMU0, 1.0 ) ;
1314 } else if ( idle_state == 3 ) {
1315 // This is the top level init routine which calls all the
1316 // other subsystem initialization routines. If you are adding
1317 // a subsystem to flightgear, its initialization call should
1318 // located in this routine.
1319 if( !fgInitSubsystems()) {
1320 SG_LOG( SG_GENERAL, SG_ALERT,
1321 "Subsystem initializations failed ..." );
1326 } else if ( idle_state == 4 ) {
1327 // setup OpenGL view parameters
1331 } else if ( idle_state == 5 ) {
1334 } else if ( idle_state == 6 ) {
1338 SG_LOG( SG_GENERAL, SG_INFO, "Panel visible = " << fgPanelVisible() );
1339 fgReshape( fgGetInt("/sim/startup/xsize"),
1340 fgGetInt("/sim/startup/ysize") );
1343 if ( idle_state == 1000 ) {
1344 // We've finished all our initialization steps, from now on we
1345 // run the main loop.
1347 glutIdleFunc(fgMainLoop);
1349 if ( fgGetBool("/sim/startup/splash-screen") ) {
1350 fgSplashUpdate(0.0, 1.0);
1355 // options.cxx needs to see this for toggle_panel()
1356 // Handle new window size or exposure
1357 void fgReshape( int width, int height ) {
1360 if ( (!fgGetBool("/sim/virtual-cockpit"))
1361 && fgPanelVisible() && idle_state == 1000 ) {
1362 view_h = (int)(height * (current_panel->getViewHeight() -
1363 current_panel->getYOffset()) / 768.0);
1369 FGViewMgr *viewmgr = globals->get_viewmgr();
1370 for ( int i = 0; i < viewmgr->size(); ++i ) {
1371 viewmgr->get_view(i)->
1372 set_aspect_ratio((float)view_h / (float)width);
1375 glViewport( 0, (GLint)(height - view_h), (GLint)(width), (GLint)(view_h) );
1377 fgSetInt("/sim/startup/xsize", width);
1378 fgSetInt("/sim/startup/ysize", height);
1379 guiInitMouse(width, height);
1381 ssgSetFOV( viewmgr->get_current_view()->get_h_fov(),
1382 viewmgr->get_current_view()->get_v_fov() );
1386 #ifdef FG_USE_CLOUDS_3D
1387 sgClouds3d->Resize( viewmgr->get_current_view()->get_h_fov(),
1388 viewmgr->get_current_view()->get_v_fov() );
1393 // Initialize GLUT and define a main window
1394 static bool fgGlutInit( int *argc, char **argv ) {
1396 #if !defined( macintosh )
1397 // GLUT will extract all glut specific options so later on we only
1398 // need wory about our own.
1399 glutInit(argc, argv);
1402 // Define Display Parameters. Clouds3d works best with --bpp32 option
1403 if ( fgGetBool("/sim/rendering/clouds3d") ) {
1404 glutInitDisplayMode( GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE | GLUT_ALPHA );
1406 glutInitDisplayMode( GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE );
1409 SG_LOG( SG_GENERAL, SG_INFO, "Opening a window: " <<
1410 fgGetInt("/sim/startup/xsize") << "x"
1411 << fgGetInt("/sim/startup/ysize") );
1413 // Define initial window size
1414 glutInitWindowSize( fgGetInt("/sim/startup/xsize"),
1415 fgGetInt("/sim/startup/ysize") );
1417 // Initialize windows
1418 if ( !fgGetBool("/sim/startup/game-mode")) {
1419 // Open the regular window
1420 glutCreateWindow("FlightGear");
1421 #ifndef GLUT_WRONG_VERSION
1423 // Open the cool new 'game mode' window
1424 char game_mode_str[256];
1425 //#define SYNC_OPENGL_WITH_DESKTOP_SETTINGS
1426 #if defined(WIN32) && defined(SYNC_OPENGL_WITH_DESKTOP_SETTINGS)
1427 #ifndef ENUM_CURRENT_SETTINGS
1428 #define ENUM_CURRENT_SETTINGS ((DWORD)-1)
1429 #define ENUM_REGISTRY_SETTINGS ((DWORD)-2)
1433 dm.dmSize = sizeof(DEVMODE);
1434 EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &dm);
1435 fgSetInt("/sim/startup/xsize", dm.dmPelsWidth);
1436 fgSetInt("/sim/startup/ysize", dm.dmPelsHeight);
1437 glutInitWindowSize( fgGetInt("/sim/startup/xsize"),
1438 fgGetInt("/sim/startup/ysize") );
1439 sprintf( game_mode_str, "%dx%d:%d@%d",
1443 dm.dmDisplayFrequency );
1445 // Open the cool new 'game mode' window
1446 sprintf( game_mode_str, "width=%d height=%d bpp=%d",
1447 fgGetInt("/sim/startup/xsize"),
1448 fgGetInt("/sim/startup/ysize"),
1449 fgGetInt("/sim/rendering/bits-per-pixel"));
1451 #endif // HAVE_WINDOWS_H
1452 SG_LOG( SG_GENERAL, SG_INFO,
1453 "game mode params = " << game_mode_str );
1454 glutGameModeString( game_mode_str );
1455 glutEnterGameMode();
1456 #endif // GLUT_WRONG_VERSION
1459 // This seems to be the absolute earliest in the init sequence
1460 // that these calls will return valid info. Too bad it's after
1461 // we've already created and sized out window. :-(
1462 general.set_glVendor( (char *)glGetString ( GL_VENDOR ) );
1463 general.set_glRenderer( (char *)glGetString ( GL_RENDERER ) );
1464 general.set_glVersion( (char *)glGetString ( GL_VERSION ) );
1465 SG_LOG( SG_GENERAL, SG_INFO, general.get_glRenderer() );
1468 glGetIntegerv( GL_MAX_TEXTURE_SIZE, &tmp );
1469 general.set_glMaxTexSize( tmp );
1470 SG_LOG ( SG_GENERAL, SG_INFO, "Max texture size = " << tmp );
1472 glGetIntegerv( GL_DEPTH_BITS, &tmp );
1473 general.set_glDepthBits( tmp );
1474 SG_LOG ( SG_GENERAL, SG_INFO, "Depth buffer bits = " << tmp );
1480 // Initialize GLUT event handlers
1481 static bool fgGlutInitEvents( void ) {
1482 // call fgReshape() on window resizes
1483 glutReshapeFunc( fgReshape );
1485 // keyboard and mouse callbacks are set in FGInput::init
1487 // call fgMainLoop() whenever there is
1488 // nothing else to do
1489 glutIdleFunc( fgIdleFunction );
1492 glutDisplayFunc( fgRenderFrame );
1497 // Main top level initialization
1498 static bool fgMainInit( int argc, char **argv ) {
1500 #if defined( macintosh )
1501 freopen ("stdout.txt", "w", stdout );
1502 freopen ("stderr.txt", "w", stderr );
1503 argc = ccommand( &argv );
1506 // set default log levels
1507 sglog().setLogLevels( SG_ALL, SG_INFO );
1510 #ifdef FLIGHTGEAR_VERSION
1511 version = FLIGHTGEAR_VERSION;
1513 version = "unknown version";
1515 SG_LOG( SG_GENERAL, SG_INFO, "FlightGear: Version "
1517 SG_LOG( SG_GENERAL, SG_INFO, "Built with " << SG_COMPILER_STR << endl );
1519 // Allocate global data structures. This needs to happen before
1520 // we parse command line options
1522 globals = new FGGlobals;
1524 #ifndef FG_WEATHERCM
1525 globals->set_environment_mgr(new FGEnvironmentMgr);
1528 // seed the random number generater
1531 SGRoute *route = new SGRoute;
1532 globals->set_route( route );
1534 FGControls *controls = new FGControls;
1535 globals->set_controls( controls );
1537 FGSteam *steam = new FGSteam;
1538 globals->set_steam( steam );
1540 string_list *col = new string_list;
1541 globals->set_channel_options_list( col );
1543 // Scan the config file(s) and command line options to see if
1544 // fg_root was specified (ignore all other options for now)
1545 fgInitFGRoot(argc, argv);
1547 // Check for the correct base package version
1548 static char required_version[] = "0.9.1";
1549 string base_version = fgBasePackageVersion();
1550 if ( !(base_version == required_version) ) {
1551 // tell the operator how to use this application
1553 cerr << endl << "Base package check failed ... " \
1554 << "Found version " << base_version << " at: " \
1555 << globals->get_fg_root() << endl;
1556 cerr << "Please upgrade to version: " << required_version << endl;
1560 // Initialize the Aircraft directory to "" (UIUC)
1563 // Load the configuration parameters. (Command line options
1564 // overrides config file options. Config file options override
1566 if ( !fgInitConfig(argc, argv) ) {
1567 SG_LOG( SG_GENERAL, SG_ALERT, "Config option parsing failed ..." );
1571 // Initialize the Window/Graphics environment.
1572 if( !fgGlutInit(&argc, argv) ) {
1573 SG_LOG( SG_GENERAL, SG_ALERT, "GLUT initialization failed ..." );
1577 // Initialize the various GLUT Event Handlers.
1578 if( !fgGlutInitEvents() ) {
1579 SG_LOG( SG_GENERAL, SG_ALERT,
1580 "GLUT event handler initialization failed ..." );
1584 // Initialize plib net interface
1585 netInit( &argc, argv );
1587 // Initialize ssg (from plib). Needs to come before we do any
1588 // other ssg stuff, but after opengl/glut has been initialized.
1591 // Initialize the user interface (we need to do this before
1592 // passing off control to glut and before fgInitGeneral to get our
1596 #ifdef GL_EXT_texture_lod_bias
1597 glTexEnvf( GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, -0.5 ) ;
1600 // get the address of our OpenGL extensions
1601 if ( fgGetBool("/sim/rendering/distance-attenuation") )
1604 glPointParameterfEXT = (PFNGLPOINTPARAMETERFEXTPROC)
1605 wglGetProcAddress("glPointParameterfEXT");
1606 glPointParameterfvEXT = (PFNGLPOINTPARAMETERFVEXTPROC)
1607 wglGetProcAddress("glPointParameterfvEXT");
1609 glPointParameterfEXT = (OpenGLFuncExt)
1610 glXGetProcAddressARB((GLubyte *)"glPointParameterfEXT");
1611 glPointParameterfvEXT = (OpenGLFuncExtv)
1612 glXGetProcAddressARB((GLubyte *)"glPointParameterfvEXT");
1616 // based on the requested presets, calculate the true starting
1620 SGTime *t = fgInitTime();
1621 globals->set_time_params( t );
1623 // Do some quick general initializations
1624 if( !fgInitGeneral()) {
1625 SG_LOG( SG_GENERAL, SG_ALERT,
1626 "General initializations failed ..." );
1630 SGPath modelpath( globals->get_fg_root() );
1631 ssgModelPath( (char *)modelpath.c_str() );
1633 // Initialize the global scenery manager
1634 globals->set_scenery( new FGScenery );
1635 globals->get_scenery()->init();
1636 globals->get_scenery()->bind();
1638 // Initialize the global tile manager
1639 globals->set_tile_mgr( new FGTileMgr );
1641 ////////////////////////////////////////////////////////////////////
1642 // Initialize the property-based built-in commands
1643 ////////////////////////////////////////////////////////////////////
1646 ////////////////////////////////////////////////////////////////////
1647 // Initialize the general model subsystem.
1648 ////////////////////////////////////////////////////////////////////
1650 globals->set_model_loader(new FGModelLoader);
1651 globals->set_texture_loader(new FGTextureLoader);
1652 globals->set_model_mgr(new FGModelMgr);
1653 globals->get_model_mgr()->init();
1654 globals->get_model_mgr()->bind();
1656 ////////////////////////////////////////////////////////////////////
1657 // Initialize the 3D aircraft model subsystem.
1658 ////////////////////////////////////////////////////////////////////
1660 globals->set_aircraft_model(new FGAircraftModel);
1661 globals->get_aircraft_model()->init();
1662 globals->get_aircraft_model()->bind();
1664 ////////////////////////////////////////////////////////////////////
1665 // Initialize the view manager subsystem.
1666 ////////////////////////////////////////////////////////////////////
1668 FGViewMgr *viewmgr = new FGViewMgr;
1669 globals->set_viewmgr( viewmgr );
1674 // Initialize the sky
1675 SGPath ephem_data_path( globals->get_fg_root() );
1676 ephem_data_path.append( "Astro" );
1677 SGEphemeris *ephem = new SGEphemeris( ephem_data_path.c_str() );
1678 ephem->update( globals->get_time_params()->getMjd(),
1679 globals->get_time_params()->getLst(),
1681 globals->set_ephem( ephem );
1683 // TODO: move to environment mgr
1685 SGPath texture_path(globals->get_fg_root());
1686 texture_path.append("Textures");
1687 texture_path.append("Sky");
1688 for (int i = 0; i < FGEnvironmentMgr::MAX_CLOUD_LAYERS; i++) {
1689 SGCloudLayer * layer = new SGCloudLayer(texture_path.str());
1690 thesky->add_cloud_layer(layer);
1694 SGPath sky_tex_path( globals->get_fg_root() );
1695 sky_tex_path.append( "Textures" );
1696 sky_tex_path.append( "Sky" );
1697 thesky->texture_path( sky_tex_path.str() );
1699 thesky->build( 550.0, 550.0,
1700 globals->get_ephem()->getNumPlanets(),
1701 globals->get_ephem()->getPlanets(), 60000.0,
1702 globals->get_ephem()->getNumStars(),
1703 globals->get_ephem()->getStars(), 60000.0 );
1705 // Initialize MagVar model
1706 SGMagVar *magvar = new SGMagVar();
1707 globals->set_mag( magvar );
1709 // airport = new ssgBranch;
1710 // airport->setName( "Airport Lighting" );
1711 // lighting->addKid( airport );
1717 #ifdef FG_NETWORK_OLK
1718 // Do the network intialization
1719 if ( fgGetBool("/sim/networking/network-olk") ) {
1720 printf("Multipilot mode %s\n",
1721 fg_net_init( globals->get_scenery()->get_scene_graph() ) );
1725 // build our custom render states
1726 fgBuildRenderStates();
1728 // pass control off to the master GLUT event handler
1731 // we never actually get here ... but to avoid compiler warnings,
1737 // $$$ end - added VS Renganathan, 15 Oct 2K
1738 // - added Venky , 12 Nov 2K
1740 #if defined(__linux__) && defined(__i386__)
1742 static void handleFPE (int);
1747 fpu_control_t fpe_flags = 0;
1748 _FPU_GETCW(fpe_flags);
1749 // fpe_flags &= ~_FPU_MASK_IM; // invalid operation
1750 // fpe_flags &= ~_FPU_MASK_DM; // denormalized operand
1751 // fpe_flags &= ~_FPU_MASK_ZM; // zero-divide
1752 // fpe_flags &= ~_FPU_MASK_OM; // overflow
1753 // fpe_flags &= ~_FPU_MASK_UM; // underflow
1754 // fpe_flags &= ~_FPU_MASK_PM; // precision (inexact result)
1755 _FPU_SETCW(fpe_flags);
1756 signal(SIGFPE, handleFPE);
1763 SG_LOG(SG_GENERAL, SG_ALERT, "Floating point interrupt (SIGFPE)");
1776 short CPSGetCurrentProcess(PSN *psn);
1777 short CPSSetProcessName (PSN *psn, char *processname);
1778 short CPSEnableForegroundOperation(PSN *psn, int _arg2, int _arg3, int _arg4, int _arg5);
1779 short CPSSetFrontProcess(PSN *psn);
1782 #define CPSEnableFG(psn) CPSEnableForegroundOperation(psn,0x03,0x3C,0x2C,0x1103)
1786 // Main entry point; catch any exceptions that have made it this far.
1787 int main ( int argc, char **argv ) {
1789 // Enable floating-point exceptions for Linux/x86
1790 #if defined(__linux__) && defined(__i386__)
1794 // Enable floating-point exceptions for Windows
1795 #if defined( _MSC_VER ) && defined( DEBUG )
1796 // Christian, we should document what this does
1797 _control87( _EM_INEXACT, _MCW_EM );
1800 #if defined( HAVE_BC5PLUS )
1801 _control87(MCW_EM, MCW_EM); /* defined in float.h */
1804 // Keyboard focus hack
1809 glutInit (&argc, argv);
1811 CPSGetCurrentProcess(&psn);
1812 CPSSetProcessName(&psn, "FlightGear");
1814 CPSSetFrontProcess(&psn);
1818 // FIXME: add other, more specific
1821 fgMainInit(argc, argv);
1822 } catch (sg_throwable &t) {
1823 // We must use cerr rather than
1824 // logging, since logging may be
1826 cerr << "Fatal error: " << t.getFormattedMessage()
1827 << "\n (received from " << t.getOrigin() << ')' << endl;
1835 void fgLoadDCS(void) {
1837 ssgEntity *ship_obj = NULL;
1839 char obj_filename[25];
1841 for ( int k = 0; k < 32; k++ ) {
1845 SGPath tile_path( globals->get_fg_root());
1846 tile_path.append( "Scenery" );
1847 tile_path.append( "Objects.txt" );
1848 sg_gzifstream in( tile_path.str() );
1849 if ( ! in.is_open() ) {
1850 SG_LOG( SG_TERRAIN, SG_ALERT, "Cannot open file: " << tile_path.str() );
1853 SGPath modelpath( globals->get_fg_root() );
1854 modelpath.append( "Models" );
1855 modelpath.append( "Geometry" );
1857 SGPath texturepath( globals->get_fg_root() );
1858 texturepath.append( "Models" );
1859 texturepath.append( "Textures" );
1861 ssgModelPath( (char *)modelpath.c_str() );
1862 ssgTexturePath( (char *)texturepath.c_str() );
1864 ship_sel = new ssgSelector;
1867 while ( ! in.eof() ) {
1869 if ( in.get( c ) && c == '#' ) {
1873 in >> obj_filename >> obj_lat[objc] >> obj_lon[objc] >> obj_alt[objc];
1874 /* cout << endl << obj_filename << " " << obj_lat[objc] << " " << obj_lon[objc] << " " << obj_alt[objc] << endl;
1875 int chj=getchar();*/
1877 obj_lon[objc] *=SGD_DEGREES_TO_RADIANS;
1878 obj_lat[objc] *=SGD_DEGREES_TO_RADIANS;
1880 ship_pos[objc] = new ssgTransform;
1882 // type "repeat" in objects.txt to load one more
1883 // instance of the last object.
1885 if ( strcmp(obj_filename,"repeat") != 0) {
1887 globals->get_model_loader()->load_model( obj_filename );
1890 if ( ship_obj != NULL ) {
1891 ship_obj->setName(obj_filename);
1893 ship_obj->clrTraversalMaskBits( SSGTRAV_HOT );
1895 ship_obj->setTraversalMaskBits( SSGTRAV_HOT );
1896 ship_pos[objc]->addKid( ship_obj ); // add object to transform node
1897 ship_sel->addKid( ship_pos[objc] ); // add transform node to selector
1898 SG_LOG( SG_TERRAIN, SG_ALERT, "Loaded file: "
1901 SG_LOG( SG_TERRAIN, SG_ALERT, "Cannot open file: "
1905 // temporary hack for deck lights - ultimately should move to PLib (when??)
1906 //const char *extn = file_extension ( obj_filename ) ;
1908 ssgVertexArray *lights = new ssgVertexArray( 100 );
1909 ssgVertexArray *lightpoints = new ssgVertexArray( 100 );
1910 ssgVertexArray *lightnormals = new ssgVertexArray( 100 );
1911 ssgVertexArray *lightdir = new ssgVertexArray( 100 );
1912 int ltype[500], light_type;
1913 static int ltcount = 0;
1915 sgVec3 rway_dir,rway_normal,lightpt;
1917 modelpath.append(obj_filename);
1918 sg_gzifstream in1( modelpath.str() );
1919 if ( ! in1.is_open() ) {
1920 SG_LOG( SG_TERRAIN, SG_ALERT, "Cannot open file: " << modelpath.str() );
1922 while ( ! in1.eof() ) {
1924 if ( in1.get( c ) && c == '#' ) {
1929 //cout << token << endl;
1930 if ( token == "runway" ) {
1932 sgSetVec3 (rway_dir, node[0], node[1], node[2] );
1933 } else if ( token == "edgelight" ) {
1935 sgSetVec3 (rway_normal, node[0], node[1], node[2] );
1937 } else if ( token == "taxi" ) {
1939 sgSetVec3 (rway_normal, node[0], node[1], node[2] );
1941 } else if ( token == "vasi" ) {
1943 sgSetVec3 (rway_normal, node[0], node[1], node[2] );
1945 } else if ( token == "threshold" ) {
1947 sgSetVec3 (rway_normal, node[0], node[1], node[2] );
1949 } else if ( token == "rabbit" ) {
1951 sgSetVec3 (rway_normal, node[0], node[1], node[2] );
1953 } else if ( token == "ols" ) {
1955 sgSetVec3 (rway_ols, node[0], node[1], node[2] );
1957 } else if ( token == "red" ) {
1959 sgSetVec3 (rway_normal, node[0], node[1], node[2] );
1961 } else if ( token == "green" ) {
1963 sgSetVec3 (rway_normal, node[0], node[1], node[2] );
1965 } else if ( token == "lp" ) {
1967 sgSetVec3 (lightpt, node[0], node[1], node[2] );
1968 lightpoints->add( lightpt );
1969 lightnormals->add( rway_normal );
1970 lightdir->add( rway_dir );
1971 ltype[ltcount]= light_type;
1974 if (in1.eof()) break;
1978 if ( lightpoints->getNum() ) {
1979 ssgBranch *lightpoints_branch;
1980 long int dummy = -999;
1981 dummy_tile = new FGTileEntry((SGBucket)dummy);
1982 dummy_tile->lightmaps_sequence = new ssgSelector;
1983 dummy_tile->ols_transform = new ssgTransform;
1985 // call function to generate the runway lights
1986 lightpoints_branch =
1987 dummy_tile->gen_runway_lights( lightpoints, lightnormals,
1989 lightpoints_brightness->addKid(lightpoints_branch);
1990 lightpoints_transform->addKid(lightpoints_brightness);
1991 //dummy_tile->lightmaps_sequence->setTraversalMaskBits( SSGTRAV_HOT );
1992 lightpoints_transform->addKid( dummy_tile->lightmaps_sequence );
1993 lightpoints_transform->ref();
1994 globals->get_scenery()->get_gnd_lights_root()->addKid( lightpoints_transform );
1998 // end hack for deck lights
2002 if (in.eof()) break;
2006 SG_LOG ( SG_TERRAIN, SG_ALERT, "Finished object processing." );
2008 globals->get_scenery()->get_terrain_branch()->addKid( ship_sel ); //add selector node to root node
2015 void fgUpdateDCS (void) {
2017 // double eye_lat,eye_lon,eye_alt;
2018 // static double obj_head;
2019 double sl_radius,obj_latgc;
2020 // float nresultmat[4][4];
2021 // sgMat4 Trans,rothead,rotlon,rot180,rotlat,resultmat1,resultmat2,resultmat3;
2024 // Instantaneous Geodetic Lat/Lon/Alt of moving object
2025 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
2027 // Deck should be the first object in objects.txt in case of fdm=ada
2029 if (!strcmp(fgGetString("/sim/flight-model"), "ada")) {
2030 if ((fdm->get_iaux(1))==1)
2032 obj_lat[1] = fdm->get_daux(1)*SGD_DEGREES_TO_RADIANS;
2033 obj_lon[1] = fdm->get_daux(2)*SGD_DEGREES_TO_RADIANS;
2034 obj_alt[1] = fdm->get_daux(3);
2035 obj_pitch[1] = fdm->get_faux(1);
2036 obj_roll[1] = fdm->get_faux(2);
2040 for ( int m = 0; m < objc; m++ ) {
2041 //cout << endl << obj_lat[m]*SGD_RADIANS_TO_DEGREES << " " << obj_lon[m]*SGD_RADIANS_TO_DEGREES << " " << obj_alt[m] << " " << objc << endl;
2044 //Geodetic to Geocentric angles for rotation
2045 sgGeodToGeoc(obj_lat[m],obj_alt[m],&sl_radius,&obj_latgc);
2047 //moving object gbs-posn in cartesian coords
2048 Point3D obj_posn = Point3D( obj_lon[m],obj_lat[m],obj_alt[m]);
2049 Point3D obj_pos = sgGeodToCart( obj_posn );
2051 // Translate moving object w.r.t eye
2052 Point3D Objtrans = obj_pos - globals->get_scenery()->get_center();
2057 // rotate dynamic objects for lat,lon & alt and other motion about its axes
2060 sgMakeTransMat4( sgTRANS, bz[0],bz[1],bz[2]);
2062 sgVec3 ship_fwd,ship_rt,ship_up;
2063 sgSetVec3( ship_fwd, 1.0, 0.0, 0.0);//east,roll
2064 sgSetVec3( ship_rt, 0.0, 1.0, 0.0);//up,pitch
2065 sgSetVec3( ship_up, 0.0, 0.0, 1.0); //north,yaw
2067 sgMat4 sgROT_lon, sgROT_lat, sgROT_hdg, sgROT_pitch, sgROT_roll;
2068 sgMakeRotMat4( sgROT_lon, obj_lon[m]*SGD_RADIANS_TO_DEGREES, ship_up );
2069 sgMakeRotMat4( sgROT_lat, 90-obj_latgc*SGD_RADIANS_TO_DEGREES, ship_rt );
2070 sgMakeRotMat4( sgROT_hdg, 180.0, ship_up );
2071 sgMakeRotMat4( sgROT_pitch, obj_pitch[m], ship_rt );
2072 sgMakeRotMat4( sgROT_roll, obj_roll[m], ship_fwd );
2075 sgCopyMat4( sgTUX, sgROT_hdg );
2076 sgPostMultMat4( sgTUX, sgROT_pitch );
2077 sgPostMultMat4( sgTUX, sgROT_roll );
2078 sgPostMultMat4( sgTUX, sgROT_lat );
2079 sgPostMultMat4( sgTUX, sgROT_lon );
2080 sgPostMultMat4( sgTUX, sgTRANS );
2083 sgSetCoord(&shippos, sgTUX );
2084 ship_pos[m]->setTransform( &shippos );
2085 // temporary hack for deck lights - ultimately should move to PLib (when ??)
2087 if (lightpoints_transform) {
2088 lightpoints_transform->setTransform( &shippos );
2089 float sun_angle = cur_light_params.sun_angle * SGD_RADIANS_TO_DEGREES;
2090 if ( sun_angle > 89 ) {
2091 lightpoints_brightness->select(0x01);
2093 lightpoints_brightness->select(0x00);
2102 sgXformPnt3( rp, rway_ols, sgTUX );
2103 vp = globals->get_current_view()->get_view_pos();
2104 to[0] = rp[0]-vp[0];
2105 to[1] = rp[1]-vp[1];
2106 to[2] = rp[2]-vp[2];
2107 float dist = sgLengthVec3( to );
2108 alt = (current_aircraft.fdm_state->get_Altitude() * SG_FEET_TO_METER)-rway_ols[2];
2110 elev = asin(alt/dist)*SGD_RADIANS_TO_DEGREES;
2112 ref_elev = elev - 3.75; // +ve above, -ve below
2116 // DO NOT DELETE THIS CODE - This is to compare a discrete FLOLS (without LOD) with analog FLOLS
2117 // if (ref_elev > 0.51) sel = 0x21;
2118 // if ((ref_elev <= 0.51) & (ref_elev > 0.17)) sel = 0x22;
2119 // if ((ref_elev <= 0.17) & (ref_elev >= -0.17)) sel = 0x24;
2120 // if ((ref_elev < -0.17) & (ref_elev >= -0.51)) sel = 0x28;
2121 // if (ref_elev < -0.51) sel = 0x30;
2122 // DO NOT DELETE THIS CODE - This is to compare a discrete FLOLS (without LOD) with analog FLOLS
2123 dummy_tile->lightmaps_sequence->select(sel);
2126 sgCopyVec3 (up, ship_up);
2128 sgScaleVec3 (up, 4.0*ref_elev*dist/750.0);
2130 sgScaleVec3 (up, 4.0*ref_elev);
2131 dummy_tile->ols_transform->setTransform(up);
2132 //cout << "ref_elev " << ref_elev << endl;
2134 // end hack for deck lights
2137 if ( ship_sel != NULL ) {
2138 ship_sel->select(0xFFFFFFFE); // first object is ownship, added to acmodel
2142 // $$$ end - added VS Renganathan, 15 Oct 2K
2143 // added Venky , 12 Nov 2K