我在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)
比例因子“测试”的东西似乎工作,它产生一个边缘周围边缘的平面视图。我想这是需要改变的。
基本上,我如何计算我需要移动相机的距离才能查看当前所有平面?我有关于飞机速度,大小等的信息。
使用正交相机时,渲染对象的大小(缩放效果)不是通过移动相机来实现的,而是通过您在相机上设置的投影平截头体的大小来实现的。 OSG相机操纵器都没有实现相机的变焦效果。请参阅此论坛主题作为参考:http://forum.openscenegraph.org/viewtopic.php?t=10763&view=next