Made the computeLocalToWorld etc method to use const NodePath's parameters.
This commit is contained in:
parent
6a48a3ffe7
commit
790da0776a
@ -37,6 +37,27 @@ class RefNodePath : public NodeList
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RefNodePath& operator = (const RefNodePath& rhs)
|
||||||
|
{
|
||||||
|
if (&rhs == this) return *this;
|
||||||
|
|
||||||
|
NodeList::operator = (rhs);
|
||||||
|
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
RefNodePath& operator = (const NodePath& rhs)
|
||||||
|
{
|
||||||
|
for(osg::NodePath::const_iterator itr=rhs.begin();
|
||||||
|
itr != rhs.end();
|
||||||
|
++itr)
|
||||||
|
{
|
||||||
|
push_back(*itr);
|
||||||
|
}
|
||||||
|
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
inline operator NodePath () const
|
inline operator NodePath () const
|
||||||
{
|
{
|
||||||
NodePath nodePath;
|
NodePath nodePath;
|
||||||
|
@ -27,21 +27,21 @@ namespace osg {
|
|||||||
|
|
||||||
/** compute the matrix which transforms objects in local coords to world coords,
|
/** compute the matrix which transforms objects in local coords to world coords,
|
||||||
* by accumulating the Transform local to world matrices along the specified node path.*/
|
* by accumulating the Transform local to world matrices along the specified node path.*/
|
||||||
extern SG_EXPORT Matrix computeLocalToWorld(NodePath& nodePath);
|
extern SG_EXPORT Matrix computeLocalToWorld(const NodePath& nodePath);
|
||||||
|
|
||||||
/** compute the matrix which transforms objects in world coords to local coords,
|
/** compute the matrix which transforms objects in world coords to local coords,
|
||||||
* by accumulating the Transform world to local matrices along the specified node path.*/
|
* by accumulating the Transform world to local matrices along the specified node path.*/
|
||||||
extern SG_EXPORT Matrix computeWorldToLocal(NodePath& nodePath);
|
extern SG_EXPORT Matrix computeWorldToLocal(const NodePath& nodePath);
|
||||||
|
|
||||||
/** compute the matrix which transforms objects in local coords to world coords,
|
/** compute the matrix which transforms objects in local coords to world coords,
|
||||||
* by accumulating the Transform local to world matrices along the specified node path
|
* by accumulating the Transform local to world matrices along the specified node path
|
||||||
* the supplied initialial camera modelview .*/
|
* the supplied initialial camera modelview .*/
|
||||||
extern SG_EXPORT Matrix computeLocalToEye(const Matrix& modelview, NodePath& nodePath);
|
extern SG_EXPORT Matrix computeLocalToEye(const Matrix& modelview, const NodePath& nodePath);
|
||||||
|
|
||||||
/** compute the matrix which transforms objects in world coords to local coords,
|
/** compute the matrix which transforms objects in world coords to local coords,
|
||||||
* by accumulating the Transform world to local matrices along the specified node path
|
* by accumulating the Transform world to local matrices along the specified node path
|
||||||
* the inverse of the supplied initialial camera modelview.*/
|
* the inverse of the supplied initialial camera modelview.*/
|
||||||
extern SG_EXPORT Matrix computeEyeToLocal(const Matrix& modelview, NodePath& nodePath);
|
extern SG_EXPORT Matrix computeEyeToLocal(const Matrix& modelview, const NodePath& nodePath);
|
||||||
|
|
||||||
|
|
||||||
/** A Transform is a group node for which all children are transformed by
|
/** A Transform is a group node for which all children are transformed by
|
||||||
|
@ -15,7 +15,9 @@
|
|||||||
#define OSGGA_NODETRACKERMANIPULATOR 1
|
#define OSGGA_NODETRACKERMANIPULATOR 1
|
||||||
|
|
||||||
#include <osgGA/MatrixManipulator>
|
#include <osgGA/MatrixManipulator>
|
||||||
|
|
||||||
#include <osg/Quat>
|
#include <osg/Quat>
|
||||||
|
#include <osg/RefNodePath>
|
||||||
|
|
||||||
namespace osgGA{
|
namespace osgGA{
|
||||||
|
|
||||||
@ -27,10 +29,15 @@ class OSGGA_EXPORT NodeTrackerManipulator : public MatrixManipulator
|
|||||||
|
|
||||||
virtual const char* className() const { return "NodeTrackerManipulator"; }
|
virtual const char* className() const { return "NodeTrackerManipulator"; }
|
||||||
|
|
||||||
void setTrackNode(osg::Node* node) { _trackNode = node; }
|
void setTrackNodePath(const osg::RefNodePath& nodePath) { _trackNodePath = nodePath; }
|
||||||
osg::Node* getTrackNode() { return _trackNode.get(); }
|
void setTrackNodePath(const osg::NodePath& nodePath) { _trackNodePath = nodePath; }
|
||||||
const osg::Node* getTrackNode() const { return _trackNode.get(); }
|
|
||||||
|
|
||||||
|
osg::RefNodePath& getTrackNodePath() { return _trackNodePath; }
|
||||||
|
const osg::RefNodePath& getTrackNodePath() const { 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(); }
|
||||||
|
|
||||||
enum TrackerMode
|
enum TrackerMode
|
||||||
{
|
{
|
||||||
@ -99,6 +106,21 @@ class OSGGA_EXPORT NodeTrackerManipulator : public MatrixManipulator
|
|||||||
protected:
|
protected:
|
||||||
|
|
||||||
virtual ~NodeTrackerManipulator();
|
virtual ~NodeTrackerManipulator();
|
||||||
|
|
||||||
|
inline bool validateNodePath() const
|
||||||
|
{
|
||||||
|
if (!_trackNodePath.valid())
|
||||||
|
{
|
||||||
|
if (_trackNodePath.empty())
|
||||||
|
{
|
||||||
|
osg::notify(osg::NOTICE)<<"Warning: tracked node path has been invalidated by changes in the scene graph."<<std::endl;
|
||||||
|
NodeTrackerManipulator* non_const_this = const_cast<NodeTrackerManipulator*>(this);
|
||||||
|
non_const_this->_trackNodePath.clear();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/** Reset the internal GUIEvent stack.*/
|
/** Reset the internal GUIEvent stack.*/
|
||||||
void flushMouseEventStack();
|
void flushMouseEventStack();
|
||||||
@ -133,7 +155,8 @@ class OSGGA_EXPORT NodeTrackerManipulator : public MatrixManipulator
|
|||||||
osg::ref_ptr<const GUIEventAdapter> _ga_t0;
|
osg::ref_ptr<const GUIEventAdapter> _ga_t0;
|
||||||
|
|
||||||
osg::ref_ptr<osg::Node> _node;
|
osg::ref_ptr<osg::Node> _node;
|
||||||
osg::ref_ptr<osg::Node> _trackNode;
|
|
||||||
|
osg::RefNodePath _trackNodePath;
|
||||||
|
|
||||||
TrackerMode _trackerMode;
|
TrackerMode _trackerMode;
|
||||||
RotationMode _rotationMode;
|
RotationMode _rotationMode;
|
||||||
|
@ -46,10 +46,11 @@ class TransformVisitor : public NodeVisitor
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void accumulate(NodePath& nodePath)
|
void accumulate(const NodePath& nodePath)
|
||||||
{
|
{
|
||||||
for(NodePath::iterator itr=nodePath.begin();
|
NodePath& non_const_nodePath = const_cast<NodePath&>(nodePath);
|
||||||
itr!=nodePath.end();
|
for(NodePath::iterator itr=non_const_nodePath.begin();
|
||||||
|
itr!=non_const_nodePath.end();
|
||||||
++itr)
|
++itr)
|
||||||
{
|
{
|
||||||
(*itr)->accept(*this);
|
(*itr)->accept(*this);
|
||||||
@ -58,7 +59,7 @@ class TransformVisitor : public NodeVisitor
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Matrix osg::computeLocalToWorld(NodePath& nodePath)
|
Matrix osg::computeLocalToWorld(const NodePath& nodePath)
|
||||||
{
|
{
|
||||||
Matrix matrix;
|
Matrix matrix;
|
||||||
TransformVisitor tv(matrix,TransformVisitor::LOCAL_TO_WORLD);
|
TransformVisitor tv(matrix,TransformVisitor::LOCAL_TO_WORLD);
|
||||||
@ -66,7 +67,7 @@ Matrix osg::computeLocalToWorld(NodePath& nodePath)
|
|||||||
return matrix;
|
return matrix;
|
||||||
}
|
}
|
||||||
|
|
||||||
Matrix osg::computeWorldToLocal(NodePath& nodePath)
|
Matrix osg::computeWorldToLocal(const NodePath& nodePath)
|
||||||
{
|
{
|
||||||
osg::Matrix matrix;
|
osg::Matrix matrix;
|
||||||
TransformVisitor tv(matrix,TransformVisitor::WORLD_TO_LOCAL);
|
TransformVisitor tv(matrix,TransformVisitor::WORLD_TO_LOCAL);
|
||||||
@ -74,7 +75,7 @@ Matrix osg::computeWorldToLocal(NodePath& nodePath)
|
|||||||
return matrix;
|
return matrix;
|
||||||
}
|
}
|
||||||
|
|
||||||
Matrix osg::computeLocalToEye(const Matrix& modelview,NodePath& nodePath)
|
Matrix osg::computeLocalToEye(const Matrix& modelview,const NodePath& nodePath)
|
||||||
{
|
{
|
||||||
Matrix matrix(modelview);
|
Matrix matrix(modelview);
|
||||||
TransformVisitor tv(matrix,TransformVisitor::LOCAL_TO_WORLD);
|
TransformVisitor tv(matrix,TransformVisitor::LOCAL_TO_WORLD);
|
||||||
@ -82,7 +83,7 @@ Matrix osg::computeLocalToEye(const Matrix& modelview,NodePath& nodePath)
|
|||||||
return matrix;
|
return matrix;
|
||||||
}
|
}
|
||||||
|
|
||||||
Matrix osg::computeEyeToLocal(const Matrix& modelview,NodePath& nodePath)
|
Matrix osg::computeEyeToLocal(const Matrix& modelview,const NodePath& nodePath)
|
||||||
{
|
{
|
||||||
Matrix matrix;
|
Matrix matrix;
|
||||||
matrix.invert(modelview);
|
matrix.invert(modelview);
|
||||||
|
@ -72,6 +72,16 @@ void NodeTrackerManipulator::setNode(osg::Node* node)
|
|||||||
if (getAutoComputeHomePosition()) computeHomePosition();
|
if (getAutoComputeHomePosition()) computeHomePosition();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NodeTrackerManipulator::setTrackNode(osg::Node* node)
|
||||||
|
{
|
||||||
|
CollectParentPaths cpp;
|
||||||
|
node->accept(cpp);
|
||||||
|
|
||||||
|
if (!cpp._nodePaths.empty())
|
||||||
|
{
|
||||||
|
_trackNodePath = cpp._nodePaths[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const osg::Node* NodeTrackerManipulator::getNode() const
|
const osg::Node* NodeTrackerManipulator::getNode() const
|
||||||
{
|
{
|
||||||
@ -321,32 +331,19 @@ void NodeTrackerManipulator::setByMatrix(const osg::Matrixd& matrix)
|
|||||||
|
|
||||||
void NodeTrackerManipulator::computeNodeWorldToLocal(osg::Matrixd& worldToLocal) const
|
void NodeTrackerManipulator::computeNodeWorldToLocal(osg::Matrixd& worldToLocal) const
|
||||||
{
|
{
|
||||||
if (_trackNode.valid())
|
if (validateNodePath())
|
||||||
{
|
{
|
||||||
CollectParentPaths cpp;
|
worldToLocal = osg::computeWorldToLocal(_trackNodePath);
|
||||||
NodeTrackerManipulator* non_const_this = const_cast<NodeTrackerManipulator*>(this);
|
|
||||||
non_const_this->_trackNode->accept(cpp);
|
|
||||||
|
|
||||||
if (!cpp._nodePaths.empty())
|
|
||||||
{
|
|
||||||
worldToLocal = osg::computeWorldToLocal(cpp._nodePaths[0]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void NodeTrackerManipulator::computeNodeLocalToWorld(osg::Matrixd& localToWorld) const
|
void NodeTrackerManipulator::computeNodeLocalToWorld(osg::Matrixd& localToWorld) const
|
||||||
{
|
{
|
||||||
if (_trackNode.valid())
|
if (validateNodePath())
|
||||||
{
|
{
|
||||||
CollectParentPaths cpp;
|
localToWorld = osg::computeLocalToWorld(_trackNodePath);
|
||||||
NodeTrackerManipulator* non_const_this = const_cast<NodeTrackerManipulator*>(this);
|
|
||||||
non_const_this->_trackNode->accept(cpp);
|
|
||||||
|
|
||||||
if (!cpp._nodePaths.empty())
|
|
||||||
{
|
|
||||||
localToWorld = osg::computeLocalToWorld(cpp._nodePaths[0]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void NodeTrackerManipulator::computeNodeCenterAndRotation(osg::Vec3d& nodeCenter, osg::Quat& nodeRotation) const
|
void NodeTrackerManipulator::computeNodeCenterAndRotation(osg::Vec3d& nodeCenter, osg::Quat& nodeRotation) const
|
||||||
@ -354,8 +351,8 @@ void NodeTrackerManipulator::computeNodeCenterAndRotation(osg::Vec3d& nodeCenter
|
|||||||
osg::Matrixd localToWorld;
|
osg::Matrixd localToWorld;
|
||||||
computeNodeLocalToWorld(localToWorld);
|
computeNodeLocalToWorld(localToWorld);
|
||||||
|
|
||||||
if (_trackNode.valid())
|
if (validateNodePath())
|
||||||
nodeCenter = _trackNode->getBound().center()*localToWorld;
|
nodeCenter = _trackNodePath.back()->getBound().center()*localToWorld;
|
||||||
else
|
else
|
||||||
nodeCenter = osg::Vec3d(0.0f,0.0f,0.0f)*localToWorld;
|
nodeCenter = osg::Vec3d(0.0f,0.0f,0.0f)*localToWorld;
|
||||||
|
|
||||||
@ -482,25 +479,13 @@ bool NodeTrackerManipulator::calcMovement()
|
|||||||
if (dx==0 && dy==0) return false;
|
if (dx==0 && dy==0) return false;
|
||||||
|
|
||||||
|
|
||||||
if (_trackNode.valid())
|
if (validateNodePath())
|
||||||
{
|
{
|
||||||
// osg::notify(osg::NOTICE)<<"_trackNode="<<_trackNode->getName()<<std::endl;
|
osg::Matrix localToWorld;
|
||||||
|
localToWorld = osg::computeLocalToWorld(_trackNodePath);
|
||||||
|
|
||||||
CollectParentPaths cpp;
|
_center = _trackNodePath.back()->getBound().center() * localToWorld;
|
||||||
_trackNode->accept(cpp);
|
}
|
||||||
|
|
||||||
// osg::notify(osg::NOTICE)<<"number of nodepaths = "<<cpp._nodePaths.size()<<std::endl;
|
|
||||||
|
|
||||||
if (!cpp._nodePaths.empty())
|
|
||||||
{
|
|
||||||
osg::Matrix localToWorld;
|
|
||||||
localToWorld = osg::computeLocalToWorld(cpp._nodePaths[0]);
|
|
||||||
|
|
||||||
_center = _trackNode->getBound().center() * localToWorld;
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned int buttonMask = _ga_t1->getButtonMask();
|
unsigned int buttonMask = _ga_t1->getButtonMask();
|
||||||
if (buttonMask==GUIEventAdapter::LEFT_MOUSE_BUTTON)
|
if (buttonMask==GUIEventAdapter::LEFT_MOUSE_BUTTON)
|
||||||
|
Loading…
Reference in New Issue
Block a user