Hi, I want to select an object after a picking. I found how to do picking but i don't know how to get the group that corresponds to the picked zone. My scene is composed of simple shapes (shapedrawable, geodes and group). I want to get the first group in the hierarchy.
Code: #ifndef _picking_h #define _picking_h #include <osg/MatrixTransform> #include <osg/ShapeDrawable> #include <osg/PolygonMode> #include <osgUtil/LineSegmentIntersector> #include "includer.h" #include "animation.h" #include "rotate.h" #include "dove.h" class PickHandler : public osgGA::GUIEventHandler { public: osg::Node* getOrCreateSelectionBox() { if ( !_selectionBox ) { osg::ref_ptr<osg::Geode> geode = new osg::Geode; geode->addDrawable(new osg::ShapeDrawable(new osg::Box(osg::Vec3(), 1.0f)) ); _selectionBox = new osg::MatrixTransform; _selectionBox->setNodeMask( 0x1 ); _selectionBox->addChild( geode.get() ); osg::StateSet* ss = _selectionBox->getOrCreateStateSet(); ss->setMode( GL_LIGHTING, osg::StateAttribute::OFF ); ss->setAttributeAndModes( new osg::PolygonMode(osg::PolygonMode::FRONT_AND_BACK, osg::PolygonMode::LINE) ); } return _selectionBox.get(); } virtual bool handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa ) { if ( ea.getEventType()!=osgGA::GUIEventAdapter::RELEASE || ea.getButton()!=osgGA::GUIEventAdapter::LEFT_MOUSE_BUTTON || !(ea.getModKeyMask()&osgGA::GUIEventAdapter::MODKEY_CTRL) ) return false; osgViewer::Viewer* viewer = dynamic_cast<osgViewer::Viewer*>(&aa); if ( viewer ) { osg::ref_ptr<osgUtil::LineSegmentIntersector> intersector = new osgUtil::LineSegmentIntersector(osgUtil::Intersector::WINDOW, ea.getX(), ea.getY()); osgUtil::IntersectionVisitor iv( intersector.get() ); iv.setTraversalMask( ~0x1 ); viewer->getCamera()->accept( iv ); if ( intersector->containsIntersections() ) { const osgUtil::LineSegmentIntersector::Intersection& result =*(intersector->getIntersections().begin()); // const osgUtil::LineSegmentIntersector::Intersection& result =*(intersector->getIntersections().begin()); osg::BoundingBox bb = result.drawable->getBound(); osg::Vec3 worldCenter = bb.center() * osg::computeLocalToWorld(result.nodePath); _selectionBox->setMatrix(osg::Matrix::scale(bb.xMax()-bb.xMin(), bb.yMax()-bb.yMin(), bb.zMax()-bb.zMin()) * osg::Matrix::translate(worldCenter) ); } } return false; } protected: osg::ref_ptr<osg::MatrixTransform> _selectionBox; }; #endif i think that I do something like that : osg::Node = result.drawable->getParent(); or osg::Nodepath = result.nodepath; but i want finally a osg::Group. Thank !!!!! Camille[/code] ------------------ Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=39433#39433 _______________________________________________ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org