OSG绘制视锥体,这一篇增加设置相机参数接口,支持通过eye、center、up设置相机参数。
代码如下:
#include "stdafx.h"
#include <osgViewer/Viewer>
#include <osg/ShapeDrawable>
#include <osg/Geode>
#include <osg/MatrixTransform>
#include <osg/Camera>
#include <osgUtil/PolytopeIntersector>
#include <osgUtil/LineSegmentIntersector>
// 在创建相机视锥体时计算视锥体顶点和设置边线
osg::ref_ptr<osg::Geode> createCameraFrustum(osg::Camera* camera) {
osg::ref_ptr<osg::Geode> geode = new osg::Geode();
osg::ref_ptr<osg::Geometry> geometry = new osg::Geometry();
// 获取相机的投影矩阵和视图矩阵
osg::Matrixd projectionMatrix = camera->getP