|
发表于 2008-8-27 19:22:14
|
显示全部楼层
- 小车爬坡碰撞~~~~~
- void PopManipulator::computeHomePosition()
- {
- if(_node.get())
- {
- const osg::BoundingSphere& boundingSphere=_node->getBound();
- osg::Vec3d ep = boundingSphere._center;
- osg::Vec3d bp = ep;
- osg::CoordinateFrame cf=getCoordinateFrame(ep);
- ep -= getUpVector(cf)* _modelScale*0.0001;
- bp -= getUpVector(cf)* _modelScale;
- // check to see if any obstruction in front.
- osgUtil::IntersectVisitor iv;
- iv.setTraversalMask(_intersectTraversalMask);
- bool positionSet = false;
- osg::ref_ptr<osg::LineSegment> segDown = new osg::LineSegment;
- segDown->set(ep,bp);
- iv.addLineSegment(segDown.get());
- _node->accept(iv);
- if (iv.hits())
- {
- osgUtil::IntersectVisitor::HitList& hitList = iv.getHitList(segDown.get());
- if (!hitList.empty())
- {
- // notify(INFO) << "Hit terrain ok"<< std::endl;
- osg::Vec3d ip = hitList.front().getWorldIntersectPoint();
- osg::Vec3d np = hitList.front().getWorldIntersectNormal();
- osg::Vec3d uv;
- if (np * getUpVector(cf)>0.0) uv = np;
- else uv = -np;
- ep = ip;
- ep += getUpVector(cf)*_height;
- osg::Vec3 lv = uv^osg::Vec3d(1.0,0.0,0.0);
- setHomePosition(ep,ep+lv,uv);
- positionSet = true;
- }
- }
- if (!positionSet)
- {
- bp = ep;
- bp += getUpVector(cf)*_modelScale;
- osg::ref_ptr<osg::LineSegment> segUp = new osg::LineSegment;
- segUp->set(ep,bp);
- iv.addLineSegment(segUp.get());
- _node->accept(iv);
- if (iv.hits())
- {
- osgUtil::IntersectVisitor::HitList& hitList = iv.getHitList(segUp.get());
- if (!hitList.empty())
- {
- // notify(INFO) << "Hit terrain ok"<< std::endl;
- osg::Vec3d ip = hitList.front().getWorldIntersectPoint();
- osg::Vec3d np = hitList.front().getWorldIntersectNormal();
- osg::Vec3d uv;
- if (np*getUpVector(cf)>0.0) uv = np;
- else uv = -np;
- ep = ip;
- ep += getUpVector(cf)*_height;
- osg::Vec3 lv = uv^osg::Vec3d(1.0,0.0,0.0);
- setHomePosition(ep,ep+lv,uv);
- positionSet = true;
- }
- }
- }
- if (!positionSet)
- {
- setHomePosition(
- boundingSphere._center+osg::Vec3d( 0.0,-2.0 * boundingSphere._radius,0.0),
- boundingSphere._center+osg::Vec3d( 0.0,-2.0 * boundingSphere._radius,0.0)+osg::Vec3d(0.0,1.0,0.0),
- osg::Vec3d(0.0,0.0,1.0));
- }
- }
- }
复制代码 |
|