| 1 | // Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
| 3 | |
| 4 | #include <QGuiApplication> |
| 5 | |
| 6 | #include <Qt3DInput/QInputAspect> |
| 7 | |
| 8 | #include <Qt3DRender/qcamera.h> |
| 9 | #include <Qt3DRender/qcameralens.h> |
| 10 | #include <Qt3DExtras/qcylindermesh.h> |
| 11 | #include <Qt3DRender/qmesh.h> |
| 12 | #include <Qt3DRender/qtechnique.h> |
| 13 | #include <Qt3DExtras/qphongmaterial.h> |
| 14 | #include <Qt3DRender/qeffect.h> |
| 15 | #include <Qt3DRender/qtexture.h> |
| 16 | #include <Qt3DRender/qrenderpass.h> |
| 17 | #include <Qt3DRender/qrenderaspect.h> |
| 18 | #include <Qt3DExtras/qforwardrenderer.h> |
| 19 | |
| 20 | #include <Qt3DCore/qentity.h> |
| 21 | #include <Qt3DCore/qtransform.h> |
| 22 | #include <Qt3DCore/qaspectengine.h> |
| 23 | |
| 24 | #include <Qt3DExtras/qt3dwindow.h> |
| 25 | #include <Qt3DExtras/qorbitcameracontroller.h> |
| 26 | |
| 27 | #include <QtGui/qquaternion.h> |
| 28 | |
| 29 | int main(int argc, char **argv) |
| 30 | { |
| 31 | QGuiApplication app(argc, argv); |
| 32 | Qt3DExtras::Qt3DWindow view; |
| 33 | |
| 34 | // Root entity |
| 35 | Qt3DCore::QEntity *rootEntity = new Qt3DCore::QEntity(); |
| 36 | |
| 37 | // Camera |
| 38 | Qt3DRender::QCamera *camera = view.camera(); |
| 39 | camera->lens()->setPerspectiveProjection(45.0f, 16.0f/9.0f, 0.1f, 1000.0f); |
| 40 | camera->setPosition(QVector3D(0, 0, 20.0f)); |
| 41 | camera->setUpVector(QVector3D(0, 1, 0)); |
| 42 | camera->setViewCenter(QVector3D(0, 0, 0)); |
| 43 | |
| 44 | // For camera controls |
| 45 | Qt3DExtras::QOrbitCameraController *cameraController = new Qt3DExtras::QOrbitCameraController(rootEntity); |
| 46 | cameraController->setCamera(camera); |
| 47 | |
| 48 | // Cylinder shape data |
| 49 | Qt3DExtras::QCylinderMesh *mesh = new Qt3DExtras::QCylinderMesh(); |
| 50 | mesh->setRadius(1); |
| 51 | mesh->setLength(3); |
| 52 | mesh->setRings(100); |
| 53 | mesh->setSlices(20); |
| 54 | |
| 55 | // Transform for cylinder |
| 56 | Qt3DCore::QTransform *transform = new Qt3DCore::QTransform; |
| 57 | transform->setScale(1.5f); |
| 58 | transform->setRotation(QQuaternion::fromAxisAndAngle(QVector3D(1, 0, 0), 45.0f)); |
| 59 | |
| 60 | // Material |
| 61 | Qt3DExtras::QPhongMaterial *material = new Qt3DExtras::QPhongMaterial(rootEntity); |
| 62 | material->setDiffuse(Qt::red); |
| 63 | |
| 64 | // Cylinder |
| 65 | Qt3DCore::QEntity *cylinder = new Qt3DCore::QEntity(rootEntity); |
| 66 | cylinder->addComponent(mesh); |
| 67 | cylinder->addComponent(transform); |
| 68 | cylinder->addComponent(material); |
| 69 | |
| 70 | // Set root object of the scene |
| 71 | view.setRootEntity(rootEntity); |
| 72 | view.show(); |
| 73 | |
| 74 | return app.exec(); |
| 75 | } |