Hi Eric,
On 1/9/07, E. Wing <[EMAIL PROTECTED]> wrote:
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.
Could you reproduce the problem with a small standard OSG example? I
can't test out Cocoa based apps.
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?
Its the type of Intersector that they are, so a LineSegmentIntersector
uses a line segment to intersect the scene (as the old
IntersectVisitor/PickVisitor did), PolytopeIntersector uses a polytope
to interesect the scene, and PlaneIntersection uses a plane to create
a slice through the scene.
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?)
If you start the IntesectionVisitor traversal from the osg::Camara the
IntersectionVisitor will use the camera's viewport, projection and
view matrix so reproject the initiali intersection from its coordinate
frame (WINDOW) into the model coordinates where it'll do the
intersections.
If your use PROJECTION as the coordinate frame then you'll need to
pass in coords in -1,1 clip space range, and then IntersectionVisitor
will just transform them by the Projection and View matrices of the
Camera.
What coordinate frame is your mouse coordinates in? If they are in
window coordiantes then just use WINDOW as you are doing.
Robert.
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/
_______________________________________________
osg-users mailing list
[email protected]
http://openscenegraph.net/mailman/listinfo/osg-users
http://www.openscenegraph.org/