On Tue, 2007-06-12 at 16:52 +0200, [EMAIL PROTECTED] wrote: > Dear All > I implemented a Picking function... > In order to debug the picking function I simply print in monitor the id of > the picked drawable. > > The problem is that the picking function is called two time for each mouse > click.
I don't think your picking function is getting called twice--I think you're seeing the same object twice in your pick results, which is something I'm running into myself. I just started learning picking this weekend, so I'm not 100% sure what's going on, but perhaps someone else will be able to chime in and help us both. I originally suspected this had something to do with having a 2D HUD Camera in my scene, but I don't think that's it. > Does anyone know why it happens? > > This in my handler: > > class PickHandler : public osgGA::GUIEventHandler { > public: > > PickHandler(osgProducer::Viewer* viewer, Player* player): > _viewer(viewer), > _player(player){} > > ~PickHandler() {} > > bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& us); > > virtual void pick(const osgGA::GUIEventAdapter& ea); > > protected: > osgProducer::Viewer* _viewer; > Player* _player; > }; > > bool PickHandler::handle(const osgGA::GUIEventAdapter& > ea,osgGA::GUIActionAdapter&) > { > if( ea.getEventType() == osgGA::GUIEventAdapter::PUSH ) { > if( ea.getButton() == osgGA::GUIEventAdapter::LEFT_MOUSE_BUTTON > ) pick(ea); > if( ea.getButton() == > osgGA::GUIEventAdapter::RIGHT_MOUSE_BUTTON ) _player->MoveToNextUpLevel(); > } > > return false; > } > > void PickHandler::pick(const osgGA::GUIEventAdapter& ea) > { > osgUtil::IntersectVisitor::HitList hlist; > if (_viewer->computeIntersections(ea.getX(),ea.getY(),hlist)) > { > for(osgUtil::IntersectVisitor::HitList::iterator hitr=hlist.begin(); > hitr!=hlist.end(); > ++hitr) > { > std::ostringstream os; > if (hitr->_geode.valid() && !hitr->_geode->getName().empty()) > { > // the geodes are identified by name. > osg::ref_ptr<NodeInfo> cellInfo = > dynamic_cast<NodeInfo*> > (hitr->_geode->getParent(0)->getParent(0)->getParent(0)->getUserData() ); > int id_time = cellInfo->GetTime(); > std::string id_cell = cellInfo->GetCellID(); > _player->CellPicked(id_cell, id_time); > } > else if (hitr->_drawable.valid()) > { > os<<"Object > \""<<hitr->_drawable->className()<<"\""<<std::endl; > } > } > } > } > > > .....and this add it to the viewer > > viewer->getEventHandlerList().push_front(new PickHandler(viewer.get(), > this)); > > Thanks!!!! > > > > ------------------------------------------------------ > Passa a Infostrada. ADSL e Telefono senza limiti e senza canone Telecom > http://click.libero.it/infostrada > > > _______________________________________________ > osg-users mailing list > osg-users@openscenegraph.net > http://openscenegraph.net/mailman/listinfo/osg-users > http://www.openscenegraph.org/ > _______________________________________________ osg-users mailing list osg-users@openscenegraph.net http://openscenegraph.net/mailman/listinfo/osg-users http://www.openscenegraph.org/