| 1 | // Copyright (C) 2019 Klaralvdalens Datakonsult AB (KDAB). |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
| 3 | |
| 4 | #include "scene.h" |
| 5 | |
| 6 | #include <QGuiApplication> |
| 7 | |
| 8 | #include <Qt3DCore/qentity.h> |
| 9 | #include <QtGui/QScreen> |
| 10 | |
| 11 | #include <QtWidgets/QApplication> |
| 12 | #include <QtWidgets/QWidget> |
| 13 | #include <QtWidgets/QHBoxLayout> |
| 14 | #include <QtWidgets/QSlider> |
| 15 | #include <QtWidgets/QLabel> |
| 16 | #include <QtWidgets/QPushButton> |
| 17 | |
| 18 | #include <Qt3DRender/qcamera.h> |
| 19 | #include <Qt3DInput/QInputAspect> |
| 20 | #include <Qt3DExtras/qforwardrenderer.h> |
| 21 | #include <Qt3DExtras/qt3dwindow.h> |
| 22 | #include <Qt3DExtras/qfirstpersoncameracontroller.h> |
| 23 | |
| 24 | int main(int argc, char **argv) |
| 25 | { |
| 26 | QApplication app(argc, argv); |
| 27 | |
| 28 | Qt3DExtras::Qt3DWindow *view = new Qt3DExtras::Qt3DWindow(); |
| 29 | view->defaultFrameGraph()->setClearColor(QColor(QRgb(0x4d4d4f))); |
| 30 | QWidget *container = QWidget::createWindowContainer(view); |
| 31 | QSize screenSize = view->screen()->size(); |
| 32 | container->setMinimumSize(QSize(200, 100)); |
| 33 | container->setMaximumSize(screenSize); |
| 34 | |
| 35 | Qt3DInput::QInputAspect *input = new Qt3DInput::QInputAspect; |
| 36 | view->registerAspect(input); |
| 37 | |
| 38 | // Root entity |
| 39 | Qt3DCore::QEntity *rootEntity = new Qt3DCore::QEntity(); |
| 40 | |
| 41 | // Camera |
| 42 | Qt3DRender::QCamera *cameraEntity = view->camera(); |
| 43 | |
| 44 | cameraEntity->setPosition(QVector3D(0, 0, 20.0f)); |
| 45 | cameraEntity->setUpVector(QVector3D(0, 1, 0)); |
| 46 | cameraEntity->setViewCenter(QVector3D(0, 0, 0)); |
| 47 | |
| 48 | // For camera controls |
| 49 | Qt3DExtras::QFirstPersonCameraController *camController = new Qt3DExtras::QFirstPersonCameraController(rootEntity); |
| 50 | camController->setCamera(cameraEntity); |
| 51 | |
| 52 | // scene |
| 53 | Scene *scene = new Scene(rootEntity); |
| 54 | scene->run(); |
| 55 | |
| 56 | // Set root object of the scene |
| 57 | view->setRootEntity(rootEntity); |
| 58 | |
| 59 | // create widget |
| 60 | QWidget *widget = new QWidget; |
| 61 | widget->setWindowTitle(QStringLiteral("QPaintedTexture Example")); |
| 62 | |
| 63 | QVBoxLayout *hLayout = new QVBoxLayout(widget); |
| 64 | hLayout->addWidget(container, 1); |
| 65 | |
| 66 | // Show window |
| 67 | widget->show(); |
| 68 | widget->resize(1200, 800); |
| 69 | |
| 70 | return app.exec(); |
| 71 | } |