From 4ebe30a8738b2720ba25b6c4aff80b63377fd27d Mon Sep 17 00:00:00 2001 From: James Turner Date: Sun, 31 Jul 2016 22:30:58 +0100 Subject: [PATCH] Adjustments to mouse picking API --- src/Input/FGMouseInput.cxx | 14 ++++++-------- src/Viewer/renderer.cxx | 13 ++++++------- src/Viewer/renderer.hxx | 4 +++- 3 files changed, 15 insertions(+), 16 deletions(-) diff --git a/src/Input/FGMouseInput.cxx b/src/Input/FGMouseInput.cxx index 90a5efde9..ccef542bf 100644 --- a/src/Input/FGMouseInput.cxx +++ b/src/Input/FGMouseInput.cxx @@ -77,8 +77,8 @@ void ActivePickCallbacks::init( int button, const osgGA::GUIEventAdapter* ea ) // That is they get sorted by distance and by scenegraph depth. // The nearest one is the first one and the deepest // (the most specialized one in the scenegraph) is the first. - SGSceneryPicks pickList; - if (!globals->get_renderer()->pick(pickList, windowPos)) { + SGSceneryPicks pickList = globals->get_renderer()->pick(windowPos); + if (pickList.empty()) { return; } @@ -223,8 +223,7 @@ public: bool didPick = false; SGPickCallback::Priority priority = SGPickCallback::PriorityScenery; - SGSceneryPicks pickList; - globals->get_renderer()->pick(pickList, windowPos); + SGSceneryPicks pickList = globals->get_renderer()->pick(windowPos); SGSceneryPicks::const_iterator i; for( i = pickList.begin(); i != pickList.end(); ++i ) @@ -276,8 +275,8 @@ public: osg::Vec2d windowPos; flightgear::eventToWindowCoords(ea, windowPos.x(), windowPos.y()); - SGSceneryPicks pickList; - if( !globals->get_renderer()->pick(pickList, windowPos) ) + SGSceneryPicks pickList = globals->get_renderer()->pick(windowPos); + if(pickList.empty()) return; for( ActivePickCallbacks::iterator mi = activePickCallbacks.begin(); @@ -579,8 +578,7 @@ void FGMouseInput::doMouseClick (int b, int updown, int x, int y, bool mainWindo osg::Vec2d windowPos; flightgear::eventToWindowCoords(ea, windowPos.x(), windowPos.y()); - SGSceneryPicks pickList; - globals->get_renderer()->pick(pickList, windowPos); + SGSceneryPicks pickList = globals->get_renderer()->pick(windowPos); if( updown != MOUSE_BUTTON_DOWN ) { diff --git a/src/Viewer/renderer.cxx b/src/Viewer/renderer.cxx index 6d18f1c82..e25cc417e 100644 --- a/src/Viewer/renderer.cxx +++ b/src/Viewer/renderer.cxx @@ -1785,16 +1785,15 @@ SGVec2d uvFromIntersection(const Intersection& hit) return toSG( osg::Vec2d(tc1 * r1 + tc2 * r2 + tc3 * r3) ); } -bool -FGRenderer::pick(std::vector& pickList, const osg::Vec2& windowPos) +PickList FGRenderer::pick(const osg::Vec2& windowPos) { - // wipe out the return ... - pickList.clear(); + PickList result; + typedef osgUtil::LineSegmentIntersector::Intersections Intersections; Intersections intersections; if (!computeIntersections(CameraGroup::getDefault(), windowPos, intersections)) - return false; + return result; for (Intersections::iterator hit = intersections.begin(), e = intersections.end(); hit != e; @@ -1819,12 +1818,12 @@ FGRenderer::pick(std::vector& pickList, const osg::Vec2& windowPo sceneryPick.info.uv = uvFromIntersection(*hit); sceneryPick.callback = pickCallback; - pickList.push_back(sceneryPick); + result.push_back(sceneryPick); } // of installed pick callbacks iteration } // of reverse node path walk } - return !pickList.empty(); + return result; } void diff --git a/src/Viewer/renderer.hxx b/src/Viewer/renderer.hxx index 6f5606724..d203df94f 100644 --- a/src/Viewer/renderer.hxx +++ b/src/Viewer/renderer.hxx @@ -44,6 +44,8 @@ class CameraGroup; class SGSky; class SGUpdateVisitor; +typedef std::vector PickList; + class FGRenderer { public: @@ -62,7 +64,7 @@ public: /** Just pick into the scene and return the pick callbacks on the way ... */ - bool pick( std::vector& pickList, const osg::Vec2& windowPos); + PickList pick(const osg::Vec2& windowPos); /** Get and set the OSG Viewer object, if any. */ -- 2.39.5