我在osg场景中有一个正交摄影机。在该场景中将显示一些平面物体(平面),我希望能够使相机自动指向它们以正面对其进行查看,并进行缩放以显示尽可能多的平面尽可能不切掉任何边缘。
到目前为止,我已经正确地定位自己以查看飞机:
osg::Vec3d eye; // dummy
osg::Vec3d center; // we only really care about this here
osg::Vec3d up; // dummy
cameraManipulator->getViewMatrixAsLookAt(eye, center, up);
osg::Vec3d desiredVec(velocityX, velocityY, velocityZ); // velocity of the plane I want to look at
desiredVec.normalize();
desiredVec = -desiredVec; // invert
desiredVec += center; // align
cameraManipulator->setViewMatrixAsLookAt(desiredVec, center, osg::Vec3d(0, 0, -1));
这样可以定位我,以便我可以正面查看飞机,但是它放大得太远了,所以我认为我需要做的是将相机沿速度矢量向后偏移一些值,然后我不知道如何计算该值。像这样:
osg::Vec3d dir = desiredVec - center; // the direction (vector) in which we want to move
dir.normalize();
double scaleFactor = (width * height) / 2; // test
desiredVec += (dir * scaleFactor); // add it to desiredVec to move back in that direction (by scaleFactor)
scaleFactor“测试”的东西似乎可以正常工作,它产生一个带有边缘的边缘的平面视图。我想这就是需要改变的地方。
基本上,如何计算为了查看当前所有平面而需要向后移动相机的距离?我有关于飞机速度,大小等的信息。
答案 0 :(得分:0)
使用正交摄影机时,渲染对象(缩放效果)的大小不是通过移动照相机来实现的,而是通过您在照相机上设置的平截头体投影的大小来实现的。 没有一个OSG相机操纵器可实现正交相机的缩放效果。 请参阅此论坛主题作为参考:http://forum.openscenegraph.org/viewtopic.php?t=10763&view=next