|
楼主 |
发表于 2009-6-16 11:21:08
|
显示全部楼层
- osgViewer::View* view = dynamic_cast<osgViewer::View*>(&aa);
- osg::Group* root = dynamic_cast<osg::Group*>(view->getSceneData());
- osg::Node* earth = dynamic_cast<osg::Node*>(root->getChild(1));
- float local_x, local_y = 0.0;
- const osg::Camera* camera = view->getCameraContainingPosition(ea.getX(), ea.getY(), local_x, local_y);
- osgUtil::LineSegmentIntersector::CoordinateFrame cf = camera->getViewport() ? osgUtil::Intersector::WINDOW : osgUtil::Intersector::PROJECTION;
- osg::ref_ptr< osgUtil::LineSegmentIntersector > picker = new osgUtil::LineSegmentIntersector(cf, local_x, local_y);
- osgUtil::IntersectionVisitor iv(picker.get());
- //earth->accept(iv);
- const_cast<osg::Camera*>(camera)->accept(iv);
- if (picker->containsIntersections())
- {
- USES_CONVERSION;
- CString t;
- t.Format(A2W("点中地球!!"));
- AfxMessageBox(t);
- }
- else
- {
- USES_CONVERSION;
- CString t;
- t.Format(A2W("没有点中!!"));
- AfxMessageBox(t);
- }
复制代码
我如果使用earth->accept(iv),最后的结果是错误的,好像就没有能选中,如果使用const_cast<osg::Camera*>(camera)->accept(iv),结果就是正确的,不知道是为什么,请大家指教!
上面的是参照view类的computeintersections函数实现的。
[ 本帖最后由 zhufu0208 于 2009-6-16 11:23 编辑 ] |
|