Hi,

I am trying to pick a primitive from my osg scene using the 
PolytopeIntersector. I am able to select my full geode but do not recieve the 
primitive index. I attached the sample code I use for picking. 

The polygons in the scene consists of osg::Geometry where each polytope 
consists of osg::Vec3Array.

If I forgot to mention something please feel free to ask ;)

Thank you!

Cheers,


Code:

osgUtil::PolytopeIntersector* picker;
            if (_useWindowCoordinates)
            {
                // use window coordinates
                // remap the mouse x,y into viewport coordinates.
                osg::Viewport* viewport = viewer->getCamera()->getViewport();
                double mx = viewport->x() + (int)((double 
)viewport->width()*(ea.getXnormalized()*0.5+0.5));
                double my = viewport->y() + (int)((double 
)viewport->height()*(ea.getYnormalized()*0.5+0.5));

                // half width, height.
                double w = 5.0f;
                double h = 5.0f;
                picker = new osgUtil::PolytopeIntersector( 
osgUtil::Intersector::WINDOW, mx-w, my-h, mx+w, my+h );
            } else {
                double mx = ea.getXnormalized();
                double my = ea.getYnormalized();
                double w = 0.05;
                double h = 0.05;
                picker = new osgUtil::PolytopeIntersector( 
osgUtil::Intersector::PROJECTION, mx-w, my-h, mx+w, my+h );
            }
            osgUtil::IntersectionVisitor iv(picker);

            viewer->getCamera()->accept(iv);

            if (picker->containsIntersections())
            {
                osgUtil::PolytopeIntersector::Intersection intersection = 
picker->getFirstIntersection();

                osg::notify(osg::NOTICE)<<"Picked 
"<<intersection.localIntersectionPoint<<std::endl
                    <<" Distance to ref. plane "<<intersection.distance
                    <<", max. dist "<<intersection.maxDistance
                    <<", primitive index "<<intersection.primitiveIndex
                    <<", numIntersectionPoints "
                    <<intersection.numIntersectionPoints
                    <<std::endl;

                osg::NodePath& nodePath = intersection.nodePath;
                node = (nodePath.size()>=1)?nodePath[nodePath.size()-1]:0;
                parent = 
(nodePath.size()>=2)?dynamic_cast<osg::Group*>(nodePath[nodePath.size()-2]):0;

                if (node) std::cout<<" Hits "<<node->className()<<" nodePath 
size "<<nodePath.size()<<std::endl;
                toggleScribe(parent, node);
            }




------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=55506#55506





_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to