Hi Eric,

I'd recommend against using PickVisitor - this class is now
deprecated, try using the new IntersectionVisitor and associated
Intersector classes.  For an example of using these for on screen
picking have a look at the osgkeyboardmouse example.

On my TODO list for today is adding intersection code into
osgViewer::Viewer, it probably won't be much of stretch for me to map
this code across to SimpleViewer.

Cheers,
Robert.

Hi Robert,
So I'm actually trying to get this integrated into a custom app that
doesn't use Producer or SimpleViewer. But I thought if I could get the
thing working in SimpleViewerCocoa, then I could figure out how to
dump it in my custom app (which only uses an osgUtil::SceneView).

Anyway, I copied the LineSegmentIntersector stuff  from
osgkeyboardmouse into my SimpleViewerCocoa, but I seem to be having
the same problem with Projection nodes as I did before. I'm also a
little uncertain about what Line/Polytope/Plane refer to. Do these
refer to the type of thing you are poking the scene with, or the type
of thing you are trying to hit? Also, I'm not sure about the
CoordinateFrame types work. I picked WINDOW to start with, and with a
scene graph with no Projection nodes, it seemed to work when I just
passed my mouse view coordinates in. I'm a little surprised it worked
at all. I thought I would have to at least setup some conversion scale
or normalize my values. How does this work? (But with the projection
node, nothing works, so maybe my test case is too trivial?)

Below is my event function.

Thanks,
Eric


- (void) doLeftMouseButtonDown:(NSEvent*)the_event
{
        // We must convert the mouse event locations from the window
coordinate system to the
        // local view coordinate system.
        NSPoint the_point = [the_event locationInWindow];
   NSPoint converted_point = [self convertPoint:the_point fromView:nil];
        if([the_event clickCount] == 1)
        {
                
simpleViewer->getEventQueue()->mouseButtonPress(converted_point.x,
converted_point.y, 1);
        }
        else
        {
                
simpleViewer->getEventQueue()->mouseDoubleButtonPress(converted_point.x,
converted_point.y, 1);

                osg::ref_ptr<osg::Node> top_most_node = 
simpleViewer->getSceneData();
                osg::ref_ptr<osg::Node> root_node = 
simpleViewer->getSceneData();
                osg::ref_ptr<osg::Viewport> the_viewport =
simpleViewer->getSceneView()->getViewport();
                osg::Matrixd proj_matrix =
simpleViewer->getSceneView()->getProjectionMatrix();
                osg::Matrixd view_matrix = 
simpleViewer->getSceneView()->getViewMatrix();
                
osg::Group* parent = 0;

//              osgUtil::LineSegmentIntersector* picker = new
osgUtil::LineSegmentIntersector( osgUtil::Intersector::WINDOW,
converted_point.x, converted_point.y);
                osgUtil::LineSegmentIntersector* picker = new
osgUtil::LineSegmentIntersector( osgUtil::Intersector::WINDOW,
converted_point.x, converted_point.y);
                osgUtil::IntersectionVisitor iv(picker);

                simpleViewer->getCamera()->accept(iv);

           if (picker->containsIntersections())
           {
                                NSLog(@"HIT FOUND!!!");
               osgUtil::LineSegmentIntersector::Intersection
intersection = picker->getFirstIntersection();
//                std::cout<<"Picked
"<<intersection.localIntersectionPoint<<std::endl;

               osg::NodePath& nodePath = intersection.nodePath;
               root_node = (nodePath.size()>=1)?nodePath[nodePath.size()-1]:0;
               parent =
(nodePath.size()>=2)?dynamic_cast<osg::Group*>(nodePath[nodePath.size()-2]):0;

               if (root_node.valid()) std::cout<<"  Hits
"<<root_node->className()<<" nodePath
size"<<nodePath.size()<<std::endl;

           }
                        else
                        {
                                NSLog(@"NO HIT!!!");

                        }

        }
        [self setNeedsDisplay:YES];
}
_______________________________________________
osg-users mailing list
[email protected]
http://openscenegraph.net/mailman/listinfo/osg-users
http://www.openscenegraph.org/

Reply via email to