alessandro terenzi schrieb:
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
O

You do not show where you create your geometry. Did you call dirtyBound() ?

Regards,

Andreas

_______________________________________________
osg-users mailing list
[email protected]
http://openscenegraph.net/mailman/listinfo/osg-users
http://www.openscenegraph.org/

Reply via email to