上一篇处理了QGraphicsView的鼠标、按键事件,本篇接着嵌入OSGEarth。
新建一继承自EventAdapter(一)的类GraphicsView,完成OSGEarth的嵌入工作。实现思路是QGraphicsView的Viewport用OpenGL来绘制,这样才可以完全OSG的update。而要完成每帧的更新,则需要一个定时器,每隔10ms更新一次,即每10ms调用一次OSG的frame操作。
实现代码:graphicsview.h
class GraphicsView : public EventAdapter
{
Q_OBJECT
public:
GraphicsView(QWidget* parent = 0);
~GraphicsView();
osgViewer::Viewer* getOSGViewer(){ return m_pViewer; }
osg::Group* getRoot(){ return m_pSceneData; }
osgEarth::MapNode* getMapNode(){ return m_pMapNode; }
const osgEarth::SpatialReference* getSRS(){ return m_pMapSRS; }
osgEarth::Util::EarthManipulator* getManipulator(){ return m_pEarthManipulator; }
protected:
// 完成OSG每一帧的update操作
virtual void drawBackground(QPainter *painter, const QRectF& rect);
virtual