Re: [osg-users] Multiple Node Intersection

2020-12-23 Thread Andrew Cunningham
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

On Fri, Dec 18, 2020 at 9:15 AM marco@elmansrl.eu
 wrote:
>
> 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?
>
> --
> 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+unsubscr...@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.

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/osg-users/CAGTJuHijBs3EbXDFeDpiLkaZkApKQQqaP%2BrOg_%3DNng2KXXYsaw%40mail.gmail.com.
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


[osg-users] Multiple Node Intersection

2020-12-18 Thread marco....@elmansrl.eu
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?

-- 
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+unsubscr...@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.
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org