if ( airports.search( AptId, &a ) )
{
current_options.set_airport_id( AptId.c_str() );
+ current_options.set_altitude( -9999.0 );
+ fgSetPosFromAirportID( AptId );
BusyCursor(0);
fgReInitSubsystems();
BusyCursor(1);
FGInterface *f = current_aircraft.fdm_state;
string id = current_options.get_airport_id();
- if ( id.length() ) {
- // set initial position from airport id
- if ( ! fgSetPosFromAirportID( id ) ) {
- exit(-1);
- }
- }
-
// set initial position from default or command line coordinates
f->set_Longitude( current_options.get_lon() * DEG_TO_RAD );
f->set_Latitude( current_options.get_lat() * DEG_TO_RAD );
+ if ( scenery.cur_elev > current_options.get_altitude() - 2 ) {
+ current_options.set_altitude( scenery.cur_elev + 2 );
+ }
+
FG_LOG( FG_GENERAL, FG_INFO,
"starting altitude is = " << current_options.get_altitude() );
FG_LOG( FG_GENERAL, FG_INFO, "Initialize Subsystems");
FG_LOG( FG_GENERAL, FG_INFO, "========== ==========");
- if ( current_options.get_flight_model() == FGInterface::FG_LARCSIM ) {
- cur_fdm_state = new FGLaRCsim;
- } else if ( current_options.get_flight_model() == FGInterface::FG_JSBSIM ) {
- cur_fdm_state = new FGJSBsim;
- } else if ( current_options.get_flight_model() ==
- FGInterface::FG_BALLOONSIM ) {
- cur_fdm_state = new FGBalloonSim;
- } else if ( current_options.get_flight_model() ==
- FGInterface::FG_MAGICCARPET ) {
- cur_fdm_state = new FGMagicCarpet;
- } else if ( current_options.get_flight_model() ==
- FGInterface::FG_EXTERNAL ) {
- cur_fdm_state = new FGExternal;
- } else {
- FG_LOG( FG_GENERAL, FG_ALERT,
- "No flight model, can't init aircraft" );
- exit(-1);
- }
-
- // allocates structures so must happen before any of the flight
- // model or control parameters are set
- fgAircraftInit(); // In the future this might not be the case.
-
- // set the initial position
- fgInitPosition();
-
// Initialize the material property lib
FGPath mpath( current_options.get_fg_root() );
mpath.append( "materials" );
exit(-1);
}
- if( global_tile_mgr.init() ) {
+ if ( global_tile_mgr.init() ) {
// Load the local scenery data
- global_tile_mgr.update( cur_fdm_state->get_Longitude(),
- cur_fdm_state->get_Latitude() );
+ global_tile_mgr.update( current_options.get_lon(),
+ current_options.get_lat() );
} else {
FG_LOG( FG_GENERAL, FG_ALERT, "Error in Tile Manager initialization!" );
exit(-1);
"Current terrain elevation after tile mgr init " <<
scenery.cur_elev );
+ if ( current_options.get_flight_model() == FGInterface::FG_LARCSIM ) {
+ cur_fdm_state = new FGLaRCsim;
+ } else if ( current_options.get_flight_model() == FGInterface::FG_JSBSIM ) {
+ cur_fdm_state = new FGJSBsim;
+ } else if ( current_options.get_flight_model() ==
+ FGInterface::FG_BALLOONSIM ) {
+ cur_fdm_state = new FGBalloonSim;
+ } else if ( current_options.get_flight_model() ==
+ FGInterface::FG_MAGICCARPET ) {
+ cur_fdm_state = new FGMagicCarpet;
+ } else if ( current_options.get_flight_model() ==
+ FGInterface::FG_EXTERNAL ) {
+ cur_fdm_state = new FGExternal;
+ } else {
+ FG_LOG( FG_GENERAL, FG_ALERT,
+ "No flight model, can't init aircraft" );
+ exit(-1);
+ }
+
+ // allocates structures so must happen before any of the flight
+ // model or control parameters are set
+ fgAircraftInit(); // In the future this might not be the case.
+
+ // set the initial position
+ fgInitPosition();
+
// Calculate ground elevation at starting point (we didn't have
// tmp_abs_view_pos calculated when fgTileMgrUpdate() was called above
//
if( !freeze )
globals->set_freeze( true );
- fgInitPosition();
if( global_tile_mgr.init() ) {
// Load the local scenery data
- global_tile_mgr.update( cur_fdm_state->get_Longitude(),
- cur_fdm_state->get_Latitude() );
+ global_tile_mgr.update( current_options.get_lon(),
+ current_options.get_lat() );
} else {
FG_LOG( FG_GENERAL, FG_ALERT, "Error in Tile Manager initialization!" );
exit(-1);
}
+
+ // cout << "current scenery elev = " << scenery.cur_elev << endl;
+
+ fgInitPosition();
fgFDMSetGroundElevation( current_options.get_flight_model(),
scenery.cur_elev );
if ( !freeze )
globals->set_freeze( true );
BusyCursor(0);
- if( global_tile_mgr.init() ) {
+ if ( global_tile_mgr.init() ) {
// Load the local scenery data
- global_tile_mgr.update( cur_fdm_state->get_Longitude(),
- cur_fdm_state->get_Latitude() );
+ global_tile_mgr.update(
+ cur_fdm_state->get_Longitude() * RAD_TO_DEG,
+ cur_fdm_state->get_Latitude() * RAD_TO_DEG );
} else {
FG_LOG( FG_GENERAL, FG_ALERT,
"Error in Tile Manager initialization!" );
#endif
// see if we need to load any new scenery tiles
- global_tile_mgr.update( cur_fdm_state->get_Longitude(),
- cur_fdm_state->get_Latitude() );
+ global_tile_mgr.update( cur_fdm_state->get_Longitude() * RAD_TO_DEG,
+ cur_fdm_state->get_Latitude() * RAD_TO_DEG );
// Process/manage pending events
global_events.Process();
// Initialize the Scenery Management system
int fgSceneryInit( void ) {
- fgOPTIONS *o;
- // char path[1024], fgpath[1024];
- // GLubyte *texbuf;
- // int width, height;
-
- o = ¤t_options;
-
FG_LOG( FG_TERRAIN, FG_INFO, "Initializing scenery subsystem" );
scenery.cur_elev = -9999;
- return(1);
+ return 1;
}
// and ... just in case we missed something ...
terrain->removeAllKids();
- FG_LOG( FG_TERRAIN, FG_DEBUG, " done with init()" );
+ FG_LOG( FG_TERRAIN, FG_INFO, " done with init()" );
}
#include <simgear/math/polar3d.hxx>
#include <simgear/math/vector.hxx>
-#include <Aircraft/aircraft.hxx>
+// #include <Aircraft/aircraft.hxx>
#include <Main/options.hxx>
#include <Main/views.hxx>
#include <Objects/obj.hxx>
if ( state != Start ) {
FG_LOG( FG_TERRAIN, FG_INFO,
- "ReInitializing the Tile Manager subsystem." );
+ "... Reinitializing." );
// This is necessay to keep bookeeping straight for the
// tile_cache -- which actually handles all the
}
} else {
FG_LOG( FG_TERRAIN, FG_INFO,
- "Initializing Tile Manager subsystem." );
+ "... First time through." );
}
global_tile_cache.init();
}
-void FGTileMgr::initialize_queue( void )
+void FGTileMgr::initialize_queue()
{
// First time through or we have teleported, initialize the
// system and load all relavant tiles
FG_LOG( FG_TERRAIN, FG_INFO, "Updating Tile list for " << current_bucket );
- FG_LOG( FG_TERRAIN, FG_INFO, " First time through ... " );
FG_LOG( FG_TERRAIN, FG_INFO, " Updating Tile list for " << current_bucket );
FG_LOG( FG_TERRAIN, FG_INFO, " Loading "
<< tile_diameter * tile_diameter << " tiles" );
// "rings"
sched_tile( current_bucket );
- Point3D geod_view_center( current_bucket.get_center_lon(),
- current_bucket.get_center_lat(),
- cur_fdm_state->get_Altitude()*FEET_TO_METER + 3 );
-
- current_view.abs_view_pos = fgGeodToCart( geod_view_center );
- current_view.view_pos = current_view.abs_view_pos - scenery.next_center;
for ( i = 3; i <= tile_diameter; i = i + 2 ) {
int j;
}
-// given the current lon/lat, fill in the array of local chunks. If
-// the chunk isn't already in the cache, then read it from disk.
-int FGTileMgr::update( double junk1, double junk2 ) {
+// given the current lon/lat (in degrees), fill in the array of local
+// chunks. If the chunk isn't already in the cache, then read it from
+// disk.
+int FGTileMgr::update( double lon, double lat ) {
// FG_LOG( FG_TERRAIN, FG_DEBUG, "FGTileMgr::update()" );
- FGInterface *f = current_aircraft.fdm_state;
+ // FGInterface *f = current_aircraft.fdm_state;
// lonlat for this update
- longitude = f->get_Longitude() * RAD_TO_DEG;
- latitude = f->get_Latitude() * RAD_TO_DEG;
+ // longitude = f->get_Longitude() * RAD_TO_DEG;
+ // latitude = f->get_Latitude() * RAD_TO_DEG;
+ longitude = lon;
+ latitude = lat;
// FG_LOG( FG_TERRAIN, FG_DEBUG, "lon "<< lonlat[LON] <<
// " lat " << lonlat[LAT] );
current_tile = global_tile_cache.get_tile(tile_index);
scenery.next_center = current_tile->center;
} else {
- FG_LOG( FG_TERRAIN, FG_WARN, "Tile not found" );
+ FG_LOG( FG_TERRAIN, FG_WARN, "Tile not found (Ok if initializing)" );
}
if ( state == Running ) {
scroll();
}
- } else if ( (state == Start) || (state == Inited) ) {
+ } else if ( state == Start || state == Inited ) {
initialize_queue();
state = Running;
}
load_tile( pending.b, pending.cache_index );
}
- // find our current elevation (feed in the current bucket to save work)
- // Point3D geod_pos = Point3D( f->get_Longitude(), f->get_Latitude(), 0.0);
- // Point3D tmp_abs_view_pos = fgGeodToCart(geod_pos);
-
- // cout << "current elevation (old) == "
- // << current_elev( f->get_Longitude(), f->get_Latitude(),
- // tmp_abs_view_pos )
- // << endl;
-
- // set scenery.cur_elev and scenery.cur_radius
+ if ( scenery.center == Point3D(0.0) ) {
+ // initializing
+ // cout << "initializing ... " << endl;
+ Point3D geod_pos = Point3D( longitude * DEG_TO_RAD,
+ latitude * DEG_TO_RAD,
+ 0.0);
+ Point3D tmp_abs_view_pos = fgGeodToCart( geod_pos );
+ scenery.center = tmp_abs_view_pos;
+ // cout << "abs_view_pos = " << tmp_abs_view_pos << endl;
+ prep_ssg_nodes();
+ current_elev_ssg( tmp_abs_view_pos,
+ Point3D( 0.0 ) );
+ } else {
+ // cout << "abs view pos = " << current_view.abs_view_pos
+ // << " view pos = " << current_view.view_pos << endl;
+ current_elev_ssg( current_view.abs_view_pos,
+ current_view.view_pos );
+ }
- current_elev_ssg( current_view.abs_view_pos,
- current_view.view_pos );
// cout << "current elevation (ssg) == " << scenery.cur_elev << endl;
previous_bucket = current_bucket;
FGTileEntry *t;
float ranges[2];
ranges[0] = 0.0f;
+ double vis = 0.0;
+
+#ifndef FG_OLD_WEATHER
+ if ( WeatherDatabase != NULL ) {
+ vis = WeatherDatabase->getWeatherVisibility();
+ } else {
+ vis = 16000;
+ }
+#else
+ vis = current_weather.get_visibility();
+#endif
+ // cout << "visibility = " << vis << endl;
// traverse the potentially viewable tile list and update range
// selector and transform
// set range selector (LOD trick) to be distance to center
// of tile + bounding radius
-#ifndef FG_OLD_WEATHER
- ranges[1] = WeatherDatabase->getWeatherVisibility()
- + t->bounding_radius;
-#else
- ranges[1] = current_weather.get_visibility()+t->bounding_radius;
-#endif
+ ranges[1] = vis + t->bounding_radius;
t->range_ptr->setRanges( ranges, 2 );
// calculate tile offset
list < FGLoadRec > load_queue;
// initialize the cache
- void initialize_queue( void );
+ void initialize_queue();
FGBucket BucketOffset( int dx, int dy );
// Initialize the Tile Manager subsystem
int init( void );
- // given the current lon/lat, fill in the array of local chunks.
- // If the chunk isn't already in the cache, then read it from
- // disk.
- int update( double junk1, double junk2 );
+ // given the current lon/lat (in degrees), fill in the array of
+ // local chunks. If the chunk isn't already in the cache, then
+ // read it from disk.
+ int update( double lon, double lat );
// Determine scenery altitude. Normally this just happens when we
// render the scene, but we'd also like to be able to do this