#include <MultiPlayer/multiplayrxmgr.hxx>
#endif
+#include <Replay/replay.hxx>
#include <Scenery/scenery.hxx>
#include <Scenery/tilemgr.hxx>
#ifdef ENABLE_AUDIO_SUPPORT
#include "fg_commands.hxx"
-glPointParameterfProc glPointParameterfPtr;
-glPointParameterfvProc glPointParameterfvPtr;
+glPointParameterfProc glPointParameterfPtr = 0;
+glPointParameterfvProc glPointParameterfvPtr = 0;
+bool glPointParameterIsSupported = false;
float default_attenuation[3] = {1.0, 0.0, 0.0};
//Required for using GL_extensions
float scene_nearplane = 0.5f;
float scene_farplane = 120000.0f;
-static double delta_time_sec = 0;
+static double delta_time_sec = 0.0;
#ifdef FG_WEATHERCM
// Update all Visuals (redraws anything graphics related)
void fgRenderFrame() {
+ bool draw_otw = fgGetBool("/sim/rendering/draw-otw");
+ bool skyblend = fgGetBool("/sim/rendering/skyblend");
+ bool enhanced_lighting = fgGetBool("/sim/rendering/enhanced-lighting");
+ bool distance_attenuation = fgGetBool("/sim/rendering/distance-attenuation");
GLfloat black[4] = { 0.0, 0.0, 0.0, 1.0 };
GLfloat white[4] = { 1.0, 1.0, 1.0, 1.0 };
clear_mask |= GL_COLOR_BUFFER_BIT;
}
- if ( fgGetBool("/sim/rendering/skyblend") ) {
+ if ( skyblend ) {
if ( fgGetBool("/sim/rendering/textures") ) {
// glClearColor(black[0], black[1], black[2], black[3]);
glClearColor(l->adj_fog_color[0], l->adj_fog_color[1],
thesky->set_visibility(visibility_meters);
thesky->modify_vis( cur_fdm_state->get_Altitude() * SG_FEET_TO_METER,
- ( global_multi_loop * fgGetInt("/sim/speed-up") )
+ ( global_multi_loop * fgGetInt("/sim/speed-up") )
/ (double)fgGetInt("/sim/model-hz") );
// Set correct opengl fog density
glFogf (GL_FOG_DENSITY, fog_exp2_density);
// update the sky dome
- if ( fgGetBool("/sim/rendering/skyblend") ) {
+ if ( skyblend ) {
/*
SG_LOG( SG_GENERAL, SG_BULK, "thesky->repaint() sky_color = "
<< cur_light_params.sky_color[0] << " "
" sun_angle = " << cur_light_params.sun_angle
<< " moon_angle = " << cur_light_params.moon_angle );
*/
- thesky->repaint( cur_light_params.sky_color,
- cur_light_params.adj_fog_color,
- cur_light_params.cloud_color,
- cur_light_params.sun_angle,
- cur_light_params.moon_angle,
- globals->get_ephem()->getNumPlanets(),
- globals->get_ephem()->getPlanets(),
- globals->get_ephem()->getNumStars(),
- globals->get_ephem()->getStars() );
+
+ static SGSkyColor scolor;
+
+ scolor.sky_color = cur_light_params.sky_color;
+ scolor.fog_color = cur_light_params.adj_fog_color;
+ scolor.cloud_color = cur_light_params.cloud_color;
+ scolor.sun_angle = cur_light_params.sun_angle;
+ scolor.moon_angle = cur_light_params.moon_angle;
+ scolor.nplanets = globals->get_ephem()->getNumPlanets();
+ scolor.nstars = globals->get_ephem()->getNumStars();
+ scolor.planet_data = globals->get_ephem()->getPlanets();
+ scolor.star_data = globals->get_ephem()->getStars();
+
+ thesky->repaint( scolor );
/*
SG_LOG( SG_GENERAL, SG_BULK,
} else {
sun_horiz_eff = moon_horiz_eff = 1.0;
}
- thesky->reposition( current__view->get_view_pos(),
- current__view->get_zero_elev(),
- current__view->get_world_up(),
- current__view->getLongitude_deg()
- * SGD_DEGREES_TO_RADIANS,
- current__view->getLatitude_deg()
- * SGD_DEGREES_TO_RADIANS,
- current__view->getAltitudeASL_ft()
- * SG_FEET_TO_METER,
- cur_light_params.sun_rotation,
- globals->get_time_params()->getGst(),
- globals->get_ephem()->getSunRightAscension(),
- globals->get_ephem()->getSunDeclination(),
- 50000.0 * sun_horiz_eff,
- globals->get_ephem()->getMoonRightAscension(),
- globals->get_ephem()->getMoonDeclination(),
- 40000.0 * moon_horiz_eff );
+
+ static SGSkyState sstate;
+
+ sstate.view_pos = current__view->get_view_pos();
+ sstate.zero_elev = current__view->get_zero_elev();
+ sstate.view_up = current__view->get_world_up();
+ sstate.lon = current__view->getLongitude_deg()
+ * SGD_DEGREES_TO_RADIANS;
+ sstate.lat = current__view->getLatitude_deg()
+ * SGD_DEGREES_TO_RADIANS;
+ sstate.alt = current__view->getAltitudeASL_ft()
+ * SG_FEET_TO_METER;
+ sstate.spin = cur_light_params.sun_rotation;
+ sstate.gst = globals->get_time_params()->getGst();
+ sstate.sun_ra = globals->get_ephem()->getSunRightAscension();
+ sstate.sun_dec = globals->get_ephem()->getSunDeclination();
+ sstate.sun_dist = 50000.0 * sun_horiz_eff;
+ sstate.moon_ra = globals->get_ephem()->getMoonRightAscension();
+ sstate.moon_dec = globals->get_ephem()->getMoonDeclination();
+ sstate.moon_dist = 40000.0 * moon_horiz_eff;
+
+ thesky->reposition( sstate );
}
glEnable( GL_DEPTH_TEST );
globals->get_multiplayer_rx_mgr()->Update();
#endif
- if ( fgGetBool("/sim/rendering/skyblend") &&
- fgGetBool("/sim/rendering/draw-otw") )
+ if ( draw_otw && skyblend )
{
// draw the sky backdrop
// draw wire frame
glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
}
- if ( fgGetBool("/sim/rendering/draw-otw") ) {
+ if ( draw_otw ) {
ssgCullAndDraw( globals->get_scenery()->get_scene_graph() );
}
glFogf (GL_FOG_DENSITY, rwy_exp2_punch_through);
ssgSetNearFar( scene_nearplane, scene_farplane );
- if (fgGetBool("/sim/rendering/enhanced-lighting")) {
+ if ( enhanced_lighting ) {
// Enable states for drawing points with GL_extension
glEnable(GL_POINT_SMOOTH);
-#ifdef GL_EXT_point_parameters
- if ( fgGetBool("/sim/rendering/distance-attenuation")
- && SGIsOpenGLExtensionSupported("GL_EXT_point_parameters") )
+ if ( distance_attenuation && glPointParameterIsSupported )
{
// Enable states for drawing points with GL_extension
glEnable(GL_POINT_SMOOTH);
glPointParameterfvPtr(GL_DISTANCE_ATTENUATION_EXT, quadratic);
glPointParameterfPtr(GL_POINT_SIZE_MIN_EXT, 1.0);
}
-#endif
glPointSize(4.0);
glPolygonMode(GL_FRONT, GL_POINT);
// draw runway lighting
- if ( fgGetBool("/sim/rendering/draw-otw") ) {
+ if ( draw_otw ) {
ssgCullAndDraw( globals->get_scenery()->get_rwy_lights_root() );
}
// sgVec3 taxi_fog;
// sgSetVec3( taxi_fog, 0.0, 0.0, 0.0 );
// glFogfv ( GL_FOG_COLOR, taxi_fog );
- if ( fgGetBool("/sim/rendering/draw-otw") ) {
+ if ( draw_otw ) {
ssgCullAndDraw( globals->get_scenery()->get_taxi_lights_root() );
}
//_frame_count++;
- if (fgGetBool("/sim/rendering/enhanced-lighting")) {
-#ifdef GL_EXT_point_parameters
- if ( fgGetBool("/sim/rendering/distance-attenuation")
- && SGIsOpenGLExtensionSupported("GL_EXT_point_parameters") )
+ if ( enhanced_lighting ) {
+ if ( distance_attenuation && glPointParameterIsSupported )
{
glPointParameterfvPtr(GL_DISTANCE_ATTENUATION_EXT,
default_attenuation);
}
-#endif
glPointSize(1.0);
glDisable(GL_POINT_SMOOTH);
// draw ground lighting
glFogf (GL_FOG_DENSITY, ground_exp2_punch_through);
- if ( fgGetBool("/sim/rendering/draw-otw") ) {
+ if ( draw_otw ) {
ssgCullAndDraw( globals->get_scenery()->get_gnd_lights_root() );
}
- if ( fgGetBool("/sim/rendering/skyblend") ) {
+ if ( skyblend ) {
// draw the sky cloud layers
- if ( fgGetBool("/environment/clouds/status") &&
- fgGetBool("/sim/rendering/draw-otw") )
+ if ( draw_otw && fgGetBool("/environment/clouds/status") )
{
thesky->postDraw( cur_fdm_state->get_Altitude()
* SG_FEET_TO_METER );
}
}
- if ( fgGetBool("/sim/rendering/clouds3d") &&
- fgGetBool("/sim/rendering/draw-otw") )
+ if ( draw_otw && fgGetBool("/sim/rendering/clouds3d") )
{
glDisable( GL_FOG );
glDisable( GL_LIGHTING );
glBlendFunc ( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ) ;
}
- if ( fgGetBool("/sim/rendering/draw-otw") ) {
+ if ( draw_otw ) {
globals->get_model_mgr()->draw();
globals->get_aircraft_model()->draw();
}
void fgUpdateTimeDepCalcs() {
static bool inited = false;
+ static const SGPropertyNode *replay_master
+ = fgGetNode( "/sim/freeze/replay", true );
+ static SGPropertyNode *replay_time
+ = fgGetNode( "/sim/replay/time", true );
+ static const SGPropertyNode *replay_end_time
+ = fgGetNode( "/sim/replay/end-time", true );
+
//SG_LOG(SG_FLIGHT,SG_INFO, "Updating time dep calcs()");
fgLIGHT *l = &cur_light_params;
// conceptually, the following block could be done for each fdm
// instance ...
- if ( !cur_fdm_state->get_inited() ) {
- // do nothing, fdm isn't inited yet
- } else {
+ if ( cur_fdm_state->get_inited() ) {
// we have been inited, and we are good to go ...
if ( !inited ) {
inited = true;
}
- globals->get_autopilot()->update(delta_time_sec);
- cur_fdm_state->update(delta_time_sec);
+ if ( ! replay_master->getBoolValue() ) {
+ globals->get_autopilot()->update( delta_time_sec );
+ cur_fdm_state->update( delta_time_sec );
+ } else {
+ FGReplay *r = (FGReplay *)(globals->get_subsystem( "replay" ));
+ r->replay( replay_time->getDoubleValue() );
+ replay_time->setDoubleValue( replay_time->getDoubleValue()
+ + ( delta_time_sec
+ * fgGetInt("/sim/speed-up") ) );
+ }
+ } else {
+ // do nothing, fdm isn't inited yet
}
globals->get_model_mgr()->update(delta_time_sec);
// What should we do when we have nothing else to do? Let's get ready
// for the next move and update the display?
static void fgMainLoop( void ) {
+ int model_hz = fgGetInt("/sim/model-hz");
static const SGPropertyNode *longitude
= fgGetNode("/position/longitude-deg");
= fgGetNode("/sim/freeze/clock", true);
static const SGPropertyNode *cur_time_override
= fgGetNode("/sim/time/cur-time-override", true);
+ static const SGPropertyNode *replay_master
+ = fgGetNode("/sim/freeze/replay", true);
// Update the elapsed time.
static bool first_time = true;
delta_time_sec = double(current_time_stamp - last_time_stamp) / 1000000.0;
if ( clock_freeze->getBoolValue() ) {
delta_time_sec = 0;
- }
+ }
last_time_stamp = current_time_stamp;
globals->inc_sim_time_sec( delta_time_sec );
SGAnimation::set_sim_time_sec( globals->get_sim_time_sec() );
cur_fdm_state->get_Runway_altitude() * SG_FEET_TO_METER,
cur_fdm_state->get_Altitude() * SG_FEET_TO_METER); */
-// Curt is this code used? I don't see any problems when I comment it out.
+#if 0
+// This code is used by LaRCsim/UIUC to position the aircraft at a proper
+// place. This code should eventually go into the LaRCsim directory.
+// Commented out at Jul 27 2003 because tests show it is not needed.
+// Can probbaly be safely removed after Spet. 2003 - EMH
+
if ( acmodel_location != 0 ) {
if ( acmodel_location->get_cur_elev_m() > -9990 && cur_fdm_state->get_inited() ) {
if ( cur_fdm_state->get_Altitude() * SG_FEET_TO_METER <
- (acmodel_location->get_cur_elev_m() + alt_adjust_m - 3.0) ) {
+ (acmodel_location->get_cur_elev_m() + alt_adjust_m - 130.0) ) {
// now set aircraft altitude above ground
printf("(*) Current Altitude = %.2f < %.2f forcing to %.2f\n",
cur_fdm_state->get_Altitude() * SG_FEET_TO_METER,
- acmodel_location->get_cur_elev_m() + alt_adjust_m - 3.0,
+ acmodel_location->get_cur_elev_m() + alt_adjust_m - 130.0,
acmodel_location->get_cur_elev_m() + alt_adjust_m );
cur_fdm_state->set_Altitude( (acmodel_location->get_cur_elev_m()
+ alt_adjust_m) * SG_METER_TO_FEET );
}
}
// End of code in question. (see Curt is this code used? above)
+#endif
/* printf("Adjustment - ground = %.2f runway = %.2f alt = %.2f\n",
scenery.get_cur_elev(),
// Calculate model iterations needed for next frame
elapsed += remainder;
- global_multi_loop = (long)(((double)elapsed * 0.000001) *
- fgGetInt("/sim/model-hz"));
- remainder = elapsed - ( (global_multi_loop*1000000) /
- fgGetInt("/sim/model-hz") );
+ global_multi_loop = (long)(((double)elapsed * 0.000001) * model_hz );
+ remainder = elapsed - ( (global_multi_loop*1000000) / model_hz );
SG_LOG( SG_ALL, SG_DEBUG,
"Model iterations needed = " << global_multi_loop
<< ", new remainder = " << remainder );
// chop max interations to something reasonable if the sim was
// delayed for an excesive amount of time
- if ( global_multi_loop > 2.0 * fgGetInt("/sim/model-hz") ) {
- global_multi_loop = (int)(2.0 * fgGetInt("/sim/model-hz") );
+ if ( global_multi_loop > 2.0 * model_hz ) {
+ global_multi_loop = (int)(2.0 * model_hz );
remainder = 0;
}
// Initialize the various GLUT Event Handlers.
if( !fgGlutInitEvents() ) {
- SG_LOG( SG_GENERAL, SG_ALERT,
+ SG_LOG( SG_GENERAL, SG_ALERT,
"GLUT event handler initialization failed ..." );
exit(-1);
}
// get the address of our OpenGL extensions
if ( fgGetBool("/sim/rendering/distance-attenuation") )
{
- glPointParameterfPtr = (glPointParameterfProc)
- SGLookupFunction("glPointParameterfEXT");
- glPointParameterfvPtr = (glPointParameterfvProc)
- SGLookupFunction("glPointParameterfvEXT");
+ if (SGIsOpenGLExtensionSupported("GL_EXT_point_parameters") ) {
+ glPointParameterIsSupported = true;
+ glPointParameterfPtr = (glPointParameterfProc)
+ SGLookupFunction("glPointParameterfEXT");
+ glPointParameterfvPtr = (glPointParameterfvProc)
+ SGLookupFunction("glPointParameterfvEXT");
+
+ } else if ( SGIsOpenGLExtensionSupported("GL_ARB_point_parameters") ) {
+ glPointParameterIsSupported = true;
+ glPointParameterfPtr = (glPointParameterfProc)
+ SGLookupFunction("glPointParameterfARB");
+ glPointParameterfvPtr = (glPointParameterfvProc)
+ SGLookupFunction("glPointParameterfvARB");
+ } else
+ glPointParameterIsSupported = false;
}
// based on the requested presets, calculate the true starting
////////////////////////////////////////////////////////////////////
// Initialize the view manager subsystem.
////////////////////////////////////////////////////////////////////
-
FGViewMgr *viewmgr = new FGViewMgr;
globals->set_viewmgr( viewmgr );
viewmgr->init();
SGMagVar *magvar = new SGMagVar();
globals->set_mag( magvar );
+
+ // kludge to initialize mag compass
+ // (should only be done for in-flight
+ // startup)
+ // update magvar model
+ globals->get_mag()->update( fgGetDouble("/position/longitude-deg")
+ * SGD_DEGREES_TO_RADIANS,
+ fgGetDouble("/position/latitude-deg")
+ * SGD_DEGREES_TO_RADIANS,
+ fgGetDouble("/position/altitude-ft")
+ * SG_FEET_TO_METER,
+ globals->get_time_params()->getJD() );
+ double var = globals->get_mag()->get_magvar() * SGD_RADIANS_TO_DEGREES;
+ fgSetDouble("/instrumentation/heading-indicator/offset-deg", -var);
+
// airport = new ssgBranch;
// airport->setName( "Airport Lighting" );
// lighting->addKid( airport );