// class to handle events with a pick class PickHandler : public osgGA::GUIEventHandler { public: PickHandler() {} ~PickHandler() {} bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& aa) { switch(ea.getEventType()) { case(osgGA::GUIEventAdapter::PUSH): { osgViewer::View* view = dynamic_cast(&aa); if (view) pick(view,ea); return false; } case(osgGA::GUIEventAdapter::KEYDOWN): { if (ea.getKey()=='c') { osgViewer::View* view = dynamic_cast(&aa); osg::ref_ptr event = new osgGA::GUIEventAdapter(ea); event->setX((ea.getXmin()+ea.getXmax())*0.5); event->setY((ea.getYmin()+ea.getYmax())*0.5); if (view) pick(view,*event); } return false; } default: return false; } } virtual void pick(osgViewer::View* view, const osgGA::GUIEventAdapter& ea) { osgUtil::LineSegmentIntersector::Intersections intersections; std::string gdlist=""; osg::ref_ptr cam = view->getCamera(); std::cout << "mouse coordinates: " << ea.getX() << ", " << ea.getY() << ", camera = " << cam->getName() << std::endl; if (view->computeIntersections(ea,intersections)) { for(osgUtil::LineSegmentIntersector::Intersections::iterator hitr = intersections.begin(); hitr != intersections.end(); ++hitr) { std::ostringstream os; if (!hitr->nodePath.empty() && !(hitr->nodePath.back()->getName().empty())) { // the geodes are identified by name. os<<"Object \""<nodePath.back()->getName()<<"\""<drawable.valid()) { os<<"Object \""<drawable->className()<<"\""<getLocalIntersectPoint()<<")"<<" normal("<getLocalIntersectNormal()<<")"<getWorldIntersectPoint()<<")"<<" normal("<getWorldIntersectNormal()<<")"<indexList; for(unsigned int i=0;i