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
58 #include <string.h> // for strcmp()
65 #ifdef HAVE_SYS_STAT_H
66 # include <sys/stat.h> // for stat()
70 # include <unistd.h> // for stat()
73 #include <plib/netChat.h>
78 #include <simgear/constants.h> // for VERSION
79 #include <simgear/debug/logstream.hxx>
80 #include <simgear/math/polar3d.hxx>
81 #include <simgear/math/sg_random.h>
82 #include <simgear/misc/sg_path.hxx>
83 #include <simgear/sky/clouds3d/SkySceneLoader.hpp>
84 #include <simgear/sky/clouds3d/SkyUtil.hpp>
85 #include <simgear/sky/sky.hxx>
86 #include <simgear/timing/sg_time.hxx>
88 #include <Include/general.hxx>
90 #include <Aircraft/aircraft.hxx>
92 #include <ATC/ATCmgr.hxx>
93 #include <ATC/ATCdisplay.hxx>
94 #include <ATC/AIMgr.hxx>
97 #include <Autopilot/newauto.hxx>
99 #include <Cockpit/cockpit.hxx>
100 #include <Cockpit/radiostack.hxx>
101 #include <Cockpit/steam.hxx>
103 #include <FDM/UIUCModel/uiuc_aircraftdir.h>
105 #include <Model/acmodel.hxx>
106 #include <Model/loader.hxx>
107 #include <Model/model.hxx>
108 #include <Model/modelmgr.hxx>
109 #include <Main/location.hxx>
110 #include <Model/panelnode.hxx>
111 #ifdef FG_NETWORK_OLK
112 #include <NetworkOLK/network.h>
114 #include <Objects/matlib.hxx>
115 #include <Scenery/scenery.hxx>
116 #include <Scenery/tilemgr.hxx>
117 #ifdef ENABLE_AUDIO_SUPPORT
118 # include <Sound/soundmgr.hxx>
119 # include <Sound/fg_fx.hxx>
120 # include <Sound/morse.hxx>
122 #include <Systems/system_mgr.hxx>
123 #include <Instrumentation/instrument_mgr.hxx>
124 #include <Time/FGEventMgr.hxx>
125 #include <Time/fg_timer.hxx>
126 #include <Time/light.hxx>
127 #include <Time/sunpos.hxx>
128 #include <Time/tmp.hxx>
131 #include <simgear/misc/sgstream.hxx>
132 #include <simgear/math/point3d.hxx>
133 #include <FDM/flight.hxx>
134 #include <FDM/ADA.hxx>
135 #include <Scenery/tileentry.hxx>
137 #include "fg_commands.hxx"
139 // #define FG_EXPERIMENTAL_LIGHTING
140 #ifdef FG_EXPERIMENTAL_LIGHTING
142 typedef void (APIENTRY * PFNGLPOINTPARAMETERFEXTPROC)(GLenum pname,
144 typedef void (APIENTRY * PFNGLPOINTPARAMETERFVEXTPROC)(GLenum pname,
145 const GLfloat *params);
147 PFNGLPOINTPARAMETERFEXTPROC glPointParameterfEXT = 0;
148 PFNGLPOINTPARAMETERFVEXTPROC glPointParameterfvEXT = 0;
152 typedef void (* OpenGLFuncExt)(GLenum pname, GLfloat param);
153 typedef void (* OpenGLFuncExtv)(GLenum pname, const GLfloat *params);
155 OpenGLFuncExt glPointParameterfEXT = 0;
156 OpenGLFuncExtv glPointParameterfvEXT = 0;
160 float default_attenuation[3] = {1.0, 0.0, 0.0};
161 //Required for using GL_extensions
162 void fgLoadDCS (void);
163 void fgUpdateDCS (void);
164 ssgSelector *ship_sel=NULL;
165 // upto 32 instances of a same object can be loaded.
166 ssgTransform *ship_pos[32];
167 double obj_lat[32],obj_lon[32],obj_alt[32],obj_pitch[32],obj_roll[32];
169 ssgSelector *lightpoints_brightness = new ssgSelector;
170 ssgTransform *lightpoints_transform = new ssgTransform;
171 FGTileEntry *dummy_tile;
174 // Clip plane settings...
175 float scene_nearplane = 0.5f;
176 float scene_farplane = 120000.0f;
178 static double delta_time_sec = 0;
182 # include <WeatherCM/FGLocalWeatherDatabase.h>
184 # include <Environment/environment_mgr.hxx>
189 #include "fg_init.hxx"
191 #include "fg_props.hxx"
192 #include "globals.hxx"
193 #include "splash.hxx"
194 #include "viewmgr.hxx"
195 #include "options.hxx"
196 #include "logger.hxx"
199 # include <console.h> // -dw- for command line dialog
203 FGEventMgr global_events;
205 // This is a record containing a bit of global housekeeping information
208 // Specify our current idle function state. This is used to run all
209 // our initializations out of the glutIdleLoop() so that we can get a
210 // splash screen up and running right away.
211 static int idle_state = 0;
212 static long global_multi_loop;
214 // forward declaration
215 void fgReshape( int width, int height );
217 // fog constants. I'm a little nervous about putting actual code out
218 // here but it seems to work (?)
219 static const double m_log01 = -log( 0.01 );
220 static const double sqrt_m_log01 = sqrt( m_log01 );
221 static GLfloat fog_exp_density;
222 static GLfloat fog_exp2_density;
223 static GLfloat rwy_exp2_punch_through;
224 static GLfloat taxi_exp2_punch_through;
225 static GLfloat ground_exp2_punch_through;
227 #ifdef FG_NETWORK_OLK
228 ssgSelector *fgd_sel = NULL;
229 ssgTransform *fgd_pos = NULL;
234 SkySceneLoader *sgClouds3d;
235 bool _bcloud_orig = true;
238 sgMat4 copy_of_ssgOpenGLAxisSwapMatrix =
240 { 1.0f, 0.0f, 0.0f, 0.0f },
241 { 0.0f, 0.0f, -1.0f, 0.0f },
242 { 0.0f, 1.0f, 0.0f, 0.0f },
243 { 0.0f, 0.0f, 0.0f, 1.0f }
246 // The following defines flightgear options. Because glutlib will also
247 // want to parse its own options, those options must not be included here
248 // or they will get parsed by the main program option parser. Hence case
249 // is significant for any option added that might be in conflict with
252 // glutlib parses for:
254 // -direct (invalid in Win32)
258 // -indirect (invalid in Win32)
261 // Note that glutlib depends upon strings while this program's
262 // option parser wants only initial characters followed by numbers
267 ssgSimpleState *cloud3d_imposter_state;
268 ssgSimpleState *default_state;
269 ssgSimpleState *hud_and_panel;
270 ssgSimpleState *menus;
272 SGTimeStamp last_time_stamp;
273 SGTimeStamp current_time_stamp;
275 void fgBuildRenderStates( void ) {
276 default_state = new ssgSimpleState;
277 default_state->ref();
278 default_state->disable( GL_TEXTURE_2D );
279 default_state->enable( GL_CULL_FACE );
280 default_state->enable( GL_COLOR_MATERIAL );
281 default_state->setColourMaterial( GL_AMBIENT_AND_DIFFUSE );
282 default_state->setMaterial( GL_EMISSION, 0, 0, 0, 1 );
283 default_state->setMaterial( GL_SPECULAR, 0, 0, 0, 1 );
284 default_state->disable( GL_BLEND );
285 default_state->disable( GL_ALPHA_TEST );
286 default_state->disable( GL_LIGHTING );
288 cloud3d_imposter_state = new ssgSimpleState;
289 cloud3d_imposter_state->ref();
290 cloud3d_imposter_state->enable( GL_TEXTURE_2D );
291 cloud3d_imposter_state->enable( GL_CULL_FACE );
292 cloud3d_imposter_state->enable( GL_COLOR_MATERIAL );
293 cloud3d_imposter_state->setColourMaterial( GL_AMBIENT_AND_DIFFUSE );
294 cloud3d_imposter_state->setMaterial( GL_DIFFUSE, 1, 1, 1, 1 );
295 cloud3d_imposter_state->setMaterial( GL_AMBIENT, 1, 1, 1, 1 );
296 cloud3d_imposter_state->setMaterial( GL_EMISSION, 0, 0, 0, 1 );
297 cloud3d_imposter_state->setMaterial( GL_SPECULAR, 0, 0, 0, 1 );
298 cloud3d_imposter_state->enable( GL_BLEND );
299 cloud3d_imposter_state->enable( GL_ALPHA_TEST );
300 cloud3d_imposter_state->disable( GL_LIGHTING );
302 hud_and_panel = new ssgSimpleState;
303 hud_and_panel->ref();
304 hud_and_panel->disable( GL_CULL_FACE );
305 hud_and_panel->disable( GL_TEXTURE_2D );
306 hud_and_panel->disable( GL_LIGHTING );
307 hud_and_panel->enable( GL_BLEND );
309 menus = new ssgSimpleState;
311 menus->disable( GL_CULL_FACE );
312 menus->disable( GL_TEXTURE_2D );
313 menus->enable( GL_BLEND );
317 // fgInitVisuals() -- Initialize various GL/view parameters
318 void fgInitVisuals( void ) {
321 l = &cur_light_params;
323 #ifndef GLUT_WRONG_VERSION
324 // Go full screen if requested ...
325 if ( fgGetBool("/sim/startup/fullscreen") ) {
330 // If enabled, normal vectors specified with glNormal are scaled
331 // to unit length after transformation. Enabling this has
332 // performance implications. See the docs for glNormal.
333 // glEnable( GL_NORMALIZE );
335 glEnable( GL_LIGHTING );
336 glEnable( GL_LIGHT0 );
337 // glLightfv( GL_LIGHT0, GL_POSITION, l->sun_vec ); // done later with ssg
340 sgSetVec3( sunpos, l->sun_vec[0], l->sun_vec[1], l->sun_vec[2] );
341 ssgGetLight( 0 ) -> setPosition( sunpos );
343 glFogi (GL_FOG_MODE, GL_EXP2);
344 if ( (!strcmp(fgGetString("/sim/rendering/fog"), "disabled")) ||
345 (!fgGetBool("/sim/rendering/shading"))) {
346 // if fastest fog requested, or if flat shading force fastest
347 glHint ( GL_FOG_HINT, GL_FASTEST );
348 } else if ( !strcmp(fgGetString("/sim/rendering/fog"), "nicest") ) {
349 glHint ( GL_FOG_HINT, GL_NICEST );
351 if ( fgGetBool("/sim/rendering/wireframe") ) {
353 glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
356 // This is the default anyways, but it can't hurt
357 glFrontFace ( GL_CCW );
360 // glEnable(GL_POINT_SMOOTH);
361 // glEnable(GL_LINE_SMOOTH);
362 // glEnable(GL_POLYGON_SMOOTH);
366 // For HiRes screen Dumps using Brian Pauls TR Library
367 void trRenderFrame( void ) {
369 if ( fgPanelVisible() ) {
370 GLfloat height = fgGetInt("/sim/startup/ysize");
372 (current_panel->getViewHeight() - current_panel->getYOffset())
373 * (height / 768.0) + 1;
374 glTranslatef( 0.0, view_h, 0.0 );
377 static GLfloat black[4] = { 0.0, 0.0, 0.0, 1.0 };
378 static GLfloat white[4] = { 1.0, 1.0, 1.0, 1.0 };
380 fgLIGHT *l = &cur_light_params;
382 glClearColor(l->adj_fog_color[0], l->adj_fog_color[1],
383 l->adj_fog_color[2], l->adj_fog_color[3]);
385 glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
387 // set the opengl state to known default values
388 default_state->force();
391 glFogf ( GL_FOG_DENSITY, fog_exp2_density);
392 glFogi ( GL_FOG_MODE, GL_EXP2 );
393 glFogfv ( GL_FOG_COLOR, l->adj_fog_color );
395 // GL_LIGHT_MODEL_AMBIENT has a default non-zero value so if
396 // we only update GL_AMBIENT for our lights we will never get
397 // a completely dark scene. So, we set GL_LIGHT_MODEL_AMBIENT
398 // explicitely to black.
399 glLightModelfv( GL_LIGHT_MODEL_AMBIENT, black );
400 glLightModeli( GL_LIGHT_MODEL_LOCAL_VIEWER, GL_FALSE );
402 ssgGetLight( 0 ) -> setColour( GL_AMBIENT, l->scene_ambient );
404 // texture parameters
405 glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ) ;
406 glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST ) ;
408 // we need a white diffuse light for the phase of the moon
409 ssgGetLight( 0 ) -> setColour( GL_DIFFUSE, white );
412 // draw the ssg scene
413 // return to the desired diffuse color
414 ssgGetLight( 0 ) -> setColour( GL_DIFFUSE, l->scene_diffuse );
415 glEnable( GL_DEPTH_TEST );
416 ssgSetNearFar( scene_nearplane, scene_farplane );
417 ssgCullAndDraw( globals->get_scenery()->get_scene_graph() );
420 glFogf (GL_FOG_DENSITY, rwy_exp2_punch_through);
421 ssgSetNearFar( scene_nearplane, scene_farplane );
422 ssgCullAndDraw( globals->get_scenery()->get_rwy_lights_root() );
424 ssgCullAndDraw( globals->get_scenery()->get_gnd_lights_root() );
426 if (fgGetBool("/environment/clouds/status"))
427 thesky->postDraw( cur_fdm_state->get_Altitude() * SG_FEET_TO_METER );
429 globals->get_model_mgr()->draw();
430 globals->get_aircraft_model()->draw();
434 // Update all Visuals (redraws anything graphics related)
435 void fgRenderFrame() {
437 GLfloat black[4] = { 0.0, 0.0, 0.0, 1.0 };
438 GLfloat white[4] = { 1.0, 1.0, 1.0, 1.0 };
440 // Process/manage pending events
441 global_events.update( delta_time_sec );
443 static const SGPropertyNode *longitude
444 = fgGetNode("/position/longitude-deg");
445 static const SGPropertyNode *latitude
446 = fgGetNode("/position/latitude-deg");
447 static const SGPropertyNode *altitude
448 = fgGetNode("/position/altitude-ft");
449 static const SGPropertyNode *groundlevel_nearplane
450 = fgGetNode("/sim/current-view/ground-level-nearplane-m");
452 // Update the default (kludged) properties.
455 FGViewer *current__view = globals->get_current_view();
457 fgLIGHT *l = &cur_light_params;
458 static double last_visibility = -9999;
461 double actual_visibility;
462 if (fgGetBool("/environment/clouds/status"))
463 actual_visibility = thesky->get_visibility();
465 actual_visibility = fgGetDouble("/environment/visibility-m");
466 if ( actual_visibility != last_visibility ) {
467 last_visibility = actual_visibility;
469 fog_exp_density = m_log01 / actual_visibility;
470 fog_exp2_density = sqrt_m_log01 / actual_visibility;
471 ground_exp2_punch_through = sqrt_m_log01 / (actual_visibility * 1.5);
472 if ( actual_visibility < 8000 ) {
473 rwy_exp2_punch_through = sqrt_m_log01 / (actual_visibility * 2.5);
474 taxi_exp2_punch_through = sqrt_m_log01 / (actual_visibility * 1.5);
476 rwy_exp2_punch_through = sqrt_m_log01 / ( 8000 * 2.5 );
477 taxi_exp2_punch_through = sqrt_m_log01 / ( 8000 * 1.5 );
482 // GLfloat black[4] = { 0.0, 0.0, 0.0, 1.0 };
483 // GLfloat white[4] = { 1.0, 1.0, 1.0, 1.0 };
484 // GLfloat terrain_color[4] = { 0.54, 0.44, 0.29, 1.0 };
485 // GLfloat mat_shininess[] = { 10.0 };
486 GLbitfield clear_mask;
488 if ( idle_state != 1000 ) {
489 // still initializing, draw the splash screen
490 if ( fgGetBool("/sim/startup/splash-screen") ) {
491 fgSplashUpdate(0.0, 1.0);
493 // Keep resetting sim time while the sim is initializing
494 globals->set_sim_time_sec( 0.0 );
496 // idle_state is now 1000 meaning we've finished all our
497 // initializations and are running the main loop, so this will
498 // now work without seg faulting the system.
500 // calculate our current position in cartesian space
501 globals->get_scenery()->set_center( globals->get_scenery()->get_next_center() );
504 fgReshape( fgGetInt("/sim/startup/xsize"),
505 fgGetInt("/sim/startup/ysize") );
507 if ( fgGetBool("/sim/rendering/clouds3d") ) {
508 glClear( GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT );
509 cloud3d_imposter_state->force();
511 glColor4f( 1.0, 1.0, 1.0, 1.0 );
512 glEnable(GL_DEPTH_TEST);
514 glBlendFunc( GL_ONE, GL_ONE_MINUS_SRC_ALPHA ) ;
517 glEnable( GL_TEXTURE_2D );
518 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
519 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
520 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
521 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
524 if ( _bcloud_orig ) {
525 Point3D c = globals->get_scenery()->get_center();
526 sgClouds3d->Set_Cloud_Orig( &c );
527 _bcloud_orig = false;
529 sgClouds3d->Update( current__view->get_absolute_view_pos() );
530 glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ) ;
531 glDisable(GL_DEPTH_TEST);
534 clear_mask = GL_DEPTH_BUFFER_BIT;
535 if ( fgGetBool("/sim/rendering/wireframe") ) {
536 clear_mask |= GL_COLOR_BUFFER_BIT;
539 if ( fgGetBool("/sim/rendering/skyblend") ) {
540 if ( fgGetBool("/sim/rendering/textures") ) {
541 // glClearColor(black[0], black[1], black[2], black[3]);
542 glClearColor(l->adj_fog_color[0], l->adj_fog_color[1],
543 l->adj_fog_color[2], l->adj_fog_color[3]);
544 clear_mask |= GL_COLOR_BUFFER_BIT;
547 glClearColor(l->sky_color[0], l->sky_color[1],
548 l->sky_color[2], l->sky_color[3]);
549 clear_mask |= GL_COLOR_BUFFER_BIT;
551 glClear( clear_mask );
553 // Tell GL we are switching to model view parameters
555 // I really should create a derived ssg node or use a call
556 // back or something so that I can draw the sky within the
557 // ssgCullAndDraw() function, but for now I just mimic what
558 // ssg does to set up the model view matrix
559 glMatrixMode(GL_MODELVIEW);
561 ssgSetCamera( (sgVec4 *)current__view->get_VIEW() );
563 // set the opengl state to known default values
564 default_state->force();
566 // update fog params if visibility has changed
567 double visibility_meters = fgGetDouble("/environment/visibility-m");
568 thesky->set_visibility(visibility_meters);
570 thesky->modify_vis( cur_fdm_state->get_Altitude() * SG_FEET_TO_METER,
571 ( global_multi_loop * fgGetInt("/sim/speed-up") )
572 / (double)fgGetInt("/sim/model-hz") );
574 // Set correct opengl fog density
575 glFogf (GL_FOG_DENSITY, fog_exp2_density);
577 // update the sky dome
578 if ( fgGetBool("/sim/rendering/skyblend") ) {
579 /* cout << "thesky->repaint() sky_color = "
580 << cur_light_params.sky_color[0] << " "
581 << cur_light_params.sky_color[1] << " "
582 << cur_light_params.sky_color[2] << " "
583 << cur_light_params.sky_color[3] << endl;
585 << cur_light_params.fog_color[0] << " "
586 << cur_light_params.fog_color[1] << " "
587 << cur_light_params.fog_color[2] << " "
588 << cur_light_params.fog_color[3] << endl;
589 cout << " sun_angle = " << cur_light_params.sun_angle
590 << " moon_angle = " << cur_light_params.moon_angle
592 thesky->repaint( cur_light_params.sky_color,
593 cur_light_params.adj_fog_color,
594 cur_light_params.sun_angle,
595 cur_light_params.moon_angle,
596 globals->get_ephem()->getNumPlanets(),
597 globals->get_ephem()->getPlanets(),
598 globals->get_ephem()->getNumStars(),
599 globals->get_ephem()->getStars() );
601 /* cout << "thesky->reposition( view_pos = " << view_pos[0] << " "
602 << view_pos[1] << " " << view_pos[2] << endl;
603 cout << " zero_elev = " << zero_elev[0] << " "
604 << zero_elev[1] << " " << zero_elev[2]
605 << " lon = " << cur_fdm_state->get_Longitude()
606 << " lat = " << cur_fdm_state->get_Latitude() << endl;
607 cout << " sun_rot = " << cur_light_params.sun_rotation
608 << " gst = " << SGTime::cur_time_params->getGst() << endl;
609 cout << " sun ra = " << globals->get_ephem()->getSunRightAscension()
610 << " sun dec = " << globals->get_ephem()->getSunDeclination()
611 << " moon ra = " << globals->get_ephem()->getMoonRightAscension()
612 << " moon dec = " << globals->get_ephem()->getMoonDeclination() << endl; */
614 thesky->reposition( current__view->get_view_pos(),
615 current__view->get_zero_elev(),
616 current__view->get_world_up(),
617 current__view->getLongitude_deg()
618 * SGD_DEGREES_TO_RADIANS,
619 current__view->getLatitude_deg()
620 * SGD_DEGREES_TO_RADIANS,
621 current__view->getAltitudeASL_ft() * SG_FEET_TO_METER,
622 cur_light_params.sun_rotation,
623 globals->get_time_params()->getGst(),
624 globals->get_ephem()->getSunRightAscension(),
625 globals->get_ephem()->getSunDeclination(),
627 globals->get_ephem()->getMoonRightAscension(),
628 globals->get_ephem()->getMoonDeclination(),
632 glEnable( GL_DEPTH_TEST );
633 if ( strcmp(fgGetString("/sim/rendering/fog"), "disabled") ) {
635 glFogi( GL_FOG_MODE, GL_EXP2 );
636 glFogfv( GL_FOG_COLOR, l->adj_fog_color );
639 // set sun/lighting parameters
640 ssgGetLight( 0 ) -> setPosition( l->sun_vec );
642 // GL_LIGHT_MODEL_AMBIENT has a default non-zero value so if
643 // we only update GL_AMBIENT for our lights we will never get
644 // a completely dark scene. So, we set GL_LIGHT_MODEL_AMBIENT
645 // explicitely to black.
646 glLightModelfv( GL_LIGHT_MODEL_AMBIENT, black );
648 ssgGetLight( 0 ) -> setColour( GL_AMBIENT, l->scene_ambient );
649 ssgGetLight( 0 ) -> setColour( GL_DIFFUSE, l->scene_diffuse );
650 ssgGetLight( 0 ) -> setColour( GL_SPECULAR, l->scene_specular );
652 // texture parameters
653 // glEnable( GL_TEXTURE_2D );
654 glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ) ;
655 glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST ) ;
657 // glMatrixMode( GL_PROJECTION );
659 ssgSetFOV( current__view->get_h_fov(),
660 current__view->get_v_fov() );
663 current_aircraft.fdm_state->get_Altitude() * SG_FEET_TO_METER
664 - globals->get_scenery()->get_cur_elev();
667 scene_nearplane = 10.0f;
668 scene_farplane = 120000.0f;
670 scene_nearplane = groundlevel_nearplane->getDoubleValue();
671 scene_farplane = 120000.0f;
674 ssgSetNearFar( scene_nearplane, scene_farplane );
676 // $$$ begin - added VS Renganthan 17 Oct 2K
679 // $$$ end - added VS Renganthan 17 Oct 2K
681 # ifdef FG_NETWORK_OLK
682 if ( fgGetBool("/sim/networking/network-olk") ) {
684 other = head->next; /* put listpointer to start */
685 while ( other != tail) { /* display all except myself */
686 if ( strcmp( other->ipadr, fgd_mcp_ip) != 0) {
687 other->fgd_sel->select(1);
688 sgSetCoord( &fgdpos, other->sgFGD_COORD );
689 other->fgd_pos->setTransform( &fgdpos );
694 // fgd_sel->select(1);
695 // sgCopyMat4( sgTUX, current_view.sgVIEW);
697 // sgSetCoord( &fgdpos, sgFGD_VIEW );
698 // fgd_pos->setTransform( &fgdpos);
702 if ( fgGetBool("/sim/rendering/skyblend") ) {
703 // draw the sky backdrop
705 // we need a white diffuse light for the phase of the moon
706 ssgGetLight( 0 ) -> setColour( GL_DIFFUSE, white );
710 // return to the desired diffuse color
711 ssgGetLight( 0 ) -> setColour( GL_DIFFUSE, l->scene_diffuse );
714 // draw the ssg scene
715 glEnable( GL_DEPTH_TEST );
717 ssgSetNearFar( scene_nearplane, scene_farplane );
718 ssgCullAndDraw( globals->get_scenery()->get_scene_graph() );
720 // This is a bit kludgy. Every 200 frames, do an extra
721 // traversal of the scene graph without drawing anything, but
722 // with the field-of-view set to 360x360 degrees. This
723 // ensures that out-of-range random objects that are not in
724 // the current view frustum will still be freed properly.
725 static int counter = 0;
727 if (counter == 200) {
730 // No need to put the near plane too close;
731 // this way, at least the aircraft can be
733 f.setNearFar(1000, 1000000);
735 ssgGetModelviewMatrix(m);
736 globals->get_scenery()->get_scene_graph()->cull(&f, m, true);
740 // change state for lighting here
742 // draw runway lighting
743 glFogf (GL_FOG_DENSITY, rwy_exp2_punch_through);
744 ssgSetNearFar( scene_nearplane, scene_farplane );
746 #ifdef FG_EXPERIMENTAL_LIGHTING
747 // Enable states for drawing points with GL_extension
748 glEnable(GL_POINT_SMOOTH);
750 if (glutExtensionSupported("GL_EXT_point_parameters")) {
751 float quadratic[3] = {1.0, 0.001, 0.0000001};
752 // makes the points fade as they move away
753 glPointParameterfvEXT(GL_DISTANCE_ATTENUATION_EXT, quadratic);
754 glPointParameterfEXT(GL_POINT_SIZE_MIN_EXT, 1.0);
758 // blending function for runway lights
759 glBlendFunc ( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) ;
762 glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
763 glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
764 glEnable(GL_TEXTURE_GEN_S);
765 glEnable(GL_TEXTURE_GEN_T);
766 glPolygonMode(GL_FRONT, GL_POINT);
768 // draw runway lighting
769 ssgCullAndDraw( globals->get_scenery()->get_rwy_lights_root() );
771 // change punch through and then draw taxi lighting
772 glFogf (GL_FOG_DENSITY, taxi_exp2_punch_through);
773 ssgCullAndDraw( globals->get_scenery()->get_taxi_lights_root() );
776 glPolygonMode(GL_FRONT, GL_FILL);
777 glDisable(GL_TEXTURE_GEN_S);
778 glDisable(GL_TEXTURE_GEN_T);
780 //static int _frame_count = 0;
781 //if (_frame_count % 30 == 0) {
782 // printf("SSG: %s\n", ssgShowStats());
790 #ifdef FG_EXPERIMENTAL_LIGHTING
791 if (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 sgClouds3d->Draw((sgVec4 *)current__view->get_VIEW());
831 glEnable( GL_LIGHTING );
832 glEnable( GL_DEPTH_TEST );
833 glBlendFunc ( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ) ;
836 globals->get_model_mgr()->draw();
837 globals->get_aircraft_model()->draw();
839 // display HUD && Panel
841 glDisable( GL_DEPTH_TEST );
842 // glDisable( GL_CULL_FACE );
843 // glDisable( GL_TEXTURE_2D );
845 // update the controls subsystem
846 globals->get_controls()->update(delta_time_sec);
848 hud_and_panel->apply();
851 // Use the hud_and_panel ssgSimpleState for rendering the ATC output
852 // This only works properly if called before the panel call
853 globals->get_ATC_display()->update(delta_time_sec);
855 // update the panel subsystem
856 if ( current_panel != NULL ) {
857 current_panel->update(delta_time_sec);
861 // We can do translucent menus, so why not. :-)
863 glBlendFunc ( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ) ;
865 // glDisable ( GL_BLEND ) ;
867 glEnable( GL_DEPTH_TEST );
870 // Fade out the splash screen over the first three seconds.
871 double t = globals->get_sim_time_sec();
873 fgSplashUpdate(0.0, 1.0);
874 } else if ( t <= 3.0) {
875 fgSplashUpdate(0.0, (3.0 - t) / 2.0);
883 // Update internal time dependent calculations (i.e. flight model)
884 // FIXME: this distinction is obsolete; all subsystems now get delta
886 void fgUpdateTimeDepCalcs() {
887 static bool inited = false;
889 //SG_LOG(SG_FLIGHT,SG_INFO, "Updating time dep calcs()");
891 fgLIGHT *l = &cur_light_params;
893 // Initialize the FDM here if it hasn't been and if we have a
894 // scenery elevation hit.
896 // cout << "cur_fdm_state->get_inited() = " << cur_fdm_state->get_inited()
897 // << " cur_elev = " << scenery.get_cur_elev() << endl;
899 if ( !cur_fdm_state->get_inited() &&
900 globals->get_scenery()->get_cur_elev() > -9990 )
902 SG_LOG(SG_FLIGHT,SG_INFO, "Finally initializing fdm");
904 cur_fdm_state->init();
905 if ( cur_fdm_state->get_bound() ) {
906 cur_fdm_state->unbind();
908 cur_fdm_state->bind();
911 // conceptually, the following block could be done for each fdm
913 if ( !cur_fdm_state->get_inited() ) {
914 // do nothing, fdm isn't inited yet
916 // we have been inited, and we are good to go ...
922 globals->get_autopilot()->update(delta_time_sec);
923 cur_fdm_state->update(delta_time_sec);
924 globals->get_steam()->update(delta_time_sec);
927 globals->get_model_mgr()->update(delta_time_sec);
928 globals->get_aircraft_model()->update(delta_time_sec);
930 // update the view angle
931 globals->get_viewmgr()->update(delta_time_sec);
935 // Update solar system
936 globals->get_ephem()->update( globals->get_time_params()->getMjd(),
937 globals->get_time_params()->getLst(),
938 cur_fdm_state->get_Latitude() );
940 // Update radio stack model
941 current_radiostack->update(delta_time_sec);
945 void fgInitTimeDepCalcs( void ) {
950 static const double alt_adjust_ft = 3.758099;
951 static const double alt_adjust_m = alt_adjust_ft * SG_FEET_TO_METER;
954 // What should we do when we have nothing else to do? Let's get ready
955 // for the next move and update the display?
956 static void fgMainLoop( void ) {
958 static const SGPropertyNode *longitude
959 = fgGetNode("/position/longitude-deg");
960 static const SGPropertyNode *latitude
961 = fgGetNode("/position/latitude-deg");
962 static const SGPropertyNode *altitude
963 = fgGetNode("/position/altitude-ft");
964 static const SGPropertyNode *clock_freeze
965 = fgGetNode("/sim/freeze/clock", true);
966 static const SGPropertyNode *cur_time_override
967 = fgGetNode("/sim/time/cur-time-override", true);
969 // Update the elapsed time.
970 static bool first_time = true;
972 last_time_stamp.stamp();
975 current_time_stamp.stamp();
976 delta_time_sec = double(current_time_stamp - last_time_stamp) / 1000000.0;
977 if (clock_freeze->getBoolValue())
979 last_time_stamp = current_time_stamp;
980 globals->inc_sim_time_sec( delta_time_sec );
982 static long remainder = 0;
984 #ifdef FANCY_FRAME_COUNTER
988 static time_t last_time = 0;
989 static int frames = 0;
990 #endif // FANCY_FRAME_COUNTER
992 SGTime *t = globals->get_time_params();
994 FGLocation * acmodel_location = 0;
995 if(cur_fdm_state->getACModel() != 0) {
996 acmodel_location = (FGLocation *) cur_fdm_state->getACModel()->get3DModel()->getFGLocation();
999 SG_LOG( SG_ALL, SG_DEBUG, "Running Main Loop");
1000 SG_LOG( SG_ALL, SG_DEBUG, "======= ==== ====");
1002 #ifdef FG_NETWORK_OLK
1003 if ( fgGetBool("/sim/networking/network-olk") ) {
1004 if ( net_is_registered == 0 ) { // We first have to reg. to fgd
1005 // printf("FGD: Netupdate\n");
1006 fgd_send_com( "A", FGFS_host); // Send Mat4 data
1007 fgd_send_com( "B", FGFS_host); // Recv Mat4 data
1012 #if defined( ENABLE_PLIB_JOYSTICK )
1013 // Read joystick and update control settings
1014 // if ( fgGetString("/sim/control-mode") == "joystick" )
1016 // fgJoystickRead();
1018 #elif defined( ENABLE_GLUT_JOYSTICK )
1019 // Glut joystick support works by feeding a joystick handler
1020 // function to glut. This is taken care of once in the joystick
1021 // init routine and we don't have to worry about it again.
1024 #ifndef FG_WEATHERCM
1025 globals->get_environment_mgr()->update(delta_time_sec);
1028 // Fix elevation. I'm just sticking this here for now, it should
1029 // probably move eventually
1031 /* printf("Before - ground = %.2f runway = %.2f alt = %.2f\n",
1032 scenery.get_cur_elev(),
1033 cur_fdm_state->get_Runway_altitude() * SG_FEET_TO_METER,
1034 cur_fdm_state->get_Altitude() * SG_FEET_TO_METER); */
1036 // Curt is this code used? I don't see any problems when I comment it out.
1037 if ( acmodel_location != 0 ) {
1038 if ( acmodel_location->get_cur_elev_m() > -9990 && cur_fdm_state->get_inited() ) {
1039 if ( cur_fdm_state->get_Altitude() * SG_FEET_TO_METER <
1040 (acmodel_location->get_cur_elev_m() + alt_adjust_m - 3.0) ) {
1041 // now set aircraft altitude above ground
1042 printf("(*) Current Altitude = %.2f < %.2f forcing to %.2f\n",
1043 cur_fdm_state->get_Altitude() * SG_FEET_TO_METER,
1044 acmodel_location->get_cur_elev_m() + alt_adjust_m - 3.0,
1045 acmodel_location->get_cur_elev_m() + alt_adjust_m );
1046 cur_fdm_state->set_Altitude( (acmodel_location->get_cur_elev_m()
1047 + alt_adjust_m) * SG_METER_TO_FEET );
1048 SG_LOG( SG_ALL, SG_DEBUG,
1049 "<*> resetting altitude to "
1050 << cur_fdm_state->get_Altitude() * SG_FEET_TO_METER
1055 // End of code in question. (see Curt is this code used? above)
1057 /* printf("Adjustment - ground = %.2f runway = %.2f alt = %.2f\n",
1058 scenery.get_cur_elev(),
1059 cur_fdm_state->get_Runway_altitude() * SG_FEET_TO_METER,
1060 cur_fdm_state->get_Altitude() * SG_FEET_TO_METER); */
1062 // cout << "Warp = " << globals->get_warp() << endl;
1065 static bool last_clock_freeze = false;
1067 if ( clock_freeze->getBoolValue() ) {
1068 // clock freeze requested
1069 if ( cur_time_override->getLongValue() == 0 ) {
1070 fgSetLong( "/sim/time/cur-time-override", t->get_cur_time() );
1071 globals->set_warp( 0 );
1074 // no clock freeze requested
1075 if ( last_clock_freeze == true ) {
1076 // clock just unfroze, let's set warp as the difference
1077 // between frozen time and current time so we don't get a
1078 // time jump (and corresponding sky object and lighting
1080 globals->set_warp( cur_time_override->getLongValue() - time(NULL) );
1081 fgSetLong( "/sim/time/cur-time-override", 0 );
1083 if ( globals->get_warp_delta() != 0 ) {
1084 globals->inc_warp( globals->get_warp_delta() );
1088 last_clock_freeze = clock_freeze->getBoolValue();
1090 t->update( longitude->getDoubleValue() * SGD_DEGREES_TO_RADIANS,
1091 latitude->getDoubleValue() * SGD_DEGREES_TO_RADIANS,
1092 cur_time_override->getLongValue(),
1093 globals->get_warp() );
1095 if ( globals->get_warp_delta() != 0 ) {
1096 fgUpdateSkyAndLightingParams();
1099 // update magvar model
1100 globals->get_mag()->update( longitude->getDoubleValue()
1101 * SGD_DEGREES_TO_RADIANS,
1102 latitude->getDoubleValue()
1103 * SGD_DEGREES_TO_RADIANS,
1104 altitude->getDoubleValue() * SG_FEET_TO_METER,
1105 globals->get_time_params()->getJD() );
1107 // Get elapsed time (in usec) for this past frame
1108 elapsed = fgGetTimeInterval();
1109 SG_LOG( SG_ALL, SG_DEBUG,
1110 "Elapsed time interval is = " << elapsed
1111 << ", previous remainder is = " << remainder );
1113 // Calculate frame rate average
1114 #ifdef FANCY_FRAME_COUNTER
1115 /* old fps calculation */
1116 if ( elapsed > 0 ) {
1119 for ( i = FG_FRAME_RATE_HISTORY - 2; i >= 0; i-- ) {
1120 tmp = general.get_frame(i);
1122 // printf("frame[%d] = %.2f\n", i, g->frames[i]);
1123 general.set_frame(i+1,tmp);
1125 tmp = 1000000.0 / (float)elapsed;
1126 general.set_frame(0,tmp);
1127 // printf("frame[0] = %.2f\n", general.frames[0]);
1129 general.set_frame_rate(accum / (float)FG_FRAME_RATE_HISTORY);
1130 // printf("ave = %.2f\n", general.frame_rate);
1133 if ( (t->get_cur_time() != last_time) && (last_time > 0) ) {
1134 general.set_frame_rate( frames );
1135 SG_LOG( SG_ALL, SG_DEBUG,
1136 "--> Frame rate is = " << general.get_frame_rate() );
1139 last_time = t->get_cur_time();
1143 // Run ATC subsystem
1144 globals->get_ATC_mgr()->update(delta_time_sec);
1146 // Run the AI subsystem
1147 if (fgGetBool("/sim/ai-traffic/enabled"))
1148 globals->get_AI_mgr()->update(delta_time_sec);
1152 // Calculate model iterations needed for next frame
1153 elapsed += remainder;
1155 global_multi_loop = (long)(((double)elapsed * 0.000001) *
1156 fgGetInt("/sim/model-hz"));
1157 remainder = elapsed - ( (global_multi_loop*1000000) /
1158 fgGetInt("/sim/model-hz") );
1159 SG_LOG( SG_ALL, SG_DEBUG,
1160 "Model iterations needed = " << global_multi_loop
1161 << ", new remainder = " << remainder );
1163 // chop max interations to something reasonable if the sim was
1164 // delayed for an excesive amount of time
1165 if ( global_multi_loop > 2.0 * fgGetInt("/sim/model-hz") ) {
1166 global_multi_loop = (int)(2.0 * fgGetInt("/sim/model-hz") );
1171 if ( global_multi_loop > 0 ) {
1172 fgUpdateTimeDepCalcs();
1174 SG_LOG( SG_ALL, SG_DEBUG,
1175 "Elapsed time is zero ... we're zinging" );
1178 // Do any I/O channel work that might need to be done
1179 globals->get_io()->update( delta_time_sec );
1181 // see if we need to load any deferred-load textures
1182 material_lib.load_next_deferred();
1184 // Run audio scheduler
1185 #ifdef ENABLE_AUDIO_SUPPORT
1186 if ( fgGetBool("/sim/sound/audible")
1187 && globals->get_soundmgr()->is_working() ) {
1188 globals->get_soundmgr()->update( delta_time_sec );
1192 globals->get_subsystem_mgr()->update(delta_time_sec);
1195 // Tile Manager updates - see if we need to load any new scenery tiles.
1196 // this code ties together the fdm, viewer and scenery classes...
1197 // we may want to move this to it's own class at some point
1199 double visibility_meters = fgGetDouble("/environment/visibility-m");
1200 FGViewer *current_view = globals->get_current_view();
1202 // update tile manager for FDM...
1203 // ...only if location is different than the viewer (to avoid duplicating effort)
1204 if( acmodel_location != current_view->getFGLocation() ) {
1205 if( acmodel_location != 0 ) {
1206 globals->get_tile_mgr()->prep_ssg_nodes( acmodel_location,
1207 visibility_meters );
1208 globals->get_tile_mgr()->
1209 update( acmodel_location, visibility_meters,
1210 acmodel_location->get_absolute_view_pos() );
1211 // save results of update in FGLocation for fdm...
1212 if ( globals->get_scenery()->get_cur_elev() > -9990 ) {
1214 set_cur_elev_m( globals->get_scenery()->get_cur_elev() );
1217 set_tile_center( globals->get_scenery()->get_next_center() );
1221 globals->get_tile_mgr()->prep_ssg_nodes( current_view->getFGLocation(),
1222 visibility_meters );
1223 // update tile manager for view...
1224 // IMPORTANT!!! the tilemgr update for view location _must_ be done last
1225 // after the FDM's until all of Flight Gear code references the viewer's location
1226 // for elevation instead of the "scenery's" current elevation.
1227 FGLocation *view_location = globals->get_current_view()->getFGLocation();
1228 globals->get_tile_mgr()->update( view_location, visibility_meters,
1229 current_view->get_absolute_view_pos() );
1230 // save results of update in FGLocation for fdm...
1231 if ( globals->get_scenery()->get_cur_elev() > -9990 ) {
1232 current_view->getFGLocation()->set_cur_elev_m( globals->get_scenery()->get_cur_elev() );
1234 current_view->getFGLocation()->set_tile_center( globals->get_scenery()->get_next_center() );
1236 // If fdm location is same as viewer's then we didn't do the update for fdm location
1237 // above so we need to save the viewer results in the fdm FGLocation as well...
1238 if( acmodel_location == current_view->getFGLocation() ) {
1239 if( acmodel_location != 0 ) {
1240 if ( globals->get_scenery()->get_cur_elev() > -9990 ) {
1241 acmodel_location->set_cur_elev_m( globals->get_scenery()->get_cur_elev() );
1243 acmodel_location->set_tile_center( globals->get_scenery()->get_next_center() );
1247 // END Tile Manager udpates
1252 SG_LOG( SG_ALL, SG_DEBUG, "" );
1256 // This is the top level master main function that is registered as
1257 // our idle funciton
1259 // The first few passes take care of initialization things (a couple
1260 // per pass) and once everything has been initialized fgMainLoop from
1263 static void fgIdleFunction ( void ) {
1264 // printf("idle state == %d\n", idle_state);
1266 if ( idle_state == 0 ) {
1267 // Initialize the splash screen right away
1268 if ( fgGetBool("/sim/startup/splash-screen") ) {
1273 } else if ( idle_state == 1 ) {
1274 // Initialize audio support
1275 #ifdef ENABLE_AUDIO_SUPPORT
1277 // Start the intro music
1278 if ( fgGetBool("/sim/startup/intro-music") ) {
1279 SGPath mp3file( globals->get_fg_root() );
1280 mp3file.append( "Sounds/intro.mp3" );
1282 SG_LOG( SG_GENERAL, SG_INFO,
1283 "Starting intro music: " << mp3file.str() );
1285 #if defined( __CYGWIN__ )
1286 string command = "start /m `cygpath -w " + mp3file.str() + "`";
1287 #elif defined( WIN32 )
1288 string command = "start /m " + mp3file.str();
1290 string command = "mpg123 " + mp3file.str() + "> /dev/null 2>&1";
1293 system ( command.c_str() );
1298 } else if ( idle_state == 2 ) {
1299 // These are a few miscellaneous things that aren't really
1300 // "subsystems" but still need to be initialized.
1303 if ( strstr ( general.get_glRenderer(), "Glide" ) ) {
1304 grTexLodBiasValue ( GR_TMU0, 1.0 ) ;
1309 } else if ( idle_state == 3 ) {
1310 // This is the top level init routine which calls all the
1311 // other subsystem initialization routines. If you are adding
1312 // a subsystem to flightgear, its initialization call should
1313 // located in this routine.
1314 if( !fgInitSubsystems()) {
1315 SG_LOG( SG_GENERAL, SG_ALERT,
1316 "Subsystem initializations failed ..." );
1321 } else if ( idle_state == 4 ) {
1322 // setup OpenGL view parameters
1326 } else if ( idle_state == 5 ) {
1329 } else if ( idle_state == 6 ) {
1333 SG_LOG( SG_GENERAL, SG_INFO, "Panel visible = " << fgPanelVisible() );
1334 fgReshape( fgGetInt("/sim/startup/xsize"),
1335 fgGetInt("/sim/startup/ysize") );
1338 if ( idle_state == 1000 ) {
1339 // We've finished all our initialization steps, from now on we
1340 // run the main loop.
1342 glutIdleFunc(fgMainLoop);
1344 if ( fgGetBool("/sim/startup/splash-screen") ) {
1345 fgSplashUpdate(0.0, 1.0);
1350 // options.cxx needs to see this for toggle_panel()
1351 // Handle new window size or exposure
1352 void fgReshape( int width, int height ) {
1355 if ( (!fgGetBool("/sim/virtual-cockpit"))
1356 && fgPanelVisible() && idle_state == 1000 ) {
1357 view_h = (int)(height * (current_panel->getViewHeight() -
1358 current_panel->getYOffset()) / 768.0);
1364 FGViewMgr *viewmgr = globals->get_viewmgr();
1365 for ( int i = 0; i < viewmgr->size(); ++i ) {
1366 viewmgr->get_view(i)->
1367 set_aspect_ratio((float)view_h / (float)width);
1370 glViewport( 0, (GLint)(height - view_h), (GLint)(width), (GLint)(view_h) );
1372 fgSetInt("/sim/startup/xsize", width);
1373 fgSetInt("/sim/startup/ysize", height);
1374 guiInitMouse(width, height);
1376 ssgSetFOV( viewmgr->get_current_view()->get_h_fov(),
1377 viewmgr->get_current_view()->get_v_fov() );
1380 sgClouds3d->Resize( viewmgr->get_current_view()->get_h_fov(),
1381 viewmgr->get_current_view()->get_v_fov() );
1384 // Initialize GLUT and define a main window
1385 static bool fgGlutInit( int *argc, char **argv ) {
1387 #if !defined( macintosh )
1388 // GLUT will extract all glut specific options so later on we only
1389 // need wory about our own.
1390 glutInit(argc, argv);
1393 // Define Display Parameters. Clouds3d works best with --bpp32 option
1394 if ( fgGetBool("/sim/rendering/clouds3d") ) {
1395 glutInitDisplayMode( GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE | GLUT_ALPHA );
1397 glutInitDisplayMode( GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE );
1400 SG_LOG( SG_GENERAL, SG_INFO, "Opening a window: " <<
1401 fgGetInt("/sim/startup/xsize") << "x"
1402 << fgGetInt("/sim/startup/ysize") );
1404 // Define initial window size
1405 glutInitWindowSize( fgGetInt("/sim/startup/xsize"),
1406 fgGetInt("/sim/startup/ysize") );
1408 // Initialize windows
1409 if ( !fgGetBool("/sim/startup/game-mode")) {
1410 // Open the regular window
1411 glutCreateWindow("FlightGear");
1412 #ifndef GLUT_WRONG_VERSION
1414 // Open the cool new 'game mode' window
1415 char game_mode_str[256];
1416 //#define SYNC_OPENGL_WITH_DESKTOP_SETTINGS
1417 #if defined(WIN32) && defined(SYNC_OPENGL_WITH_DESKTOP_SETTINGS)
1418 #ifndef ENUM_CURRENT_SETTINGS
1419 #define ENUM_CURRENT_SETTINGS ((DWORD)-1)
1420 #define ENUM_REGISTRY_SETTINGS ((DWORD)-2)
1424 dm.dmSize = sizeof(DEVMODE);
1425 EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &dm);
1426 fgSetInt("/sim/startup/xsize", dm.dmPelsWidth);
1427 fgSetInt("/sim/startup/ysize", dm.dmPelsHeight);
1428 glutInitWindowSize( fgGetInt("/sim/startup/xsize"),
1429 fgGetInt("/sim/startup/ysize") );
1430 sprintf( game_mode_str, "%dx%d:%d@%d",
1434 dm.dmDisplayFrequency );
1436 // Open the cool new 'game mode' window
1437 sprintf( game_mode_str, "width=%d height=%d bpp=%d",
1438 fgGetInt("/sim/startup/xsize"),
1439 fgGetInt("/sim/startup/ysize"),
1440 fgGetInt("/sim/rendering/bits-per-pixel"));
1442 #endif // HAVE_WINDOWS_H
1443 SG_LOG( SG_GENERAL, SG_INFO,
1444 "game mode params = " << game_mode_str );
1445 glutGameModeString( game_mode_str );
1446 glutEnterGameMode();
1447 #endif // GLUT_WRONG_VERSION
1450 // This seems to be the absolute earliest in the init sequence
1451 // that these calls will return valid info. Too bad it's after
1452 // we've already created and sized out window. :-(
1453 general.set_glVendor( (char *)glGetString ( GL_VENDOR ) );
1454 general.set_glRenderer( (char *)glGetString ( GL_RENDERER ) );
1455 general.set_glVersion( (char *)glGetString ( GL_VERSION ) );
1456 SG_LOG( SG_GENERAL, SG_INFO, general.get_glRenderer() );
1459 glGetIntegerv( GL_MAX_TEXTURE_SIZE, &tmp );
1460 general.set_glMaxTexSize( tmp );
1461 SG_LOG ( SG_GENERAL, SG_INFO, "Max texture size = " << tmp );
1463 glGetIntegerv( GL_DEPTH_BITS, &tmp );
1464 general.set_glDepthBits( tmp );
1465 SG_LOG ( SG_GENERAL, SG_INFO, "Depth buffer bits = " << tmp );
1471 // Initialize GLUT event handlers
1472 static bool fgGlutInitEvents( void ) {
1473 // call fgReshape() on window resizes
1474 glutReshapeFunc( fgReshape );
1476 // keyboard and mouse callbacks are set in FGInput::init
1478 // call fgMainLoop() whenever there is
1479 // nothing else to do
1480 glutIdleFunc( fgIdleFunction );
1483 glutDisplayFunc( fgRenderFrame );
1488 // Main top level initialization
1489 static bool fgMainInit( int argc, char **argv ) {
1491 #if defined( macintosh )
1492 freopen ("stdout.txt", "w", stdout );
1493 freopen ("stderr.txt", "w", stderr );
1494 argc = ccommand( &argv );
1497 // set default log levels
1498 sglog().setLogLevels( SG_ALL, SG_INFO );
1501 #ifdef FLIGHTGEAR_VERSION
1502 version = FLIGHTGEAR_VERSION;
1504 version = "unknown version";
1506 SG_LOG( SG_GENERAL, SG_INFO, "FlightGear: Version "
1508 SG_LOG( SG_GENERAL, SG_INFO, "Built with " << SG_COMPILER_STR << endl );
1510 // Allocate global data structures. This needs to happen before
1511 // we parse command line options
1513 globals = new FGGlobals;
1515 #ifndef FG_WEATHERCM
1516 globals->set_environment_mgr(new FGEnvironmentMgr);
1519 // seed the random number generater
1522 SGRoute *route = new SGRoute;
1523 globals->set_route( route );
1525 FGControls *controls = new FGControls;
1526 globals->set_controls( controls );
1528 FGSteam *steam = new FGSteam;
1529 globals->set_steam( steam );
1531 string_list *col = new string_list;
1532 globals->set_channel_options_list( col );
1534 // Scan the config file(s) and command line options to see if
1535 // fg_root was specified (ignore all other options for now)
1536 fgInitFGRoot(argc, argv);
1538 // Check for the correct base package version
1539 static char required_version[] = "0.9.1";
1540 string base_version = fgBasePackageVersion();
1541 if ( !(base_version == required_version) ) {
1542 // tell the operator how to use this application
1544 cerr << endl << "Base package check failed ... " \
1545 << "Found version " << base_version << " at: " \
1546 << globals->get_fg_root() << endl;
1547 cerr << "Please upgrade to version" << required_version << endl;
1551 // Initialize the Aircraft directory to "" (UIUC)
1554 // Load the configuration parameters. (Command line options
1555 // overrides config file options. Config file options override
1557 if ( !fgInitConfig(argc, argv) ) {
1558 SG_LOG( SG_GENERAL, SG_ALERT, "Config option parsing failed ..." );
1562 // Initialize the Window/Graphics environment.
1563 if( !fgGlutInit(&argc, argv) ) {
1564 SG_LOG( SG_GENERAL, SG_ALERT, "GLUT initialization failed ..." );
1568 // Initialize the various GLUT Event Handlers.
1569 if( !fgGlutInitEvents() ) {
1570 SG_LOG( SG_GENERAL, SG_ALERT,
1571 "GLUT event handler initialization failed ..." );
1575 // Initialize plib net interface
1576 netInit( &argc, argv );
1578 // Initialize ssg (from plib). Needs to come before we do any
1579 // other ssg stuff, but after opengl/glut has been initialized.
1582 // Initialize the user interface (we need to do this before
1583 // passing off control to glut and before fgInitGeneral to get our
1587 #ifdef GL_EXT_texture_lod_bias
1588 glTexEnvf( GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, -0.5 ) ;
1591 #ifdef FG_EXPERIMENTAL_LIGHTING
1592 // get the address of our OpenGL extensions
1594 glPointParameterfEXT = (PFNGLPOINTPARAMETERFEXTPROC)
1595 wglGetProcAddress("glPointParameterfEXT");
1596 glPointParameterfvEXT = (PFNGLPOINTPARAMETERFVEXTPROC)
1597 wglGetProcAddress("glPointParameterfvEXT");
1599 glPointParameterfEXT = (OpenGLFuncExt)
1600 glXGetProcAddressARB((GLubyte *)"glPointParameterfEXT");
1601 glPointParameterfvEXT = (OpenGLFuncExtv)
1602 glXGetProcAddressARB((GLubyte *)"glPointParameterfvEXT");
1606 // based on the requested presets, calculate the true starting
1610 SGTime *t = fgInitTime();
1611 globals->set_time_params( t );
1613 // Do some quick general initializations
1614 if( !fgInitGeneral()) {
1615 SG_LOG( SG_GENERAL, SG_ALERT,
1616 "General initializations failed ..." );
1620 SGPath modelpath( globals->get_fg_root() );
1621 ssgModelPath( (char *)modelpath.c_str() );
1623 // Initialize the global scenery manager
1624 globals->set_scenery( new FGScenery );
1625 globals->get_scenery()->init();
1626 globals->get_scenery()->bind();
1628 // Initialize the global tile manager
1629 globals->set_tile_mgr( new FGTileMgr );
1631 ////////////////////////////////////////////////////////////////////
1632 // Initialize the property-based built-in commands
1633 ////////////////////////////////////////////////////////////////////
1636 ////////////////////////////////////////////////////////////////////
1637 // Initialize the general model subsystem.
1638 ////////////////////////////////////////////////////////////////////
1640 globals->set_model_loader(new FGModelLoader);
1641 globals->set_texture_loader(new FGTextureLoader);
1642 globals->set_model_mgr(new FGModelMgr);
1643 globals->get_model_mgr()->init();
1644 globals->get_model_mgr()->bind();
1646 ////////////////////////////////////////////////////////////////////
1647 // Initialize the 3D aircraft model subsystem.
1648 ////////////////////////////////////////////////////////////////////
1650 globals->set_aircraft_model(new FGAircraftModel);
1651 globals->get_aircraft_model()->init();
1652 globals->get_aircraft_model()->bind();
1654 ////////////////////////////////////////////////////////////////////
1655 // Initialize the view manager subsystem.
1656 ////////////////////////////////////////////////////////////////////
1658 FGViewMgr *viewmgr = new FGViewMgr;
1659 globals->set_viewmgr( viewmgr );
1664 // Initialize the sky
1665 SGPath ephem_data_path( globals->get_fg_root() );
1666 ephem_data_path.append( "Astro" );
1667 SGEphemeris *ephem = new SGEphemeris( ephem_data_path.c_str() );
1668 ephem->update( globals->get_time_params()->getMjd(),
1669 globals->get_time_params()->getLst(),
1671 globals->set_ephem( ephem );
1673 // TODO: move to environment mgr
1675 SGPath texture_path(globals->get_fg_root());
1676 texture_path.append("Textures");
1677 texture_path.append("Sky");
1678 for (int i = 0; i < FGEnvironmentMgr::MAX_CLOUD_LAYERS; i++) {
1679 SGCloudLayer * layer = new SGCloudLayer(texture_path.str());
1680 thesky->add_cloud_layer(layer);
1684 SGPath sky_tex_path( globals->get_fg_root() );
1685 sky_tex_path.append( "Textures" );
1686 sky_tex_path.append( "Sky" );
1687 thesky->texture_path( sky_tex_path.str() );
1689 thesky->build( 550.0, 550.0,
1690 globals->get_ephem()->getNumPlanets(),
1691 globals->get_ephem()->getPlanets(), 60000.0,
1692 globals->get_ephem()->getNumStars(),
1693 globals->get_ephem()->getStars(), 60000.0 );
1695 // Initialize MagVar model
1696 SGMagVar *magvar = new SGMagVar();
1697 globals->set_mag( magvar );
1699 // airport = new ssgBranch;
1700 // airport->setName( "Airport Lighting" );
1701 // lighting->addKid( airport );
1707 #ifdef FG_NETWORK_OLK
1708 // Do the network intialization
1709 if ( fgGetBool("/sim/networking/network-olk") ) {
1710 printf("Multipilot mode %s\n",
1711 fg_net_init( globals->get_scenery()->get_scene_graph() ) );
1715 // build our custom render states
1716 fgBuildRenderStates();
1718 // pass control off to the master GLUT event handler
1721 // we never actually get here ... but to avoid compiler warnings,
1727 // $$$ end - added VS Renganathan, 15 Oct 2K
1728 // - added Venky , 12 Nov 2K
1730 #if defined(__linux__) && defined(__i386__)
1732 static void handleFPE (int);
1737 fpu_control_t fpe_flags = 0;
1738 _FPU_GETCW(fpe_flags);
1739 // fpe_flags &= ~_FPU_MASK_IM; // invalid operation
1740 // fpe_flags &= ~_FPU_MASK_DM; // denormalized operand
1741 // fpe_flags &= ~_FPU_MASK_ZM; // zero-divide
1742 // fpe_flags &= ~_FPU_MASK_OM; // overflow
1743 // fpe_flags &= ~_FPU_MASK_UM; // underflow
1744 // fpe_flags &= ~_FPU_MASK_PM; // precision (inexact result)
1745 _FPU_SETCW(fpe_flags);
1746 signal(SIGFPE, handleFPE);
1753 SG_LOG(SG_GENERAL, SG_ALERT, "Floating point interrupt (SIGFPE)");
1766 short CPSGetCurrentProcess(PSN *psn);
1767 short CPSSetProcessName (PSN *psn, char *processname);
1768 short CPSEnableForegroundOperation(PSN *psn, int _arg2, int _arg3, int _arg4, int _arg5);
1769 short CPSSetFrontProcess(PSN *psn);
1772 #define CPSEnableFG(psn) CPSEnableForegroundOperation(psn,0x03,0x3C,0x2C,0x1103)
1776 // Main entry point; catch any exceptions that have made it this far.
1777 int main ( int argc, char **argv ) {
1779 // Enable floating-point exceptions for Linux/x86
1780 #if defined(__linux__) && defined(__i386__)
1784 // Enable floating-point exceptions for Windows
1785 #if defined( _MSC_VER ) && defined( DEBUG )
1786 // Christian, we should document what this does
1787 _control87( _EM_INEXACT, _MCW_EM );
1790 #if defined( HAVE_BC5PLUS )
1791 _control87(MCW_EM, MCW_EM); /* defined in float.h */
1794 // Keyboard focus hack
1799 glutInit (&argc, argv);
1801 CPSGetCurrentProcess(&psn);
1802 CPSSetProcessName(&psn, "FlightGear");
1804 CPSSetFrontProcess(&psn);
1808 // FIXME: add other, more specific
1811 fgMainInit(argc, argv);
1812 } catch (sg_throwable &t) {
1813 // We must use cerr rather than
1814 // logging, since logging may be
1816 cerr << "Fatal error: " << t.getFormattedMessage()
1817 << "\n (received from " << t.getOrigin() << ')' << endl;
1825 void fgLoadDCS(void) {
1827 ssgEntity *ship_obj = NULL;
1829 char obj_filename[25];
1831 for ( int k = 0; k < 32; k++ ) {
1835 SGPath tile_path( globals->get_fg_root());
1836 tile_path.append( "Scenery" );
1837 tile_path.append( "Objects.txt" );
1838 sg_gzifstream in( tile_path.str() );
1839 if ( ! in.is_open() ) {
1840 SG_LOG( SG_TERRAIN, SG_ALERT, "Cannot open file: " << tile_path.str() );
1843 SGPath modelpath( globals->get_fg_root() );
1844 modelpath.append( "Models" );
1845 modelpath.append( "Geometry" );
1847 SGPath texturepath( globals->get_fg_root() );
1848 texturepath.append( "Models" );
1849 texturepath.append( "Textures" );
1851 ssgModelPath( (char *)modelpath.c_str() );
1852 ssgTexturePath( (char *)texturepath.c_str() );
1854 ship_sel = new ssgSelector;
1857 while ( ! in.eof() ) {
1859 if ( in.get( c ) && c == '#' ) {
1863 in >> obj_filename >> obj_lat[objc] >> obj_lon[objc] >> obj_alt[objc];
1864 /* cout << endl << obj_filename << " " << obj_lat[objc] << " " << obj_lon[objc] << " " << obj_alt[objc] << endl;
1865 int chj=getchar();*/
1867 obj_lon[objc] *=SGD_DEGREES_TO_RADIANS;
1868 obj_lat[objc] *=SGD_DEGREES_TO_RADIANS;
1870 ship_pos[objc] = new ssgTransform;
1872 // type "repeat" in objects.txt to load one more
1873 // instance of the last object.
1875 if ( strcmp(obj_filename,"repeat") != 0) {
1877 globals->get_model_loader()->load_model( obj_filename );
1880 if ( ship_obj != NULL ) {
1881 ship_obj->setName(obj_filename);
1883 ship_obj->clrTraversalMaskBits( SSGTRAV_HOT );
1885 ship_obj->setTraversalMaskBits( SSGTRAV_HOT );
1886 ship_pos[objc]->addKid( ship_obj ); // add object to transform node
1887 ship_sel->addKid( ship_pos[objc] ); // add transform node to selector
1888 SG_LOG( SG_TERRAIN, SG_ALERT, "Loaded file: "
1891 SG_LOG( SG_TERRAIN, SG_ALERT, "Cannot open file: "
1895 // temporary hack for deck lights - ultimately should move to PLib (when??)
1896 //const char *extn = file_extension ( obj_filename ) ;
1898 ssgVertexArray *lights = new ssgVertexArray( 100 );
1899 ssgVertexArray *lightpoints = new ssgVertexArray( 100 );
1900 ssgVertexArray *lightnormals = new ssgVertexArray( 100 );
1901 ssgVertexArray *lightdir = new ssgVertexArray( 100 );
1902 int ltype[500], light_type;
1903 static int ltcount = 0;
1905 sgVec3 rway_dir,rway_normal,lightpt;
1907 modelpath.append(obj_filename);
1908 sg_gzifstream in1( modelpath.str() );
1909 if ( ! in1.is_open() ) {
1910 SG_LOG( SG_TERRAIN, SG_ALERT, "Cannot open file: " << modelpath.str() );
1912 while ( ! in1.eof() ) {
1914 if ( in1.get( c ) && c == '#' ) {
1919 //cout << token << endl;
1920 if ( token == "runway" ) {
1922 sgSetVec3 (rway_dir, node[0], node[1], node[2] );
1923 } else if ( token == "edgelight" ) {
1925 sgSetVec3 (rway_normal, node[0], node[1], node[2] );
1927 } else if ( token == "taxi" ) {
1929 sgSetVec3 (rway_normal, node[0], node[1], node[2] );
1931 } else if ( token == "vasi" ) {
1933 sgSetVec3 (rway_normal, node[0], node[1], node[2] );
1935 } else if ( token == "threshold" ) {
1937 sgSetVec3 (rway_normal, node[0], node[1], node[2] );
1939 } else if ( token == "rabbit" ) {
1941 sgSetVec3 (rway_normal, node[0], node[1], node[2] );
1943 } else if ( token == "ols" ) {
1945 sgSetVec3 (rway_ols, node[0], node[1], node[2] );
1947 } else if ( token == "red" ) {
1949 sgSetVec3 (rway_normal, node[0], node[1], node[2] );
1951 } else if ( token == "green" ) {
1953 sgSetVec3 (rway_normal, node[0], node[1], node[2] );
1955 } else if ( token == "lp" ) {
1957 sgSetVec3 (lightpt, node[0], node[1], node[2] );
1958 lightpoints->add( lightpt );
1959 lightnormals->add( rway_normal );
1960 lightdir->add( rway_dir );
1961 ltype[ltcount]= light_type;
1964 if (in1.eof()) break;
1968 if ( lightpoints->getNum() ) {
1969 ssgBranch *lightpoints_branch;
1970 long int dummy = -999;
1971 dummy_tile = new FGTileEntry((SGBucket)dummy);
1972 dummy_tile->lightmaps_sequence = new ssgSelector;
1973 dummy_tile->ols_transform = new ssgTransform;
1975 // call function to generate the runway lights
1976 lightpoints_branch =
1977 dummy_tile->gen_runway_lights( lightpoints, lightnormals,
1979 lightpoints_brightness->addKid(lightpoints_branch);
1980 lightpoints_transform->addKid(lightpoints_brightness);
1981 //dummy_tile->lightmaps_sequence->setTraversalMaskBits( SSGTRAV_HOT );
1982 lightpoints_transform->addKid( dummy_tile->lightmaps_sequence );
1983 lightpoints_transform->ref();
1984 globals->get_scenery()->get_gnd_lights_root()->addKid( lightpoints_transform );
1988 // end hack for deck lights
1992 if (in.eof()) break;
1996 SG_LOG ( SG_TERRAIN, SG_ALERT, "Finished object processing." );
1998 globals->get_scenery()->get_terrain_branch()->addKid( ship_sel ); //add selector node to root node
2005 void fgUpdateDCS (void) {
2007 // double eye_lat,eye_lon,eye_alt;
2008 // static double obj_head;
2009 double sl_radius,obj_latgc;
2010 // float nresultmat[4][4];
2011 // sgMat4 Trans,rothead,rotlon,rot180,rotlat,resultmat1,resultmat2,resultmat3;
2014 // Instantaneous Geodetic Lat/Lon/Alt of moving object
2015 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
2017 // Deck should be the first object in objects.txt in case of fdm=ada
2019 if (!strcmp(fgGetString("/sim/flight-model"), "ada")) {
2020 if ((fdm->get_iaux(1))==1)
2022 obj_lat[1] = fdm->get_daux(1)*SGD_DEGREES_TO_RADIANS;
2023 obj_lon[1] = fdm->get_daux(2)*SGD_DEGREES_TO_RADIANS;
2024 obj_alt[1] = fdm->get_daux(3);
2025 obj_pitch[1] = fdm->get_faux(1);
2026 obj_roll[1] = fdm->get_faux(2);
2030 for ( int m = 0; m < objc; m++ ) {
2031 //cout << endl << obj_lat[m]*SGD_RADIANS_TO_DEGREES << " " << obj_lon[m]*SGD_RADIANS_TO_DEGREES << " " << obj_alt[m] << " " << objc << endl;
2034 //Geodetic to Geocentric angles for rotation
2035 sgGeodToGeoc(obj_lat[m],obj_alt[m],&sl_radius,&obj_latgc);
2037 //moving object gbs-posn in cartesian coords
2038 Point3D obj_posn = Point3D( obj_lon[m],obj_lat[m],obj_alt[m]);
2039 Point3D obj_pos = sgGeodToCart( obj_posn );
2041 // Translate moving object w.r.t eye
2042 Point3D Objtrans = obj_pos - globals->get_scenery()->get_center();
2047 // rotate dynamic objects for lat,lon & alt and other motion about its axes
2050 sgMakeTransMat4( sgTRANS, bz[0],bz[1],bz[2]);
2052 sgVec3 ship_fwd,ship_rt,ship_up;
2053 sgSetVec3( ship_fwd, 1.0, 0.0, 0.0);//east,roll
2054 sgSetVec3( ship_rt, 0.0, 1.0, 0.0);//up,pitch
2055 sgSetVec3( ship_up, 0.0, 0.0, 1.0); //north,yaw
2057 sgMat4 sgROT_lon, sgROT_lat, sgROT_hdg, sgROT_pitch, sgROT_roll;
2058 sgMakeRotMat4( sgROT_lon, obj_lon[m]*SGD_RADIANS_TO_DEGREES, ship_up );
2059 sgMakeRotMat4( sgROT_lat, 90-obj_latgc*SGD_RADIANS_TO_DEGREES, ship_rt );
2060 sgMakeRotMat4( sgROT_hdg, 180.0, ship_up );
2061 sgMakeRotMat4( sgROT_pitch, obj_pitch[m], ship_rt );
2062 sgMakeRotMat4( sgROT_roll, obj_roll[m], ship_fwd );
2065 sgCopyMat4( sgTUX, sgROT_hdg );
2066 sgPostMultMat4( sgTUX, sgROT_pitch );
2067 sgPostMultMat4( sgTUX, sgROT_roll );
2068 sgPostMultMat4( sgTUX, sgROT_lat );
2069 sgPostMultMat4( sgTUX, sgROT_lon );
2070 sgPostMultMat4( sgTUX, sgTRANS );
2073 sgSetCoord(&shippos, sgTUX );
2074 ship_pos[m]->setTransform( &shippos );
2075 // temporary hack for deck lights - ultimately should move to PLib (when ??)
2077 if (lightpoints_transform) {
2078 lightpoints_transform->setTransform( &shippos );
2079 float sun_angle = cur_light_params.sun_angle * SGD_RADIANS_TO_DEGREES;
2080 if ( sun_angle > 89 ) {
2081 lightpoints_brightness->select(0x01);
2083 lightpoints_brightness->select(0x00);
2092 sgXformPnt3( rp, rway_ols, sgTUX );
2093 vp = globals->get_current_view()->get_view_pos();
2094 to[0] = rp[0]-vp[0];
2095 to[1] = rp[1]-vp[1];
2096 to[2] = rp[2]-vp[2];
2097 float dist = sgLengthVec3( to );
2098 alt = (current_aircraft.fdm_state->get_Altitude() * SG_FEET_TO_METER)-rway_ols[2];
2100 elev = asin(alt/dist)*SGD_RADIANS_TO_DEGREES;
2102 ref_elev = elev - 3.75; // +ve above, -ve below
2106 // DO NOT DELETE THIS CODE - This is to compare a discrete FLOLS (without LOD) with analog FLOLS
2107 // if (ref_elev > 0.51) sel = 0x21;
2108 // if ((ref_elev <= 0.51) & (ref_elev > 0.17)) sel = 0x22;
2109 // if ((ref_elev <= 0.17) & (ref_elev >= -0.17)) sel = 0x24;
2110 // if ((ref_elev < -0.17) & (ref_elev >= -0.51)) sel = 0x28;
2111 // if (ref_elev < -0.51) sel = 0x30;
2112 // DO NOT DELETE THIS CODE - This is to compare a discrete FLOLS (without LOD) with analog FLOLS
2113 dummy_tile->lightmaps_sequence->select(sel);
2116 sgCopyVec3 (up, ship_up);
2118 sgScaleVec3 (up, 4.0*ref_elev*dist/750.0);
2120 sgScaleVec3 (up, 4.0*ref_elev);
2121 dummy_tile->ols_transform->setTransform(up);
2122 //cout << "ref_elev " << ref_elev << endl;
2124 // end hack for deck lights
2127 if ( ship_sel != NULL ) {
2128 ship_sel->select(0xFFFFFFFE); // first object is ownship, added to acmodel
2132 // $$$ end - added VS Renganathan, 15 Oct 2K
2133 // added Venky , 12 Nov 2K