osgengine.cpp:970:28: error: no member named 'getDimensions' in 'osg::Viewport'
时间: 2023-07-28 21:10:30 浏览: 41
非常抱歉,我之前的回答还是有误。在OpenSceneGraph 3.6.5版本中,`osg::Viewport`没有`getDimensions()`函数。
正确的方法是使用`osg::Viewport`的`width()`和`height()`函数来获取视口的宽度和高度。以下是一个示例代码:
```
osg::ref_ptr<osgViewer::Viewer> viewer = new osgViewer::Viewer;
osg::ref_ptr<osg::Camera> camera = viewer->getCamera();
// 获取相机的视口高度和宽度
int width = camera->getViewport()->width();
int height = camera->getViewport()->height();
// 计算相机的视角高度
float aspectRatio = static_cast<float>(width) / static_cast<float>(height);
float vFov = camera->getFov().y();
float hFov = 2.0f * atan(tan(vFov / 2.0f) * aspectRatio);
float height = tan(vFov / 2.0f) * camera->getNearPlane();
// 输出相机的视角高度
std::cout << "Camera viewport height: " << height * 2.0f << std::endl;
```
这将输出当前相机的视角高度,我们通过获取相机的视口宽度和高度,以及相机的垂直视角来计算视角高度。