osg学习(七十)如何根据视口对象自动调整视点位置距离
Posted hankern
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了osg学习(七十)如何根据视口对象自动调整视点位置距离相关的知识,希望对你有一定的参考价值。
osgGA/CameraManipulator.cpp
void CameraManipulator::computeHomePosition(const osg::Camera *camera, bool useBoundingBox)
double dist = 3.5f * boundingSphere.radius();
if (camera)
// try to compute dist from frustum
double left,right,bottom,top,zNear,zFar;
if (camera->getProjectionMatrixAsFrustum(left,right,bottom,top,zNear,zFar))
double vertical2 = fabs(right - left) / zNear / 2.;
double horizontal2 = fabs(top - bottom) / zNear / 2.;
double dim = horizontal2 < vertical2 ? horizontal2 : vertical2;
double viewAngle = atan2(dim,1.);
dist = boundingSphere.radius() / sin(viewAngle);
// set home position
setHomePosition(boundingSphere.center() + osg::Vec3d(0.0,-dist,0.0f),
boundingSphere.center(),
osg::Vec3d(0.0f,0.0f,1.0f),
_autoComputeHomePosition);
以上是关于osg学习(七十)如何根据视口对象自动调整视点位置距离的主要内容,如果未能解决你的问题,请参考以下文章
osg学习(七十三)缩放条件下计算gl_NormalMatrix