|
楼主 |
发表于 2009-4-8 12:08:33
|
显示全部楼层
我采用了如下方法,但是还是没有交点:
//首先将屏幕坐标转换为世界坐标,通过近平面和远平面两个点来确定一条线,
osg::Matrix VPW = camera->getViewMatrix() *
camera->getProjectionMatrix() *
camera->getViewport()->computeWindowMatrix();
osg::Matrix inverseVPW;
inverseVPW.invert(VPW);
osg::Vec3d world_near = osg::Vec3d(x, y, 0.0) * inverseVPW; // x, y为屏幕坐标, 0.0表示近平面
osg::Vec3d world_far = osg::Vec3d(x, y, 1.0) * inverseVPW;
//然后用这条线和场景求交
osg::ref_ptr< osgUtil:ineSegmentIntersector > picker =
new osgUtil::LineSegmentIntersector(osgUtil::Intersector::MODEL, world_near, world_far);
osgUtil::IntersectionVisitor iv(picker.get());
iv.setTraversalMask(0xffffffff);
camera->accept(iv);
osgUtil::LineSegmentIntersector::Intersections intersections ;
if (picker->containsIntersections())
{
intersections = picker->getIntersections();
}
结果,无论怎么样都没有交点
[ 本帖最后由 panbin 于 2009-4-8 12:11 编辑 ] |
|