>
> The for loop you point to is actually because the intersection test
>
might return multiple results (objects behind one another, for
> example). In your case, you probably just want the closest
> intersection. Check the documentation for the
> osgUtil::LineSegmentIntersector::Intersection structure to find out
> how to get that.
>
Well, I have tried running my application with only a shape drawable
sphere, and nothing else. But even so, it didn't work.
I've put an osg::notify(osg::NOTICE) inside the 'for' nest and outside
the if(drawable.valid()) nest and I saw that it never entered the 'for'...
Just in case you've erased my previous messages, I'm copying the new code
with the appear-if-worked messages (that didn't appear).
Thanks
Renan Mendes
bool PickHandler::handle(const osgGA::GUIEventAdapter& ea,
osgGA::GUIActionAdapter& aa)
{
osgViewer::Viewer* viewer = dynamic_cast<osgViewer::Viewer*>( &aa );
osgUtil::LineSegmentIntersector::Intersections intersections;
if(!viewer)
{ return false; }
switch(ea.getEventType())
{
case(osgGA::GUIEventAdapter::PUSH):
{
if(Intersecao(viewer, ea, intersections))
{
osg::notify(osg::NOTICE)<< "SELECAO" << std::endl;
for(osgUtil::LineSegmentIntersector::Intersections::iterator hitr =
intersections.begin(); hitr != intersections.end();
++hitr)
{
osg::notify(osg::NOTICE)<< "ENTERED THE FOR" <<
std::endl;
if(!hitr->drawable.valid())
{
osg::notify(osg::NOTICE)<< "ENTERED HERE" <<
std::endl;
osg::ShapeDrawable* shapedrawable =
dynamic_cast<osg::ShapeDrawable*>(hitr->drawable.get());
shapedrawable->setColor(osg::Vec4(1.0, 0.0, 0.0,
1.0));
}
}
}
}
}
}
bool PickHandler::Intersecao(osgViewer::Viewer* viewer, const
osgGA::GUIEventAdapter& ea,
osgUtil::LineSegmentIntersector::Intersections
intersections)
{
return (viewer->computeIntersections(ea.getX(),ea.getY
(),intersections));
}
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org