Multiple Node Intersection

25 views
Skip to first unread message

marco....@elmansrl.eu

unread,
Dec 18, 2020, 12:15:30 PM12/18/20
to OpenSceneGraph Users
Hi,

I need to make the selection (pick) of a node, going to check if that node is present within an area built around the mouse click point.

This should mean that, if there are more nodes inside that area, the pick event returns them to me.

Currently for the point selection, therefore of a single node in a specific x and y, I successfully use osgUtil :: LineSegmentIntersector.

Studying on the OSG book, I read that selection existed by checking inside a box, implemented by osgUtil :: PolytopeIntersector.

Below I propose part of the code,

double w(200), h(200);
osgUtil::PolytopeIntersector* picker = new osgUtil::PolytopeIntersector(osgUtil::Intersector::CoordinateFrame::WINDOW, x - w, y - h, x + w, y + h);
osgUtil::IntersectionVisitor iv(picker);
viewer->getCamera()->accept(iv);
if (picker->containsIntersections())
{
const osg::NodePath& nodePath = picker->getFirstIntersection().nodePath;
auto intersections = picker->getIntersections();
if (intersections.size() != 0) {
auto hitr = intersections.begin();
if (hitr->nodePath.size() != 0) {
for (int i = 0; i < hitr->nodePath.size(); i++) {
if (systemTargetMap[hitr->nodePath.at(i)->getName()]) {
      cout << "Node Name: " << systemTargetMap[hitr->nodePath.at(i)->getName()] << endl;
}
}
}
}}

Unfortunately, this selection only returns me one node, even if there are two (or more) very close together.

What am I doing wrong?

Andrew Cunningham

unread,
Dec 23, 2020, 7:01:49 PM12/23/20
to osg-...@googlegroups.com
Hi ,
Maybe you figured it out by now, but you are only looking at the
"first intersection" of the picker ( getFirstIntersection). You need
to iterate over all intersections.

Andrew
> --
> You received this message because you are subscribed to the Google Groups "OpenSceneGraph Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to osg-users+...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/osg-users/d757a21a-bab6-4718-a6bf-2ebdf59650a7n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages