HI ? Could you sign your post so we know how to address you :-) >From the description of the problem it looks likely to be a precision issue where the line segment aligns right along the edge between two triangles with neither triangle passing the test.
In the svn/trunk version of the OSG there is a IntersectionVisitor::setPrecisionHint(PrecisionHint hint) method that you can use to hint to the intersectors to use double maths. The LineSegmentIntersector supports this. Could you try this out to see if it helps? Robert. On 5 October 2014 09:51, weijianggood <weijiangg...@163.com> wrote: > > Hi, > When i use LineSegmentIntersector in the following code. > there must be 8 lines. but after I run the code, only 7 lines exist. > > [image: Lines.png] > > int main( int argc, char** argv ){ > > float height = 5.f; > > osg::ref_ptr<osg::TessellationHints> hints; > hints = new osg::TessellationHints; > hints->setDetailRatio(0.5f); > hints->setCreateBody(true); > hints->setCreateBottom(false); > hints->setCreateTop(false); > osg::ref_ptr<osg::Geode> mynode = new osg::Geode; > > osg::ref_ptr<osg::ShapeDrawable> drawable = new > osg::ShapeDrawable(new > osg::Cylinder(osg::Vec3(0.0f,0.0f,0.0f),1.0f,height),hints); > > osg::ref_ptr<osg::ShapeDrawable> drawable2 = new > osg::ShapeDrawable(new > osg::Cylinder(osg::Vec3(0.0f,0.0f,0.0f),4.0f,height),hints); > > mynode->addDrawable(drawable.get()); // geom.get() or gemo. > both are ok. > mynode->addDrawable(drawable2.get()); > > osg::ref_ptr<osg::Group> root = new osg::Group; > root->addChild(mynode.get() ); > float angle = 0.0; > float angleDelta = 2.0f*osg::PI/8; > > for(int i=0; i<8;i++){ > float c = cosf(angle); > float s = sinf(angle); > > osg::ref_ptr<osgUtil::LineSegmentIntersector> intersector = > new osgUtil::LineSegmentIntersector( osg::Vec3(0.0f,0.0f,0.0f), > osg::Vec3(10.0f*c,10.0f*s,0.0f) ); > > osgUtil::IntersectionVisitor iv( intersector.get() ); > mynode->accept( iv ); > > if ( intersector->containsIntersections() ) > { > osgUtil::LineSegmentIntersector::Intersections > > &intersections = > intersector->getIntersections(); > > std::cout <<"intersection size > "<<intersections.size()<<std::endl; > > osg::ref_ptr<osg::Geode> geode=new osg::Geode; > osg::ref_ptr<osg::Geometry> geom=new osg::Geometry; > > osg::ref_ptr<osg::Vec3Array> v3a=new osg::Vec3Array; > > osg::ref_ptr<osg::Vec4Array> colors = new > osg::Vec4Array; > colors->push_back( osg::Vec4(1.0, 0.0, 0.0, 1.0) ); > > > > osgUtil::LineSegmentIntersector::Intersections::iterator itr; > > for ( itr = intersections.begin(); itr != > intersections.end(); ++itr ) { > > std::cout <<" X" << > itr->getWorldIntersectPoint().x() > > << " Y" << > itr->getWorldIntersectPoint().y() > > << " Z" << > itr->getWorldIntersectPoint().z(); > if(itr == intersections.begin()) > > v3a->push_back( > itr->getWorldIntersectPoint()); > > } > itr--; > > v3a->push_back( > itr->getWorldIntersectPoint()); > std::cout<<std::endl; > geom->setVertexArray(v3a); > geom->setColorArray(colors.get() ); > geom->setColorBinding(osg::Geometry::BIND_OVERALL); > for(int k=0; k<v3a->size(); k++){ > > std::cout<<"vectex: "<<v3a->at(k).x()<<" > "<<v3a->at(k).y()<<" "<<v3a->at(k).z(); > } > std::cout<<std::endl; > > geom->addPrimitiveSet(new > osg::DrawArrays(osg::PrimitiveSet::LINES,0,v3a->size())); > geode->addDrawable(geom); > root->addChild(geode); > }else{ > std::cout<<"no intersection for i="<<i<<std::endl; > > std::cout<<"x "<<intersector->getStart().x()<<" y > "<<intersector->getStart().y()<<" z "<<intersector->getStart().z()<<std::endl; > > std::cout<<"x "<<intersector->getEnd().x()<<" y > "<<intersector->getEnd().y()<<" z "<<intersector->getEnd().z()<<std::endl; > } > angle+=angleDelta; > } > osgViewer::Viewer viewer; > viewer.setSceneData(root.get()); > viewer.addEventHandler(new osgViewer::WindowSizeHandler); > return viewer.run(); > > } > > Thanks. > > ------------------------------ > > > _______________________________________________ > osg-users mailing list > osg-users@lists.openscenegraph.org > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org > >
_______________________________________________ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org