Re: [osg-users] Can't pick HUD geometry under perspective projection
Now that my problem is resolved, I thought about why I was having so much trouble finding the resolution. It occured to me early on that my near/far settings might be involved early on and appearently my attempt to override what I was setting was ineffective. The problem was ultimately something along the lines of what Frank suggested, only simpler. The HUD geometries are rendered with depth OFF, so they're visible despite the near/far settings of the projection matrix. However, when picking the near/far settings would cause the HUD geometries to be culled and would never register a pick hit. There seems to be no reason not to keep near/far wide open (-1., 1.) in the HUD camera projection. -Don ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Can't pick HUD geometry under perspective projection
hi all, I found a fix for my problem. After making only very slow progress trying to debug actions mainly taking place in inline functions, I found that I merely needed to open up the near and far distances in setProjectionMatrixAsOrtho for my HUD camera. If anyone has advice on debugging inline functions, I'm all ears. Thanks to those who offered up possible solutions for this problem. -Don ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Can't pick HUD geometry under perspective projection
I had a problem in my application some time ago that sounds similar. I have worked around the issue in a way not unlike Jean-Sébastien Guay. If I remember correctly, the problem I was experiencing was due to the fact that the intersections are sorted by depth without regard to viewports. So even though the HUD geometry is rendered ontop of the perspective geometry it could have a larger depth and thus ends up further down the list. You can easily check if this is your issue by printing all of the intersections. Frank On Wed, 2010-06-30 at 19:17 -0400, Don Leich wrote: Hi J-S, Thanks for your suggestion, but your workaround didn't work for me. I've been running OSG 2.8.3 and also tried 2.9.7 with no improvement. In my code _s_scene-getHUDCamera() returns the post render camera for my HUD geometry. I also have a pre render camera used for a background image that I skip with a NodeMask. If I disable the NodeMask the only node I intersect with the perspective camera is my background image quad. Could this be a clue, or is it just a side issue? -Don class Picking : public osg::Referenced { public: Picking() {} ~Picking() {} // Pick at the given mouse coordinates void pick( int mx, int my, osgViewer::View* view, osg::Node *skipNode, int id, int seed, float3 lcs, float3 wcs ) { id = -1; seed = -1; lcs[0] = lcs[1] = lcs[2] = 0.; wcs[0] = wcs[1] = wcs[2] = 0.; osg::Drawable* drawable = 0; osg::Node* node = 0; osg::Group* parent = 0; osg::Viewport* viewport = view-getCamera()-getViewport(); // Save and replace the node mask for a node to skip here, // typically the background image quad. osg::Node::NodeMask origNodeMask = skipNode-getNodeMask(); skipNode-setNodeMask( 0x ); bool gotPick = false; // Use PolytopeIntersector exclusively. Works on all primitive types. if ( viewport != NULL ) { osgUtil::PolytopeIntersector* picker; { // use window coordinates double fx = viewport-x() + mx; double fy = viewport-y() + (viewport-height()-1) - my; // invert Y double ap = 2.; // pick frustum aperture radius picker = new osgUtil::PolytopeIntersector( osgUtil::Intersector::WINDOW, fx-ap, fy-ap, fx+ap, fy+ap ); } osgUtil::IntersectionVisitor iv(picker); view-getCamera()-accept(iv); // // If we fail to find any intersections with the main camera, run the // accept on the HUD camera. This didn't help. With a perspective main // camera we never see the HUD geometry. // if (! picker-containsIntersections()) _s_scene-getHUDCamera()-accept(iv); if (picker-containsIntersections()) { osgUtil::PolytopeIntersector::Intersection intersection = picker-getFirstIntersection(); // Removed application stuff here. // Local coordinate system point (really the average of all hits). osg::Vec3 lip; lip[0] = intersection.localIntersectionPoint[0]; lip[1] = intersection.localIntersectionPoint[1]; lip[2] = intersection.localIntersectionPoint[2]; lcs[0] = lip[0]; lcs[1] = lip[1]; lcs[2] = lip[2]; // Transform local coordinate system point into world coordinate system point. osg::Vec3 wip = lip * (*intersection.matrix.get()); wcs[0] = wip[0]; wcs[1] = wip[1]; wcs[2] = wip[2]; drawable = intersection.drawable; gotPick = true; } } // Removed application stuff here. skipNode-setNodeMask( origNodeMask ); // restore } // Removed application stuff here. }; Jean-Sébastien Guay wrote: Hi Don, I'm having a problem with not being able to pick on my HUD geometry when the main camera has a perspective projection. My app is able to toggle between perspective and orthographic. Picking on the HUD geometry works fine with orthographic, and the HUDs are visible in both projections. This sounds a bit like the reason why in the example I sent a little while ago to test out the changed I had made to QWidgetImage, I had to customize the computeIntersections() method when my widget was under an ortho projection (i.e. displayed
Re: [osg-users] Can't pick HUD geometry under perspective projection
Thanks Frank. I don't think I'm having the same problem. I fail to get an interestion hit of my HUD geometry when it's over the background. I don't get 3-D geometry instead. I get nothing. I'm not sure if J-S's idea that something in changing between the perspective and orthogonal cameras is the problem either. I saw no improvement running accept on the HUD camera first. It seems we wouldn't be changing in that case. It looks like I need some quality debugging time. -Don Frank Miller wrote: I had a problem in my application some time ago that sounds similar. I have worked around the issue in a way not unlike Jean-Sébastien Guay. If I remember correctly, the problem I was experiencing was due to the fact that the intersections are sorted by depth without regard to viewports. So even though the HUD geometry is rendered ontop of the perspective geometry it could have a larger depth and thus ends up further down the list. You can easily check if this is your issue by printing all of the intersections. Frank On Wed, 2010-06-30 at 19:17 -0400, Don Leich wrote: Hi J-S, Thanks for your suggestion, but your workaround didn't work for me. I've been running OSG 2.8.3 and also tried 2.9.7 with no improvement. In my code _s_scene-getHUDCamera() returns the post render camera for my HUD geometry. I also have a pre render camera used for a background image that I skip with a NodeMask. If I disable the NodeMask the only node I intersect with the perspective camera is my background image quad. Could this be a clue, or is it just a side issue? -Don class Picking : public osg::Referenced { public: Picking() {} ~Picking() {} // Pick at the given mouse coordinates void pick( int mx, int my, osgViewer::View* view, osg::Node *skipNode, int id, int seed, float3 lcs, float3 wcs ) { id = -1; seed = -1; lcs[0] = lcs[1] = lcs[2] = 0.; wcs[0] = wcs[1] = wcs[2] = 0.; osg::Drawable* drawable = 0; osg::Node* node = 0; osg::Group* parent = 0; osg::Viewport* viewport = view-getCamera()-getViewport(); // Save and replace the node mask for a node to skip here, // typically the background image quad. osg::Node::NodeMask origNodeMask = skipNode-getNodeMask(); skipNode-setNodeMask( 0x ); bool gotPick = false; // Use PolytopeIntersector exclusively. Works on all primitive types. if ( viewport != NULL ) { osgUtil::PolytopeIntersector* picker; { // use window coordinates double fx = viewport-x() + mx; double fy = viewport-y() + (viewport-height()-1) - my; // invert Y double ap = 2.; // pick frustum aperture radius picker = new osgUtil::PolytopeIntersector( osgUtil::Intersector::WINDOW, fx-ap, fy-ap, fx+ap, fy+ap ); } osgUtil::IntersectionVisitor iv(picker); view-getCamera()-accept(iv); // // If we fail to find any intersections with the main camera, run the // accept on the HUD camera. This didn't help. With a perspective main // camera we never see the HUD geometry. // if (! picker-containsIntersections()) _s_scene-getHUDCamera()-accept(iv); if (picker-containsIntersections()) { osgUtil::PolytopeIntersector::Intersection intersection = picker-getFirstIntersection(); // Removed application stuff here. // Local coordinate system point (really the average of all hits). osg::Vec3 lip; lip[0] = intersection.localIntersectionPoint[0]; lip[1] = intersection.localIntersectionPoint[1]; lip[2] = intersection.localIntersectionPoint[2]; lcs[0] = lip[0]; lcs[1] = lip[1]; lcs[2] = lip[2]; // Transform local coordinate system point into world coordinate system point. osg::Vec3 wip = lip * (*intersection.matrix.get()); wcs[0] = wip[0]; wcs[1] = wip[1]; wcs[2] = wip[2]; drawable = intersection.drawable; gotPick = true; } } // Removed application stuff here. skipNode-setNodeMask( origNodeMask ); // restore } // Removed application stuff here. }; Jean-Sébastien Guay wrote: Hi Don, I'm having a problem with not being able to pick on my HUD geometry when the main camera has a perspective projection. My app is able to toggle between perspective and orthographic. Picking on the HUD geometry works fine with
Re: [osg-users] Can't pick HUD geometry under perspective projection
Hi Don, If you put some smallish geodes into your (non-HUD) scene - not just a background, but some test cubes or spheres or something - does your picker class pick those objects as you expect? Cheers, Tom -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=29643#29643 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Can't pick HUD geometry under perspective projection
Hi Don, Sorry to hear your problem doesn't seem to be the same as mine. It looks like I need some quality debugging time. That generally helps make things clear. In particular for the intersectors it's generally pretty easy to see why your node is being rejected when you're tracing through the code. Just make sure you use a simple scene to debug with, and giving clear and unique names to your nodes and drawables will help you keep a clear idea of where you're at. Good luck, J-S -- __ Jean-Sebastien Guayjean-sebastien.g...@cm-labs.com http://www.cm-labs.com/ http://whitestar02.webhop.org/ ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Can't pick HUD geometry under perspective projection
Hey guys, I managed to squeeze in a little debugging on this problem. Here's what I've got so far. I've pared down my scene to a small set 3-D lines and a single annotation arrow in my HUD camera. If I pick on the arrow when the main camera is orthogonal I can see than inside PolytopeIntersector::enter _polytope.contains() evaluates to either true or false depending on where we are in the scene graph. If I pick on the arrow when the main camera is perspective _polytope.contains() will always evaluate false. Whatever this means will have to wait over the long weekend. Thanks for the help, and have a good one yourselves. -Don ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Can't pick HUD geometry under perspective projection
I meant to say the archives *weren't* very helpful. -Don Don Leich wrote: hi all, I'm having a problem with not being able to pick on my HUD geometry when the main camera has a perspective projection. My app is able to toggle between perspective and orthographic. Picking on the HUD geometry works fine with orthographic, and the HUDs are visible in both projections. I am setting near far for the perspective projection, an obvious difference from orthographic. I tried altering the camera to set setComputeNearFarMode( osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR) just prior to picking with no change. The same problem occurs with osgUtil::LineSegmentIntersector and osgUtil::PolytopeIntersector. Does anyone have an idea what's going on here? The archives were very helpful. -Don Leich ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Can't pick HUD geometry under perspective projection
Hi Don, I'm having a problem with not being able to pick on my HUD geometry when the main camera has a perspective projection. My app is able to toggle between perspective and orthographic. Picking on the HUD geometry works fine with orthographic, and the HUDs are visible in both projections. This sounds a bit like the reason why in the example I sent a little while ago to test out the changed I had made to QWidgetImage, I had to customize the computeIntersections() method when my widget was under an ortho projection (i.e. displayed fullscreen). Unfortunately I didn't get to look into why that was, I just worked around it. The workaround I used was to give the IntersectionVisitor directly to the ortho camera instead of starting it from the root (the viewer's main camera, which is the perspective one). If I had to venture a guess I'd say it looks like some values are lingering around from the perspective projection once the IntersectionVisitor gets to the ortho camera, almost as if it hadn't seen that the ortho camera is in referenceFrame ABSOLUTE_RF (which means it should start over fresh, not multiply by the previous matrix). But as I said, I haven't dug any deeper, so that's just a hunch. Hope this helps in some small way, J-S -- __ Jean-Sebastien Guayjean-sebastien.g...@cm-labs.com http://www.cm-labs.com/ http://whitestar02.webhop.org/ ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Can't pick HUD geometry under perspective projection
Hi J-S, Thanks for your suggestion, but your workaround didn't work for me. I've been running OSG 2.8.3 and also tried 2.9.7 with no improvement. In my code _s_scene-getHUDCamera() returns the post render camera for my HUD geometry. I also have a pre render camera used for a background image that I skip with a NodeMask. If I disable the NodeMask the only node I intersect with the perspective camera is my background image quad. Could this be a clue, or is it just a side issue? -Don class Picking : public osg::Referenced { public: Picking() {} ~Picking() {} // Pick at the given mouse coordinates void pick( int mx, int my, osgViewer::View* view, osg::Node *skipNode, int id, int seed, float3 lcs, float3 wcs ) { id = -1; seed = -1; lcs[0] = lcs[1] = lcs[2] = 0.; wcs[0] = wcs[1] = wcs[2] = 0.; osg::Drawable* drawable = 0; osg::Node* node = 0; osg::Group* parent = 0; osg::Viewport* viewport = view-getCamera()-getViewport(); // Save and replace the node mask for a node to skip here, // typically the background image quad. osg::Node::NodeMask origNodeMask = skipNode-getNodeMask(); skipNode-setNodeMask( 0x ); bool gotPick = false; // Use PolytopeIntersector exclusively. Works on all primitive types. if ( viewport != NULL ) { osgUtil::PolytopeIntersector* picker; { // use window coordinates double fx = viewport-x() + mx; double fy = viewport-y() + (viewport-height()-1) - my; // invert Y double ap = 2.; // pick frustum aperture radius picker = new osgUtil::PolytopeIntersector( osgUtil::Intersector::WINDOW, fx-ap, fy-ap, fx+ap, fy+ap ); } osgUtil::IntersectionVisitor iv(picker); view-getCamera()-accept(iv); // // If we fail to find any intersections with the main camera, run the // accept on the HUD camera. This didn't help. With a perspective main // camera we never see the HUD geometry. // if (! picker-containsIntersections()) _s_scene-getHUDCamera()-accept(iv); if (picker-containsIntersections()) { osgUtil::PolytopeIntersector::Intersection intersection = picker-getFirstIntersection(); // Removed application stuff here. // Local coordinate system point (really the average of all hits). osg::Vec3 lip; lip[0] = intersection.localIntersectionPoint[0]; lip[1] = intersection.localIntersectionPoint[1]; lip[2] = intersection.localIntersectionPoint[2]; lcs[0] = lip[0]; lcs[1] = lip[1]; lcs[2] = lip[2]; // Transform local coordinate system point into world coordinate system point. osg::Vec3 wip = lip * (*intersection.matrix.get()); wcs[0] = wip[0]; wcs[1] = wip[1]; wcs[2] = wip[2]; drawable = intersection.drawable; gotPick = true; } } // Removed application stuff here. skipNode-setNodeMask( origNodeMask ); // restore } // Removed application stuff here. }; Jean-Sébastien Guay wrote: Hi Don, I'm having a problem with not being able to pick on my HUD geometry when the main camera has a perspective projection. My app is able to toggle between perspective and orthographic. Picking on the HUD geometry works fine with orthographic, and the HUDs are visible in both projections. This sounds a bit like the reason why in the example I sent a little while ago to test out the changed I had made to QWidgetImage, I had to customize the computeIntersections() method when my widget was under an ortho projection (i.e. displayed fullscreen). Unfortunately I didn't get to look into why that was, I just worked around it. The workaround I used was to give the IntersectionVisitor directly to the ortho camera instead of starting it from the root (the viewer's main camera, which is the perspective one). If I had to venture a guess I'd say it looks like some values are lingering around from the perspective projection once the IntersectionVisitor gets to the ortho camera, almost as if it hadn't seen that the ortho camera is in referenceFrame ABSOLUTE_RF (which means it should start over fresh, not multiply by the previous matrix). But as I said, I haven't dug any deeper, so that's just a hunch. Hope this helps in some small way, J-S ___ osg-users