3

I'd like to set up a multiple view port scene akin to https://doc.qt.io/archives/qt-5.10/qt3d-multiviewport-example.html without having to use QML.

At the moment I've got a single view working with:

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;
}

In essence, the question is how do I convert the QML code supplied in the example to C++.

Xxomen
  • 33
  • 4

1 Answers1

0

You have to use QViewport class and setNormalizedRect function to specify with in [0.0, 0.0, 1.0, 1.0].

Something like below.

//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

Pavan Chandaka
  • 11,671
  • 5
  • 26
  • 34
  • Thanks. How would I go about attaching the viewports to the main Qt3Dwindow? Based on the QML sample, the view ports have a QCameraSelector child node and have a singular viewport as a parent node. How do I attach the CameraSelector child node to the viewport, the four viewports to the main viewport, and finally the main viewport to the Qt3DWindow? – Xxomen Jun 06 '18 at 21:56
  • You can pass the parent object in the constructor. QViewport::QViewport(Qt3DCore::QNode *parent = nullptr) – Pavan Chandaka Jun 06 '18 at 22:03
  • You can use QFrameGraph. I will update the answer. Look into link http://doc.qt.io/qt-5.6/qt3d-cpp-example-main-cpp.html – Pavan Chandaka Jun 06 '18 at 22:18
  • It looks like the example may be a bit outdated. In newer iterations of QT3D C++ samples, they forego the use of Qt3DCore::QAspectEngine and Qt3DRender::QFrameGraph seems to either be renamed/removed. I'm able to set up a main view port and attach it to a technique filter, but since there's no framegraph class, I'm not able to attach the technique filter to the framegraph nor am I able to change the current frame graph of my Qt3DExtras::Qt3DWindow. Here's one of the latest samples provided using Qt3D - https://doc.qt.io/qt-5/qt3d-simple-cpp-main-cpp.html – Xxomen Jun 06 '18 at 23:51