1

我正在用 OSGEarth 制作无人机模拟器。我以前从未使用过 OSG,所以我在理解相机方面有些困难。我正在尝试将相机移动到特定位置(纬度/经度),并在 OSG 地球中具有特定的滚动、俯仰和偏航。

我需要多台摄像机,所以我使用复合查看器。但我不明白如何移动特定的相机。目前,我有一个使用 EarthManipulator 的设备,效果很好。

 class NovaManipulator : publicosgGA::CameraManipulator {
         osg::Matrixd NovaManipulator::getMatrix() const
            {
              //drone_ is only a struct which contains updated infomations
              float roll = drone_->roll(),
              pitch = drone_->pitch(),
              yaw = drone_->yaw();

          auto position = drone_->position();
          osg::Vec3d world_position;
          position.toWorld(world_position);

          cam_view_->setPosition(world_position);

          const osg::Vec3d rollAxis(0.0, 1.0, 0.0);
          const osg::Vec3d pitchAxis(1.0, 0.0, 0.0);
          const osg::Vec3d yawAxis(0.0, 0.0, 1.0);

           //if found this code : 
           // https://stackoverflow.com/questions/32595198/controling-openscenegraph-camera-with-cartesian-coordinates-and-euler-angles
           osg::Quat rotationQuat;
           rotationQuat.makeRotate(
               osg::DegreesToRadians(pitch + 90), pitchAxis,
               osg::DegreesToRadians(roll),          rollAxis,
               osg::DegreesToRadians(yaw),          yawAxis);

          cam_view_->setAttitude(rotationQuat);

          // I don't really understand this also
          auto nodePathList = cam_view_->getParentalNodePaths();
          return osg::computeLocalToWorld(nodePathList[0]);
        }

        osg::Matrixd NovaManipulator::getInverseMatrix() const
        {
          //Don't know why need to be inverted
          return osg::Matrix::inverse(getMatrix());
        } 
    };

然后我将操纵器安装到查看器。当我模拟世界时,相机在好地方(纬度/经度/高度)。但是方向完全错误,我找不到需要“纠正”轴的位置。

实际上我的无人机在法国,但“向上”矢量不好,它仍然向北而不是相对于地面“垂直”。 看看我在正确的相机上得到了什么

我需要相对于北方(0 ==> North)有一个偏航,当我的滚动和俯仰设置为零时,我需要与地面“平行”。

我的方法(通过制作操纵器)是最好的吗?我可以将相机对象放在 Graph 节点内(在 a 后面osgEarth::GeoTransform(它适用于我的模型))吗?

谢谢 :)

4

2 回答 2

1

过去,我做过一个可爱的技巧,涉及使用 ObjectLocator 对象(获取世界位置和平面与表面相切的方向),并结合矩阵来应用 HPR。那里有一个反转,可以使它成为一个相机方向矩阵,而不是一个对象放置矩阵,但它工作正常。

http://forum.osgearth.org/void-ObjectLocator-setOrientation-default-orientation-td7496768.html#a7496844

由于许多变量的类型并不明显,因此查看代码片段中发生的事情有点棘手。

AlphaPixel 做了很多遥测 / osgEarth 类型的东西,所以如果你需要帮助就喊吧。

于 2018-06-20T18:16:37.997 回答
0

这可能只是您的旋转顺序 - 矩阵和四元数乘法取决于顺序。我会建议:

  1. 尝试在 MakeRotate 调用中交换俯仰和滚动的顺序。
  2. 如果这不起作用,一次将除 1 个旋转以外的所有旋转设置为 0°,确保每个旋转都符合您的预期,然后您可以使用订单(只有 6 个可能的订单)。
  3. 您还可以制作单独的四元数 q1、q2、q3,其中每个分别代表 h、p 和 r,然后自己将它们相乘以控制顺序。这就是您正在使用的 MakeRotate 的重载在幕后所做的。

通常你想先做你的偏航,然后是你的俯仰,然后是你的滚动(或者如果你愿意,也可以完全跳过滚动),但我不记得 osg::quat 是在 pre-mult 还是 post-mult 中连接时尚,所以它可能是撬订单。

于 2018-06-19T18:03:11.440 回答