OSG地球相机位置

时间:2020-02-05 09:25:54

标签: c++ camera position openscenegraph osgearth

经过几次否定尝试,我正在写信给你。

我正在使用 OSGEarth ,特别是我无法为起始位置设置摄像机的经度,纬度和高度。

恐怕这与我使用 EarthManipulator

的事实有关

所以我创建了相机:

osg::ref_ptr<osg::GraphicsContext> gc = osg::GraphicsContext::createGraphicsContext(traits.get());  
osg::ref_ptr<osg::Camera> camera = new osg::Camera;
camera->setGraphicsContext(gc);
camera->setViewport(new osg::Viewport(0, 0, traits->width, traits->height));
camera->setClearMask(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);

然后,我创建一个视图,并将 EarthManipulator

传递给该视图
osg::ref_ptr<osgViewer::Viewer> g_viewer = new osgViewer::Viewer;

osg::Vec3d eye(1110.0, 1110.0, 1110.0);
osg::Vec3d center(10.0, 10.0, 10.0);
osg::Vec3d up(0.0, 1.0, 0.0);

g_viewer->setCamera(camera.get());

EarthManipulator* manip = new EarthManipulator();

manip->setViewpoint(Viewpoint(
    "Home",
    -71.0763, 42.34425, 0,
    // -71.0763, 42.34425, 0,   // longitude, latitude, altitude
    24.261, -21.6, 3450.0), // heading, pitch, range//3450
    4.0);     // duration, 4.0);

g_viewer->setCameraManipulator(manip);

但是我不能偏离通常的观点。

我还尝试过EarthMipulator,特别是设置原始位置

manip-> setHomePosition()

但没有任何变化

1 个答案:

答案 0 :(得分:2)

您想要的方法是EarthManipulator :: setHomeViewpoint:

manip->setHomeViewpoint(Viewpoint(
    "Home",
    -71.0763, 42.34425, 0,   // longitude, latitude, altitude
    24.261, -21.6, 3450.0)); // heading, pitch, range

希望这会有所帮助!