|
osg三维渲染引擎编程指南里有一个例子是讲自定义漫游器的。好像里面的碰撞检测没用。
所以我仅仅改了一下里面的碰撞检测,发现还是不能检测,依然穿墙,而且一直有invalid line segment的warning,不知道为什么。- // 位置变换函数
- void TravelManipulator::ChangePosition(osg::Vec3& delta)
- {
- //碰撞检测
- if (m_bPeng)
- {
- //得到新的位置
- osg::Vec3 newPos1 = m_vPosition + delta;
- osgUtil::IntersectVisitor intersection;
- osg::ref_ptr<osg::LineSegment> lineZ = new osg::LineSegment(newPos1+osg::Vec3(0.0f,0.0f,10.0f),
- newPos1-osg::Vec3(0.0f,0.0f,-10.0f)) ;
- intersection.addLineSegment(lineZ.get()) ;
- //结构交集检测
- m_pHostViewer->getSceneData()->accept(intersection) ;
- if(intersection.hits())
- {
- osgUtil::IntersectVisitor::HitList& hitList = intersection.getHitList(lineZ.get());
- if (!hitList.empty())
- {
- //取得碰撞交点
- osg::Vec3d ip = hitList.front().getWorldIntersectPoint();
- m_vPosition.z() = ip.z()+2;
- }
- }
- m_vPosition+= delta;
- }
- }
复制代码 |
|