-dnl aclocal.m4 generated automatically by aclocal 1.4
+dnl aclocal.m4 generated automatically by aclocal 1.4-p4
dnl Copyright (C) 1994, 1995-8, 1999 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
double agl;
agl = cur_fdm_state->get_Altitude() * SG_FEET_TO_METER
- - scenery.cur_elev;
+ - scenery.get_cur_elev();
return( agl );
}
target_alt = new_altitude * SG_FEET_TO_METER;
}
- if( target_alt < scenery.cur_elev ) {
- target_alt = scenery.cur_elev;
+ if( target_alt < scenery.get_cur_elev() ) {
+ target_alt = scenery.get_cur_elev();
}
TargetAltitude = target_alt;
if ( fgGetString("/sim/startup/units") == "feet" ) {
agl = (current_aircraft.fdm_state->get_Altitude()
- - scenery.cur_elev * SG_METER_TO_FEET);
+ - scenery.get_cur_elev() * SG_METER_TO_FEET);
} else {
agl = (current_aircraft.fdm_state->get_Altitude() * SG_FEET_TO_METER
- - scenery.cur_elev);
+ - scenery.get_cur_elev());
}
return agl;
// Convert from the FGInterface struct to the FGADA struct (output)
bool FGADA::copy_to_FGADA () {
-
- ground_elevation = scenery.cur_elev;
+ ground_elevation = scenery.get_cur_elev();
return true;
}
}
Position->SetSeaLevelRadius( get_Sea_level_radius() );
- Position->SetRunwayRadius( scenery.cur_elev*SG_METER_TO_FEET
+ Position->SetRunwayRadius( scenery.get_cur_elev()*SG_METER_TO_FEET
+ get_Sea_level_radius() );
Atmosphere->SetExTemperature(get_Static_temperature());
// Inform LaRCsim of the local terrain altitude
// Runway_altitude = get_Runway_altitude();
- Runway_altitude = scenery.cur_elev * SG_METER_TO_FEET;
+ Runway_altitude = scenery.get_cur_elev() * SG_METER_TO_FEET;
// Weather
/* V_north_airmass = get_V_north_airmass();
}
FGInterface::FGInterface( double dt ) {
-
_setup();
delta_t = dt;
remainder = elapsed = multi_loop = 0;
void
FGInterface::_setup ()
{
+ inited = false;
+ bound = false;
+
init_vec( d_pilot_rp_body_v );
init_vec( d_cg_rp_body_v );
init_vec( f_body_total_v );
{
SG_LOG(SG_FLIGHT, SG_INFO, "Start initializing FGInterface");
+ inited = true;
+
stamp();
set_remainder(0);
SG_LOG(SG_FLIGHT, SG_INFO, "...initializing position...");
set_Longitude(fgGetDouble("/position/longitude-deg") * SGD_DEGREES_TO_RADIANS);
set_Latitude(fgGetDouble("/position/latitude-deg") * SGD_DEGREES_TO_RADIANS);
- double ground_elev_m = scenery.cur_elev + 1;
+ double ground_elev_m = scenery.get_cur_elev() + 1;
double ground_elev_ft = ground_elev_m * METERS_TO_FEET;
if (fgGetBool("/sim/startup/onground") ||
fgGetDouble("/position/altitude-ft") < ground_elev_ft)
// Set sea-level radius
SG_LOG(SG_FLIGHT, SG_INFO, "...initializing sea-level radius...");
+ SG_LOG(SG_FLIGHT, SG_INFO, " lat = " << get_Latitude() << " alt = "
+ << get_Altitude() );
double sea_level_radius_meters;
double lat_geoc;
sgGeodToGeoc(get_Latitude(), get_Altitude(),
void
FGInterface::bind ()
{
+ bound = true;
+
// Time management (read-only)
fgTie("/fdm/time/delta_t", this,
&FGInterface::get_delta_t); // read-only
void
FGInterface::unbind ()
{
+ bound = false;
+
fgUntie("/fdm/time/delta_t");
fgUntie("/fdm/time/elapsed");
fgUntie("/fdm/time/remainder");
fgUntie("/position/latitude-deg");
fgUntie("/position/longitude-deg");
fgUntie("/position/altitude-ft");
- fgUntie("/position/heading");
- fgUntie("/position/pitch");
- fgUntie("/position/roll");
+ fgUntie("/position/altitude-agl-ft");
+ fgUntie("/orientation/heading-deg");
+ fgUntie("/orientation/pitch-deg");
+ fgUntie("/orientation/roll-deg");
fgUntie("/velocities/airspeed-kt");
fgUntie("/velocities/speed-north-fps");
fgUntie("/velocities/speed-east-fps");
_set_Geodetic_Position( lat_geod, lon, alt );
_set_Sea_level_radius( sl_radius2 * SG_METER_TO_FEET );
- _set_Runway_altitude( scenery.cur_elev*METERS_TO_FEET );
+ _set_Runway_altitude( scenery.get_cur_elev()*METERS_TO_FEET );
_set_sin_lat_geocentric( lat_geoc );
_set_cos_lat_geocentric( lat_geoc );
private:
+ // Has the init() method been called. This is used to delay
+ // initialization until scenery can be loaded and we know the true
+ // ground elevation.
+ bool inited;
+
+ // Have we bound to the property system
+ bool bound;
+
// periodic update management variable. This is a scheme to run
// the fdm with a fixed delta-t. We control how many iteration of
// the fdm to run with the fixed dt based on the elapsed time from
FG_EXTERNAL = 10
};
+ // initialization
+ inline bool get_inited() const { return inited; }
+ inline void set_inited( bool value ) { inited = value; }
+
+ inline bool get_bound() const { return bound; }
+
// time and update management values
inline double get_delta_t() const { return delta_t; }
inline void set_delta_t( double dt ) { delta_t = dt; }
void AptDialog_OK (puObject *)
{
+ static const SGPropertyNode *longitude
+ = fgGetNode("/position/longitude-deg");
+ static const SGPropertyNode *latitude
+ = fgGetNode("/position/latitude-deg");
+
SGPath path( globals->get_fg_root() );
path.append( "Airports" );
path.append( "simple.mk4" );
if ( airports.search( AptId, &a ) )
{
+ // unbind the current fdm state so property changes
+ // don't get lost when we subsequently delete this fdm
+ // and create a new one.
+ cur_fdm_state->unbind();
+
AptId = a.id.c_str(); /// NHV fix wrong case crash
fgSetString("/sim/startup/airport-id", AptId.c_str() );
// fgSetDouble("/position/altitude-ft", -9999.0 );
SGD_RADIANS_TO_DEGREES);
BusyCursor(0);
fgReInitSubsystems();
- if ( global_tile_mgr.init() ) {
+ // if ( global_tile_mgr.init() ) {
// Load the local scenery data
- global_tile_mgr.update(
- cur_fdm_state->get_Longitude()
- * SGD_RADIANS_TO_DEGREES,
- cur_fdm_state->get_Latitude()
- * SGD_RADIANS_TO_DEGREES );
- } else {
- SG_LOG( SG_GENERAL, SG_ALERT,
- "Error in Tile Manager initialization!" );
- exit(-1);
- }
+ global_tile_mgr.update( longitude->getDoubleValue(),
+ longitude->getDoubleValue() );
+ // } else {
+ // SG_LOG( SG_GENERAL, SG_ALERT,
+ // "Error in Tile Manager initialization!" );
+ // exit(-1);
+ // }
BusyCursor(1);
} else {
AptId += " not in database.";
mkDialog(AptId.c_str());
}
}
- if(!freeze)
+ if ( !freeze ) {
globals->set_freeze( false );
+ }
}
if ( ! root.length() ) {
// No root path set? Then bail ...
SG_LOG( SG_GENERAL, SG_ALERT,
- "Cannot continue without environment variable FG_ROOT"
+ "Cannot continue without a path to the base package "
<< "being defined." );
exit(-1);
}
// Initialize the scenery management subsystem.
////////////////////////////////////////////////////////////////////
- if ( fgSceneryInit() ) {
- // Material lib initialized ok.
- } else {
- SG_LOG( SG_GENERAL, SG_ALERT, "Error in Scenery initialization!" );
- exit(-1);
- }
+ scenery.init();
+ scenery.bind();
if ( global_tile_mgr.init() ) {
// Load the local scenery data
SG_LOG( SG_GENERAL, SG_DEBUG,
"Current terrain elevation after tile mgr init " <<
- scenery.cur_elev );
+ scenery.get_cur_elev() );
////////////////////////////////////////////////////////////////////
exit(-1);
}
- cur_fdm_state->init();
- cur_fdm_state->bind();
+ // Actual fdm initialization is delayed until we get a proper
+ // scenery elevation hit. This is checked for in main.cxx
+ // cur_fdm_state->init();
+ // cur_fdm_state->bind();
// allocates structures so must happen before any of the flight
// model or control parameters are set
void fgReInitSubsystems( void )
{
+ static const SGPropertyNode *longitude
+ = fgGetNode("/position/longitude-deg");
+ static const SGPropertyNode *latitude
+ = fgGetNode("/position/latitude-deg");
+ static const SGPropertyNode *altitude
+ = fgGetNode("/position/altitude-ft");
+
SG_LOG( SG_GENERAL, SG_INFO,
- "/position/altitude = " << fgGetDouble("/position/altitude-ft") );
+ "/position/altitude = " << altitude->getDoubleValue() );
bool freeze = globals->get_freeze();
- if( !freeze )
+ if( !freeze ) {
globals->set_freeze( true );
+ }
// Initialize the Scenery Management subsystem
- if ( ! fgSceneryInit() ) {
- SG_LOG( SG_GENERAL, SG_ALERT, "Error in Scenery initialization!" );
- exit(-1);
- }
+ scenery.init();
- if( global_tile_mgr.init() ) {
+ // if( global_tile_mgr.init() ) {
// Load the local scenery data
- global_tile_mgr.update( fgGetDouble("/position/longitude-deg"),
- fgGetDouble("/position/latitude-deg") );
- } else {
- SG_LOG( SG_GENERAL, SG_ALERT, "Error in Tile Manager initialization!" );
- exit(-1);
+ global_tile_mgr.update( longitude->getDoubleValue(),
+ latitude->getDoubleValue() );
+ // } else {
+ // SG_LOG( SG_GENERAL, SG_ALERT, "Error in Tile Manager initialization!" );
+ // exit(-1);
+ // }
+
+ // Delete then Initialize the flight model subsystem.
+ delete cur_fdm_state;
+
+ double dt = 1.0 / fgGetInt("/sim/model-hz");
+ aircraft_dir = fgGetString("/sim/aircraft-dir");
+ const string &model = fgGetString("/sim/flight-model");
+ try {
+ if (model == "larcsim") {
+ cur_fdm_state = new FGLaRCsim( dt );
+ } else if (model == "jsb") {
+ cur_fdm_state = new FGJSBsim( dt );
+ } else if (model == "ada") {
+ cur_fdm_state = new FGADA( dt );
+ } else if (model == "balloon") {
+ cur_fdm_state = new FGBalloonSim( dt );
+ } else if (model == "magic") {
+ cur_fdm_state = new FGMagicCarpet( dt );
+ } else if (model == "external") {
+ cur_fdm_state = new FGExternal( dt );
+ } else {
+ SG_LOG(SG_GENERAL, SG_ALERT,
+ "Unrecognized flight model '" << model
+ << ", can't init aircraft");
+ exit(-1);
+ }
+ } catch ( ... ) {
+ SG_LOG(SG_GENERAL, SG_ALERT, "FlightGear aborting\n\n");
+ exit(-1);
}
// Initialize view parameters
pilot_view->set_view_offset( 0.0 );
pilot_view->set_goal_view_offset( 0.0 );
- pilot_view->set_geod_view_pos( cur_fdm_state->get_Longitude(),
- cur_fdm_state->get_Lat_geocentric(),
- cur_fdm_state->get_Altitude() *
- SG_FEET_TO_METER );
- pilot_view->set_sea_level_radius( cur_fdm_state->get_Sea_level_radius() *
- SG_FEET_TO_METER );
+ pilot_view->set_geod_view_pos( longitude->getDoubleValue()
+ * SGD_DEGREES_TO_RADIANS,
+ latitude->getDoubleValue()
+ * SGD_DEGREES_TO_RADIANS,
+ cur_fdm_state->get_Altitude()
+ * SG_FEET_TO_METER );
pilot_view->set_rph( cur_fdm_state->get_Phi(),
cur_fdm_state->get_Theta(),
cur_fdm_state->get_Psi() );
SG_LOG( SG_GENERAL, SG_DEBUG, " abs_view_pos = "
<< globals->get_current_view()->get_abs_view_pos());
- cur_fdm_state->init();
-
globals->get_controls()->reset_all();
current_autopilot->reset();
static double
getRPM ()
{
- if ( current_aircraft.fdm_state->get_engine(0) != NULL ) {
+ if ( current_aircraft.fdm_state->get_num_engines() > 0 ) {
return current_aircraft.fdm_state->get_engine(0)->get_RPM();
} else {
return 0.0;
static double
getEGT ()
{
- if ( current_aircraft.fdm_state->get_engine(0) != NULL ) {
+ if ( current_aircraft.fdm_state->get_num_engines() > 0 ) {
return current_aircraft.fdm_state->get_engine(0)->get_EGT();
} else {
return 0.0;
static double
getCHT ()
{
- if ( current_aircraft.fdm_state->get_engine(0) != NULL ) {
+ if ( current_aircraft.fdm_state->get_num_engines() > 0 ) {
return current_aircraft.fdm_state->get_engine(0)->get_CHT();
} else {
return 0.0;
static double
getOilTemp ()
{
- if ( current_aircraft.fdm_state->get_engine(0) != NULL ) {
+ if ( current_aircraft.fdm_state->get_num_engines() > 0 ) {
return current_aircraft.fdm_state->get_engine(0)->get_Oil_Temp();
} else {
return 0.0;
static double
getMP ()
{
- if ( current_aircraft.fdm_state->get_engine(0) != NULL ) {
+ if ( current_aircraft.fdm_state->get_num_engines() > 0 ) {
return current_aircraft.fdm_state->get_engine(0)->get_Manifold_Pressure();
} else {
return 0.0;
static double
getFuelFlow ()
{
- if ( current_aircraft.fdm_state->get_engine(0) != NULL ) {
+ if ( current_aircraft.fdm_state->get_num_engines() > 0 ) {
return current_aircraft.fdm_state->get_engine(0)->get_Fuel_Flow();
} else {
return 0.0;
static bool
getRunningFlag ()
{
- if ( current_aircraft.fdm_state->get_engine(0) != NULL ) {
+ if ( current_aircraft.fdm_state->get_num_engines() > 0 ) {
return current_aircraft.fdm_state->get_engine(0)->get_Running_Flag();
} else {
return false;
static bool
getCrankingFlag ()
{
- if ( current_aircraft.fdm_state->get_engine(0) != NULL ) {
+ if ( current_aircraft.fdm_state->get_num_engines() > 0 ) {
return current_aircraft.fdm_state->get_engine(0)->get_Cranking_Flag();
} else {
return false;
static void
setRunningFlag (bool flag)
{
- if(current_aircraft.fdm_state->get_engine(0) != NULL) {
+ if ( current_aircraft.fdm_state->get_num_engines() > 0 ) {
current_aircraft.fdm_state->get_engine(0)->set_Running_Flag( flag );
}
}
static void
setCrankingFlag (bool flag)
{
- if(current_aircraft.fdm_state->get_engine(0) != NULL) {
+ if ( current_aircraft.fdm_state->get_num_engines() > 0 ) {
current_aircraft.fdm_state->get_engine(0)->set_Cranking_Flag( flag );
}
}
# include <unistd.h> // for stat()
#endif
-// #ifdef HAVE_LIBX11
-// # include <GL/glext.h>
-// #endif
-
#include <plib/netChat.h>
#include <plib/pu.h>
#include <plib/ssg.h>
static int idle_state = 0;
static long global_multi_loop;
-// attempt to avoid a large bounce at startup
-static bool initial_freeze = true;
-
// forward declaration
void fgReshape( int width, int height );
// Update all Visuals (redraws anything graphics related)
void fgRenderFrame( void ) {
+ static const SGPropertyNode *longitude
+ = fgGetNode("/position/longitude-deg");
+ static const SGPropertyNode *latitude
+ = fgGetNode("/position/latitude-deg");
+ static const SGPropertyNode *altitude
+ = fgGetNode("/position/altitude-ft");
+
// Update the default (kludged) properties.
fgUpdateProps();
// initializations and are running the main loop, so this will
// now work without seg faulting the system.
- // printf("Ground = %.2f Altitude = %.2f\n", scenery.cur_elev,
+ // printf("Ground = %.2f Altitude = %.2f\n", scenery.get_cur_elev(),
// FG_Altitude * SG_FEET_TO_METER);
// this is just a temporary hack, to make me understand Pui
// end of hack
// calculate our current position in cartesian space
- scenery.center = scenery.next_center;
+ scenery.set_center( scenery.get_next_center() );
// printf("scenery center = %.2f %.2f %.2f\n", scenery.center.x(),
// scenery.center.y(), scenery.center.z());
FGViewerRPH *pilot_view =
(FGViewerRPH *)globals->get_viewmgr()->get_view( 0 );
- pilot_view->set_geod_view_pos( cur_fdm_state->get_Longitude(),
- cur_fdm_state->get_Lat_geocentric(),
- cur_fdm_state->get_Altitude() *
- SG_FEET_TO_METER );
- pilot_view->set_sea_level_radius( cur_fdm_state->
- get_Sea_level_radius() *
- SG_FEET_TO_METER );
+ pilot_view->set_geod_view_pos( longitude->getDoubleValue()
+ * SGD_DEGREES_TO_RADIANS,
+ latitude->getDoubleValue()
+ * SGD_DEGREES_TO_RADIANS,
+ altitude->getDoubleValue()
+ * SG_FEET_TO_METER );
pilot_view->set_rph( cur_fdm_state->get_Phi(),
cur_fdm_state->get_Theta(),
cur_fdm_state->get_Psi() );
sgXformVec3( po, *pPO, pilot_view->get_UP() );
sgXformVec3( npo, po, CXFM );
- chase_view->set_geod_view_pos( cur_fdm_state->get_Longitude(),
- cur_fdm_state->get_Lat_geocentric(),
- cur_fdm_state->get_Altitude() *
- SG_FEET_TO_METER );
- chase_view->set_sea_level_radius( cur_fdm_state->
- get_Sea_level_radius() *
- SG_FEET_TO_METER );
+ chase_view->set_geod_view_pos( longitude->getDoubleValue()
+ * SGD_DEGREES_TO_RADIANS,
+ latitude->getDoubleValue()
+ * SGD_DEGREES_TO_RADIANS,
+ altitude->getDoubleValue()
+ * SG_FEET_TO_METER );
chase_view->set_pilot_offset( npo[0], npo[1], npo[2] );
chase_view->set_view_forward( pilot_view->get_view_pos() );
chase_view->set_view_up( wup );
thesky->reposition( globals->get_current_view()->get_view_pos(),
globals->get_current_view()->get_zero_elev(),
globals->get_current_view()->get_world_up(),
- cur_fdm_state->get_Longitude(),
- cur_fdm_state->get_Latitude(),
- cur_fdm_state->get_Altitude() * SG_FEET_TO_METER,
+ longitude->getDoubleValue()
+ * SGD_DEGREES_TO_RADIANS,
+ latitude->getDoubleValue()
+ * SGD_DEGREES_TO_RADIANS,
+ altitude->getDoubleValue() * SG_FEET_TO_METER,
cur_light_params.sun_rotation,
globals->get_time_params()->getGst(),
globals->get_ephem()->getSunRightAscension(),
ssgSetFOV(fov, fov * globals->get_current_view()->get_fov_ratio());
double agl = current_aircraft.fdm_state->get_Altitude() * SG_FEET_TO_METER
- - scenery.cur_elev;
+ - scenery.get_cur_elev();
// SG_LOG( SG_ALL, SG_INFO, "visibility is "
// << current_weather.get_visibility() );
fgCockpitUpdate();
// update the panel subsystem
- if (current_panel != 0)
- current_panel->update();
+ if ( current_panel != NULL ) {
+ current_panel->update();
+ }
// We can do translucent menus, so why not. :-)
menus->apply();
void fgUpdateTimeDepCalcs() {
static bool inited = false;
+ // cout << "Updating time dep calcs()" << endl;
+
fgLIGHT *l = &cur_light_params;
int i;
long multi_loop = 1;
- if ( !globals->get_freeze() && !initial_freeze ) {
- // conceptually, this could be done for each fdm instance ...
+ // Initialize the FDM here if it hasn't been and if we have a
+ // scenery elevation hit.
+
+ // cout << "cur_fdm_state->get_inited() = " << cur_fdm_state->get_inited()
+ // << " cur_elev = " << scenery.get_cur_elev() << endl;
+
+ if ( !cur_fdm_state->get_inited() && scenery.get_cur_elev() > -9990 ) {
+ cout << "Finally initializing fdm" << endl;
+ cur_fdm_state->init();
+ if ( cur_fdm_state->get_bound() ) {
+ cur_fdm_state->unbind();
+ }
+ cur_fdm_state->bind();
+ }
+
+ // 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 ( globals->get_freeze() ) {
+ // we are frozen, run the fdm's with 0 time slices in case
+ // they want to do something with that.
+
+ cur_fdm_state->update( 0 );
+ FGSteam::update( 0 );
+ } else {
+ // we have been inited, and we are not frozen, we are good to go ...
if ( !inited ) {
cur_fdm_state->stamp();
cur_fdm_state->update( 1 );
}
FGSteam::update( multi_loop * fgGetInt("/sim/speed-up") );
- } else {
- cur_fdm_state->update( 0 );
- FGSteam::update( 0 );
-
- //if ( global_tile_mgr.queue_size() == 0 ) {
- initial_freeze = false;
- //}
}
if ( fgGetString("/sim/view-mode") == "pilot" ) {
// 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 ) {
+ static const SGPropertyNode *longitude
+ = fgGetNode("/position/longitude-deg");
+ static const SGPropertyNode *latitude
+ = fgGetNode("/position/latitude-deg");
+ static const SGPropertyNode *altitude
+ = fgGetNode("/position/altitude-ft");
+
static long remainder = 0;
long elapsed;
#ifdef FANCY_FRAME_COUNTER
// probably move eventually
/* printf("Before - ground = %.2f runway = %.2f alt = %.2f\n",
- scenery.cur_elev,
+ scenery.get_cur_elev(),
cur_fdm_state->get_Runway_altitude() * SG_FEET_TO_METER,
cur_fdm_state->get_Altitude() * SG_FEET_TO_METER); */
- if ( scenery.cur_elev > -9990 ) {
+ if ( scenery.get_cur_elev() > -9990 ) {
if ( cur_fdm_state->get_Altitude() * SG_FEET_TO_METER <
- (scenery.cur_elev + alt_adjust_m - 3.0) ) {
+ (scenery.get_cur_elev() + alt_adjust_m - 3.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,
- scenery.cur_elev + alt_adjust_m - 3.0,
- scenery.cur_elev + alt_adjust_m );
+ scenery.get_cur_elev() + alt_adjust_m - 3.0,
+ scenery.get_cur_elev() + alt_adjust_m );
fgFDMForceAltitude( fgGetString("/sim/flight-model"),
- scenery.cur_elev + alt_adjust_m );
+ scenery.get_cur_elev() + alt_adjust_m );
SG_LOG( SG_ALL, SG_DEBUG,
"<*> resetting altitude to "
}
/* printf("Adjustment - ground = %.2f runway = %.2f alt = %.2f\n",
- scenery.cur_elev,
+ scenery.get_cur_elev(),
cur_fdm_state->get_Runway_altitude() * SG_FEET_TO_METER,
cur_fdm_state->get_Altitude() * SG_FEET_TO_METER); */
globals->inc_warp( globals->get_warp_delta() );
}
- t->update( cur_fdm_state->get_Longitude(),
- cur_fdm_state->get_Latitude(),
+ t->update( longitude->getDoubleValue() * SGD_DEGREES_TO_RADIANS,
+ latitude->getDoubleValue() * SGD_DEGREES_TO_RADIANS,
globals->get_warp() );
if ( globals->get_warp_delta() != 0 ) {
}
// update magvar model
- globals->get_mag()->update( cur_fdm_state->get_Longitude(),
- cur_fdm_state->get_Latitude(),
- cur_fdm_state->get_Altitude()* SG_FEET_TO_METER,
+ globals->get_mag()->update( longitude->getDoubleValue()
+ * SGD_DEGREES_TO_RADIANS,
+ latitude->getDoubleValue()
+ * SGD_DEGREES_TO_RADIANS,
+ altitude->getDoubleValue() * SG_FEET_TO_METER,
globals->get_time_params()->getJD() );
// Get elapsed time (in usec) for this past frame
if ( global_multi_loop > 0 ) {
fgUpdateTimeDepCalcs();
} else {
- SG_LOG( SG_ALL, SG_DEBUG,
+ SG_LOG( SG_ALL, SG_INFO,
"Elapsed time is zero ... we're zinging" );
}
#endif
// see if we need to load any new scenery tiles
- global_tile_mgr.update( cur_fdm_state->get_Longitude()
- * SGD_RADIANS_TO_DEGREES,
- cur_fdm_state->get_Latitude()
- * SGD_RADIANS_TO_DEGREES );
+ global_tile_mgr.update( longitude->getDoubleValue(),
+ latitude->getDoubleValue() );
// see if we need to load any deferred-load textures
material_lib.load_next_deferred();
// Main loop
int mainLoop( int argc, char **argv ) {
-
#if defined( macintosh )
freopen ("stdout.txt", "w", stdout );
freopen ("stderr.txt", "w", stderr );
fgGetDouble("/orientation/heading-deg") );
}
+ // Any time after globals is created we are ready to use the
+ // property system
+ static const SGPropertyNode *longitude
+ = fgGetNode("/position/longitude-deg", true);
+ static const SGPropertyNode *latitude
+ = fgGetNode("/position/latitude-deg", true);
+
+
// Initialize time
SGPath zone( globals->get_fg_root() );
zone.append( "Timezone" );
- SGTime *t = new SGTime( fgGetDouble("/position/longitude-deg") * SGD_DEGREES_TO_RADIANS,
- fgGetDouble("/position/latitude-deg") * SGD_DEGREES_TO_RADIANS,
+ SGTime *t = new SGTime( longitude->getDoubleValue()
+ * SGD_DEGREES_TO_RADIANS,
+ latitude->getDoubleValue()
+ * SGD_DEGREES_TO_RADIANS,
zone.str() );
// Handle potential user specified time offsets
Point3D obj_pos = sgGeodToCart( obj_posn );
// Translate moving object w.r.t eye
- Point3D Objtrans = obj_pos-scenery.center;
+ Point3D Objtrans = obj_pos-scenery.get_center();
bz[0]=Objtrans.x();
bz[1]=Objtrans.y();
bz[2]=Objtrans.z();
#include <simgear/debug/logstream.hxx>
#include <simgear/math/point3d.hxx>
#include <simgear/math/polar3d.hxx>
+#include <simgear/math/sg_geodesy.hxx>
#include <simgear/math/vector.hxx>
#include <Scenery/scenery.hxx>
Point3D tmp;
sgVec3 minus_z;
+ // convert to geocentric coordinates
+ double geoc_lat;
+ sgGeodToGeoc( geod_view_pos[1], geod_view_pos[2],
+ &sea_level_radius, &geoc_lat );
+
// calculate the cartesion coords of the current lat/lon/0 elev
- Point3D p = Point3D( geod_view_pos[0],
- geod_view_pos[1],
- sea_level_radius );
+ Point3D p = Point3D( geod_view_pos[0], geoc_lat, sea_level_radius );
- tmp = sgPolarToCart3d(p) - scenery.center;
+ tmp = sgPolarToCart3d(p) - scenery.get_center();
sgSetVec3( zero_elev, tmp[0], tmp[1], tmp[2] );
// calculate view position in current FG view coordinate system
// p.lon & p.lat are already defined earlier, p.radius was set to
// the sea level radius, so now we add in our altitude.
- if ( geod_view_pos[2] > (scenery.cur_elev + 0.5 * SG_METER_TO_FEET) ) {
+ if ( geod_view_pos[2] > (scenery.get_cur_elev() + 0.5 * SG_METER_TO_FEET) ) {
p.setz( p.radius() + geod_view_pos[2] );
} else {
- p.setz( p.radius() + scenery.cur_elev + 0.5 * SG_METER_TO_FEET );
+ p.setz( p.radius() + scenery.get_cur_elev() + 0.5 * SG_METER_TO_FEET );
}
tmp = sgPolarToCart3d(p);
// view_pos = abs_view_pos - scenery.center;
sgdVec3 sc;
- sgdSetVec3( sc, scenery.center.x(), scenery.center.y(), scenery.center.z());
+ sgdSetVec3( sc,
+ scenery.get_center().x(),
+ scenery.get_center().y(),
+ scenery.get_center().z() );
sgdVec3 vp;
sgdSubVec3( vp, abs_view_pos, sc );
sgSetVec3( view_pos, vp );
#include <simgear/debug/logstream.hxx>
#include <simgear/math/point3d.hxx>
#include <simgear/math/polar3d.hxx>
+#include <simgear/math/sg_geodesy.hxx>
#include <simgear/math/vector.hxx>
#include <Scenery/scenery.hxx>
sgVec3 minus_z, forward;
sgMat4 VIEWo;
+ // convert to geocentric coordinates
+ double geoc_lat;
+ sgGeodToGeoc( geod_view_pos[1], geod_view_pos[2],
+ &sea_level_radius, &geoc_lat );
+
// calculate the cartesion coords of the current lat/lon/0 elev
- Point3D p = Point3D( geod_view_pos[0],
- geod_view_pos[1],
- sea_level_radius );
+ Point3D p = Point3D( geod_view_pos[0], geoc_lat, sea_level_radius );
- tmp = sgPolarToCart3d(p) - scenery.center;
+ tmp = sgPolarToCart3d(p) - scenery.get_center();
sgSetVec3( zero_elev, tmp[0], tmp[1], tmp[2] );
// calculate view position in current FG view coordinate system
// p.lon & p.lat are already defined earlier, p.radius was set to
// the sea level radius, so now we add in our altitude.
- if ( geod_view_pos[2] > (scenery.cur_elev + 0.5 * SG_METER_TO_FEET) ) {
+ if ( geod_view_pos[2] > (scenery.get_cur_elev() + 0.5 * SG_METER_TO_FEET) ) {
p.setz( p.radius() + geod_view_pos[2] );
} else {
- p.setz( p.radius() + scenery.cur_elev + 0.5 * SG_METER_TO_FEET );
+ p.setz( p.radius() + scenery.get_cur_elev() + 0.5 * SG_METER_TO_FEET );
}
tmp = sgPolarToCart3d(p);
// view_pos = abs_view_pos - scenery.center;
sgdVec3 sc;
- sgdSetVec3( sc, scenery.center.x(), scenery.center.y(), scenery.center.z());
+ sgdSetVec3( sc,
+ scenery.get_center().x(),
+ scenery.get_center().y(),
+ scenery.get_center().z() );
sgdVec3 vp;
sgdSubVec3( vp, abs_view_pos, sc );
sgSetVec3( view_pos, vp );
raw->brake[i] = globals->get_controls()->get_brake(i);
}
- raw->hground = scenery.cur_elev;
+ raw->hground = scenery.get_cur_elev();
}
for ( i = 0; i < FG_MAX_WHEELS; ++i ) {
globals->get_controls()->set_brake( i, raw->brake[i] );
}
- scenery.cur_elev = raw->hground;
+ scenery.set_cur_elev( raw->hground );
} else {
SG_LOG( SG_IO, SG_ALERT, "Error: version mismatch in raw2global()" );
SG_LOG( SG_IO, SG_ALERT,
#include <simgear/debug/logstream.hxx>
+#include <Main/fg_props.hxx>
+
#include "scenery.hxx"
// Shared structure to hold current scenery parameters
-struct fgSCENERY scenery;
+FGScenery scenery;
-// Initialize the Scenery Management system
-int fgSceneryInit( void ) {
+// Scenery Management system
+FGScenery::FGScenery() {
SG_LOG( SG_TERRAIN, SG_INFO, "Initializing scenery subsystem" );
- scenery.center = Point3D(0.0);
- scenery.cur_elev = -9999;
+ center = Point3D(0.0);
+ cur_elev = -9999;
+}
+
+// Initialize the Scenery Management system
+FGScenery::~FGScenery() {
+}
+
+void FGScenery::init() {
+}
+
+void FGScenery::update() {
+}
+
+void FGScenery::bind() {
+ fgTie("/environment/ground-elevation-m", this,
+ &FGScenery::get_cur_elev, &FGScenery::set_cur_elev);
+}
- return 1;
+void FGScenery::unbind() {
+ fgUntie("/environment/ground-elevation-m");
}
#include <plib/sg.h>
#include <simgear/math/point3d.hxx>
+#include <Main/fgfs.hxx>
+
// Define a structure containing global scenery parameters
-struct fgSCENERY {
+class FGScenery : public FGSubsystem {
// center of current scenery chunk
Point3D center;
// unit normal at point used to determine current elevation
sgdVec3 cur_normal;
+
+public:
+
+ FGScenery();
+ ~FGScenery();
+
+ // Implementation of FGSubsystem.
+ void init ();
+ void bind ();
+ void unbind ();
+ void update ();
+
+ inline double get_cur_elev() const { return cur_elev; }
+ inline void set_cur_elev( double e ) { cur_elev = e; }
+
+ inline Point3D get_center() const { return center; }
+ inline void set_center( Point3D p ) { center = p; }
+
+ inline Point3D get_next_center() const { return next_center; }
+ inline void set_next_center( Point3D p ) { next_center = p; }
+
+ inline void set_cur_radius( double r ) { cur_radius = r; }
+ inline void set_cur_normal( sgdVec3 n ) { sgdCopyVec3( cur_normal, n ); }
};
-extern struct fgSCENERY scenery;
+
+extern FGScenery scenery;
// Initialize the Scenery Management system
double agl;
if ( current_aircraft.fdm_state ) {
agl = current_aircraft.fdm_state->get_Altitude() * SG_FEET_TO_METER
- - scenery.cur_elev;
+ - scenery.get_cur_elev();
} else {
agl = 0.0;
}
double agl1;
if ( current_aircraft.fdm_state ) {
agl1 = current_aircraft.fdm_state->get_Altitude() * SG_FEET_TO_METER
- - scenery.cur_elev;
+ - scenery.get_cur_elev();
} else {
agl1 = 0.0;
}
terra_transform->addKid( terra_range );
// calculate initial tile offset
- SetOffset( scenery.center );
+ SetOffset( scenery.get_center() );
sgCoord sgcoord;
sgSetCoord( &sgcoord,
offset.x(), offset.y(), offset.z(),
// schedule a needed buckets for loading
void FGTileMgr::schedule_needed() {
+ cout << "scheduling needed tiles for " << longitude << " " << latitude << endl;
#ifndef FG_OLD_WEATHER
if ( WeatherDatabase != NULL ) {
vis = WeatherDatabase->getWeatherVisibility();
// chunks. If the chunk isn't already in the cache, then read it from
// disk.
int FGTileMgr::update( double lon, double lat ) {
- SG_LOG( SG_TERRAIN, SG_DEBUG, "FGTileMgr::update()" );
+ SG_LOG( SG_TERRAIN, SG_DEBUG, "FGTileMgr::update() for" << lon << " " << lat );
- // FGInterface *f = current_aircraft.fdm_state;
-
- // lonlat for this update
- // longitude = f->get_Longitude() * SGD_RADIANS_TO_DEGREES;
- // latitude = f->get_Latitude() * SGD_RADIANS_TO_DEGREES;
longitude = lon;
latitude = lat;
// SG_LOG( SG_TERRAIN, SG_DEBUG, "lon "<< lonlat[LON] <<
if ( tile_cache.exists( current_bucket ) ) {
current_tile = tile_cache.get_tile( current_bucket );
- scenery.next_center = current_tile->center;
+ scenery.set_next_center( current_tile->center );
} else {
SG_LOG( SG_TERRAIN, SG_WARN, "Tile not found (Ok if initializing)" );
}
if ( state == Running ) {
+ SG_LOG( SG_TERRAIN, SG_DEBUG, "State == Running" );
if ( !(current_bucket == previous_bucket) ) {
// We've moved to a new bucket, we need to schedule any
// needed tiles for loading.
schedule_needed();
}
} else if ( state == Start || state == Inited ) {
+ SG_LOG( SG_TERRAIN, SG_INFO, "State == Start || Inited" );
initialize_queue();
state = Running;
- }
- // load the next tile in the load queue (or authorize the next
- // load in the case of the threaded tile pager)
- loader.update();
+ // load the next tile in the load queue (or authorize the next
+ // load in the case of the threaded tile pager)
+ loader.update();
+ }
// load the next model in the load queue. Currently this must
// happen in the render thread because model loading can trigger
delete dm;
}
- // cout << "current elevation (ssg) == " << scenery.cur_elev << endl;
+ // cout << "current elevation (ssg) == " << scenery.get_cur_elev() << endl;
previous_bucket = current_bucket;
last_longitude = longitude;
// activate loader thread one out of every 5 frames
if ( counter_hack == 0 ) {
// Notify the tile loader that it can load another tile
- // loader.update();
+ loader.update();
- if ( !attach_queue.empty() ) {
+ }
+ counter_hack = (counter_hack + 1) % 5;
+
+ if ( !attach_queue.empty() ) {
#ifdef ENABLE_THREADS
- FGTileEntry* e = attach_queue.pop();
+ FGTileEntry* e = attach_queue.pop();
#else
- FGTileEntry* e = attach_queue.front();
- attach_queue.pop();
+ FGTileEntry* e = attach_queue.front();
+ attach_queue.pop();
#endif
- e->add_ssg_nodes( terrain, ground );
- // cout << "Adding ssg nodes for "
- }
+ e->add_ssg_nodes( terrain, ground );
+ // cout << "Adding ssg nodes for "
}
- counter_hack = (counter_hack + 1) % 5;
+
sgdVec3 sc;
- sgdSetVec3( sc, scenery.center[0], scenery.center[1], scenery.center[2] );
+ sgdSetVec3( sc,
+ scenery.get_center()[0],
+ scenery.get_center()[1],
+ scenery.get_center()[2] );
+#if 0
if ( scenery.center == Point3D(0.0) ) {
// initializing
cout << "initializing scenery current elevation ... " << endl;
if ( fgCurrentElev(tmp_abs_view_pos, sc, &hit_list,
&tmp_elev, &scenery.cur_radius, scenery.cur_normal) )
{
- scenery.cur_elev = tmp_elev;
+ scenery.set_cur_elev( tmp_elev );
} else {
- scenery.cur_elev = 0.0;
+ scenery.set_cur_elev( 0.0 );
}
- cout << "result = " << scenery.cur_elev << endl;
+ cout << "result = " << scenery.get_cur_elev() << endl;
} else {
+#endif
// cout << "abs view pos = " << current_view.abs_view_pos
// << " view pos = " << current_view.view_pos << endl;
double tmp_elev;
+ double tmp_radius;
+ sgdVec3 tmp_normal;
if ( fgCurrentElev(globals->get_current_view()->get_abs_view_pos(),
sc, &hit_list,
- &tmp_elev, &scenery.cur_radius, scenery.cur_normal) )
+ &tmp_elev, &tmp_radius, tmp_normal) )
{
- scenery.cur_elev = tmp_elev;
+ scenery.set_cur_elev( tmp_elev );
+ scenery.set_cur_radius( tmp_radius );
+ scenery.set_cur_normal( tmp_normal );
} else {
- scenery.cur_elev = 0.0;
+ scenery.set_cur_elev( -9999.0 );
}
+#if 0
}
+#endif
return 1;
}
while ( ! tile_cache.at_end() ) {
// cout << "processing a tile" << endl;
if ( (e = tile_cache.get_current()) ) {
- e->prep_ssg_node( scenery.center, vis);
+ e->prep_ssg_node( scenery.get_center(), vis);
} else {
cout << "warning ... empty tile in cache" << endl;
}
Point3D vp( v->get_view_pos()[0],
v->get_view_pos()[1],
v->get_view_pos()[2] );
- rel_moonpos = l->fg_moonpos - ( vp + scenery.center );
+ rel_moonpos = l->fg_moonpos - ( vp + scenery.get_center() );
sgSetVec3( to_moon, rel_moonpos.x(), rel_moonpos.y(), rel_moonpos.z() );
// printf( "Vector to moon = %.2f %.2f %.2f\n",
// to_moon[0], to_moon[1], to_moon[2]);
Point3D vp( v->get_view_pos()[0],
v->get_view_pos()[1],
v->get_view_pos()[2] );
- rel_sunpos = l->fg_sunpos - ( vp + scenery.center );
+ rel_sunpos = l->fg_sunpos - ( vp + scenery.get_center() );
sgSetVec3( to_sun, rel_sunpos.x(), rel_sunpos.y(), rel_sunpos.z() );
// printf( "Vector to sun = %.2f %.2f %.2f\n",
// v->to_sun[0], v->to_sun[1], v->to_sun[2]);