From 03d5e55b57b64776466dc00506a2915d9153894d Mon Sep 17 00:00:00 2001 From: James Turner Date: Sun, 17 Jan 2016 21:21:20 -0500 Subject: [PATCH] Move data updating into the View class --- src/Viewer/viewer.cxx | 61 ++++++++++++++++++++++++++++++++++++++++++ src/Viewer/viewer.hxx | 24 ++++++++++++++++- src/Viewer/viewmgr.cxx | 33 ++--------------------- 3 files changed, 86 insertions(+), 32 deletions(-) diff --git a/src/Viewer/viewer.cxx b/src/Viewer/viewer.cxx index 65b006070..36e7fa967 100644 --- a/src/Viewer/viewer.cxx +++ b/src/Viewer/viewer.cxx @@ -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()); +} diff --git a/src/Viewer/viewer.hxx b/src/Viewer/viewer.hxx index 38c14f876..97f92ff69 100644 --- a/src/Viewer/viewer.hxx +++ b/src/Viewer/viewer.hxx @@ -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 // ////////////////////////////////////////////////////////////////// diff --git a/src/Viewer/viewmgr.cxx b/src/Viewer/viewmgr.cxx index c0ecba978..a9ec45933 100644 --- a/src/Viewer/viewmgr.cxx +++ b/src/Viewer/viewmgr.cxx @@ -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() -- 2.39.5