Esempio n. 1
0
bool Widget::computeIntersections(osgGA::EventVisitor* ev, osgGA::GUIEventAdapter* event, Intersections& intersections, osg::Node::NodeMask traversalMask) const
{
    osgGA::GUIActionAdapter* aa = ev ? ev->getActionAdapter() : 0;
    osgUtil::LineSegmentIntersector::Intersections source_intersections;
    if (aa && aa->computeIntersections(*event, ev->getNodePath(), source_intersections, traversalMask))
    {
        typedef std::vector<const osgUtil::LineSegmentIntersector::Intersection*> IntersectionPointerList;
        IntersectionPointerList intersectionsToSort;

        // populate the temporay vector of poiners to the original intersection pointers.
        for(osgUtil::LineSegmentIntersector::Intersections::iterator itr = source_intersections.begin();
            itr != source_intersections.end();
            ++itr)
        {
            if (itr->drawable->getName()!="DepthSetPanel")
            {
                intersectionsToSort.push_back(&(*itr));
            }
        }

        // sort the pointer list into order based on child traversal order, to be consistent with osgUI rendering order.
        std::sort(intersectionsToSort.begin(), intersectionsToSort.end(), SortTraversalOrder());

        // copy the pointers to final Intersection container
        for(IntersectionPointerList::iterator itr = intersectionsToSort.begin();
            itr != intersectionsToSort.end();
            ++itr)
        {
            intersections.push_back(*(*itr));
        }
        return true;
    }
    return false;
}