1
0
Fork 0

Adjustments to mouse picking API

This commit is contained in:
James Turner 2016-07-31 22:30:58 +01:00
parent b8e2fb07df
commit b06f4208e4
3 changed files with 15 additions and 16 deletions

View file

@ -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 )
{

View file

@ -1785,16 +1785,15 @@ SGVec2d uvFromIntersection(const Intersection& hit)
return toSG( osg::Vec2d(tc1 * r1 + tc2 * r2 + tc3 * r3) );
}
bool
FGRenderer::pick(std::vector<SGSceneryPick>& 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<SGSceneryPick>& 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

View file

@ -44,6 +44,8 @@ class CameraGroup;
class SGSky;
class SGUpdateVisitor;
typedef std::vector<SGSceneryPick> 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<SGSceneryPick>& pickList, const osg::Vec2& windowPos);
PickList pick(const osg::Vec2& windowPos);
/** Get and set the OSG Viewer object, if any.
*/