[osg-users] Multiple Node Intersection

marco....@elmansrl.eu marco.maisano at elmansrl.eu
Fri Dec 18 09:15:29 PST 2020


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 
x - w, y - h, x + w, y + h);
osgUtil::IntersectionVisitor iv(picker);
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?

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+unsubscribe at 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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20201218/5e6cf08d/attachment.html>

More information about the osg-users mailing list