From c5082cb85c9692db25c28a4f9167de2a9eaba2c8 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 10 Jan 2007 10:40:12 +0000 Subject: [PATCH] Added support for vertex ratios into LineSegmentIntersector. --- examples/osgmovie/osgmovie.cpp | 48 ++++++-------------------- include/osgUtil/LineSegmentIntersector | 4 ++- src/osgUtil/LineSegmentIntersector.cpp | 20 ++++++++--- src/osgViewer/View.cpp | 2 -- 4 files changed, 30 insertions(+), 44 deletions(-) diff --git a/examples/osgmovie/osgmovie.cpp b/examples/osgmovie/osgmovie.cpp index 3b9bdfff0..764f2325e 100644 --- a/examples/osgmovie/osgmovie.cpp +++ b/examples/osgmovie/osgmovie.cpp @@ -118,13 +118,10 @@ bool MovieEventHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIAction { osgViewer::View* view = dynamic_cast(&aa); - osg::notify(osg::NOTICE)<<"osgmovie - view = "<computeIntersections(ea.getX(), ea.getY(), nv->getNodePath().back(), intersections)) + if (view && view->computeIntersections(ea.getX(), ea.getY(), nv->getNodePath(), intersections)) { -#if 1 - osg::notify(osg::NOTICE)<<"osgmovie - Vertex interpolation not implemented yet"<start(); - osg::Vec3 p2 = intersection.getLocalLineSegment()->end(); + unsigned int i1 = indices[0]; + unsigned int i2 = indices[1]; + unsigned int i3 = indices[2]; - osg::Vec3 p12 = p1-p2; - osg::Vec3 v13 = v1-v3; - osg::Vec3 v23 = v2-v3; - osg::Vec3 p1v3 = p1-v3; - - osg::Matrix matrix(p12.x(), v13.x(), v23.x(), 0.0, - p12.y(), v13.y(), v23.y(), 0.0, - p12.z(), v13.z(), v23.z(), 0.0, - 0.0, 0.0, 0.0, 1.0); - - osg::Matrix inverse; - inverse.invert(matrix); - - osg::Vec3 ratio = inverse*p1v3; - - // extract the baricentric coordinates. - float r1 = ratio.y(); - float r2 = ratio.z(); - float r3 = 1.0f-r1-r2; + float r1 = ratios[0]; + float r2 = ratios[1]; + float r3 = ratios[2]; osg::Array* texcoords = (geometry->getNumTexCoordArrays()>0) ? geometry->getTexCoordArray(0) : 0; osg::Vec2Array* texcoords_Vec2Array = dynamic_cast(texcoords); @@ -188,7 +163,6 @@ bool MovieEventHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIAction } } -#endif } else { diff --git a/include/osgUtil/LineSegmentIntersector b/include/osgUtil/LineSegmentIntersector index a617b00d2..b10fe85c0 100644 --- a/include/osgUtil/LineSegmentIntersector +++ b/include/osgUtil/LineSegmentIntersector @@ -45,7 +45,8 @@ class OSGUTIL_EXPORT LineSegmentIntersector : public Intersector bool operator < (const Intersection& rhs) const { return ratio < rhs.ratio; } - typedef std::vector IndexList; + typedef std::vector IndexList; + typedef std::vector RatioList; double ratio; osg::NodePath nodePath; @@ -54,6 +55,7 @@ class OSGUTIL_EXPORT LineSegmentIntersector : public Intersector osg::Vec3d localIntersectionPoint; osg::Vec3 localIntersectionNormal; IndexList indexList; + RatioList ratioList; unsigned int primitiveIndex; }; diff --git a/src/osgUtil/LineSegmentIntersector.cpp b/src/osgUtil/LineSegmentIntersector.cpp index aa5c4cce2..f1ddbbbab 100644 --- a/src/osgUtil/LineSegmentIntersector.cpp +++ b/src/osgUtil/LineSegmentIntersector.cpp @@ -324,12 +324,24 @@ void LineSegmentIntersector::intersect(osgUtil::IntersectionVisitor& iv, osg::Dr if (vertices) { osg::Vec3* first = &(vertices->front()); - if (triHit._v1) hit.indexList.push_back(triHit._v1-first); - if (triHit._v2) hit.indexList.push_back(triHit._v2-first); - if (triHit._v3) hit.indexList.push_back(triHit._v3-first); + if (triHit._v1) + { + hit.indexList.push_back(triHit._v1-first); + hit.ratioList.push_back(triHit._r1); + } + if (triHit._v2) + { + hit.indexList.push_back(triHit._v2-first); + hit.ratioList.push_back(triHit._r2); + } + if (triHit._v3) + { + hit.indexList.push_back(triHit._v3-first); + hit.ratioList.push_back(triHit._r3); + } } } - + insertIntersection(hit); } diff --git a/src/osgViewer/View.cpp b/src/osgViewer/View.cpp index 7f52e6082..76ddead49 100644 --- a/src/osgViewer/View.cpp +++ b/src/osgViewer/View.cpp @@ -413,8 +413,6 @@ bool View::computeIntersections(float x,float y, osg::NodePath& nodePath, osgUti { if (!_camera.valid()) return false; - osg::notify(osg::NOTICE)<<"View::computeIntersections(x,y,node,intersections) not implemented"<getViewMatrix() * _camera->getProjectionMatrix(); double zNear = -1.0;