OSG 中 相交測試 模組 工作流程及原理

來源:互聯網
上載者:User

標籤: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();}

其中enter、leave 、intersect 函數中又會反過來調用 osgUtil::PolytopeIntersector 中相應的方法,如:

 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)

如果想寫自己的相交測試演算法,也基本上只需重寫intersect 函數即可。



聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.