// 屏幕坐标转世界坐标
osg::Vec3d ScreenToWorld(const osg::Vec3d screen)
{
osg::Camera* camera = _global->Viewer->getCamera();
osg::Matrix VPW = camera->getViewMatrix() * camera->getProjectionMatrix() * camera->getViewport()->computeWindowMatrix();
osg::Matrix inverseVPW = osg::Matrix::inverse(VPW);
osg::Vec3d world = screen * inverseVPW;
return world;
}
// 世界坐标转屏幕坐标
osg::Vec3d WorldToScreen(const osg::Vec3d world)
{
osg::Camera* camera = _global->Viewer->getCamera();
osg::Matrix VPW = camera->getViewMatrix() * camera->getProjectionMatrix() * camera->getViewport()->computeWindowMatrix();
osg::Vec3d screen = world * VPW;
return screen;
}
// 世界坐标转经纬度
osg::Vec3d WorldToLonLatAlt(const osg::Vec3d world)
{
osg::EllipsoidModel* em = new osg::EllipsoidModel();
osg::Vec3d lonLatAlt;
em->convertXYZToLatLongHeight(world.x(), world.y(), world.z(), lonLatAlt.y(), lonLatAlt.x(), lonLatAlt.z());
lonLatAlt.x() = osg::RadiansToDegrees(lonLatAlt.x());
lonLatAlt.y() = osg::RadiansToDegrees(lonLatAlt.y());
return lonLatAlt;
}
// 经纬度转世界坐标
osg::Vec3d LonLatAltToWorld(const osg::Vec3d lonLatAlt)
{
osg::Vec3d world;
osg::EllipsoidModel* em = new osg::EllipsoidModel();
em->convertLatLongHeightToXYZ(osg::DegreesToRadians(lonLatAlt.y()), osg::DegreesToRadians(lonLatAlt.x()), lonLatAlt.z(), world.x(), world.y(), world.z());
return world;
}
// 屏幕坐标转经纬度
osg::Vec3d ScreenToLonLatAlt(const osg::Vec3d screen)
{
return WorldToLonLatAlt(ScreenToWorld(screen));
}
// 经纬度转屏幕坐标
osg::Vec3d LonLatAltToScreen(const osg::Vec3d lonLatAlt)
{
return WorldToScreen(LonLatAltToWorld(lonLatAlt));
}
OSGEarth之坐标转换
最新推荐文章于 2024-03-18 14:12:11 发布