]> git.mxchange.org Git - flightgear.git/commitdiff
Helpers to access view position.
authorJames Turner <zakalawe@mac.com>
Tue, 25 Sep 2012 09:06:30 +0000 (10:06 +0100)
committerJames Turner <zakalawe@mac.com>
Tue, 25 Sep 2012 09:06:56 +0000 (10:06 +0100)
Avoid direct use of FGViewer in various places, by providing property-based accessors to the current view position.

src/AIModel/AIAircraft.cxx
src/AIModel/AICarrier.cxx
src/Instrumentation/adf.cxx
src/Main/globals.cxx
src/Main/globals.hxx
src/Scenery/tilemgr.cxx
src/Time/light.cxx
src/Traffic/TrafficMgr.cxx

index 180f0bfc8b27809e6f500e81d62d8165b0f89cd6..82f21a4e4dfddc12eb45149591adf2b3777b7745 100644 (file)
@@ -24,7 +24,6 @@
 
 #include <Main/fg_props.hxx>
 #include <Main/globals.hxx>
-#include <Viewer/viewer.hxx>
 #include <Scenery/scenery.hxx>
 #include <Scenery/tilemgr.hxx>
 #include <Airports/dynamics.hxx>
@@ -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);
 }
 
 
index 408375539b6aa53d86e5e8f37fbeba564c5cd279..e9aea5207d1f6337f7899fedbc6f2290d4b5b6e0 100644 (file)
@@ -30,7 +30,6 @@
 
 #include <math.h>
 #include <Main/util.hxx>
-#include <Viewer/viewer.hxx>
 
 #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;
index 3dfe9f3bd6c7e94b69556812039f90f6497668c8..8e7de862675c75ad741013342949dd73ffb82bf7 100644 (file)
@@ -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(),
index b126d795c1d33f565c4c48f09d0e4a2c0feab6f8..1d3e14264843da9f94e27ccaa681f46c0d8972bb 100644 (file)
@@ -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
index 40c2b697ee838bd34a260668c55cbaf8e0466cc9..5fd300ced5376cb2094bb1523777414ec14d7eff 100644 (file)
@@ -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;
     }
index 51f24044bc831a27044a3a03fdebe1739db00728..8a3c39fe0266bd02aff4ae0ea3f2de0a8dbbd5a4 100644 (file)
@@ -41,7 +41,6 @@
 #include <Main/globals.hxx>
 #include <Main/fg_props.hxx>
 #include <Viewer/renderer.hxx>
-#include <Viewer/viewer.hxx>
 #include <Viewer/splash.hxx>
 #include <Scripting/NasalSys.hxx>
 
@@ -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();
 
index 0c3face551d5d821674c82880a50cf4f156273ee..dc176ae6a9bc472ae17b76a4b3ccb6687029eafb 100644 (file)
@@ -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;
index 2de3be5d099e8ef8ac782d6e8490cc55283a1d10..2a0a51b86cd28a669a0d6e5e7203bb4a0f6f059d 100644 (file)
@@ -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();