我想设置一个类似https://doc.qt.io/archives/qt-5.10/qt3d-multiviewport-example.html的多视口项目 无需使用QML。
目前,我有一个使用的视图:
Qt3DExtras::Qt3DWindow* createView ( Qt3DCore::QEntity* rootEntity ) {
Qt3DExtras::Qt3DWindow* view = new Qt3DExtras::Qt3DWindow();
Qt3DRender::QCamera* camera = view->camera();
camera->lens()->setPerspectiveProjection ( 45.0f, 16.0f / 9.0f, 0.1f, 1000.0f );
camera->setPosition ( QVector3D ( 0, 0, 10.0f ) );
camera->setViewCenter ( QVector3D ( 0, 0, 0 ) );
Qt3DExtras::QOrbitCameraController* manipulator = new Qt3DExtras::QOrbitCameraController ( rootEntity );
manipulator->setLinearSpeed ( 5.0f );
manipulator->setLookSpeed ( 180.f );
manipulator->setZoomInLimit ( 5.0f );
manipulator->setCamera ( camera );
return view;
}
实质上,问题是如何将示例中提供的QML代码转换为C ++。
答案 0 :(得分:0)
您必须使用QViewport
类和setNormalizedRect
函数来指定[0.0,0.0,1.0,1.0]。
如下所示。
//DECLARE A FRAME GRAPH
Qt3DRender::QFrameGraph *frameGraph = new Qt3DRender::QFrameGraph();
Qt3DRender::QTechniqueFilter *techniqueFilter = new Qt3DRender::QTechniqueFilter();
Qt3DRender::QViewport *viewport1 = new Qt3DRender::QViewport(techniqueFilter);
Qt3DRender::QViewport *viewport2 = new Qt3DRender::QViewport(techniqueFilter);
Qt3DRender::QViewport *viewport3 = new Qt3DRender::QViewport(techniqueFilter);
Qt3DRender::QViewport *viewport4 = new Qt3DRender::QViewport(techniqueFilter);
viewport1->setNormalizedRect(QRectF(0, 0, 0.5, 0.5));
viewport2->setNormalizedRect(QRectF(0.5, 0, 0.5, 0.5));
viewport3->setNormalizedRect(QRectF(0, 0.5, 0.5, 0.5));
viewport4->setNormalizedRect(QRectF(0.5, 0.5, 0.5, 0.5));
//SET ACTIVE FRAME GRAPH NODE TO YOUR WINDOW
your_qt3d_wndObject->setActiveFrameGraph(frameGraph->activeFrameGraph());
https://doc-snapshots.qt.io/qt5-5.9/qt3drender-qviewport.html