I cleaned up my code and here a simple example showing my problem:
...here's the handle method:
bool myEventHandler::handle( const osgGA::GUIEventAdapter& ea,
osgGA::GUIActionAdapter& aa )
{
osgViewer::Viewer* viewer = dynamic_cast<osgViewer::Viewer*>( &aa );
if (!viewer)
return false;
switch( ea.getEventType() )
{
case osgGA::GUIEventAdapter::PUSH:
case osgGA::GUIEventAdapter::MOVE:
{
_mX = ea.getX();
_mY = ea.getY();
return false;
}
case osgGA::GUIEventAdapter::RELEASE:
{
if (_mX == ea.getX() && _mY == ea.getY())
{
if (pick( ea.getXnormalized(),ea.getYnormalized(), viewer ))
return true;
}
return false;
}
default:
return false;
}
}
...and here's the pick method:
bool myEventHandler::pick( const double x, const double y,
osgViewer::Viewer* viewer )
{
if (!viewer->getSceneData())
// Nothing to pick.
return false;
double w( .05 ), h( .05 );
osgUtil::PolytopeIntersector* picker = new
osgUtil::PolytopeIntersector(osgUtil::Intersector::PROJECTION, x-w, y-h,
x+w, y+h );
osgUtil::IntersectionVisitor iv(picker);
viewer->getCamera()->accept(iv);
if (picker->containsIntersections())
{
std::cout<< "Found intersections..."<<std::endl;
osg::NodePath& nodePath = picker->getFirstIntersection().nodePath;
unsigned int idx = nodePath.size();
while (idx--)
{
// look for osg::Geode object
osg::Geode* my_geode = dynamic_cast<osg::Geode*>(nodePath[idx]);
if(my_geode == NULL)
continue;
std::cout<< "Picking successful..."<<std::endl;
break;
}
}
else
{
std::cout<<"Picking failed [no intersections]... "<<std::endl;
return false;
}
return true;
}
...and finally the main:
int main(int argc, char* argv[])
{
osgViewer::Viewer viewer;
osg::ref_ptr<osg::Node> scene = createPyramid(50.0f, 50.0f);
viewer.addEventHandler(new myEventHandler);
viewer.setSceneData(scene.get());
return viewer.run();
}
The behaviour I'm experiencing is as follow: after clicking far away from
the pyramid I got this output on the console:
*Picking failed [no intersections]...*
after clicking inside one of the pyramid's faces, I got:
*Picking failed [no intersections]...*
finally when I clicked on the apex, I got:
*Found intersections...
Picking successful...*
Any Idea about what is wrong?
Thanks.
Alessandro
On 4/17/07, Paul Martz <[EMAIL PROTECTED]> wrote:
The Quick Start Guide example code is based on the osgkeyboardmouse
example,
just a simplified version to demonstrate mouse-based picking.
You might try creating a simple reproducer program that draws a single
large
quad and fails to pick it when you click in the quad center. I'd like to
see
that code.
-Paul
> -----Original Message-----
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] On Behalf Of
> Andreas Goebel
> Sent: Tuesday, April 17, 2007 1:14 PM
> To: osg users
> Subject: Re: [osg-users] mouse picking problem
>
> alessandro terenzi schrieb:
> > I'm implementig mouse picking into my application...I used
> the code of
> > the Quick Start Guide as a reference but, instead of looking for
> > osg::MatrixTransform node, I look for my osg::Group derived
> > objects...my problem is that picking seems to work just
> when I click
> > close to vertices but it doesn't work if I click in the middle of a
> > polygon defined by those same vertices. I thought that the various
> > intersectors checked for any intersection against a bounding
> > volume...any suggestion?
> >
> > Thanks.
> > Alessandro
> Hi,
>
> I haven“t read the Quick-Start-Guide, but in case you modify
> the vertices in your geometry you have to call dirtyBound()
> after that to force recomputing the boundingBox after the
> next traversal.
>
> This will give you the right picks.
>
> Regards,
>
> Andreas
>
> _______________________________________________
> osg-users mailing list
> [email protected]
> http://openscenegraph.net/mailman/listinfo/osg-users
> http://www.openscenegraph.org/
_______________________________________________
osg-users mailing list
[email protected]
http://openscenegraph.net/mailman/listinfo/osg-users
http://www.openscenegraph.org/
_______________________________________________
osg-users mailing list
[email protected]
http://openscenegraph.net/mailman/listinfo/osg-users
http://www.openscenegraph.org/