From 5363736caac527dcaf70599241e38a233995afd1 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 10 Dec 2008 11:12:37 +0000 Subject: [PATCH] Refactored computeIntersections() float x,float y, const osg::NodePath& nodePath. --- include/osgViewer/View | 2 +- src/osgViewer/View.cpp | 18 +++++++++++++----- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/include/osgViewer/View b/include/osgViewer/View index 2b647ca90..cbe4a5ee4 100644 --- a/include/osgViewer/View +++ b/include/osgViewer/View @@ -197,7 +197,7 @@ class OSGVIEWER_EXPORT View : public osg::View, public osgGA::GUIActionAdapter bool computeIntersections(float x,float y, osgUtil::LineSegmentIntersector::Intersections& intersections,osg::Node::NodeMask traversalMask = 0xffffffff); /** Compute intersections between a ray through the specified master cameras window/eye coords and a specified nodePath's subgraph. */ - bool computeIntersections(float x,float y, osg::NodePath& nodePath, osgUtil::LineSegmentIntersector::Intersections& intersections,osg::Node::NodeMask traversalMask = 0xffffffff); + bool computeIntersections(float x,float y, const osg::NodePath& nodePath, osgUtil::LineSegmentIntersector::Intersections& intersections,osg::Node::NodeMask traversalMask = 0xffffffff); virtual void requestRedraw(); diff --git a/src/osgViewer/View.cpp b/src/osgViewer/View.cpp index e71081b7f..c4dd57332 100644 --- a/src/osgViewer/View.cpp +++ b/src/osgViewer/View.cpp @@ -1811,7 +1811,7 @@ const osg::Camera* View::getCameraContainingPosition(float x, float y, float& lo return 0; } -bool View::computeIntersections(float x,float y, osgUtil::LineSegmentIntersector::Intersections& intersections,osg::Node::NodeMask traversalMask) +bool View::computeIntersections(float x,float y, osgUtil::LineSegmentIntersector::Intersections& intersections, osg::Node::NodeMask traversalMask) { if (!_camera.valid()) return false; @@ -1899,15 +1899,23 @@ bool View::computeIntersections(float x,float y, osgUtil::LineSegmentIntersector return false; } -bool View::computeIntersections(float x,float y, osg::NodePath& nodePath, osgUtil::LineSegmentIntersector::Intersections& intersections,osg::Node::NodeMask traversalMask) +bool View::computeIntersections(float x,float y, const osg::NodePath& nodePath, osgUtil::LineSegmentIntersector::Intersections& intersections,osg::Node::NodeMask traversalMask) { - if (!_camera.valid()) return false; + if (!_camera.valid() || nodePath.empty()) return false; float local_x, local_y = 0.0; const osg::Camera* camera = getCameraContainingPosition(x, y, local_x, local_y); if (!camera) camera = _camera.get(); - osg::Matrix matrix = osg::computeWorldToLocal(nodePath) * camera->getViewMatrix() * camera->getProjectionMatrix(); + osg::Matrixd matrix; + if (nodePath.size()>1) + { + osg::NodePath prunedNodePath(nodePath.begin(),nodePath.end()-1); + matrix = osg::computeLocalToWorld(prunedNodePath); + } + + matrix.postMult(camera->getViewMatrix()); + matrix.postMult(camera->getProjectionMatrix()); double zNear = -1.0; double zFar = 1.0; @@ -1918,7 +1926,7 @@ bool View::computeIntersections(float x,float y, osg::NodePath& nodePath, osgUti zFar = 1.0; } - osg::Matrix inverse; + osg::Matrixd inverse; inverse.invert(matrix); osg::Vec3d startVertex = osg::Vec3d(local_x,local_y,zNear) * inverse;