Added handling of co-incident start and end points.
This commit is contained in:
parent
9a9c543ffa
commit
10595e49e3
@ -284,10 +284,15 @@ void LineSegmentIntersector::intersect(osgUtil::IntersectionVisitor& iv, osg::Dr
|
|||||||
osg::Vec3d s(_start), e(_end);
|
osg::Vec3d s(_start), e(_end);
|
||||||
if ( !intersectAndClip( s, e, drawable->getBound() ) ) return;
|
if ( !intersectAndClip( s, e, drawable->getBound() ) ) return;
|
||||||
|
|
||||||
// reset the clipped range as it can be too close in on the BB, and cause missing due precission issues.
|
double epsilon = 1e-8;
|
||||||
s = _start;
|
if ((s-e).length()<epsilon)
|
||||||
e = _end;
|
{
|
||||||
|
osg::Vec3d delta_e_end = _end - e;
|
||||||
|
osg::Vec3d delta_s_start = _start - s;
|
||||||
|
double scale = 0.001;
|
||||||
|
s += (delta_s_start * scale);
|
||||||
|
e += (delta_e_end * scale);
|
||||||
|
}
|
||||||
|
|
||||||
osg::KdTree* kdTree = dynamic_cast<osg::KdTree*>(drawable->getShape());
|
osg::KdTree* kdTree = dynamic_cast<osg::KdTree*>(drawable->getShape());
|
||||||
if (kdTree)
|
if (kdTree)
|
||||||
@ -315,7 +320,11 @@ void LineSegmentIntersector::intersect(osgUtil::IntersectionVisitor& iv, osg::Dr
|
|||||||
hit.drawable = drawable;
|
hit.drawable = drawable;
|
||||||
hit.primitiveIndex = lsi.primitiveIndex;
|
hit.primitiveIndex = lsi.primitiveIndex;
|
||||||
|
|
||||||
hit.localIntersectionPoint = lsi.intersectionPoint; // s*(1.0f-ratio) + e*ratio;
|
#if 0
|
||||||
|
hit.localIntersectionPoint = lsi.intersectionPoint;
|
||||||
|
#else
|
||||||
|
hit.localIntersectionPoint = s*(1.0f-ratio) + e*ratio;
|
||||||
|
#endif
|
||||||
hit.localIntersectionNormal = lsi.intersectionNormal;
|
hit.localIntersectionNormal = lsi.intersectionNormal;
|
||||||
|
|
||||||
hit.indexList.swap(lsi.indexList);
|
hit.indexList.swap(lsi.indexList);
|
||||||
@ -347,21 +356,25 @@ void LineSegmentIntersector::intersect(osgUtil::IntersectionVisitor& iv, osg::Dr
|
|||||||
{
|
{
|
||||||
|
|
||||||
// get ratio in s,e range
|
// get ratio in s,e range
|
||||||
float ratio = thitr->first;
|
double ratio = thitr->first;
|
||||||
|
|
||||||
// remap ratio into _start, _end range
|
// remap ratio into _start, _end range
|
||||||
ratio = ((s-_start).length() + ratio * (e-s).length() )/(_end-_start).length();
|
double remap_ratio = ((s-_start).length() + ratio * (e-s).length() )/(_end-_start).length();
|
||||||
|
|
||||||
LineSegmentIntersectorUtils::TriangleIntersection& triHit = thitr->second;
|
LineSegmentIntersectorUtils::TriangleIntersection& triHit = thitr->second;
|
||||||
|
|
||||||
Intersection hit;
|
Intersection hit;
|
||||||
hit.ratio = ratio;
|
hit.ratio = remap_ratio;
|
||||||
hit.matrix = iv.getModelMatrix();
|
hit.matrix = iv.getModelMatrix();
|
||||||
hit.nodePath = iv.getNodePath();
|
hit.nodePath = iv.getNodePath();
|
||||||
hit.drawable = drawable;
|
hit.drawable = drawable;
|
||||||
hit.primitiveIndex = triHit._index;
|
hit.primitiveIndex = triHit._index;
|
||||||
|
|
||||||
hit.localIntersectionPoint = s*(1.0f-ratio) + e*ratio;
|
#if 1
|
||||||
|
hit.localIntersectionPoint = _start*(1.0-remap_ratio) + _end*remap_ratio;
|
||||||
|
#else
|
||||||
|
hit.localIntersectionPoint = s*(1.0-ratio) + e*ratio;
|
||||||
|
#endif
|
||||||
hit.localIntersectionNormal = triHit._normal;
|
hit.localIntersectionNormal = triHit._normal;
|
||||||
|
|
||||||
if (geometry)
|
if (geometry)
|
||||||
|
Loading…
Reference in New Issue
Block a user