Hi Brett,

I found intersection of  a line segment with a triangle mesh using intersection 
visitor in osg.But I dont want the line segment to penetrate into the triangle 
mesh.Can someone help me in doing this using osg please.

OSG is not a collision detection library, it's a graphics library. Intersection testing in OSG exists primarily for user interaction, for example picking an object. If you want something more involved than that, you'd be better off using a physics/collision detection library.

Note that if all you want is to find the length of the line segment that touches the first geometry, you can get the first intersection returned by the intersection visitor. In that data structure there is a ratio variable, that is the ratio of where the intersection occured between the start and end of your original segment. So for example:

  osg::Vec3 start(0,0,0);
  osg::Vec3 end(0,10000,0);

  osg::ref_ptr<osgUtil::LineSegmentIntersector> intersector =
      new osgUtil::LineSegmentIntersector( start, end );
  osgUtil::IntersectionVisitor iv(intersector.get());

  viewer->getCamera()->accept(iv);

  osgUtil::LineSegmentIntersector::Intersections& intersections =
      intersector->getIntersections();

  // First intersection:
  osgUtil::LineSegmentIntersector::Intersection firstHit =
      intersections.front();

  // This is easy since we know our ray was along the Y axis:
  double distance = (end.y() - start.y()) * firstHit.ratio;

  // Or if the ray could be in any direction:
  // Vector from start to hit point
  osg::Vec3 hitVec = (end - start) * ratio;
  double distance2 = hitVec.length();

Hope this helps,

J-S
--
______________________________________________________
Jean-Sebastien Guay    [email protected]
                               http://www.cm-labs.com/
                        http://whitestar02.webhop.org/
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to