zoukankan      html  css  js  c++  java
  • 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 函数就可以。



  • 相关阅读:
    C#修饰符
    Exploring jQuery .live() and .die()
    ASP.NET Session丢失问题原因及解决方案
    5个 PHP 安全措施(转)
    jQuery方法click() bind() live() delegate()区别
    高性能网站的十四条黄金法则(雅虎14条)
    计算机科学概论读书笔记系列——绪论
    进程、线程、应用程序域、托管代码、元数据等。
    互联网协议入门(转)
    js跨域访问问题
  • 原文地址:https://www.cnblogs.com/tlnshuju/p/6791442.html
Copyright © 2011-2022 走看看