|
我在“lz.osg”上修改坐标偏移量后,能右键哪里飞机就跑到哪里,但是我在.ply格式的地形上鼠标右键控制物体移动时,总是坐标计算错误得很离谱,不知道用的函数是不是错了,求获得地形上点的函数。- osgUtil::LineSegmentIntersector::Intersections intersections;
- if (m_OSG->mViewer->computeIntersections(point.x, point.y, intersections))
- {
- osgUtil::LineSegmentIntersector::Intersection intersection = *intersections.begin();
- osg::NodePath& nodePath = intersection.nodePath;
- view_position = intersection.getWorldIntersectPoint();
- //float a = abs(25.0*view_position.x() + 90 * view_position.y() + 4500.0) / sqrt(25.0*25 + 90*90);
- //view_position.x() = view_position.x() - 2*a*25/83.0;
- //view_position.y() = view_position.y() - 2*a*80/83.0;
- //view_position.z() = 20.0f;
- osg::PositionAttitudeTransform* tankXform = new osg::PositionAttitudeTransform();
- tankXform->addChild(osgDB::readNodeFile("cessna.osg"));
- tankXform->setPosition(view_position);// osg::Vec3(670.5f, 500,20)
- tankXform->setAttitude(osg::Quat(0.0f, osg::Vec3(0,0,1)) );
- m_OSG->mRoot->addChild(tankXform);
- }
复制代码 |
|