|
本帖最后由 qylibohao 于 2010-10-12 14:18 编辑
本人先通过鼠标点选地面获取交点的世界坐标存储起来,然后将这些地面点连起来
我用PlaneIntersector构建求交的面但是求出来的交线有问题,就是坐标不对。
代码是按照网上的资料写的,先贴出来:
osgUtil::PlaneIntersector::Intersections intersections;
osg::Plane plane;
osg::Vec3d upVector (0.0, 1.0, 0.0);
for (int i = 0 ;i<_PositionArrayInWorld->size()-1;i++) /////_positionArrayInWorld 保存了鼠标点选是地面的世界坐标点
{
osg::Vec3 startPt = (*_PositionArrayInWorld)[0];
osg::Vec3 endPt = (*_PositionArrayInWorld)[1];
osg::Vec3f planeNormal = (endPt-startPt)^upVector;
planeNormal.normalize();
plane.set( planeNormal, startPt);
//osg::Vec3f startPlaneNormal = upVector^planeNormal;
//startPlaneNormal.normalize();
osg::Vec3f startPlaneNormal = osg::Vec3f(1,0,0);
osg::Polytope polytope;
polytope.add( osg::Plane(startPlaneNormal,startPt));
//osg::Vec3f endPlaneNormal = planeNormal^upVector;
//endPlaneNormal.normalize();
osg::Vec3f endPlaneNormal = osg::Vec3f(-1,0,0);
polytope.add( osg::Plane(endPlaneNormal,endPt));
osg::ref_ptr<osgUtil::PlaneIntersector>intersector = new osgUtil::PlaneIntersector(plane,polytope);
osgUtil::IntersectionVisitor iv(intersector.get());
viewer->getSceneData()->accept(iv);
if (intersector->containsIntersections())
{
osgUtil::PlaneIntersector::Intersections& intersections = intersector->getIntersections();
osgUtil::PlaneIntersector::Intersections::iterator itr;
double x1,y1,z1;
for (itr = intersections.begin() ; itr != intersections.end();++itr)
{
for( unsigned int i=0; i<(*itr).polyline.size(); ++i)
{
x1 = (*itr).polyline.x();
y1 = (*itr).polyline.y();
z1 = (*itr).polyline.z();
linepoint->push_back(osg::Vec3(x1,y1,z1));
}
}
}
}
现在就是传进去的世界坐标标点,计算出来的x1 y1 z1 很小,不知道是什么问题,难道计算出来的坐标不是世界
坐标点吗?请大家帮帮忙,解答一下问题。 |
|