From 649d579124130d92a908c588c6972673fa0ac064 Mon Sep 17 00:00:00 2001 From: James Turner Date: Tue, 25 Sep 2012 10:06:30 +0100 Subject: [PATCH] Helpers to access view position. Avoid direct use of FGViewer in various places, by providing property-based accessors to the current view position. --- src/AIModel/AIAircraft.cxx | 12 ++++-------- src/AIModel/AICarrier.cxx | 3 +-- src/Instrumentation/adf.cxx | 2 +- src/Main/globals.cxx | 19 ++++++++++++++++++- src/Main/globals.hxx | 7 ++++++- src/Scenery/tilemgr.cxx | 4 +--- src/Time/light.cxx | 3 +-- src/Traffic/TrafficMgr.cxx | 2 +- 8 files changed, 33 insertions(+), 19 deletions(-) diff --git a/src/AIModel/AIAircraft.cxx b/src/AIModel/AIAircraft.cxx index 180f0bfc8..82f21a4e4 100644 --- a/src/AIModel/AIAircraft.cxx +++ b/src/AIModel/AIAircraft.cxx @@ -24,7 +24,6 @@ #include
#include
-#include #include #include #include @@ -172,8 +171,7 @@ void FGAIAircraft::setPerformance(const std::string& acclass) { void FGAIAircraft::checkVisibility() { double visibility_meters = fgGetDouble("/environment/visibility-m"); - FGViewer* vw = globals->get_current_view(); - invisible = (SGGeodesy::distanceM(vw->getPosition(), pos) > visibility_meters); + invisible = (SGGeodesy::distanceM(globals->get_view_position(), pos) > visibility_meters); } @@ -516,10 +514,8 @@ void FGAIAircraft::getGroundElev(double dt) { // Only do the proper hitlist stuff if we are within visible range of the viewer. if (!invisible) { - double visibility_meters = fgGetDouble("/environment/visibility-m"); - FGViewer* vw = globals->get_current_view(); - - if (SGGeodesy::distanceM(vw->getPosition(), pos) > visibility_meters) { + double visibility_meters = fgGetDouble("/environment/visibility-m"); + if (SGGeodesy::distanceM(globals->get_view_position(), pos) > visibility_meters) { return; } @@ -839,7 +835,7 @@ bool FGAIAircraft::aiTrafficVisible() SGVec3d cartPos = SGVec3d::fromGeod(pos); const double d2 = (TRAFFICTOAIDISTTODIE * SG_NM_TO_METER) * (TRAFFICTOAIDISTTODIE * SG_NM_TO_METER); - return (distSqr(cartPos, globals->get_aircraft_positon_cart()) < d2); + return (distSqr(cartPos, globals->get_aircraft_position_cart()) < d2); } diff --git a/src/AIModel/AICarrier.cxx b/src/AIModel/AICarrier.cxx index 408375539..e9aea5207 100644 --- a/src/AIModel/AICarrier.cxx +++ b/src/AIModel/AICarrier.cxx @@ -30,7 +30,6 @@ #include #include
-#include #include "AICarrier.hxx" @@ -166,7 +165,7 @@ void FGAICarrier::update(double dt) { SGVec3d cartPos = SGVec3d::fromGeod(pos); // The position of the eyepoint - at least near that ... - SGVec3d eyePos(globals->get_current_view()->get_view_pos()); + SGVec3d eyePos(globals->get_view_position_cart()); // Add the position offset of the AIModel to gain the earth // centered position SGVec3d eyeWrtCarrier = eyePos - cartPos; diff --git a/src/Instrumentation/adf.cxx b/src/Instrumentation/adf.cxx index 3dfe9f3bd..8e7de8626 100644 --- a/src/Instrumentation/adf.cxx +++ b/src/Instrumentation/adf.cxx @@ -164,7 +164,7 @@ ADF::update (double delta_time_sec) } // Calculate the bearing to the transmitter - SGVec3d location = globals->get_aircraft_positon_cart(); + SGVec3d location = globals->get_aircraft_position_cart(); double distance_nm = dist(_transmitter_cart, location) * SG_METER_TO_NM; double range_nm = adjust_range(_transmitter_pos.getElevationFt(), diff --git a/src/Main/globals.cxx b/src/Main/globals.cxx index b126d795c..1d3e14264 100644 --- a/src/Main/globals.cxx +++ b/src/Main/globals.cxx @@ -148,6 +148,10 @@ FGGlobals::FGGlobals() : positionLat = props->getNode("position/latitude-deg", true); positionAlt = props->getNode("position/altitude-ft", true); + viewLon = props->getNode("sim/current-view/viewer-lon-deg", true); + viewLat = props->getNode("sim/current-view/viewer-lat-deg", true); + viewAlt = props->getNode("sim/current-view/viewer-elev-ft", true); + orientPitch = props->getNode("orientation/pitch-deg", true); orientHeading = props->getNode("orientation/heading-deg", true); orientRoll = props->getNode("orientation/roll-deg", true); @@ -380,7 +384,7 @@ FGGlobals::get_aircraft_position() const } SGVec3d -FGGlobals::get_aircraft_positon_cart() const +FGGlobals::get_aircraft_position_cart() const { return SGVec3d::fromGeod(get_aircraft_position()); } @@ -392,6 +396,19 @@ void FGGlobals::get_aircraft_orientation(double& heading, double& pitch, double& roll = orientRoll->getDoubleValue(); } +SGGeod +FGGlobals::get_view_position() const +{ + return SGGeod::fromDegFt(viewLon->getDoubleValue(), + viewLat->getDoubleValue(), + viewAlt->getDoubleValue()); +} + +SGVec3d +FGGlobals::get_view_position_cart() const +{ + return SGVec3d::fromGeod(get_view_position()); +} // Save the current state as the initial state. void diff --git a/src/Main/globals.hxx b/src/Main/globals.hxx index 40c2b697e..5fd300ced 100644 --- a/src/Main/globals.hxx +++ b/src/Main/globals.hxx @@ -148,6 +148,7 @@ private: bool haveUserSettings; SGPropertyNode_ptr positionLon, positionLat, positionAlt; + SGPropertyNode_ptr viewLon, viewLat, viewAlt; SGPropertyNode_ptr orientHeading, orientPitch, orientRoll; public: @@ -249,10 +250,14 @@ public: SGGeod get_aircraft_position() const; - SGVec3d get_aircraft_positon_cart() const; + SGVec3d get_aircraft_position_cart() const; void get_aircraft_orientation(double& heading, double& pitch, double& roll); + SGGeod get_view_position() const; + + SGVec3d get_view_position_cart() const; + inline string_list *get_channel_options_list () { return channel_options_list; } diff --git a/src/Scenery/tilemgr.cxx b/src/Scenery/tilemgr.cxx index 51f24044b..8a3c39fe0 100644 --- a/src/Scenery/tilemgr.cxx +++ b/src/Scenery/tilemgr.cxx @@ -41,7 +41,6 @@ #include
#include
#include -#include #include #include @@ -314,9 +313,8 @@ void FGTileMgr::update_queues() // disk. void FGTileMgr::update(double) { - SGVec3d viewPos = globals->get_current_view()->get_view_pos(); double vis = _visibilityMeters->getDoubleValue(); - schedule_tiles_at(SGGeod::fromCart(viewPos), vis); + schedule_tiles_at(globals->get_view_position(), vis); update_queues(); diff --git a/src/Time/light.cxx b/src/Time/light.cxx index 0c3face55..dc176ae6a 100644 --- a/src/Time/light.cxx +++ b/src/Time/light.cxx @@ -410,8 +410,7 @@ void FGLight::updateSunPos() _sun_vec_inv = - _sun_vec; // calculate the sun's relative angle to local up - FGViewer *v = globals->get_current_view(); - SGQuatd hlOr = SGQuatd::fromLonLat( v->getPosition() ); + SGQuatd hlOr = SGQuatd::fromLonLat( globals->get_view_position() ); SGVec3d world_up = hlOr.backTransform( -SGVec3d::e3() ); // cout << "nup = " << nup[0] << "," << nup[1] << "," // << nup[2] << endl; diff --git a/src/Traffic/TrafficMgr.cxx b/src/Traffic/TrafficMgr.cxx index 2de3be5d0..2a0a51b86 100644 --- a/src/Traffic/TrafficMgr.cxx +++ b/src/Traffic/TrafficMgr.cxx @@ -303,7 +303,7 @@ void FGTrafficManager::update(double /*dt */ ) return; } - SGVec3d userCart = globals->get_aircraft_positon_cart(); + SGVec3d userCart = globals->get_aircraft_position_cart(); if (currAircraft == scheduledAircraft.end()) { currAircraft = scheduledAircraft.begin();