- osgViewer::Viewer* viewer = globals->get_renderer()->getViewer();
- // wipe out the return ...
- pickList.resize(0);
-
- if (sceneView.valid()) {
- osg::Node* sceneData = globals->get_scenery()->get_scene_graph();
- if (!sceneData)
- return false;
-
- osg::Viewport* viewport = sceneView->getViewport();
- if (!viewport)
- return false;
- // don't know why, but the update has partly happened somehow,
- // so update the scenery part of the viewer
- FGViewer *current_view = globals->get_current_view();
- // Force update of center dependent values ...
- current_view->set_dirty();
- SGVec3d position = current_view->getViewPosition();
- SGQuatd attitude = current_view->getViewOrientation();
- SGVec3d osgPosition = attitude.transform(-position);
- mCameraView->setPosition(osgPosition.osg());
- mCameraView->setAttitude(inverse(attitude).osg());
-
- osg::Matrix projection(sceneView->getProjectionMatrix());
- osg::Matrix modelview(sceneView->getViewMatrix());
-
- osg::NodePathList nodePath = sceneData->getParentalNodePaths();
- // modify the view matrix so that it accounts for this nodePath's
- // accumulated transform
- if (!nodePath.empty())
- modelview.preMult(computeLocalToWorld(nodePath.front()));
-
- // swap the y values ...
- y = viewport->height() - y;
- // set up the pick visitor
- osgUtil::PickVisitor pickVisitor(viewport, projection, modelview, x, y);
- sceneData->accept(pickVisitor);
- if (!pickVisitor.hits())
- return false;
-
- // collect all interaction callbacks on the pick ray.
- // They get stored in the pickCallbacks list where they are sorted back
- // to front and croasest to finest wrt the scenery node they are attached to
- osgUtil::PickVisitor::LineSegmentHitListMap::const_iterator mi;
- for (mi = pickVisitor.getSegHitList().begin();
- mi != pickVisitor.getSegHitList().end();
- ++mi) {
- osgUtil::IntersectVisitor::HitList::const_iterator hi;
- for (hi = mi->second.begin(); hi != mi->second.end(); ++hi) {
- // ok, go back the nodes and ask for intersection callbacks,
- // execute them in top down order
- const osg::NodePath& np = hi->getNodePath();
- osg::NodePath::const_reverse_iterator npi;
- for (npi = np.rbegin(); npi != np.rend(); ++npi) {
- SGSceneUserData* ud = SGSceneUserData::getSceneUserData(*npi);
- if (!ud)
- continue;
- for (unsigned i = 0; i < ud->getNumPickCallbacks(); ++i) {
- SGPickCallback* pickCallback = ud->getPickCallback(i);
- if (!pickCallback)
- continue;
- SGSceneryPick sceneryPick;
- /// note that this is done totally in doubles instead of
- /// just using getWorldIntersectionPoint
- osg::Vec3d localPt = hi->getLocalIntersectPoint();
- sceneryPick.info.local = SGVec3d(localPt);
- if (hi->getMatrix())
- sceneryPick.info.wgs84 = SGVec3d(localPt*(*hi->getMatrix()));
- else
- sceneryPick.info.wgs84 = SGVec3d(localPt);
- sceneryPick.callback = pickCallback;
- pickList.push_back(sceneryPick);
- }
- }
- }
- }
-
- return !pickList.empty();
-
- } else if (viewer) {
-
- // just compute intersections in the viewers method ...