我正在用 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
(它适用于我的模型))吗?
谢谢 :)