]> git.mxchange.org Git - flightgear.git/commitdiff
Move data updating into the View class
authorJames Turner <zakalawe@mac.com>
Mon, 18 Jan 2016 02:21:20 +0000 (21:21 -0500)
committerJames Turner <zakalawe@mac.com>
Wed, 17 Feb 2016 21:25:39 +0000 (21:25 +0000)
src/Viewer/viewer.cxx
src/Viewer/viewer.hxx
src/Viewer/viewmgr.cxx

index 65b0060704d8beebb5035fae7a97047abf705d58..36e7fa967bdacb1e09e45fff2ae4aa7236ea5805 100644 (file)
@@ -175,6 +175,9 @@ View* View::createFromProperties(SGPropertyNode_ptr config)
                            roll_offset_deg, fov_deg, aspect_ratio_multiplier,
                            target_x_offset_m, target_y_offset_m,
                          target_z_offset_m, near_m, internal );
+        if (!from_model) {
+            v->_targetProperties = PositionAttitudeProperties(config, "target-");
+        }
     } else {
         v = new View ( FG_LOOKFROM, from_model, from_model_index,
                        false, 0, 0.0, 0.0, 0.0,
@@ -184,6 +187,10 @@ View* View::createFromProperties(SGPropertyNode_ptr config)
                          0, 0, 0, near_m, internal );
     }
 
+    if (!from_model) {
+        v->_eyeProperties = PositionAttitudeProperties(config, "eye-");
+    }
+
     v->_name = config->getParent()->getStringValue("name");
     v->_typeString = type;
     v->_configHeadingOffsetDeg = config->getDoubleValue("default-heading-offset-deg");
@@ -758,6 +765,32 @@ View::get_v_fov()
     return 0.0;
 }
 
+void
+View::updateData()
+{
+    if (!_from_model) {
+        SGVec3d pos = _eyeProperties.position();
+        SGVec3d att = _eyeProperties.attitude();
+
+        setPosition(pos.x(), pos.y(), pos.z());
+        setOrientation(att[2], att[1], att[0]);
+    } else {
+        set_dirty();
+    }
+
+    // if lookat (type 1) then get target data...
+    if (getType() == FG_LOOKAT) {
+        if (!_from_model) {
+            SGVec3d pos = _targetProperties.position();
+            SGVec3d att = _targetProperties.attitude();
+            setTargetPosition(pos.x(), pos.y(), pos.z());
+            setTargetOrientation(att[2], att[1], att[0]);
+        } else {
+            set_dirty();
+        }
+    }
+}
+
 void
 View::update (double dt)
 {
@@ -843,3 +876,31 @@ double View::get_aspect_ratio() const
 {
     return flightgear::CameraGroup::getDefault()->getMasterAspectRatio();
 }
+
+View::PositionAttitudeProperties::PositionAttitudeProperties()
+{
+}
+
+View::PositionAttitudeProperties::PositionAttitudeProperties(SGPropertyNode_ptr parent, const std::string& prefix)
+{
+    _lonProp = parent->getNode(prefix + "lon-deg-path", 0, true);
+    _latProp = parent->getNode(prefix + "lat-deg-path", 0, true);
+    _altProp = parent->getNode(prefix + "alt-ft-path", 0, true);
+    _headingProp = parent->getNode(prefix + "heading-deg-path", 0, true);
+    _pitchProp = parent->getNode(prefix + "pitch-deg-path", 0, true);
+    _rollProp = parent->getNode(prefix + "roll-deg-path", 0, true);
+}
+
+SGVec3d View::PositionAttitudeProperties::position() const
+{
+    return SGVec3d(_lonProp->getDoubleValue(),
+                   _latProp->getDoubleValue(),
+                   _altProp->getDoubleValue());
+}
+
+SGVec3d View::PositionAttitudeProperties::attitude() const
+{
+    return SGVec3d(_headingProp->getDoubleValue(),
+                   _pitchProp->getDoubleValue(),
+                   _rollProp->getDoubleValue());
+}
index 38c14f876398f15333fd3e83a245c3dede04f850..97f92ff692b5b621d7802b9eee086f9725fd7ce8 100644 (file)
@@ -79,7 +79,8 @@ public:
     //////////////////////////////////////////////////////////////////////
 
     void resetOffsetsAndFOV();
-
+    void updateData();
+    
     ViewType getType() const { return _type; }
     void setType( int type );
 
@@ -326,6 +327,27 @@ private:
     // multiplied into the aspect_ratio to get the actual vertical fov
     double _aspect_ratio_multiplier;
 
+    class PositionAttitudeProperties
+    {
+    public:
+        PositionAttitudeProperties();
+        
+        PositionAttitudeProperties(SGPropertyNode_ptr parent, const std::string& prefix);
+
+        SGVec3d position() const;
+        SGVec3d attitude() const; // as heading pitch roll
+    private:
+        SGPropertyNode_ptr _lonProp,
+            _latProp,
+        _altProp,
+        _headingProp,
+        _pitchProp,
+        _rollProp;
+    };
+
+    PositionAttitudeProperties _eyeProperties;
+    PositionAttitudeProperties _targetProperties;
+
     //////////////////////////////////////////////////////////////////
     // private functions                                            //
     //////////////////////////////////////////////////////////////////
index c0ecba9789e2dd6f73603f27a90096af65128d13..a9ec459338a24df81a093fbf6a0e180b0914be31 100644 (file)
@@ -232,37 +232,7 @@ FGViewMgr::update (double dt)
 
   // Set up view location and orientation
 
-  if (!config->getBoolValue("from-model")) {
-    lon_deg = fgGetDouble(config->getStringValue("eye-lon-deg-path"));
-    lat_deg = fgGetDouble(config->getStringValue("eye-lat-deg-path"));
-    alt_ft = fgGetDouble(config->getStringValue("eye-alt-ft-path"));
-    roll_deg = fgGetDouble(config->getStringValue("eye-roll-deg-path"));
-    pitch_deg = fgGetDouble(config->getStringValue("eye-pitch-deg-path"));
-    heading_deg = fgGetDouble(config->getStringValue("eye-heading-deg-path"));
-
-    currentView->setPosition(lon_deg, lat_deg, alt_ft);
-    currentView->setOrientation(roll_deg, pitch_deg, heading_deg);
-  } else {
-    // force recalc in viewer
-    currentView->set_dirty();
-  }
-
-  // if lookat (type 1) then get target data...
-    if (currentView->getType() == flightgear::View::FG_LOOKAT) {
-    if (!config->getBoolValue("from-model")) {
-      lon_deg = fgGetDouble(config->getStringValue("target-lon-deg-path"));
-      lat_deg = fgGetDouble(config->getStringValue("target-lat-deg-path"));
-      alt_ft = fgGetDouble(config->getStringValue("target-alt-ft-path"));
-      roll_deg = fgGetDouble(config->getStringValue("target-roll-deg-path"));
-      pitch_deg = fgGetDouble(config->getStringValue("target-pitch-deg-path"));
-      heading_deg = fgGetDouble(config->getStringValue("target-heading-deg-path"));
-
-      currentView->setTargetPosition(lon_deg, lat_deg, alt_ft);
-      currentView->setTargetOrientation(roll_deg, pitch_deg, heading_deg);
-    } else {
-      currentView->set_dirty();
-    }
-  }
+    currentView->updateData();
 
     // these properties aren't tied - manually propogate them to the
     // currently active view
@@ -300,6 +270,7 @@ FGViewMgr::update (double dt)
 void
 FGViewMgr::copyToCurrent()
 {
+
 }
 
 void FGViewMgr::clear()