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/cockpit.hxx>
99 #include <Cockpit/radiostack.hxx>
100 #include <Cockpit/steam.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>
113 #include <Objects/matlib.hxx>
114 #include <Scenery/scenery.hxx>
115 #include <Scenery/tilemgr.hxx>
116 #ifdef ENABLE_AUDIO_SUPPORT
117 # include <Sound/soundmgr.hxx>
118 # include <Sound/fg_fx.hxx>
119 # include <Sound/morse.hxx>
121 #include <Systems/system_mgr.hxx>
122 #include <Instrumentation/instrument_mgr.hxx>
123 #include <Time/FGEventMgr.hxx>
124 #include <Time/fg_timer.hxx>
125 #include <Time/light.hxx>
126 #include <Time/sunpos.hxx>
127 #include <Time/tmp.hxx>
130 #include <simgear/misc/sgstream.hxx>
131 #include <simgear/math/point3d.hxx>
132 #include <FDM/flight.hxx>
133 #include <FDM/ADA.hxx>
134 #include <Scenery/tileentry.hxx>
136 #include "fg_commands.hxx"
139 typedef void (APIENTRY * PFNGLPOINTPARAMETERFEXTPROC)(GLenum pname,
141 typedef void (APIENTRY * PFNGLPOINTPARAMETERFVEXTPROC)(GLenum pname,
142 const GLfloat *params);
144 PFNGLPOINTPARAMETERFEXTPROC glPointParameterfEXT = 0;
145 PFNGLPOINTPARAMETERFVEXTPROC glPointParameterfvEXT = 0;
149 typedef void (* OpenGLFuncExt)(GLenum pname, GLfloat param);
150 typedef void (* OpenGLFuncExtv)(GLenum pname, const GLfloat *params);
152 OpenGLFuncExt glPointParameterfEXT = 0;
153 OpenGLFuncExtv glPointParameterfvEXT = 0;
156 float default_attenuation[3] = {1.0, 0.0, 0.0};
157 //Required for using GL_extensions
158 void fgLoadDCS (void);
159 void fgUpdateDCS (void);
160 ssgSelector *ship_sel=NULL;
161 // upto 32 instances of a same object can be loaded.
162 ssgTransform *ship_pos[32];
163 double obj_lat[32],obj_lon[32],obj_alt[32],obj_pitch[32],obj_roll[32];
165 ssgSelector *lightpoints_brightness = new ssgSelector;
166 ssgTransform *lightpoints_transform = new ssgTransform;
167 FGTileEntry *dummy_tile;
170 // Clip plane settings...
171 float scene_nearplane = 0.5f;
172 float scene_farplane = 120000.0f;
174 static double delta_time_sec = 0;
178 # include <WeatherCM/FGLocalWeatherDatabase.h>
180 # include <Environment/environment_mgr.hxx>
185 #include "fg_init.hxx"
187 #include "fg_props.hxx"
188 #include "globals.hxx"
189 #include "splash.hxx"
190 #include "viewmgr.hxx"
191 #include "options.hxx"
192 #include "logger.hxx"
195 # include <console.h> // -dw- for command line dialog
199 FGEventMgr global_events;
201 // This is a record containing a bit of global housekeeping information
204 // Specify our current idle function state. This is used to run all
205 // our initializations out of the glutIdleLoop() so that we can get a
206 // splash screen up and running right away.
207 static int idle_state = 0;
208 static long global_multi_loop;
210 // forward declaration
211 void fgReshape( int width, int height );
213 // fog constants. I'm a little nervous about putting actual code out
214 // here but it seems to work (?)
215 static const double m_log01 = -log( 0.01 );
216 static const double sqrt_m_log01 = sqrt( m_log01 );
217 static GLfloat fog_exp_density;
218 static GLfloat fog_exp2_density;
219 static GLfloat rwy_exp2_punch_through;
220 static GLfloat taxi_exp2_punch_through;
221 static GLfloat ground_exp2_punch_through;
223 #ifdef FG_NETWORK_OLK
224 ssgSelector *fgd_sel = NULL;
225 ssgTransform *fgd_pos = NULL;
231 #ifdef FG_USE_CLOUDS_3D
232 SkySceneLoader *sgClouds3d;
233 bool _bcloud_orig = true;
237 sgMat4 copy_of_ssgOpenGLAxisSwapMatrix =
239 { 1.0f, 0.0f, 0.0f, 0.0f },
240 { 0.0f, 0.0f, -1.0f, 0.0f },
241 { 0.0f, 1.0f, 0.0f, 0.0f },
242 { 0.0f, 0.0f, 0.0f, 1.0f }
245 // The following defines flightgear options. Because glutlib will also
246 // want to parse its own options, those options must not be included here
247 // or they will get parsed by the main program option parser. Hence case
248 // is significant for any option added that might be in conflict with
251 // glutlib parses for:
253 // -direct (invalid in Win32)
257 // -indirect (invalid in Win32)
260 // Note that glutlib depends upon strings while this program's
261 // option parser wants only initial characters followed by numbers
266 ssgSimpleState *cloud3d_imposter_state;
267 ssgSimpleState *default_state;
268 ssgSimpleState *hud_and_panel;
269 ssgSimpleState *menus;
271 SGTimeStamp last_time_stamp;
272 SGTimeStamp current_time_stamp;
274 void fgBuildRenderStates( void ) {
275 default_state = new ssgSimpleState;
276 default_state->ref();
277 default_state->disable( GL_TEXTURE_2D );
278 default_state->enable( GL_CULL_FACE );
279 default_state->enable( GL_COLOR_MATERIAL );
280 default_state->setColourMaterial( GL_AMBIENT_AND_DIFFUSE );
281 default_state->setMaterial( GL_EMISSION, 0, 0, 0, 1 );
282 default_state->setMaterial( GL_SPECULAR, 0, 0, 0, 1 );
283 default_state->disable( GL_BLEND );
284 default_state->disable( GL_ALPHA_TEST );
285 default_state->disable( GL_LIGHTING );
287 cloud3d_imposter_state = new ssgSimpleState;
288 cloud3d_imposter_state->ref();
289 cloud3d_imposter_state->enable( GL_TEXTURE_2D );
290 cloud3d_imposter_state->enable( GL_CULL_FACE );
291 cloud3d_imposter_state->enable( GL_COLOR_MATERIAL );
292 cloud3d_imposter_state->setColourMaterial( GL_AMBIENT_AND_DIFFUSE );
293 cloud3d_imposter_state->setMaterial( GL_DIFFUSE, 1, 1, 1, 1 );
294 cloud3d_imposter_state->setMaterial( GL_AMBIENT, 1, 1, 1, 1 );
295 cloud3d_imposter_state->setMaterial( GL_EMISSION, 0, 0, 0, 1 );
296 cloud3d_imposter_state->setMaterial( GL_SPECULAR, 0, 0, 0, 1 );
297 cloud3d_imposter_state->enable( GL_BLEND );
298 cloud3d_imposter_state->enable( GL_ALPHA_TEST );
299 cloud3d_imposter_state->disable( GL_LIGHTING );
301 hud_and_panel = new ssgSimpleState;
302 hud_and_panel->ref();
303 hud_and_panel->disable( GL_CULL_FACE );
304 hud_and_panel->disable( GL_TEXTURE_2D );
305 hud_and_panel->disable( GL_LIGHTING );
306 hud_and_panel->enable( GL_BLEND );
308 menus = new ssgSimpleState;
310 menus->disable( GL_CULL_FACE );
311 menus->disable( GL_TEXTURE_2D );
312 menus->enable( GL_BLEND );
316 // fgInitVisuals() -- Initialize various GL/view parameters
317 void fgInitVisuals( void ) {
320 l = &cur_light_params;
322 #ifndef GLUT_WRONG_VERSION
323 // Go full screen if requested ...
324 if ( fgGetBool("/sim/startup/fullscreen") ) {
329 // If enabled, normal vectors specified with glNormal are scaled
330 // to unit length after transformation. Enabling this has
331 // performance implications. See the docs for glNormal.
332 // glEnable( GL_NORMALIZE );
334 glEnable( GL_LIGHTING );
335 glEnable( GL_LIGHT0 );
336 // glLightfv( GL_LIGHT0, GL_POSITION, l->sun_vec ); // done later with ssg
339 sgSetVec3( sunpos, l->sun_vec[0], l->sun_vec[1], l->sun_vec[2] );
340 ssgGetLight( 0 ) -> setPosition( sunpos );
342 glFogi (GL_FOG_MODE, GL_EXP2);
343 if ( (!strcmp(fgGetString("/sim/rendering/fog"), "disabled")) ||
344 (!fgGetBool("/sim/rendering/shading"))) {
345 // if fastest fog requested, or if flat shading force fastest
346 glHint ( GL_FOG_HINT, GL_FASTEST );
347 } else if ( !strcmp(fgGetString("/sim/rendering/fog"), "nicest") ) {
348 glHint ( GL_FOG_HINT, GL_NICEST );
350 if ( fgGetBool("/sim/rendering/wireframe") ) {
352 glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
355 // This is the default anyways, but it can't hurt
356 glFrontFace ( GL_CCW );
359 // glEnable(GL_POINT_SMOOTH);
360 // glEnable(GL_LINE_SMOOTH);
361 // glEnable(GL_POLYGON_SMOOTH);
365 // For HiRes screen Dumps using Brian Pauls TR Library
366 void trRenderFrame( void ) {
368 if ( fgPanelVisible() ) {
369 GLfloat height = fgGetInt("/sim/startup/ysize");
371 (current_panel->getViewHeight() - current_panel->getYOffset())
372 * (height / 768.0) + 1;
373 glTranslatef( 0.0, view_h, 0.0 );
376 static GLfloat black[4] = { 0.0, 0.0, 0.0, 1.0 };
377 static GLfloat white[4] = { 1.0, 1.0, 1.0, 1.0 };
379 fgLIGHT *l = &cur_light_params;
381 glClearColor(l->adj_fog_color[0], l->adj_fog_color[1],
382 l->adj_fog_color[2], l->adj_fog_color[3]);
384 glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
386 // set the opengl state to known default values
387 default_state->force();
390 glFogf ( GL_FOG_DENSITY, fog_exp2_density);
391 glFogi ( GL_FOG_MODE, GL_EXP2 );
392 glFogfv ( GL_FOG_COLOR, l->adj_fog_color );
394 // GL_LIGHT_MODEL_AMBIENT has a default non-zero value so if
395 // we only update GL_AMBIENT for our lights we will never get
396 // a completely dark scene. So, we set GL_LIGHT_MODEL_AMBIENT
397 // explicitely to black.
398 glLightModelfv( GL_LIGHT_MODEL_AMBIENT, black );
399 glLightModeli( GL_LIGHT_MODEL_LOCAL_VIEWER, GL_FALSE );
401 ssgGetLight( 0 ) -> setColour( GL_AMBIENT, l->scene_ambient );
403 // texture parameters
404 glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ) ;
405 glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST ) ;
407 // we need a white diffuse light for the phase of the moon
408 ssgGetLight( 0 ) -> setColour( GL_DIFFUSE, white );
411 // draw the ssg scene
412 // return to the desired diffuse color
413 ssgGetLight( 0 ) -> setColour( GL_DIFFUSE, l->scene_diffuse );
414 glEnable( GL_DEPTH_TEST );
415 ssgSetNearFar( scene_nearplane, scene_farplane );
416 ssgCullAndDraw( globals->get_scenery()->get_scene_graph() );
419 glFogf (GL_FOG_DENSITY, rwy_exp2_punch_through);
420 ssgSetNearFar( scene_nearplane, scene_farplane );
421 ssgCullAndDraw( globals->get_scenery()->get_rwy_lights_root() );
423 ssgCullAndDraw( globals->get_scenery()->get_gnd_lights_root() );
425 if (fgGetBool("/environment/clouds/status"))
426 thesky->postDraw( cur_fdm_state->get_Altitude() * SG_FEET_TO_METER );
428 globals->get_model_mgr()->draw();
429 globals->get_aircraft_model()->draw();
433 // Update all Visuals (redraws anything graphics related)
434 void fgRenderFrame() {
436 GLfloat black[4] = { 0.0, 0.0, 0.0, 1.0 };
437 GLfloat white[4] = { 1.0, 1.0, 1.0, 1.0 };
439 // Process/manage pending events
440 global_events.update( delta_time_sec );
442 static const SGPropertyNode *longitude
443 = fgGetNode("/position/longitude-deg");
444 static const SGPropertyNode *latitude
445 = fgGetNode("/position/latitude-deg");
446 static const SGPropertyNode *altitude
447 = fgGetNode("/position/altitude-ft");
448 static const SGPropertyNode *groundlevel_nearplane
449 = fgGetNode("/sim/current-view/ground-level-nearplane-m");
451 // Update the default (kludged) properties.
454 FGViewer *current__view = globals->get_current_view();
456 fgLIGHT *l = &cur_light_params;
457 static double last_visibility = -9999;
460 double actual_visibility;
461 if (fgGetBool("/environment/clouds/status"))
462 actual_visibility = thesky->get_visibility();
464 actual_visibility = fgGetDouble("/environment/visibility-m");
465 if ( actual_visibility != last_visibility ) {
466 last_visibility = actual_visibility;
468 fog_exp_density = m_log01 / actual_visibility;
469 fog_exp2_density = sqrt_m_log01 / actual_visibility;
470 ground_exp2_punch_through = sqrt_m_log01 / (actual_visibility * 1.5);
471 if ( actual_visibility < 8000 ) {
472 rwy_exp2_punch_through = sqrt_m_log01 / (actual_visibility * 2.5);
473 taxi_exp2_punch_through = sqrt_m_log01 / (actual_visibility * 1.5);
475 rwy_exp2_punch_through = sqrt_m_log01 / ( 8000 * 2.5 );
476 taxi_exp2_punch_through = sqrt_m_log01 / ( 8000 * 1.5 );
481 // GLfloat black[4] = { 0.0, 0.0, 0.0, 1.0 };
482 // GLfloat white[4] = { 1.0, 1.0, 1.0, 1.0 };
483 // GLfloat terrain_color[4] = { 0.54, 0.44, 0.29, 1.0 };
484 // GLfloat mat_shininess[] = { 10.0 };
485 GLbitfield clear_mask;
487 if ( idle_state != 1000 ) {
488 // still initializing, draw the splash screen
489 if ( fgGetBool("/sim/startup/splash-screen") ) {
490 fgSplashUpdate(0.0, 1.0);
492 // Keep resetting sim time while the sim is initializing
493 globals->set_sim_time_sec( 0.0 );
495 // idle_state is now 1000 meaning we've finished all our
496 // initializations and are running the main loop, so this will
497 // now work without seg faulting the system.
499 // calculate our current position in cartesian space
500 globals->get_scenery()->set_center( globals->get_scenery()->get_next_center() );
503 fgReshape( fgGetInt("/sim/startup/xsize"),
504 fgGetInt("/sim/startup/ysize") );
506 if ( fgGetBool("/sim/rendering/clouds3d") ) {
507 glClear( GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT );
508 cloud3d_imposter_state->force();
510 glColor4f( 1.0, 1.0, 1.0, 1.0 );
511 glEnable(GL_DEPTH_TEST);
513 glBlendFunc( GL_ONE, GL_ONE_MINUS_SRC_ALPHA ) ;
515 #ifdef FG_USE_CLOUDS_3D
516 if ( _bcloud_orig ) {
517 Point3D c = globals->get_scenery()->get_center();
518 sgClouds3d->Set_Cloud_Orig( &c );
519 _bcloud_orig = false;
521 sgClouds3d->Update( current__view->get_absolute_view_pos() );
523 glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ) ;
524 glDisable(GL_DEPTH_TEST);
527 clear_mask = GL_DEPTH_BUFFER_BIT;
528 if ( fgGetBool("/sim/rendering/wireframe") ) {
529 clear_mask |= GL_COLOR_BUFFER_BIT;
532 if ( fgGetBool("/sim/rendering/skyblend") ) {
533 if ( fgGetBool("/sim/rendering/textures") ) {
534 // glClearColor(black[0], black[1], black[2], black[3]);
535 glClearColor(l->adj_fog_color[0], l->adj_fog_color[1],
536 l->adj_fog_color[2], l->adj_fog_color[3]);
537 clear_mask |= GL_COLOR_BUFFER_BIT;
540 glClearColor(l->sky_color[0], l->sky_color[1],
541 l->sky_color[2], l->sky_color[3]);
542 clear_mask |= GL_COLOR_BUFFER_BIT;
544 glClear( clear_mask );
546 // Tell GL we are switching to model view parameters
548 // I really should create a derived ssg node or use a call
549 // back or something so that I can draw the sky within the
550 // ssgCullAndDraw() function, but for now I just mimic what
551 // ssg does to set up the model view matrix
552 glMatrixMode(GL_MODELVIEW);
554 ssgSetCamera( (sgVec4 *)current__view->get_VIEW() );
556 // set the opengl state to known default values
557 default_state->force();
559 // update fog params if visibility has changed
560 double visibility_meters = fgGetDouble("/environment/visibility-m");
561 thesky->set_visibility(visibility_meters);
563 thesky->modify_vis( cur_fdm_state->get_Altitude() * SG_FEET_TO_METER,
564 ( global_multi_loop * fgGetInt("/sim/speed-up") )
565 / (double)fgGetInt("/sim/model-hz") );
567 // Set correct opengl fog density
568 glFogf (GL_FOG_DENSITY, fog_exp2_density);
570 // update the sky dome
571 if ( fgGetBool("/sim/rendering/skyblend") ) {
572 /* cout << "thesky->repaint() sky_color = "
573 << cur_light_params.sky_color[0] << " "
574 << cur_light_params.sky_color[1] << " "
575 << cur_light_params.sky_color[2] << " "
576 << cur_light_params.sky_color[3] << endl;
578 << cur_light_params.fog_color[0] << " "
579 << cur_light_params.fog_color[1] << " "
580 << cur_light_params.fog_color[2] << " "
581 << cur_light_params.fog_color[3] << endl;
582 cout << " sun_angle = " << cur_light_params.sun_angle
583 << " moon_angle = " << cur_light_params.moon_angle
585 thesky->repaint( cur_light_params.sky_color,
586 cur_light_params.adj_fog_color,
587 cur_light_params.sun_angle,
588 cur_light_params.moon_angle,
589 globals->get_ephem()->getNumPlanets(),
590 globals->get_ephem()->getPlanets(),
591 globals->get_ephem()->getNumStars(),
592 globals->get_ephem()->getStars() );
594 /* cout << "thesky->reposition( view_pos = " << view_pos[0] << " "
595 << view_pos[1] << " " << view_pos[2] << endl;
596 cout << " zero_elev = " << zero_elev[0] << " "
597 << zero_elev[1] << " " << zero_elev[2]
598 << " lon = " << cur_fdm_state->get_Longitude()
599 << " lat = " << cur_fdm_state->get_Latitude() << endl;
600 cout << " sun_rot = " << cur_light_params.sun_rotation
601 << " gst = " << SGTime::cur_time_params->getGst() << endl;
602 cout << " sun ra = " << globals->get_ephem()->getSunRightAscension()
603 << " sun dec = " << globals->get_ephem()->getSunDeclination()
604 << " moon ra = " << globals->get_ephem()->getMoonRightAscension()
605 << " moon dec = " << globals->get_ephem()->getMoonDeclination() << endl; */
607 thesky->reposition( current__view->get_view_pos(),
608 current__view->get_zero_elev(),
609 current__view->get_world_up(),
610 current__view->getLongitude_deg()
611 * SGD_DEGREES_TO_RADIANS,
612 current__view->getLatitude_deg()
613 * SGD_DEGREES_TO_RADIANS,
614 current__view->getAltitudeASL_ft() * SG_FEET_TO_METER,
615 cur_light_params.sun_rotation,
616 globals->get_time_params()->getGst(),
617 globals->get_ephem()->getSunRightAscension(),
618 globals->get_ephem()->getSunDeclination(),
620 globals->get_ephem()->getMoonRightAscension(),
621 globals->get_ephem()->getMoonDeclination(),
625 glEnable( GL_DEPTH_TEST );
626 if ( strcmp(fgGetString("/sim/rendering/fog"), "disabled") ) {
628 glFogi( GL_FOG_MODE, GL_EXP2 );
629 glFogfv( GL_FOG_COLOR, l->adj_fog_color );
632 // set sun/lighting parameters
633 ssgGetLight( 0 ) -> setPosition( l->sun_vec );
635 // GL_LIGHT_MODEL_AMBIENT has a default non-zero value so if
636 // we only update GL_AMBIENT for our lights we will never get
637 // a completely dark scene. So, we set GL_LIGHT_MODEL_AMBIENT
638 // explicitely to black.
639 glLightModelfv( GL_LIGHT_MODEL_AMBIENT, black );
641 ssgGetLight( 0 ) -> setColour( GL_AMBIENT, l->scene_ambient );
642 ssgGetLight( 0 ) -> setColour( GL_DIFFUSE, l->scene_diffuse );
643 ssgGetLight( 0 ) -> setColour( GL_SPECULAR, l->scene_specular );
645 // texture parameters
646 // glEnable( GL_TEXTURE_2D );
647 glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ) ;
648 glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST ) ;
650 // glMatrixMode( GL_PROJECTION );
652 ssgSetFOV( current__view->get_h_fov(),
653 current__view->get_v_fov() );
656 current_aircraft.fdm_state->get_Altitude() * SG_FEET_TO_METER
657 - globals->get_scenery()->get_cur_elev();
660 scene_nearplane = 10.0f;
661 scene_farplane = 120000.0f;
663 scene_nearplane = groundlevel_nearplane->getDoubleValue();
664 scene_farplane = 120000.0f;
667 ssgSetNearFar( scene_nearplane, scene_farplane );
669 // $$$ begin - added VS Renganthan 17 Oct 2K
672 // $$$ end - added VS Renganthan 17 Oct 2K
674 # ifdef FG_NETWORK_OLK
675 if ( fgGetBool("/sim/networking/network-olk") ) {
677 other = head->next; /* put listpointer to start */
678 while ( other != tail) { /* display all except myself */
679 if ( strcmp( other->ipadr, fgd_mcp_ip) != 0) {
680 other->fgd_sel->select(1);
681 sgSetCoord( &fgdpos, other->sgFGD_COORD );
682 other->fgd_pos->setTransform( &fgdpos );
687 // fgd_sel->select(1);
688 // sgCopyMat4( sgTUX, current_view.sgVIEW);
690 // sgSetCoord( &fgdpos, sgFGD_VIEW );
691 // fgd_pos->setTransform( &fgdpos);
695 if ( fgGetBool("/sim/rendering/skyblend") ) {
696 // draw the sky backdrop
698 // we need a white diffuse light for the phase of the moon
699 ssgGetLight( 0 ) -> setColour( GL_DIFFUSE, white );
703 // return to the desired diffuse color
704 ssgGetLight( 0 ) -> setColour( GL_DIFFUSE, l->scene_diffuse );
707 // draw the ssg scene
708 glEnable( GL_DEPTH_TEST );
710 ssgSetNearFar( scene_nearplane, scene_farplane );
711 ssgCullAndDraw( globals->get_scenery()->get_scene_graph() );
713 // This is a bit kludgy. Every 200 frames, do an extra
714 // traversal of the scene graph without drawing anything, but
715 // with the field-of-view set to 360x360 degrees. This
716 // ensures that out-of-range random objects that are not in
717 // the current view frustum will still be freed properly.
718 static int counter = 0;
720 if (counter == 200) {
723 // No need to put the near plane too close;
724 // this way, at least the aircraft can be
726 f.setNearFar(1000, 1000000);
728 ssgGetModelviewMatrix(m);
729 globals->get_scenery()->get_scene_graph()->cull(&f, m, true);
733 // change state for lighting here
735 // draw runway lighting
736 glFogf (GL_FOG_DENSITY, rwy_exp2_punch_through);
737 ssgSetNearFar( scene_nearplane, scene_farplane );
739 #ifdef FG_EXPERIMENTAL_POINT_LIGHTING
740 // Enable states for drawing points with GL_extension
741 glEnable(GL_POINT_SMOOTH);
743 if ( fgGetBool("/sim/rendering/distance-attenuation")
744 && glutExtensionSupported("GL_EXT_point_parameters") )
746 float quadratic[3] = {1.0, 0.001, 0.0000001};
747 // makes the points fade as they move away
748 glPointParameterfvEXT(GL_DISTANCE_ATTENUATION_EXT, quadratic);
749 glPointParameterfEXT(GL_POINT_SIZE_MIN_EXT, 1.0);
753 // blending function for runway lights
754 glBlendFunc ( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) ;
757 glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
758 glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
759 glEnable(GL_TEXTURE_GEN_S);
760 glEnable(GL_TEXTURE_GEN_T);
761 glPolygonMode(GL_FRONT, GL_POINT);
763 // draw runway lighting
764 ssgCullAndDraw( globals->get_scenery()->get_rwy_lights_root() );
766 // change punch through and then draw taxi lighting
767 glFogf ( GL_FOG_DENSITY, fog_exp2_density );
769 // sgSetVec3( taxi_fog, 0.0, 0.0, 0.0 );
770 // glFogfv ( GL_FOG_COLOR, taxi_fog );
771 ssgCullAndDraw( globals->get_scenery()->get_taxi_lights_root() );
774 glPolygonMode(GL_FRONT, GL_FILL);
775 glDisable(GL_TEXTURE_GEN_S);
776 glDisable(GL_TEXTURE_GEN_T);
778 //static int _frame_count = 0;
779 //if (_frame_count % 30 == 0) {
780 // printf("SSG: %s\n", ssgShowStats());
788 #ifdef FG_EXPERIMENTAL_POINT_LIGHTING
789 if ( fgGetBool("/sim/rendering/distance-attenuation")
790 && glutExtensionSupported("GL_EXT_point_parameters") )
792 glPointParameterfvEXT(GL_DISTANCE_ATTENUATION_EXT,
793 default_attenuation);
797 glDisable(GL_POINT_SMOOTH);
800 // draw ground lighting
801 glFogf (GL_FOG_DENSITY, ground_exp2_punch_through);
802 ssgCullAndDraw( globals->get_scenery()->get_gnd_lights_root() );
804 if ( fgGetBool("/sim/rendering/skyblend") ) {
805 // draw the sky cloud layers
806 if (fgGetBool("/environment/clouds/status")) {
807 thesky->postDraw( cur_fdm_state->get_Altitude()
808 * SG_FEET_TO_METER );
812 if ( fgGetBool("/sim/rendering/clouds3d") ) {
814 glDisable( GL_LIGHTING );
815 // cout << "drawing new clouds" << endl;
817 glEnable(GL_DEPTH_TEST);
819 glBlendFunc( GL_ONE, GL_ONE_MINUS_SRC_ALPHA ) ;
822 glEnable( GL_TEXTURE_2D );
823 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
824 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
825 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
826 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
829 #ifdef FG_USE_CLOUDS_3D
830 sgClouds3d->Draw((sgVec4 *)current__view->get_VIEW());
833 glEnable( GL_LIGHTING );
834 glEnable( GL_DEPTH_TEST );
835 glBlendFunc ( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ) ;
838 globals->get_model_mgr()->draw();
839 globals->get_aircraft_model()->draw();
841 // display HUD && Panel
843 glDisable( GL_DEPTH_TEST );
844 // glDisable( GL_CULL_FACE );
845 // glDisable( GL_TEXTURE_2D );
847 // update the controls subsystem
848 globals->get_controls()->update(delta_time_sec);
850 hud_and_panel->apply();
853 // Use the hud_and_panel ssgSimpleState for rendering the ATC output
854 // This only works properly if called before the panel call
855 globals->get_ATC_display()->update(delta_time_sec);
857 // update the panel subsystem
858 if ( current_panel != NULL ) {
859 current_panel->update(delta_time_sec);
863 // We can do translucent menus, so why not. :-)
865 glBlendFunc ( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ) ;
867 // glDisable ( GL_BLEND ) ;
869 glEnable( GL_DEPTH_TEST );
872 // Fade out the splash screen over the first three seconds.
873 double t = globals->get_sim_time_sec();
875 fgSplashUpdate(0.0, 1.0);
876 } else if ( t <= 3.0) {
877 fgSplashUpdate(0.0, (3.0 - t) / 2.0);
885 // Update internal time dependent calculations (i.e. flight model)
886 // FIXME: this distinction is obsolete; all subsystems now get delta
888 void fgUpdateTimeDepCalcs() {
889 static bool inited = false;
891 //SG_LOG(SG_FLIGHT,SG_INFO, "Updating time dep calcs()");
893 fgLIGHT *l = &cur_light_params;
895 // Initialize the FDM here if it hasn't been and if we have a
896 // scenery elevation hit.
898 // cout << "cur_fdm_state->get_inited() = " << cur_fdm_state->get_inited()
899 // << " cur_elev = " << scenery.get_cur_elev() << endl;
901 if ( !cur_fdm_state->get_inited() &&
902 globals->get_scenery()->get_cur_elev() > -9990 )
904 SG_LOG(SG_FLIGHT,SG_INFO, "Finally initializing fdm");
906 cur_fdm_state->init();
907 if ( cur_fdm_state->get_bound() ) {
908 cur_fdm_state->unbind();
910 cur_fdm_state->bind();
913 // conceptually, the following block could be done for each fdm
915 if ( !cur_fdm_state->get_inited() ) {
916 // do nothing, fdm isn't inited yet
918 // we have been inited, and we are good to go ...
924 globals->get_autopilot()->update(delta_time_sec);
925 cur_fdm_state->update(delta_time_sec);
926 globals->get_steam()->update(delta_time_sec);
929 globals->get_model_mgr()->update(delta_time_sec);
930 globals->get_aircraft_model()->update(delta_time_sec);
932 // update the view angle
933 globals->get_viewmgr()->update(delta_time_sec);
937 // Update solar system
938 globals->get_ephem()->update( globals->get_time_params()->getMjd(),
939 globals->get_time_params()->getLst(),
940 cur_fdm_state->get_Latitude() );
942 // Update radio stack model
943 current_radiostack->update(delta_time_sec);
947 void fgInitTimeDepCalcs( void ) {
952 static const double alt_adjust_ft = 3.758099;
953 static const double alt_adjust_m = alt_adjust_ft * SG_FEET_TO_METER;
956 // What should we do when we have nothing else to do? Let's get ready
957 // for the next move and update the display?
958 static void fgMainLoop( void ) {
960 static const SGPropertyNode *longitude
961 = fgGetNode("/position/longitude-deg");
962 static const SGPropertyNode *latitude
963 = fgGetNode("/position/latitude-deg");
964 static const SGPropertyNode *altitude
965 = fgGetNode("/position/altitude-ft");
966 static const SGPropertyNode *clock_freeze
967 = fgGetNode("/sim/freeze/clock", true);
968 static const SGPropertyNode *cur_time_override
969 = fgGetNode("/sim/time/cur-time-override", true);
971 // Update the elapsed time.
972 static bool first_time = true;
974 last_time_stamp.stamp();
977 current_time_stamp.stamp();
978 delta_time_sec = double(current_time_stamp - last_time_stamp) / 1000000.0;
979 if (clock_freeze->getBoolValue())
981 last_time_stamp = current_time_stamp;
982 globals->inc_sim_time_sec( delta_time_sec );
984 static long remainder = 0;
986 #ifdef FANCY_FRAME_COUNTER
990 static time_t last_time = 0;
991 static int frames = 0;
992 #endif // FANCY_FRAME_COUNTER
994 SGTime *t = globals->get_time_params();
996 FGLocation * acmodel_location = 0;
997 if(cur_fdm_state->getACModel() != 0) {
998 acmodel_location = (FGLocation *) cur_fdm_state->getACModel()->get3DModel()->getFGLocation();
1001 SG_LOG( SG_ALL, SG_DEBUG, "Running Main Loop");
1002 SG_LOG( SG_ALL, SG_DEBUG, "======= ==== ====");
1004 #ifdef FG_NETWORK_OLK
1005 if ( fgGetBool("/sim/networking/network-olk") ) {
1006 if ( net_is_registered == 0 ) { // We first have to reg. to fgd
1007 // printf("FGD: Netupdate\n");
1008 fgd_send_com( "A", FGFS_host); // Send Mat4 data
1009 fgd_send_com( "B", FGFS_host); // Recv Mat4 data
1014 #if defined( ENABLE_PLIB_JOYSTICK )
1015 // Read joystick and update control settings
1016 // if ( fgGetString("/sim/control-mode") == "joystick" )
1018 // fgJoystickRead();
1020 #elif defined( ENABLE_GLUT_JOYSTICK )
1021 // Glut joystick support works by feeding a joystick handler
1022 // function to glut. This is taken care of once in the joystick
1023 // init routine and we don't have to worry about it again.
1026 #ifndef FG_WEATHERCM
1027 globals->get_environment_mgr()->update(delta_time_sec);
1030 // Fix elevation. I'm just sticking this here for now, it should
1031 // probably move eventually
1033 /* printf("Before - ground = %.2f runway = %.2f alt = %.2f\n",
1034 scenery.get_cur_elev(),
1035 cur_fdm_state->get_Runway_altitude() * SG_FEET_TO_METER,
1036 cur_fdm_state->get_Altitude() * SG_FEET_TO_METER); */
1038 // Curt is this code used? I don't see any problems when I comment it out.
1039 if ( acmodel_location != 0 ) {
1040 if ( acmodel_location->get_cur_elev_m() > -9990 && cur_fdm_state->get_inited() ) {
1041 if ( cur_fdm_state->get_Altitude() * SG_FEET_TO_METER <
1042 (acmodel_location->get_cur_elev_m() + alt_adjust_m - 3.0) ) {
1043 // now set aircraft altitude above ground
1044 printf("(*) Current Altitude = %.2f < %.2f forcing to %.2f\n",
1045 cur_fdm_state->get_Altitude() * SG_FEET_TO_METER,
1046 acmodel_location->get_cur_elev_m() + alt_adjust_m - 3.0,
1047 acmodel_location->get_cur_elev_m() + alt_adjust_m );
1048 cur_fdm_state->set_Altitude( (acmodel_location->get_cur_elev_m()
1049 + alt_adjust_m) * SG_METER_TO_FEET );
1050 SG_LOG( SG_ALL, SG_DEBUG,
1051 "<*> resetting altitude to "
1052 << cur_fdm_state->get_Altitude() * SG_FEET_TO_METER
1057 // End of code in question. (see Curt is this code used? above)
1059 /* printf("Adjustment - ground = %.2f runway = %.2f alt = %.2f\n",
1060 scenery.get_cur_elev(),
1061 cur_fdm_state->get_Runway_altitude() * SG_FEET_TO_METER,
1062 cur_fdm_state->get_Altitude() * SG_FEET_TO_METER); */
1064 // cout << "Warp = " << globals->get_warp() << endl;
1067 static bool last_clock_freeze = false;
1069 if ( clock_freeze->getBoolValue() ) {
1070 // clock freeze requested
1071 if ( cur_time_override->getLongValue() == 0 ) {
1072 fgSetLong( "/sim/time/cur-time-override", t->get_cur_time() );
1073 globals->set_warp( 0 );
1076 // no clock freeze requested
1077 if ( last_clock_freeze == true ) {
1078 // clock just unfroze, let's set warp as the difference
1079 // between frozen time and current time so we don't get a
1080 // time jump (and corresponding sky object and lighting
1082 globals->set_warp( cur_time_override->getLongValue() - time(NULL) );
1083 fgSetLong( "/sim/time/cur-time-override", 0 );
1085 if ( globals->get_warp_delta() != 0 ) {
1086 globals->inc_warp( globals->get_warp_delta() );
1090 last_clock_freeze = clock_freeze->getBoolValue();
1092 t->update( longitude->getDoubleValue() * SGD_DEGREES_TO_RADIANS,
1093 latitude->getDoubleValue() * SGD_DEGREES_TO_RADIANS,
1094 cur_time_override->getLongValue(),
1095 globals->get_warp() );
1097 if ( globals->get_warp_delta() != 0 ) {
1098 fgUpdateSkyAndLightingParams();
1101 // update magvar model
1102 globals->get_mag()->update( longitude->getDoubleValue()
1103 * SGD_DEGREES_TO_RADIANS,
1104 latitude->getDoubleValue()
1105 * SGD_DEGREES_TO_RADIANS,
1106 altitude->getDoubleValue() * SG_FEET_TO_METER,
1107 globals->get_time_params()->getJD() );
1109 // Get elapsed time (in usec) for this past frame
1110 elapsed = fgGetTimeInterval();
1111 SG_LOG( SG_ALL, SG_DEBUG,
1112 "Elapsed time interval is = " << elapsed
1113 << ", previous remainder is = " << remainder );
1115 // Calculate frame rate average
1116 #ifdef FANCY_FRAME_COUNTER
1117 /* old fps calculation */
1118 if ( elapsed > 0 ) {
1121 for ( i = FG_FRAME_RATE_HISTORY - 2; i >= 0; i-- ) {
1122 tmp = general.get_frame(i);
1124 // printf("frame[%d] = %.2f\n", i, g->frames[i]);
1125 general.set_frame(i+1,tmp);
1127 tmp = 1000000.0 / (float)elapsed;
1128 general.set_frame(0,tmp);
1129 // printf("frame[0] = %.2f\n", general.frames[0]);
1131 general.set_frame_rate(accum / (float)FG_FRAME_RATE_HISTORY);
1132 // printf("ave = %.2f\n", general.frame_rate);
1135 if ( (t->get_cur_time() != last_time) && (last_time > 0) ) {
1136 general.set_frame_rate( frames );
1137 SG_LOG( SG_ALL, SG_DEBUG,
1138 "--> Frame rate is = " << general.get_frame_rate() );
1141 last_time = t->get_cur_time();
1145 // Run ATC subsystem
1146 globals->get_ATC_mgr()->update(delta_time_sec);
1148 // Run the AI subsystem
1149 if (fgGetBool("/sim/ai-traffic/enabled"))
1150 globals->get_AI_mgr()->update(delta_time_sec);
1154 // Calculate model iterations needed for next frame
1155 elapsed += remainder;
1157 global_multi_loop = (long)(((double)elapsed * 0.000001) *
1158 fgGetInt("/sim/model-hz"));
1159 remainder = elapsed - ( (global_multi_loop*1000000) /
1160 fgGetInt("/sim/model-hz") );
1161 SG_LOG( SG_ALL, SG_DEBUG,
1162 "Model iterations needed = " << global_multi_loop
1163 << ", new remainder = " << remainder );
1165 // chop max interations to something reasonable if the sim was
1166 // delayed for an excesive amount of time
1167 if ( global_multi_loop > 2.0 * fgGetInt("/sim/model-hz") ) {
1168 global_multi_loop = (int)(2.0 * fgGetInt("/sim/model-hz") );
1173 if ( global_multi_loop > 0 ) {
1174 fgUpdateTimeDepCalcs();
1176 SG_LOG( SG_ALL, SG_DEBUG,
1177 "Elapsed time is zero ... we're zinging" );
1180 // Do any I/O channel work that might need to be done
1181 globals->get_io()->update( delta_time_sec );
1183 // see if we need to load any deferred-load textures
1184 material_lib.load_next_deferred();
1186 // Run audio scheduler
1187 #ifdef ENABLE_AUDIO_SUPPORT
1188 if ( fgGetBool("/sim/sound/audible")
1189 && globals->get_soundmgr()->is_working() ) {
1190 globals->get_soundmgr()->update( delta_time_sec );
1194 globals->get_subsystem_mgr()->update(delta_time_sec);
1197 // Tile Manager updates - see if we need to load any new scenery tiles.
1198 // this code ties together the fdm, viewer and scenery classes...
1199 // we may want to move this to it's own class at some point
1201 double visibility_meters = fgGetDouble("/environment/visibility-m");
1202 FGViewer *current_view = globals->get_current_view();
1204 // update tile manager for FDM...
1205 // ...only if location is different than the viewer (to avoid duplicating effort)
1206 if( acmodel_location != current_view->getFGLocation() ) {
1207 if( acmodel_location != 0 ) {
1208 globals->get_tile_mgr()->prep_ssg_nodes( acmodel_location,
1209 visibility_meters );
1210 globals->get_tile_mgr()->
1211 update( acmodel_location, visibility_meters,
1212 acmodel_location->get_absolute_view_pos() );
1213 // save results of update in FGLocation for fdm...
1214 if ( globals->get_scenery()->get_cur_elev() > -9990 ) {
1216 set_cur_elev_m( globals->get_scenery()->get_cur_elev() );
1219 set_tile_center( globals->get_scenery()->get_next_center() );
1223 globals->get_tile_mgr()->prep_ssg_nodes( current_view->getFGLocation(),
1224 visibility_meters );
1225 // update tile manager for view...
1226 // IMPORTANT!!! the tilemgr update for view location _must_ be done last
1227 // after the FDM's until all of Flight Gear code references the viewer's location
1228 // for elevation instead of the "scenery's" current elevation.
1229 FGLocation *view_location = globals->get_current_view()->getFGLocation();
1230 globals->get_tile_mgr()->update( view_location, visibility_meters,
1231 current_view->get_absolute_view_pos() );
1232 // save results of update in FGLocation for fdm...
1233 if ( globals->get_scenery()->get_cur_elev() > -9990 ) {
1234 current_view->getFGLocation()->set_cur_elev_m( globals->get_scenery()->get_cur_elev() );
1236 current_view->getFGLocation()->set_tile_center( globals->get_scenery()->get_next_center() );
1238 // If fdm location is same as viewer's then we didn't do the update for fdm location
1239 // above so we need to save the viewer results in the fdm FGLocation as well...
1240 if( acmodel_location == current_view->getFGLocation() ) {
1241 if( acmodel_location != 0 ) {
1242 if ( globals->get_scenery()->get_cur_elev() > -9990 ) {
1243 acmodel_location->set_cur_elev_m( globals->get_scenery()->get_cur_elev() );
1245 acmodel_location->set_tile_center( globals->get_scenery()->get_next_center() );
1249 // END Tile Manager udpates
1254 SG_LOG( SG_ALL, SG_DEBUG, "" );
1258 // This is the top level master main function that is registered as
1259 // our idle funciton
1261 // The first few passes take care of initialization things (a couple
1262 // per pass) and once everything has been initialized fgMainLoop from
1265 static void fgIdleFunction ( void ) {
1266 // printf("idle state == %d\n", idle_state);
1268 if ( idle_state == 0 ) {
1269 // Initialize the splash screen right away
1270 if ( fgGetBool("/sim/startup/splash-screen") ) {
1275 } else if ( idle_state == 1 ) {
1276 // Initialize audio support
1277 #ifdef ENABLE_AUDIO_SUPPORT
1279 // Start the intro music
1280 if ( fgGetBool("/sim/startup/intro-music") ) {
1281 SGPath mp3file( globals->get_fg_root() );
1282 mp3file.append( "Sounds/intro.mp3" );
1284 SG_LOG( SG_GENERAL, SG_INFO,
1285 "Starting intro music: " << mp3file.str() );
1287 #if defined( __CYGWIN__ )
1288 string command = "start /m `cygpath -w " + mp3file.str() + "`";
1289 #elif defined( WIN32 )
1290 string command = "start /m " + mp3file.str();
1292 string command = "mpg123 " + mp3file.str() + "> /dev/null 2>&1";
1295 system ( command.c_str() );
1300 } else if ( idle_state == 2 ) {
1301 // These are a few miscellaneous things that aren't really
1302 // "subsystems" but still need to be initialized.
1305 if ( strstr ( general.get_glRenderer(), "Glide" ) ) {
1306 grTexLodBiasValue ( GR_TMU0, 1.0 ) ;
1311 } else if ( idle_state == 3 ) {
1312 // This is the top level init routine which calls all the
1313 // other subsystem initialization routines. If you are adding
1314 // a subsystem to flightgear, its initialization call should
1315 // located in this routine.
1316 if( !fgInitSubsystems()) {
1317 SG_LOG( SG_GENERAL, SG_ALERT,
1318 "Subsystem initializations failed ..." );
1323 } else if ( idle_state == 4 ) {
1324 // setup OpenGL view parameters
1328 } else if ( idle_state == 5 ) {
1331 } else if ( idle_state == 6 ) {
1335 SG_LOG( SG_GENERAL, SG_INFO, "Panel visible = " << fgPanelVisible() );
1336 fgReshape( fgGetInt("/sim/startup/xsize"),
1337 fgGetInt("/sim/startup/ysize") );
1340 if ( idle_state == 1000 ) {
1341 // We've finished all our initialization steps, from now on we
1342 // run the main loop.
1344 glutIdleFunc(fgMainLoop);
1346 if ( fgGetBool("/sim/startup/splash-screen") ) {
1347 fgSplashUpdate(0.0, 1.0);
1352 // options.cxx needs to see this for toggle_panel()
1353 // Handle new window size or exposure
1354 void fgReshape( int width, int height ) {
1357 if ( (!fgGetBool("/sim/virtual-cockpit"))
1358 && fgPanelVisible() && idle_state == 1000 ) {
1359 view_h = (int)(height * (current_panel->getViewHeight() -
1360 current_panel->getYOffset()) / 768.0);
1366 FGViewMgr *viewmgr = globals->get_viewmgr();
1367 for ( int i = 0; i < viewmgr->size(); ++i ) {
1368 viewmgr->get_view(i)->
1369 set_aspect_ratio((float)view_h / (float)width);
1372 glViewport( 0, (GLint)(height - view_h), (GLint)(width), (GLint)(view_h) );
1374 fgSetInt("/sim/startup/xsize", width);
1375 fgSetInt("/sim/startup/ysize", height);
1376 guiInitMouse(width, height);
1378 ssgSetFOV( viewmgr->get_current_view()->get_h_fov(),
1379 viewmgr->get_current_view()->get_v_fov() );
1383 #ifdef FG_USE_CLOUDS_3D
1384 sgClouds3d->Resize( viewmgr->get_current_view()->get_h_fov(),
1385 viewmgr->get_current_view()->get_v_fov() );
1390 // Initialize GLUT and define a main window
1391 static bool fgGlutInit( int *argc, char **argv ) {
1393 #if !defined( macintosh )
1394 // GLUT will extract all glut specific options so later on we only
1395 // need wory about our own.
1396 glutInit(argc, argv);
1399 // Define Display Parameters. Clouds3d works best with --bpp32 option
1400 if ( fgGetBool("/sim/rendering/clouds3d") ) {
1401 glutInitDisplayMode( GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE | GLUT_ALPHA );
1403 glutInitDisplayMode( GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE );
1406 SG_LOG( SG_GENERAL, SG_INFO, "Opening a window: " <<
1407 fgGetInt("/sim/startup/xsize") << "x"
1408 << fgGetInt("/sim/startup/ysize") );
1410 // Define initial window size
1411 glutInitWindowSize( fgGetInt("/sim/startup/xsize"),
1412 fgGetInt("/sim/startup/ysize") );
1414 // Initialize windows
1415 if ( !fgGetBool("/sim/startup/game-mode")) {
1416 // Open the regular window
1417 glutCreateWindow("FlightGear");
1418 #ifndef GLUT_WRONG_VERSION
1420 // Open the cool new 'game mode' window
1421 char game_mode_str[256];
1422 //#define SYNC_OPENGL_WITH_DESKTOP_SETTINGS
1423 #if defined(WIN32) && defined(SYNC_OPENGL_WITH_DESKTOP_SETTINGS)
1424 #ifndef ENUM_CURRENT_SETTINGS
1425 #define ENUM_CURRENT_SETTINGS ((DWORD)-1)
1426 #define ENUM_REGISTRY_SETTINGS ((DWORD)-2)
1430 dm.dmSize = sizeof(DEVMODE);
1431 EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &dm);
1432 fgSetInt("/sim/startup/xsize", dm.dmPelsWidth);
1433 fgSetInt("/sim/startup/ysize", dm.dmPelsHeight);
1434 glutInitWindowSize( fgGetInt("/sim/startup/xsize"),
1435 fgGetInt("/sim/startup/ysize") );
1436 sprintf( game_mode_str, "%dx%d:%d@%d",
1440 dm.dmDisplayFrequency );
1442 // Open the cool new 'game mode' window
1443 sprintf( game_mode_str, "width=%d height=%d bpp=%d",
1444 fgGetInt("/sim/startup/xsize"),
1445 fgGetInt("/sim/startup/ysize"),
1446 fgGetInt("/sim/rendering/bits-per-pixel"));
1448 #endif // HAVE_WINDOWS_H
1449 SG_LOG( SG_GENERAL, SG_INFO,
1450 "game mode params = " << game_mode_str );
1451 glutGameModeString( game_mode_str );
1452 glutEnterGameMode();
1453 #endif // GLUT_WRONG_VERSION
1456 // This seems to be the absolute earliest in the init sequence
1457 // that these calls will return valid info. Too bad it's after
1458 // we've already created and sized out window. :-(
1459 general.set_glVendor( (char *)glGetString ( GL_VENDOR ) );
1460 general.set_glRenderer( (char *)glGetString ( GL_RENDERER ) );
1461 general.set_glVersion( (char *)glGetString ( GL_VERSION ) );
1462 SG_LOG( SG_GENERAL, SG_INFO, general.get_glRenderer() );
1465 glGetIntegerv( GL_MAX_TEXTURE_SIZE, &tmp );
1466 general.set_glMaxTexSize( tmp );
1467 SG_LOG ( SG_GENERAL, SG_INFO, "Max texture size = " << tmp );
1469 glGetIntegerv( GL_DEPTH_BITS, &tmp );
1470 general.set_glDepthBits( tmp );
1471 SG_LOG ( SG_GENERAL, SG_INFO, "Depth buffer bits = " << tmp );
1477 // Initialize GLUT event handlers
1478 static bool fgGlutInitEvents( void ) {
1479 // call fgReshape() on window resizes
1480 glutReshapeFunc( fgReshape );
1482 // keyboard and mouse callbacks are set in FGInput::init
1484 // call fgMainLoop() whenever there is
1485 // nothing else to do
1486 glutIdleFunc( fgIdleFunction );
1489 glutDisplayFunc( fgRenderFrame );
1494 // Main top level initialization
1495 static bool fgMainInit( int argc, char **argv ) {
1497 #if defined( macintosh )
1498 freopen ("stdout.txt", "w", stdout );
1499 freopen ("stderr.txt", "w", stderr );
1500 argc = ccommand( &argv );
1503 // set default log levels
1504 sglog().setLogLevels( SG_ALL, SG_INFO );
1507 #ifdef FLIGHTGEAR_VERSION
1508 version = FLIGHTGEAR_VERSION;
1510 version = "unknown version";
1512 SG_LOG( SG_GENERAL, SG_INFO, "FlightGear: Version "
1514 SG_LOG( SG_GENERAL, SG_INFO, "Built with " << SG_COMPILER_STR << endl );
1516 // Allocate global data structures. This needs to happen before
1517 // we parse command line options
1519 globals = new FGGlobals;
1521 #ifndef FG_WEATHERCM
1522 globals->set_environment_mgr(new FGEnvironmentMgr);
1525 // seed the random number generater
1528 SGRoute *route = new SGRoute;
1529 globals->set_route( route );
1531 FGControls *controls = new FGControls;
1532 globals->set_controls( controls );
1534 FGSteam *steam = new FGSteam;
1535 globals->set_steam( steam );
1537 string_list *col = new string_list;
1538 globals->set_channel_options_list( col );
1540 // Scan the config file(s) and command line options to see if
1541 // fg_root was specified (ignore all other options for now)
1542 fgInitFGRoot(argc, argv);
1544 // Check for the correct base package version
1545 static char required_version[] = "0.9.1";
1546 string base_version = fgBasePackageVersion();
1547 if ( !(base_version == required_version) ) {
1548 // tell the operator how to use this application
1550 cerr << endl << "Base package check failed ... " \
1551 << "Found version " << base_version << " at: " \
1552 << globals->get_fg_root() << endl;
1553 cerr << "Please upgrade to version: " << required_version << endl;
1557 // Initialize the Aircraft directory to "" (UIUC)
1560 // Load the configuration parameters. (Command line options
1561 // overrides config file options. Config file options override
1563 if ( !fgInitConfig(argc, argv) ) {
1564 SG_LOG( SG_GENERAL, SG_ALERT, "Config option parsing failed ..." );
1568 // Initialize the Window/Graphics environment.
1569 if( !fgGlutInit(&argc, argv) ) {
1570 SG_LOG( SG_GENERAL, SG_ALERT, "GLUT initialization failed ..." );
1574 // Initialize the various GLUT Event Handlers.
1575 if( !fgGlutInitEvents() ) {
1576 SG_LOG( SG_GENERAL, SG_ALERT,
1577 "GLUT event handler initialization failed ..." );
1581 // Initialize plib net interface
1582 netInit( &argc, argv );
1584 // Initialize ssg (from plib). Needs to come before we do any
1585 // other ssg stuff, but after opengl/glut has been initialized.
1588 // Initialize the user interface (we need to do this before
1589 // passing off control to glut and before fgInitGeneral to get our
1593 #ifdef GL_EXT_texture_lod_bias
1594 glTexEnvf( GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, -0.5 ) ;
1597 // get the address of our OpenGL extensions
1598 if ( fgGetBool("/sim/rendering/distance-attenuation") )
1601 glPointParameterfEXT = (PFNGLPOINTPARAMETERFEXTPROC)
1602 wglGetProcAddress("glPointParameterfEXT");
1603 glPointParameterfvEXT = (PFNGLPOINTPARAMETERFVEXTPROC)
1604 wglGetProcAddress("glPointParameterfvEXT");
1606 glPointParameterfEXT = (OpenGLFuncExt)
1607 glXGetProcAddressARB((GLubyte *)"glPointParameterfEXT");
1608 glPointParameterfvEXT = (OpenGLFuncExtv)
1609 glXGetProcAddressARB((GLubyte *)"glPointParameterfvEXT");
1613 // based on the requested presets, calculate the true starting
1617 SGTime *t = fgInitTime();
1618 globals->set_time_params( t );
1620 // Do some quick general initializations
1621 if( !fgInitGeneral()) {
1622 SG_LOG( SG_GENERAL, SG_ALERT,
1623 "General initializations failed ..." );
1627 SGPath modelpath( globals->get_fg_root() );
1628 ssgModelPath( (char *)modelpath.c_str() );
1630 // Initialize the global scenery manager
1631 globals->set_scenery( new FGScenery );
1632 globals->get_scenery()->init();
1633 globals->get_scenery()->bind();
1635 // Initialize the global tile manager
1636 globals->set_tile_mgr( new FGTileMgr );
1638 ////////////////////////////////////////////////////////////////////
1639 // Initialize the property-based built-in commands
1640 ////////////////////////////////////////////////////////////////////
1643 ////////////////////////////////////////////////////////////////////
1644 // Initialize the general model subsystem.
1645 ////////////////////////////////////////////////////////////////////
1647 globals->set_model_loader(new FGModelLoader);
1648 globals->set_texture_loader(new FGTextureLoader);
1649 globals->set_model_mgr(new FGModelMgr);
1650 globals->get_model_mgr()->init();
1651 globals->get_model_mgr()->bind();
1653 ////////////////////////////////////////////////////////////////////
1654 // Initialize the 3D aircraft model subsystem.
1655 ////////////////////////////////////////////////////////////////////
1657 globals->set_aircraft_model(new FGAircraftModel);
1658 globals->get_aircraft_model()->init();
1659 globals->get_aircraft_model()->bind();
1661 ////////////////////////////////////////////////////////////////////
1662 // Initialize the view manager subsystem.
1663 ////////////////////////////////////////////////////////////////////
1665 FGViewMgr *viewmgr = new FGViewMgr;
1666 globals->set_viewmgr( viewmgr );
1671 // Initialize the sky
1672 SGPath ephem_data_path( globals->get_fg_root() );
1673 ephem_data_path.append( "Astro" );
1674 SGEphemeris *ephem = new SGEphemeris( ephem_data_path.c_str() );
1675 ephem->update( globals->get_time_params()->getMjd(),
1676 globals->get_time_params()->getLst(),
1678 globals->set_ephem( ephem );
1680 // TODO: move to environment mgr
1682 SGPath texture_path(globals->get_fg_root());
1683 texture_path.append("Textures");
1684 texture_path.append("Sky");
1685 for (int i = 0; i < FGEnvironmentMgr::MAX_CLOUD_LAYERS; i++) {
1686 SGCloudLayer * layer = new SGCloudLayer(texture_path.str());
1687 thesky->add_cloud_layer(layer);
1691 SGPath sky_tex_path( globals->get_fg_root() );
1692 sky_tex_path.append( "Textures" );
1693 sky_tex_path.append( "Sky" );
1694 thesky->texture_path( sky_tex_path.str() );
1696 thesky->build( 550.0, 550.0,
1697 globals->get_ephem()->getNumPlanets(),
1698 globals->get_ephem()->getPlanets(), 60000.0,
1699 globals->get_ephem()->getNumStars(),
1700 globals->get_ephem()->getStars(), 60000.0 );
1702 // Initialize MagVar model
1703 SGMagVar *magvar = new SGMagVar();
1704 globals->set_mag( magvar );
1706 // airport = new ssgBranch;
1707 // airport->setName( "Airport Lighting" );
1708 // lighting->addKid( airport );
1714 #ifdef FG_NETWORK_OLK
1715 // Do the network intialization
1716 if ( fgGetBool("/sim/networking/network-olk") ) {
1717 printf("Multipilot mode %s\n",
1718 fg_net_init( globals->get_scenery()->get_scene_graph() ) );
1722 // build our custom render states
1723 fgBuildRenderStates();
1725 // pass control off to the master GLUT event handler
1728 // we never actually get here ... but to avoid compiler warnings,
1734 // $$$ end - added VS Renganathan, 15 Oct 2K
1735 // - added Venky , 12 Nov 2K
1737 #if defined(__linux__) && defined(__i386__)
1739 static void handleFPE (int);
1744 fpu_control_t fpe_flags = 0;
1745 _FPU_GETCW(fpe_flags);
1746 // fpe_flags &= ~_FPU_MASK_IM; // invalid operation
1747 // fpe_flags &= ~_FPU_MASK_DM; // denormalized operand
1748 // fpe_flags &= ~_FPU_MASK_ZM; // zero-divide
1749 // fpe_flags &= ~_FPU_MASK_OM; // overflow
1750 // fpe_flags &= ~_FPU_MASK_UM; // underflow
1751 // fpe_flags &= ~_FPU_MASK_PM; // precision (inexact result)
1752 _FPU_SETCW(fpe_flags);
1753 signal(SIGFPE, handleFPE);
1760 SG_LOG(SG_GENERAL, SG_ALERT, "Floating point interrupt (SIGFPE)");
1773 short CPSGetCurrentProcess(PSN *psn);
1774 short CPSSetProcessName (PSN *psn, char *processname);
1775 short CPSEnableForegroundOperation(PSN *psn, int _arg2, int _arg3, int _arg4, int _arg5);
1776 short CPSSetFrontProcess(PSN *psn);
1779 #define CPSEnableFG(psn) CPSEnableForegroundOperation(psn,0x03,0x3C,0x2C,0x1103)
1783 // Main entry point; catch any exceptions that have made it this far.
1784 int main ( int argc, char **argv ) {
1786 // Enable floating-point exceptions for Linux/x86
1787 #if defined(__linux__) && defined(__i386__)
1791 // Enable floating-point exceptions for Windows
1792 #if defined( _MSC_VER ) && defined( DEBUG )
1793 // Christian, we should document what this does
1794 _control87( _EM_INEXACT, _MCW_EM );
1797 #if defined( HAVE_BC5PLUS )
1798 _control87(MCW_EM, MCW_EM); /* defined in float.h */
1801 // Keyboard focus hack
1806 glutInit (&argc, argv);
1808 CPSGetCurrentProcess(&psn);
1809 CPSSetProcessName(&psn, "FlightGear");
1811 CPSSetFrontProcess(&psn);
1815 // FIXME: add other, more specific
1818 fgMainInit(argc, argv);
1819 } catch (sg_throwable &t) {
1820 // We must use cerr rather than
1821 // logging, since logging may be
1823 cerr << "Fatal error: " << t.getFormattedMessage()
1824 << "\n (received from " << t.getOrigin() << ')' << endl;
1832 void fgLoadDCS(void) {
1834 ssgEntity *ship_obj = NULL;
1836 char obj_filename[25];
1838 for ( int k = 0; k < 32; k++ ) {
1842 SGPath tile_path( globals->get_fg_root());
1843 tile_path.append( "Scenery" );
1844 tile_path.append( "Objects.txt" );
1845 sg_gzifstream in( tile_path.str() );
1846 if ( ! in.is_open() ) {
1847 SG_LOG( SG_TERRAIN, SG_ALERT, "Cannot open file: " << tile_path.str() );
1850 SGPath modelpath( globals->get_fg_root() );
1851 modelpath.append( "Models" );
1852 modelpath.append( "Geometry" );
1854 SGPath texturepath( globals->get_fg_root() );
1855 texturepath.append( "Models" );
1856 texturepath.append( "Textures" );
1858 ssgModelPath( (char *)modelpath.c_str() );
1859 ssgTexturePath( (char *)texturepath.c_str() );
1861 ship_sel = new ssgSelector;
1864 while ( ! in.eof() ) {
1866 if ( in.get( c ) && c == '#' ) {
1870 in >> obj_filename >> obj_lat[objc] >> obj_lon[objc] >> obj_alt[objc];
1871 /* cout << endl << obj_filename << " " << obj_lat[objc] << " " << obj_lon[objc] << " " << obj_alt[objc] << endl;
1872 int chj=getchar();*/
1874 obj_lon[objc] *=SGD_DEGREES_TO_RADIANS;
1875 obj_lat[objc] *=SGD_DEGREES_TO_RADIANS;
1877 ship_pos[objc] = new ssgTransform;
1879 // type "repeat" in objects.txt to load one more
1880 // instance of the last object.
1882 if ( strcmp(obj_filename,"repeat") != 0) {
1884 globals->get_model_loader()->load_model( obj_filename );
1887 if ( ship_obj != NULL ) {
1888 ship_obj->setName(obj_filename);
1890 ship_obj->clrTraversalMaskBits( SSGTRAV_HOT );
1892 ship_obj->setTraversalMaskBits( SSGTRAV_HOT );
1893 ship_pos[objc]->addKid( ship_obj ); // add object to transform node
1894 ship_sel->addKid( ship_pos[objc] ); // add transform node to selector
1895 SG_LOG( SG_TERRAIN, SG_ALERT, "Loaded file: "
1898 SG_LOG( SG_TERRAIN, SG_ALERT, "Cannot open file: "
1902 // temporary hack for deck lights - ultimately should move to PLib (when??)
1903 //const char *extn = file_extension ( obj_filename ) ;
1905 ssgVertexArray *lights = new ssgVertexArray( 100 );
1906 ssgVertexArray *lightpoints = new ssgVertexArray( 100 );
1907 ssgVertexArray *lightnormals = new ssgVertexArray( 100 );
1908 ssgVertexArray *lightdir = new ssgVertexArray( 100 );
1909 int ltype[500], light_type;
1910 static int ltcount = 0;
1912 sgVec3 rway_dir,rway_normal,lightpt;
1914 modelpath.append(obj_filename);
1915 sg_gzifstream in1( modelpath.str() );
1916 if ( ! in1.is_open() ) {
1917 SG_LOG( SG_TERRAIN, SG_ALERT, "Cannot open file: " << modelpath.str() );
1919 while ( ! in1.eof() ) {
1921 if ( in1.get( c ) && c == '#' ) {
1926 //cout << token << endl;
1927 if ( token == "runway" ) {
1929 sgSetVec3 (rway_dir, node[0], node[1], node[2] );
1930 } else if ( token == "edgelight" ) {
1932 sgSetVec3 (rway_normal, node[0], node[1], node[2] );
1934 } else if ( token == "taxi" ) {
1936 sgSetVec3 (rway_normal, node[0], node[1], node[2] );
1938 } else if ( token == "vasi" ) {
1940 sgSetVec3 (rway_normal, node[0], node[1], node[2] );
1942 } else if ( token == "threshold" ) {
1944 sgSetVec3 (rway_normal, node[0], node[1], node[2] );
1946 } else if ( token == "rabbit" ) {
1948 sgSetVec3 (rway_normal, node[0], node[1], node[2] );
1950 } else if ( token == "ols" ) {
1952 sgSetVec3 (rway_ols, node[0], node[1], node[2] );
1954 } else if ( token == "red" ) {
1956 sgSetVec3 (rway_normal, node[0], node[1], node[2] );
1958 } else if ( token == "green" ) {
1960 sgSetVec3 (rway_normal, node[0], node[1], node[2] );
1962 } else if ( token == "lp" ) {
1964 sgSetVec3 (lightpt, node[0], node[1], node[2] );
1965 lightpoints->add( lightpt );
1966 lightnormals->add( rway_normal );
1967 lightdir->add( rway_dir );
1968 ltype[ltcount]= light_type;
1971 if (in1.eof()) break;
1975 if ( lightpoints->getNum() ) {
1976 ssgBranch *lightpoints_branch;
1977 long int dummy = -999;
1978 dummy_tile = new FGTileEntry((SGBucket)dummy);
1979 dummy_tile->lightmaps_sequence = new ssgSelector;
1980 dummy_tile->ols_transform = new ssgTransform;
1982 // call function to generate the runway lights
1983 lightpoints_branch =
1984 dummy_tile->gen_runway_lights( lightpoints, lightnormals,
1986 lightpoints_brightness->addKid(lightpoints_branch);
1987 lightpoints_transform->addKid(lightpoints_brightness);
1988 //dummy_tile->lightmaps_sequence->setTraversalMaskBits( SSGTRAV_HOT );
1989 lightpoints_transform->addKid( dummy_tile->lightmaps_sequence );
1990 lightpoints_transform->ref();
1991 globals->get_scenery()->get_gnd_lights_root()->addKid( lightpoints_transform );
1995 // end hack for deck lights
1999 if (in.eof()) break;
2003 SG_LOG ( SG_TERRAIN, SG_ALERT, "Finished object processing." );
2005 globals->get_scenery()->get_terrain_branch()->addKid( ship_sel ); //add selector node to root node
2012 void fgUpdateDCS (void) {
2014 // double eye_lat,eye_lon,eye_alt;
2015 // static double obj_head;
2016 double sl_radius,obj_latgc;
2017 // float nresultmat[4][4];
2018 // sgMat4 Trans,rothead,rotlon,rot180,rotlat,resultmat1,resultmat2,resultmat3;
2021 // Instantaneous Geodetic Lat/Lon/Alt of moving object
2022 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
2024 // Deck should be the first object in objects.txt in case of fdm=ada
2026 if (!strcmp(fgGetString("/sim/flight-model"), "ada")) {
2027 if ((fdm->get_iaux(1))==1)
2029 obj_lat[1] = fdm->get_daux(1)*SGD_DEGREES_TO_RADIANS;
2030 obj_lon[1] = fdm->get_daux(2)*SGD_DEGREES_TO_RADIANS;
2031 obj_alt[1] = fdm->get_daux(3);
2032 obj_pitch[1] = fdm->get_faux(1);
2033 obj_roll[1] = fdm->get_faux(2);
2037 for ( int m = 0; m < objc; m++ ) {
2038 //cout << endl << obj_lat[m]*SGD_RADIANS_TO_DEGREES << " " << obj_lon[m]*SGD_RADIANS_TO_DEGREES << " " << obj_alt[m] << " " << objc << endl;
2041 //Geodetic to Geocentric angles for rotation
2042 sgGeodToGeoc(obj_lat[m],obj_alt[m],&sl_radius,&obj_latgc);
2044 //moving object gbs-posn in cartesian coords
2045 Point3D obj_posn = Point3D( obj_lon[m],obj_lat[m],obj_alt[m]);
2046 Point3D obj_pos = sgGeodToCart( obj_posn );
2048 // Translate moving object w.r.t eye
2049 Point3D Objtrans = obj_pos - globals->get_scenery()->get_center();
2054 // rotate dynamic objects for lat,lon & alt and other motion about its axes
2057 sgMakeTransMat4( sgTRANS, bz[0],bz[1],bz[2]);
2059 sgVec3 ship_fwd,ship_rt,ship_up;
2060 sgSetVec3( ship_fwd, 1.0, 0.0, 0.0);//east,roll
2061 sgSetVec3( ship_rt, 0.0, 1.0, 0.0);//up,pitch
2062 sgSetVec3( ship_up, 0.0, 0.0, 1.0); //north,yaw
2064 sgMat4 sgROT_lon, sgROT_lat, sgROT_hdg, sgROT_pitch, sgROT_roll;
2065 sgMakeRotMat4( sgROT_lon, obj_lon[m]*SGD_RADIANS_TO_DEGREES, ship_up );
2066 sgMakeRotMat4( sgROT_lat, 90-obj_latgc*SGD_RADIANS_TO_DEGREES, ship_rt );
2067 sgMakeRotMat4( sgROT_hdg, 180.0, ship_up );
2068 sgMakeRotMat4( sgROT_pitch, obj_pitch[m], ship_rt );
2069 sgMakeRotMat4( sgROT_roll, obj_roll[m], ship_fwd );
2072 sgCopyMat4( sgTUX, sgROT_hdg );
2073 sgPostMultMat4( sgTUX, sgROT_pitch );
2074 sgPostMultMat4( sgTUX, sgROT_roll );
2075 sgPostMultMat4( sgTUX, sgROT_lat );
2076 sgPostMultMat4( sgTUX, sgROT_lon );
2077 sgPostMultMat4( sgTUX, sgTRANS );
2080 sgSetCoord(&shippos, sgTUX );
2081 ship_pos[m]->setTransform( &shippos );
2082 // temporary hack for deck lights - ultimately should move to PLib (when ??)
2084 if (lightpoints_transform) {
2085 lightpoints_transform->setTransform( &shippos );
2086 float sun_angle = cur_light_params.sun_angle * SGD_RADIANS_TO_DEGREES;
2087 if ( sun_angle > 89 ) {
2088 lightpoints_brightness->select(0x01);
2090 lightpoints_brightness->select(0x00);
2099 sgXformPnt3( rp, rway_ols, sgTUX );
2100 vp = globals->get_current_view()->get_view_pos();
2101 to[0] = rp[0]-vp[0];
2102 to[1] = rp[1]-vp[1];
2103 to[2] = rp[2]-vp[2];
2104 float dist = sgLengthVec3( to );
2105 alt = (current_aircraft.fdm_state->get_Altitude() * SG_FEET_TO_METER)-rway_ols[2];
2107 elev = asin(alt/dist)*SGD_RADIANS_TO_DEGREES;
2109 ref_elev = elev - 3.75; // +ve above, -ve below
2113 // DO NOT DELETE THIS CODE - This is to compare a discrete FLOLS (without LOD) with analog FLOLS
2114 // if (ref_elev > 0.51) sel = 0x21;
2115 // if ((ref_elev <= 0.51) & (ref_elev > 0.17)) sel = 0x22;
2116 // if ((ref_elev <= 0.17) & (ref_elev >= -0.17)) sel = 0x24;
2117 // if ((ref_elev < -0.17) & (ref_elev >= -0.51)) sel = 0x28;
2118 // if (ref_elev < -0.51) sel = 0x30;
2119 // DO NOT DELETE THIS CODE - This is to compare a discrete FLOLS (without LOD) with analog FLOLS
2120 dummy_tile->lightmaps_sequence->select(sel);
2123 sgCopyVec3 (up, ship_up);
2125 sgScaleVec3 (up, 4.0*ref_elev*dist/750.0);
2127 sgScaleVec3 (up, 4.0*ref_elev);
2128 dummy_tile->ols_transform->setTransform(up);
2129 //cout << "ref_elev " << ref_elev << endl;
2131 // end hack for deck lights
2134 if ( ship_sel != NULL ) {
2135 ship_sel->select(0xFFFFFFFE); // first object is ownship, added to acmodel
2139 // $$$ end - added VS Renganathan, 15 Oct 2K
2140 // added Venky , 12 Nov 2K