osgviewerMFC pick problem

69 views
Skip to first unread message

沈鑫

unread,
Jun 29, 2020, 5:56:01 AM6/29/20
to OpenSceneGraph Users
hi~I have a box,and click on model's face in osgviewerMFC(osgpick example) ,but sometime i will get wrong coordinate(most of click are near side),and i do the same operate only in osgviewer ,it works well! !!
For Example,sometime i should get 2 coordinates in a perspective view because of picking overlap part of two faces,if my pick return just 2 coodinates,the result is good,but sometime return only 1 ,and the one is not top coordinate!
I really confused about this case!Hope your reply~

OpenSceneGraph Users

unread,
Jun 29, 2020, 7:56:26 AM6/29/20
to OpenSceneGraph Users
Does this happen with all models?

The underlying intersection code will be the same whether you using osgick code integrated with osgviewerMFC or using the osgpick.  I don't know why you mention vsgviewer as it doesn't having picing code it, so do you add it?

The thing that will change with the different viewer might be the mouse coordinates or the projection matrices used.  The other possibility is that it's just fluke and it just happens that with your modified osgviewerMFC it's showing problems.

If it's not a viewer specific issue then numerical precision issues can cause intersection misses.  The osgUtil::IntersectionVisitor/LineSegmentIntersector that underpins picking has had various improvements over the years to help minimize this.  You can also select double precision maths.

You don't mention anything about your data, or the OSG version you are using so we can only provide general statements.   You'll need to provide more information about your data, OSG version, the exact code modifications you've made for us to be provide any further help.

Robert.

沈鑫

unread,
Jul 2, 2020, 2:33:01 AM7/2/20
to OpenSceneGraph Users


在 2020年6月29日星期一 UTC+8下午7:56:26,OpenSceneGraph Users写道:
MFCpick.jpg
osgpick.jpg
20200624_ceshi_pick.obj
MFC_OSG.cpp
MFC_OSG.h

Robert Osfield

unread,
Jul 2, 2020, 3:01:34 AM7/2/20
to OpenSceneGraph Users
Please upgrade to OpenSceneGraph-3.6.5.  It contains various improvements. including to the intersection code.

沈鑫

unread,
Jul 2, 2020, 11:36:55 PM7/2/20
to OpenSceneGraph Users
ok,thanks a lot~

在 2020年7月2日星期四 UTC+8下午3:01:34,Robert Osfield写道:

alexandre.vai...@gmail.com

unread,
Apr 18, 2021, 9:42:24 PM4/18/21
to OpenSceneGraph Users
Hello sxd?!

I took a quick look at your code, and I noticed that you have two different ways of calling the "pick" function: one where you take the event of OSG directly, and one where you create a new event with the supplied x/y and pass it along.

Both of those will then call computeIntersections. From my own experience with this, there are chances that there are subtle differences in what is found inside the event and that will end up influencing how the intersection computation is done.

For some reasons, I did not want to add an event handler to do the picking in the scene so I used Windows calls to get data to supply to OSG in order to perform the intersection. I came up with this code which appears to be working as expected. (Note that I only check the first object picked; the coordinates returned appear to be the appropriate ones.) I dug a bit into the code of OSG to come up with this.

  POINT p;
  if ( ::GetCursorPos( &p ) and ::ScreenToClient( viewHWND_, &p ) )
  {
    RECT rect;

    ::GetClientRect( viewHWND_, &rect );
    const float clientWidth = rect.right - rect.left;
    const float clientHeight = rect.bottom - rect.top;
   
    const float xNorm = (p.x-0)/(clientWidth-0)*2.0f-1.0f;
    const float yNorm = ((clientHeight-p.y)-0)/(clientHeight-0)*2.0f-1.0f;
    // From GUIEventAdapter struct PointerData:
    // float getXnormalized() const { return (x-xMin)/(xMax-xMin)*2.0f-1.0f; }
    // From osgViewer\View.cpp bool View::computeIntersections(const osgGA::GUIEventAdapter& ea, osgUtil::LineSegmentIntersector::Intersections& intersections,osg::Node::NodeMask traversalMask)
    // computeIntersections(camera, osgUtil::Intersector::PROJECTION, pd->getXnormalized(), pd->getYnormalized(), intersections, traversalMask);
    osgUtil::LineSegmentIntersector::Intersections intersections;
    if ( osgViewerView_->computeIntersections( mainViewCamera_, osgUtil::Intersector::PROJECTION, xNorm, yNorm, intersections ) )
      optionalIntersection_ = *(intersections.begin());
  }



I hope it helps, either you or someone else.
Reply all
Reply to author
Forward
0 new messages