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.
On 1/9/07, E. Wing <[EMAIL PROTECTED]> wrote:
I'm trying to get hit-detection (via osgUtil::PickVisitor) working
with my osgsimpleviewerCocoa class. (I'm trying to understand how to
use it so I can integrate it in my app.) I have a Projection node in
my scene graph which I don't know how to handle.
My test case is that I have a simple osgText attached to a geode which
is attached to an osg::Projection with its matrix set to
osg::Matrix::ortho2D(0, 800, 0, 600). The projection node is attached
to an osg::Swtich which is my root node (which is passed to
simpleViewer->setSceneData(...)).
Without the Projection Node, the code seems to properly hit the text.
With the Projection node, I have not been able to hit the text. I
copied a bunch of code out of osgProducer/Viewer which I thought might
handle the case based on an old message in the mailing list archives,
but I seem to be doing something wrong.
The following code is my mouse event:
- (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);
osgUtil::IntersectVisitor::HitList hit_list;
osg::Node::NodeMask traversalMask = 0xffffffff;
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::NodePathList parentNodePaths =
top_most_node->getParentalNodePaths();
for(unsigned int i=0;i<parentNodePaths.size();++i)
{
osg::NodePath& nodePath = parentNodePaths[i];
// remove the intersection node from the nodePath as it'll
be accounted for
// in the PickVisitor traversal, so we don't double
account for its transform.
if (!nodePath.empty()) nodePath.pop_back();
osg::Matrixd modelview(view_matrix);
// modify the view matrix so that it accounts for this
nodePath's accumulated transform
if (!nodePath.empty())
modelview.preMult(computeLocalToWorld(nodePath));
osgUtil::PickVisitor pick(the_viewport.get(),
proj_matrix,
modelview, converted_point.x, converted_point.y);
pick.setTraversalMask(traversalMask);
top_most_node.get()->accept(pick);
// copy all the hits across to the external hits list
for(osgUtil::PickVisitor::LineSegmentHitListMap::iterator iter =
pick.getSegHitList().begin();
iter != pick.getSegHitList().end();
++iter)
{
hit_list.insert(hit_list.end(),iter->second.begin(), iter->second.end());
}
// return true if we now have more hits than
before
if(hit_list.size() > 0)
{
NSLog(@"Found Hit");
}
else
{
NSLog(@"Didn't Hit");
}
}
}
[self setNeedsDisplay:YES];
}
Can anybody tell me how to fix this?
Thanks,
Eric
_______________________________________________
osg-users mailing list
[email protected]
http://openscenegraph.net/mailman/listinfo/osg-users
http://www.openscenegraph.org/
_______________________________________________
osg-users mailing list
[email protected]
http://openscenegraph.net/mailman/listinfo/osg-users
http://www.openscenegraph.org/