From bd6009f9f2a64938ed86223ee417b1d9b6bd12af Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 3 Feb 2011 17:07:01 +0000 Subject: [PATCH] Refactored NodeTrackerManipulator to use osg::ObserverNodePath rather than it's only local equivilant. --- include/osgGA/NodeTrackerManipulator | 18 +++---- src/osgGA/NodeTrackerManipulator.cpp | 70 ++++++++++------------------ 2 files changed, 30 insertions(+), 58 deletions(-) diff --git a/include/osgGA/NodeTrackerManipulator b/include/osgGA/NodeTrackerManipulator index cc94f4a2b..01b2e0bc3 100644 --- a/include/osgGA/NodeTrackerManipulator +++ b/include/osgGA/NodeTrackerManipulator @@ -15,6 +15,7 @@ #define OSGGA_NODE_TRACKER_MANIPULATOR 1 #include +#include namespace osgGA { @@ -33,15 +34,13 @@ class OSGGA_EXPORT NodeTrackerManipulator : public OrbitManipulator META_Object( osgGA, NodeTrackerManipulator ); - typedef std::vector< osg::observer_ptr > ObserverNodePath; - void setTrackNodePath(const osg::NodePath& nodePath); - void setTrackNodePath(const ObserverNodePath& nodePath) { _trackNodePath = nodePath; } - ObserverNodePath& getTrackNodePath() { return _trackNodePath; } + void setTrackNodePath(const osg::ObserverNodePath& nodePath) { _trackNodePath = nodePath; } + osg::ObserverNodePath& getTrackNodePath() { return _trackNodePath; } void setTrackNode(osg::Node* node); - osg::Node* getTrackNode() { return _trackNodePath.empty() ? 0 : _trackNodePath.back().get(); } - const osg::Node* getTrackNode() const { return _trackNodePath.empty() ? 0 : _trackNodePath.back().get(); } + osg::Node* getTrackNode() { osg::NodePath nodePath; return _trackNodePath.getNodePath(nodePath) && !nodePath.empty() ? nodePath.back() : 0; } + const osg::Node* getTrackNode() const { osg::NodePath nodePath; return _trackNodePath.getNodePath(nodePath) && !nodePath.empty() ? nodePath.back() : 0; } enum TrackerMode { @@ -90,10 +89,6 @@ class OSGGA_EXPORT NodeTrackerManipulator : public OrbitManipulator virtual bool performMovementMiddleMouseButton(const double eventTimeDelta, const double dx, const double dy); virtual bool performMovementRightMouseButton(const double eventTimeDelta, const double dx, const double dy); - osg::NodePath getNodePath() const; - - bool validateNodePath() const; - void computeNodeWorldToLocal(osg::Matrixd& worldToLocal) const; void computeNodeLocalToWorld(osg::Matrixd& localToWorld) const; @@ -102,8 +97,7 @@ class OSGGA_EXPORT NodeTrackerManipulator : public OrbitManipulator void computePosition(const osg::Vec3d& eye,const osg::Vec3d& lv,const osg::Vec3d& up); - ObserverNodePath _trackNodePath; - + osg::ObserverNodePath _trackNodePath; TrackerMode _trackerMode; }; diff --git a/src/osgGA/NodeTrackerManipulator.cpp b/src/osgGA/NodeTrackerManipulator.cpp index 42b110720..ef3d10e9d 100644 --- a/src/osgGA/NodeTrackerManipulator.cpp +++ b/src/osgGA/NodeTrackerManipulator.cpp @@ -39,40 +39,10 @@ NodeTrackerManipulator::NodeTrackerManipulator( const NodeTrackerManipulator& m, void NodeTrackerManipulator::setTrackNodePath(const osg::NodePath& nodePath) { - _trackNodePath.clear(); - _trackNodePath.reserve(nodePath.size()); - std::copy(nodePath.begin(), nodePath.end(), std::back_inserter(_trackNodePath)); + _trackNodePath.setNodePath(nodePath); } -osg::NodePath NodeTrackerManipulator::getNodePath() const -{ - osg::NodePath nodePath; - for(ObserverNodePath::const_iterator itr = _trackNodePath.begin(); - itr != _trackNodePath.end(); - ++itr) - { - nodePath.push_back(const_cast(itr->get())); - } - return nodePath; -} - -bool NodeTrackerManipulator::validateNodePath() const -{ - for(ObserverNodePath::const_iterator itr = _trackNodePath.begin(); - itr != _trackNodePath.begin(); - ++itr) - { - if (*itr==0) - { - OSG_NOTICE<<"Warning: tracked node path has been invalidated by changes in the scene graph."<(_trackNodePath).clear(); - return false; - } - } - return true; -} - void NodeTrackerManipulator::setTrackerMode(TrackerMode mode) { _trackerMode = mode; @@ -125,28 +95,33 @@ void NodeTrackerManipulator::setTrackNode(osg::Node* node) OSG_NOTICE<<"osgGA::NodeTrackerManipualtor::setTrackNode(..) taking first parent path, ignoring others."<className()<getName()<<"): Path set"<getName()<<")"<className()<<" '"<<_trackNodePath[i]->getName()<<"'"<getBound(); @@ -168,17 +143,19 @@ void NodeTrackerManipulator::setByMatrix(const osg::Matrixd& matrix) void NodeTrackerManipulator::computeNodeWorldToLocal(osg::Matrixd& worldToLocal) const { - if (validateNodePath()) + osg::NodePath nodePath; + if (_trackNodePath.getNodePath(nodePath)) { - worldToLocal = osg::computeWorldToLocal(getNodePath()); + worldToLocal = osg::computeWorldToLocal(nodePath); } } void NodeTrackerManipulator::computeNodeLocalToWorld(osg::Matrixd& localToWorld) const { - if (validateNodePath()) + osg::NodePath nodePath; + if (_trackNodePath.getNodePath(nodePath)) { - localToWorld = osg::computeLocalToWorld(getNodePath()); + localToWorld = osg::computeLocalToWorld(nodePath); } } @@ -189,8 +166,9 @@ void NodeTrackerManipulator::computeNodeCenterAndRotation(osg::Vec3d& nodeCenter computeNodeLocalToWorld(localToWorld); computeNodeWorldToLocal(worldToLocal); - if (validateNodePath()) - nodeCenter = osg::Vec3d(_trackNodePath.back()->getBound().center())*localToWorld; + osg::NodePath nodePath; + if (_trackNodePath.getNodePath(nodePath)) + nodeCenter = osg::Vec3d(nodePath.back()->getBound().center())*localToWorld; else nodeCenter = osg::Vec3d(0.0f,0.0f,0.0f)*localToWorld;