多视口问题Qt C ++

时间:2019-05-14 14:02:07

标签: c++ qt

我正在尝试使用以下代码实现多视口场景。对于我来说,对于这种功能的实现还不熟悉,因此对于功能场景而言,可能不需要某些代码行。我混合了多种建议,不确定这是否是整理3D场景所需的正确方法。

当我运行我的项目时,它仅显示一个黑屏,并且不确定它是否已经是一个多视口场景还是单个视图。我当时在想,可能无法将其中一个视口链接到主视图。目前,我正在使用单个视图,它可以毫无问题地显示3D场景,但是我现在想做的是仅通过4个视频端口之一显示相同的视图作为测试,并最终定义多个摄像机以支持其余的视口

谢谢!

MyView3D::MyView3D(QWidget *parent)
: QWidget(parent){
this->view = new Qt3DExtras::Qt3DWindow();
this->view->defaultFrameGraph()->setClearColor(QColor(135,206,235));
this->container  = QWidget::createWindowContainer(this->view);
this->screenSize = view->screen()->size();
this->container->setMinimumSize(QSize(200, 100));
this->container->setMaximumSize(screenSize);
this->container->resize(200, 100);
this->view->resize(200,100);

this->hLayout  = new QHBoxLayout(this);
this->hLayout->addWidget(this->container, 1);

this->font = new QFont ("Courier New");
font->setPixelSize ( 11 );
this->logMessage = new QTextEdit;
this->logMessage->setReadOnly ( 1 );
this->logMessage->setLineWrapMode ( QTextEdit::NoWrap );
this->logMessage->setCurrentFont ( * font );
this->logMessage->setLineWrapColumnOrWidth ( 50 );
this->logMessage->setMinimumHeight ( 50 );

this->input = new Qt3DInput::QInputAspect;
this->view->registerAspect(this->input);

// Root entity
this->rootEntity = new Qt3DCore::QEntity();
this->frameGraph = new Qt3DRender::QFrameGraphNode();
this->techniqueFilter = new Qt3DRender::QTechniqueFilter();
Qt3DRender::QRenderSettings *activeFrameGraph = new Qt3DRender::QRenderSettings();
this ->viewport1 = new Qt3DRender::QViewport(techniqueFilter);
this->viewport2 = new Qt3DRender::QViewport(techniqueFilter);
this->viewport3 = new Qt3DRender::QViewport(techniqueFilter);
this->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
this->clearBuffer = new Qt3DRender::QClearBuffers(viewport1);
this->cameraSelector = new Qt3DRender::QCameraSelector(clearBuffer);
(void) new Qt3DRender::QRenderPassFilter(cameraSelector);
clearBuffer->setBuffers(Qt3DRender::QClearBuffers::ColorDepthBuffer);

// Camera
this->cameraEntity = this->view->camera();
this->cameraEntity->lens()->setPerspectiveProjection(45.0f, 16.0f/9.0f, 0.1f, 1000.0f);
this->cameraEntity->setPosition(QVector3D(-7, -3, 1.0f));
this->cameraEntity->setUpVector(QVector3D(0, 0, 1));  // defines z-direction
this->cameraEntity->setViewCenter(QVector3D(10, 0, 0));
Qt3DRender::QRenderSurfaceSelector *surfaceSelector = new Qt3DRender::QRenderSurfaceSelector;
cameraSelector->setCamera(this->cameraEntity);
this->view->setActiveFrameGraph(frameGraph);
m_dummySurface = new QOffscreenSurface;
m_dummySurface->setParent(this);
m_dummySurface->create();
surfaceSelector->setSurface(view);

0 个答案:

没有答案