标签:set section min 实例 ++i 实例化 ice notice osg
主要涉及三个类:
1. osgUtil::PolytopeIntersector // 详细不同算法实现类
2. osgUtil::IntersectionVisitor //用来遍历节点树的每一个节点
3.osg::Node * mNode; // 你要做相交測试的根节点
先看使用方法:
osg::ref_ptr<osgUtil::PolytopeIntersector> intersector = new osgUtil::PolytopeIntersector(osgUtil::Intersector::WINDOW, xMin, yMin, xMax, yMax); intersector->setIntersectionLimit(osgUtil::Intersector::LIMIT_ONE_PER_DRAWABLE); osgUtil::IntersectionVisitor iv( intersector.get() ); mRootNode->accept(iv);
关系
osgUtil::IntersectionVisitor 中含有一个osgUtil::PolytopeIntersector的实例化对象。功能是主要负责遍历每一个节点,然后把每一个节点的信息传入到 osgUtil::PolytopeIntersector 中
(含有一系列的apply方法)如:
void IntersectionVisitor::apply(osg::Group& group)
{
if (!enter(group)) return;
traverse(group);
leave();
}
void IntersectionVisitor::apply(osg::Geode& geode)
{
// OSG_NOTICE<<"apply(Geode&)"<<std::endl;
if (!enter(geode)) return;
// OSG_NOTICE<<"inside apply(Geode&)"<<std::endl;
for(unsigned int i=0; i<geode.getNumDrawables(); ++i)
{
intersect( geode.getDrawable(i) );
}
leave();
} inline bool enter(const osg::Node& node) { return _intersectorStack.empty() ? false : _intersectorStack.back()->enter(node); }
inline void leave() { _intersectorStack.back()->leave(); }
inline void intersect(osg::Drawable* drawable) { _intersectorStack.back()->intersect(*this, drawable); }
inline void push_clone() { _intersectorStack.push_back ( _intersectorStack.front()->clone(*this) ); }
inline void pop_clone() { if (_intersectorStack.size()>=2) _intersectorStack.pop_back(); }这样差点儿全部的算法都集中到了 osgUtil::PolytopeIntersector 中 intersect 方法中
void PolytopeIntersector::intersect(osgUtil::IntersectionVisitor& iv, osg::Drawable* drawable)
标签:set section min 实例 ++i 实例化 ice notice osg
原文地址:http://www.cnblogs.com/tlnshuju/p/6791442.html