osgQT
1 osgQT的移植
首先参考官方项目:
https://github.com/openscenegraph/osgQt
这里先给出结果图:
1.1 修改osgviewerqt.cpp如下: 这样你就能自己读模型了
1 |
|
1.2 qt中使用
1 封装一个自己的类:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/*
* this class is mainly for initialize the pWidget
*/
class QOsgWidget {
public:
// essential widget, use this ptr to be the real widget
osgQOpenGLWidget* pWidget = nullptr;
// QOsgWidget(QWidget* parent = nullptr);
QOsgWidget(const std::string& modelPath, QWidget* parent = nullptr);
~QOsgWidget();
// osg base vars
osg::ref_ptr<osg::Group> mRoot = nullptr;
osg::ref_ptr<osg::Camera> camera = nullptr;
osg::ref_ptr<osgViewer::Viewer> mViewer = nullptr;
osg::ref_ptr<osgGA::TrackballManipulator> trackball = nullptr;
osg::ref_ptr<osgGA::KeySwitchMatrixManipulator> keyswitchManipulator = nullptr;
// for experiment:
osg::ref_ptr<osgViewer::StatsHandler> pStat = nullptr;
osg::ref_ptr<osgGA::TrackballManipulator> pTrackball = nullptr;
osg::ref_ptr<osgViewer::Viewer> pmViewer = nullptr;
// osg base funcs
void InitManipulators();
// load model into the mRoot
void InitModel(const std::string& modelPathm, osg::ref_ptr<osg::Group>& mRoot);
// init the cmaera
void InitCameraConfig();
osg::ref_ptr<osgViewer::Viewer> getViewer() { return mViewer; }
// QObject::connect(&widget, &osgQOpenGLWidget::initialized);
};2 调用这个类:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15QOsgWidget *bBoxEdit = new QOsgWidget(modelPath, static_cast<QWidget*>(this));
// use an ArgumentParser object to manage the program arguments.
bBoxEdit->pWidget = new osgQOpenGLWidget(&arguments, this);
bBoxEdit->pWidget->show();
// init the manipulators
bBoxEdit->InitManipulators();
// init Scene Graph, that is to load the model
bBoxEdit->InitModel(modelPath, bBoxEdit->mRoot);
// init camera config
bBoxEdit->InitCameraConfig();
// 在这一行,将这个worksapceWidget添加到你想要添加的位置上就ok
workspaceWidget = static_cast<QOpenGLWidget*>(&(*(bBoxEdit->pWidget)));