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( 0x00000000 );
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 mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org