Simon Hammett wrote:
> 
> Right I've had time to play with ClipNode, and what I said above is rubbish.
> 
> You just need the matrix which transforms from the parent to the
> intersection node.
> 
> Given you are writing a tool kit, I suspect you can quickly and easily work 
> out
> that transform from your objects.
> 
> If not you to just need to find the parent node in the 'nodePath'
> member of the intersection result and then run through to the end of
> the nodePath
> accumulating any matrices you find.
> 
> Then invert that matrix and multiply the intersection point with it
> and test it to inside
> or outside your clip node as appropriate.


Ok, now ive got it working great. I solved it!

I worked out that depending on the scoll position of the scroll panel, i got a 
different result from hitr->getLocalIntersectPoint() so i had to translate the 
point.

Which way would be better, what i have now or what you just suggested?

Thank you Simon, your suggestions helped me loads!

Heres my finished code:

PWidgetBase* PWidgetHandler::pick(osg::ref_ptr<osgViewer::View> view, const 
osgGA::GUIEventAdapter& ea)
        {
                osgUtil::LineSegmentIntersector::Intersections intersections;

                std::string gdlist="";
                float x = ea.getX();
                float y = ea.getY();
#if 0
                osg::ref_ptr< osgUtil::LineSegmentIntersector > picker = new 
osgUtil::LineSegmentIntersector(osgUtil::Intersector::WINDOW, x, y);
                osgUtil::IntersectionVisitor iv(picker.get());
                view->getCamera()->accept(iv);
                if (picker->containsIntersections())
                {
                        intersections = picker->getIntersections();
#else
                if (view->computeIntersections(x,y,intersections))
                {
#endif
                        for 
(osgUtil::LineSegmentIntersector::Intersections::iterator hitr = 
intersections.begin();
                                hitr != intersections.end();
                                ++hitr)
                        {
                                if (!hitr->nodePath.empty())
                                {
                                        osg::Node* node = hitr->nodePath.back();

                                        if (node && node->getNumParents() > 0)
                                        {
                                                node = node->getParent(0);

                                                while (node != NULL)
                                                {
                                                        if (node && 
strcmp(node->className(), "PWidgetBase") == 0)
                                                        {
                                                                PWidgetBase* 
obj = (PWidgetBase*)node;
                                                                if (obj)
                                                                {
                                                                        bool 
outside = false;
                                                                        if 
(obj->getParentWidget() && obj->getParentWidget()->getUsingClipBoundingBox())
                                                                        {
                                                                                
osg::ref_ptr<osg::ClipNode> clipNode = obj->getParentWidget()->getClipNode();
                                                                                
if (clipNode)
                                                                                
{
                                                                                
        osg::Vec3d pt = hitr->getLocalIntersectPoint();

                                                                                
        osg::Vec3 position = obj->getPosition();
                                                                                
        pt.x() += position.x() / 2.f;
                                                                                
        pt.x() *= 2.f;
                                                                                
        pt.y() += position.y();
                                                                                
        pt.y() *= 2.f;
                                                                                
        pt.z() += position.z() / 2.f;
                                                                                
        pt.z() *= 5.f;

                                                                                
        for (unsigned int i = 0; i < clipNode->getNumClipPlanes(); i++)
                                                                                
        {
                                                                                
                osg::ref_ptr<osg::ClipPlane> plane = clipNode->getClipPlane(i);
                                                                                
                osg::Vec4d pl = plane->getClipPlane();

                                                                                
                switch (i)
                                                                                
                {
                                                                                
                case 0:
                                                                                
                        {
                                                                                
                                if (pt.x() > pl.x())
                                                                                
                                        outside = true;
                                                                                
                                break;
                                                                                
                        }

                                                                                
                case 1:
                                                                                
                        {
                                                                                
                                if (pt.x() < pl.x())
                                                                                
                                        outside = true;
                                                                                
                                break;
                                                                                
                        }

                                                                                
                case 4:
                                                                                
                        {
                                                                                
                                if (pt.z() > pl.z())
                                                                                
                                        outside = true;
                                                                                
                                break;
                                                                                
                        }

                                                                                
                case 5:
                                                                                
                        {
                                                                                
                                if (pt.z() < pl.z())
                                                                                
                                        outside = true;
                                                                                
                                break;
                                                                                
                        }
                                                                                
                }

                                                                                
                if (outside)
                                                                                
                        break;
                                                                                
        }
                                                                                
}
                                                                        }

                                                                        if 
(!outside)
                                                                                
return obj;
                                                                        else
                                                                                
break;
                                                                }
                                                        }

                                                        if 
(node->getNumParents() > 0)
                                                                node = 
node->getParent(0);
                                                        else
                                                                break;
                                                }
                                        }
                                }
                                else if (hitr->drawable.valid())
                                {
                                        return NULL;
                                }
                        }
                }
                return NULL;
        };

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





_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to