| 191 | | |
| 192 | | #if 1 |
| 193 | | |
| 194 | | osgUtil::LineSegmentIntersector* picker = new osgUtil::LineSegmentIntersector(osg::Vec3d(mx,my,0.0), osg::Vec3d(mx,my,1.0) ); |
| 195 | | picker->setCoordinateFrame(osgUtil::Intersector::WINDOW); |
| | 199 | osgUtil::LineSegmentIntersector* picker = new osgUtil::LineSegmentIntersector(osgUtil::Intersector::WINDOW, osg::Vec3d(mx,my,0.0), osg::Vec3d(mx,my,1.0) ); |
| | 200 | #endif |
| 241 | | |
| 242 | | } |
| 243 | | |
| 244 | | |
| 245 | | #else |
| 246 | | |
| 247 | | // do the pick traversal. |
| 248 | | osgUtil::PickVisitor pick(_sceneView->getViewport(), |
| 249 | | _sceneView->getProjectionMatrix(), |
| 250 | | _sceneView->getViewMatrix(), mx, my); |
| 251 | | scene->accept(pick); |
| 252 | | |
| 253 | | osgUtil::PickVisitor::LineSegmentHitListMap& segHitList = pick.getSegHitList(); |
| 254 | | if (!segHitList.empty() && !segHitList.begin()->second.empty()) |
| 255 | | { |
| 256 | | std::cout<<"Got hits"<<std::endl; |
| 257 | | |
| 258 | | // get the hits for the first segment |
| 259 | | osgUtil::PickVisitor::HitList& hits = segHitList.begin()->second; |
| 260 | | |
| 261 | | // just take the first hit - nearest the eye point. |
| 262 | | osgUtil::Hit& hit = hits.front(); |
| 263 | | |
| 264 | | osg::NodePath& nodePath = hit._nodePath; |
| 265 | | osg::Node* node = (nodePath.size()>=1)?nodePath[nodePath.size()-1]:0; |
| 266 | | osg::Group* parent = (nodePath.size()>=2)?dynamic_cast<osg::Group*>(nodePath[nodePath.size()-2]):0; |
| 267 | | |
| 268 | | if (node) std::cout<<" Hits "<<node->className()<<" nodePath size"<<nodePath.size()<<std::endl; |
| 269 | | |
| 270 | | // now we try to decorate the hit node by the osgFX::Scribe to show that its been "picked" |
| 271 | | if (parent && node) |
| 272 | | { |
| 273 | | |
| 274 | | std::cout<<" parent "<<parent->className()<<std::endl; |
| 275 | | |
| 276 | | osgFX::Scribe* parentAsScribe = dynamic_cast<osgFX::Scribe*>(parent); |
| 277 | | if (!parentAsScribe) |
| 278 | | { |
| 279 | | // node not already picked, so highlight it with an osgFX::Scribe |
| 280 | | osgFX::Scribe* scribe = new osgFX::Scribe(); |
| 281 | | scribe->addChild(node); |
| 282 | | parent->replaceChild(node,scribe); |
| 283 | | } |
| 284 | | else |
| 285 | | { |
| 286 | | // node already picked so we want to remove scribe to unpick it. |
| 287 | | osg::Node::ParentList parentList = parentAsScribe->getParents(); |
| 288 | | for(osg::Node::ParentList::iterator itr=parentList.begin(); |
| 289 | | itr!=parentList.end(); |
| 290 | | ++itr) |
| 291 | | { |
| 292 | | (*itr)->replaceChild(parentAsScribe,node); |
| 293 | | } |
| 294 | | } |
| 295 | | } |
| 296 | | |
| 297 | | } |
| | 247 | |
| | 248 | } |
| | 249 | |
| | 250 | |
| | 251 | { |
| | 252 | float mx = _sceneView->getViewport()->x() + (int)((float)_sceneView->getViewport()->width()*(ea.getXnormalized()*0.5f+0.5f)); |
| | 253 | float my = _sceneView->getViewport()->y() + (int)((float)_sceneView->getViewport()->height()*(ea.getYnormalized()*0.5f+0.5f)); |
| | 254 | |
| | 255 | // do the pick traversal use the other PickVisitor to double check results. |
| | 256 | osgUtil::PickVisitor pick(_sceneView->getViewport(), |
| | 257 | _sceneView->getProjectionMatrix(), |
| | 258 | _sceneView->getViewMatrix(), mx, my); |
| | 259 | scene->accept(pick); |
| | 260 | |
| | 261 | osgUtil::PickVisitor::LineSegmentHitListMap& segHitList = pick.getSegHitList(); |
| | 262 | if (!segHitList.empty() && !segHitList.begin()->second.empty()) |
| | 263 | { |
| | 264 | |
| | 265 | // get the hits for the first segment |
| | 266 | osgUtil::PickVisitor::HitList& hits = segHitList.begin()->second; |
| | 267 | |
| | 268 | // just take the first hit - nearest the eye point. |
| | 269 | osgUtil::Hit& hit = hits.front(); |
| | 270 | |
| | 271 | std::cout<<"Got hits"<<hit.getLocalIntersectPoint()<<std::endl; |
| | 272 | } |
| | 273 | } |