首页 技术 正文
技术 2022年11月8日
0 收藏 480 点赞 1,700 浏览 1617 个字

主要涉及三个类:

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 函数就可以。

上一篇: 对session的操作
下一篇: 自学Ajax
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,492
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,907
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,740
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,495
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,132
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,297