Refactor various NodeTracker and MatrixManipulator classes to use the osg::ObserverNodePath and osg::oberserver_ptr<> classes

This commit is contained in:
Robert Osfield
2010-02-15 20:15:32 +00:00
parent 4a567d9954
commit ff38da1290
10 changed files with 92 additions and 151 deletions

View File

@@ -18,7 +18,7 @@
#include <osg/Node>
#include <osg/NodeCallback>
#include <osg/observer_ptr>
#include <osg/ObserverNodePath>
namespace osg
{
@@ -27,22 +27,15 @@ class OSG_EXPORT NodeTrackerCallback : public NodeCallback
{
public:
typedef std::vector< observer_ptr<Node> > ObserverNodePath;
void setTrackNodePath(const osg::NodePath& nodePath)
{
_trackNodePath.clear();
_trackNodePath.reserve(nodePath.size());
std::copy(nodePath.begin(), nodePath.end(), std::back_inserter(_trackNodePath));
}
void setTrackNodePath(const osg::NodePath& nodePath) { _trackNodePath.setNodePath(nodePath); }
void setTrackNodePath(const ObserverNodePath& nodePath) { _trackNodePath = nodePath; }
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();
const osg::Node* getTrackNode() const;
/** Implements the callback. */
virtual void operator()(Node* node, NodeVisitor* nv);
@@ -50,9 +43,6 @@ class OSG_EXPORT NodeTrackerCallback : public NodeCallback
/** Update the node to track the nodepath.*/
void update(osg::Node& node);
bool validateNodePath() const;
protected:
ObserverNodePath _trackNodePath;

View File

@@ -94,7 +94,7 @@ class OSGGA_EXPORT DriveManipulator : public MatrixManipulator
osg::ref_ptr<const GUIEventAdapter> _ga_t1;
osg::ref_ptr<const GUIEventAdapter> _ga_t0;
osg::ref_ptr<osg::Node> _node;
osg::observer_ptr<osg::Node> _node;
double _modelScale;
double _velocity;

View File

@@ -99,7 +99,7 @@ class OSGGA_EXPORT FlightManipulator : public MatrixManipulator
osg::ref_ptr<const GUIEventAdapter> _ga_t1;
osg::ref_ptr<const GUIEventAdapter> _ga_t0;
osg::ref_ptr<osg::Node> _node;
osg::observer_ptr<osg::Node> _node;
double _modelScale;
double _acceleration;

View File

@@ -15,11 +15,8 @@
#define OSGGA_NODETRACKERMANIPULATOR 1
#include <osgGA/MatrixManipulator>
#include <osg/ObserverNodePath>
#include <osg/Quat>
#include <osg/observer_ptr>
#include <iterator>
namespace osgGA{
@@ -31,21 +28,13 @@ class OSGGA_EXPORT NodeTrackerManipulator : public MatrixManipulator
virtual const char* className() const { return "NodeTrackerManipulator"; }
typedef std::vector< osg::observer_ptr<osg::Node> > ObserverNodePath;
void setTrackNodePath(const osg::NodePath& nodePath)
{
_trackNodePath.clear();
_trackNodePath.reserve(nodePath.size());
std::copy(nodePath.begin(), nodePath.end(), std::back_inserter(_trackNodePath));
}
void setTrackNodePath(const ObserverNodePath& nodePath) { _trackNodePath = nodePath; }
ObserverNodePath& getTrackNodePath() { return _trackNodePath; }
void setTrackNodePath(const osg::NodePath& nodePath) { _trackNodePath.setNodePath(nodePath); }
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();
const osg::Node* getTrackNode() const;
enum TrackerMode
{
@@ -128,19 +117,13 @@ class OSGGA_EXPORT NodeTrackerManipulator : public MatrixManipulator
protected:
virtual ~NodeTrackerManipulator();
osg::NodePath getNodePath() const;
bool validateNodePath() const;
/** Reset the internal GUIEvent stack.*/
void flushMouseEventStack();
/** Add the current mouse GUIEvent to internal stack.*/
void addMouseEvent(const GUIEventAdapter& ea);
void computeNodeWorldToLocal(osg::Matrixd& worldToLocal) const;
void computeNodeLocalToWorld(osg::Matrixd& localToWorld) const;
void computeNodeCenterAndRotation(osg::Vec3d& center, osg::Quat& rotation) const;
void computePosition(const osg::Vec3d& eye,const osg::Vec3d& lv,const osg::Vec3d& up);
@@ -165,15 +148,15 @@ class OSGGA_EXPORT NodeTrackerManipulator : public MatrixManipulator
osg::ref_ptr<const GUIEventAdapter> _ga_t1;
osg::ref_ptr<const GUIEventAdapter> _ga_t0;
osg::ref_ptr<osg::Node> _node;
ObserverNodePath _trackNodePath;
osg::observer_ptr<osg::Node> _node;
osg::ObserverNodePath _trackNodePath;
TrackerMode _trackerMode;
RotationMode _rotationMode;
bool _thrown;
osg::Quat _nodeRotation;
osg::Quat _rotation;
float _distance;

View File

@@ -1,3 +1,15 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details.
*/
#ifndef __SphericalManipulator_h__
#define __SphericalManipulator_h__
@@ -135,7 +147,7 @@ class OSGGA_EXPORT SphericalManipulator : public MatrixManipulator
osg::ref_ptr<const osgGA::GUIEventAdapter> _ga_t1;
osg::ref_ptr<const osgGA::GUIEventAdapter> _ga_t0;
osg::ref_ptr<osg::Node> _node;
osg::observer_ptr<osg::Node> _node;
double _modelScale;
double _minimumZoomScale;

View File

@@ -121,7 +121,7 @@ class OSGGA_EXPORT TerrainManipulator : public MatrixManipulator
osg::ref_ptr<const GUIEventAdapter> _ga_t1;
osg::ref_ptr<const GUIEventAdapter> _ga_t0;
osg::ref_ptr<osg::Node> _node;
osg::observer_ptr<osg::Node> _node;
RotationMode _rotationMode;

View File

@@ -141,7 +141,7 @@ class OSGGA_EXPORT TrackballManipulator : public MatrixManipulator
osg::ref_ptr<const GUIEventAdapter> _ga_t1;
osg::ref_ptr<const GUIEventAdapter> _ga_t0;
osg::ref_ptr<osg::Node> _node;
osg::observer_ptr<osg::Node> _node;
double _modelScale;
double _minimumZoomScale;

View File

@@ -134,7 +134,7 @@ class OSGGA_EXPORT UFOManipulator : public osgGA::MatrixManipulator
bool intersect(const osg::Vec3d& start, const osg::Vec3d& end, osg::Vec3d& intersection) const;
osg::ref_ptr<osg::Node> _node;
osg::observer_ptr<osg::Node> _node;
float _viewAngle;
osg::Matrixd _matrix;
osg::Matrixd _inverseMatrix;