您的位置:首页 > 其它

osg例子osgpick的一些知识点的理解

2012-03-17 12:13 369 查看
在例子“osgpick”中,有一段类似下面的代码
if (view->computeIntersections(x, y, intersections))
{
osgUtil::LineSegmentIntersector::Intersection intersection = *intersections.begin();
osg::NodePath& nodePath = intersection.nodePath;
//得到选择的物体
node = (nodePath.size()>=1)?nodePath[nodePath.size()-1]:0;
parent = (nodePath.size()>=2)?dynamic_cast<osg::Group*>(nodePath[nodePath.size()-2]):0;
}


这段代码中 if 判断从当前 camera 的角度及屏幕点确定的射线是否与场景中的物体相交,返回的 intersections , 即是相交的物体的集合.

每个 intersections 的元素是一个 vector , 从下标0至vector最后,是在这个交集中从大到小与这条射线发生相交的node,这个 vector 最后一个元素是是被选中的这个物体(geode) , 也即代码中的nodePath[nodePath.size()-1] .

参考:http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/2007-September/002055.html
http://cart033.blog.163.com/blog/static/68760122201212003510619/
而下段代码中,

const osgUtil::LineSegmentIntersector::Intersection::IndexList& vil = hitr->indexList;
for(unsigned int i=0;i<vil.size();++i)
{
os<<"        vertex indices ["<<i<<"] = "<<vil[i]<<std::endl;
}


indexList是片元的顶点信息,即获得相交对象后,取得此对象的顶点数组,indexList中的数,即为这个片元的顶点坐标下标。

参考:http://www.haogongju.net/art/884120
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: