summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2014-10-02 21:06:57 +0200
committerSean Harmer <sean.harmer@kdab.com>2014-10-02 21:18:35 +0200
commitdccc95f7f4ac186dc64f06b10c7e636e4c16db4d (patch)
treeb8eb9590e0dfcbad20ce9b4e5b9a3776778e7bf7 /examples
parent257ab4b0e37bd001a20808fad30db81f6171e565 (diff)
Add simple-cpp example
Change-Id: Ifb3725ddd43e6feae6814feba18b84bcecb2f42e Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Diffstat (limited to 'examples')
-rw-r--r--examples/examples.pro1
-rw-r--r--examples/simple-cpp/main.cpp187
-rw-r--r--examples/simple-cpp/simple-cpp.pro5
3 files changed, 193 insertions, 0 deletions
diff --git a/examples/examples.pro b/examples/examples.pro
index 4d30d7344..3db38fc01 100644
--- a/examples/examples.pro
+++ b/examples/examples.pro
@@ -4,6 +4,7 @@ SUBDIRS += \
exampleresources \
playground-qml \
simple-qml \
+ simple-cpp \
gltf \
assimp \
cpp_example \
diff --git a/examples/simple-cpp/main.cpp b/examples/simple-cpp/main.cpp
new file mode 100644
index 000000000..bc75cfed5
--- /dev/null
+++ b/examples/simple-cpp/main.cpp
@@ -0,0 +1,187 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QGuiApplication>
+
+#include <Qt3DCore/QEntity>
+#include <Qt3DCore/Window>
+#include <Qt3DCore/QCamera>
+#include <Qt3DCore/QCameraLens>
+#include <Qt3DCore/QTransform>
+#include <Qt3DCore/QLookAtTransform>
+#include <Qt3DCore/QScaleTransform>
+#include <Qt3DCore/QRotateTransform>
+#include <Qt3DCore/QTranslateTransform>
+
+#include <Qt3DRenderer/RendererAspect>
+#include <Qt3DRenderer/QFrameGraph>
+#include <Qt3DRenderer/QViewport>
+#include <Qt3DRenderer/QCameraSelector>
+#include <Qt3DRenderer/QClearBuffer>
+#include <Qt3DRenderer/QMaterial>
+#include <Qt3DRenderer/QEffect>
+
+#include <Qt3DRenderer/QCylinderMesh>
+#include <Qt3DRenderer/QSphereMesh>
+#include <Qt3DRenderer/QTorusMesh>
+
+#include <QPropertyAnimation>
+
+int main(int argc, char* argv[])
+{
+ QGuiApplication app(argc, argv);
+
+ Qt3D::Window view;
+ view.registerAspect(new Qt3D::RendererAspect());
+
+
+ // Root entity
+ Qt3D::QEntity *rootEntity = new Qt3D::QEntity();
+
+
+ // Camera
+ Qt3D::QCamera *cameraEntity = new Qt3D::QCamera();
+ Qt3D::QCameraLens *cameraLens = new Qt3D::QCameraLens();
+ Qt3D::QTransform *cameraTransform = new Qt3D::QTransform();
+ Qt3D::QLookAtTransform *cameraLookAtTransform = new Qt3D::QLookAtTransform();
+
+ cameraLens->setPerspectiveProjection(45.0f, 16.0f/9.0f, 0.1f, 1000.0f);
+ cameraLookAtTransform->setPosition(QVector3D(0, 0, -40.0f));
+ cameraLookAtTransform->setUpVector(QVector3D(0, 1, 0));
+ cameraLookAtTransform->setViewCenter(QVector3D(0, 0, 0));
+ cameraTransform->appendTransform(cameraLookAtTransform);
+ cameraEntity->setTransform(cameraTransform);
+ cameraEntity->setLens(cameraLens);
+ view.setCamera(cameraEntity);
+
+
+ // FrameGraph
+ Qt3D::QFrameGraph *frameGraph = new Qt3D::QFrameGraph();
+ Qt3D::QViewport *viewport = new Qt3D::QViewport();
+ Qt3D::QCameraSelector *cameraSelector = new Qt3D::QCameraSelector();
+ Qt3D::QClearBuffer *clearBuffer = new Qt3D::QClearBuffer();
+
+ viewport->setRect(QRectF(0, 0, 1, 1));
+ viewport->setClearColor(QColor::fromRgbF(0.0, 0.5, 1.0, 1.0));
+ viewport->addChild(cameraSelector);
+ cameraSelector->setCamera(cameraEntity);
+ cameraSelector->addChild(clearBuffer);
+ clearBuffer->setBuffers(Qt3D::QClearBuffer::ColorDepthBuffer);
+
+ frameGraph->setActiveFrameGraph(viewport);
+
+
+ // Material
+ Qt3D::QMaterial *materialEntity = new Qt3D::QMaterial;
+ Qt3D::QEffect *effect = new Qt3D::QEffect;
+ materialEntity->setEffect(effect);
+
+
+ // Torus
+ Qt3D::QEntity *torusEntity = new Qt3D::QEntity;
+ Qt3D::QTorusMesh *torusMesh = new Qt3D::QTorusMesh;
+ torusMesh->setRadius(5);
+ torusMesh->setMinorRadius(1);
+ torusMesh->setRings(100);
+ torusMesh->setSlices(20);
+
+ Qt3D::QTransform *torusTransform = new Qt3D::QTransform;
+ Qt3D::QScaleTransform *torusScaleTransform = new Qt3D::QScaleTransform;
+ torusScaleTransform->setScale3D(QVector3D(1.5, 1, 0.5));
+
+ Qt3D::QRotateTransform *torusRotateTransform = new Qt3D::QRotateTransform;
+ torusRotateTransform->setAxis(QVector3D(1, 0, 0));
+ torusRotateTransform->setAngleDeg(45);
+
+ torusTransform->appendTransform(torusScaleTransform);
+ torusTransform->appendTransform(torusRotateTransform);
+
+
+ torusEntity->addComponent(torusMesh);
+ torusEntity->addComponent(torusTransform);
+ torusEntity->addComponent(materialEntity);
+
+
+ // Sphere
+ Qt3D::QEntity *sphereEntity = new Qt3D::QEntity;
+ Qt3D::QSphereMesh *sphereMesh = new Qt3D::QSphereMesh;
+ sphereMesh->setRadius(3);
+
+ Qt3D::QTransform *sphereTransform = new Qt3D::QTransform;
+ Qt3D::QTranslateTransform *sphereTranslateTransform = new Qt3D::QTranslateTransform;
+ sphereTranslateTransform->setTranslation(QVector3D(20, 0, 0));
+
+ Qt3D::QRotateTransform *sphereRotateTransform = new Qt3D::QRotateTransform;
+ sphereRotateTransform->setAxis(QVector3D(0, 1, 0));
+ sphereRotateTransform->setAngleDeg(0);
+
+ QPropertyAnimation *sphereRotateTransformAnimation = new QPropertyAnimation(sphereRotateTransform);
+ sphereRotateTransformAnimation->setTargetObject(sphereRotateTransform);
+ sphereRotateTransformAnimation->setPropertyName("angle");
+ sphereRotateTransformAnimation->setStartValue(QVariant::fromValue(0));
+ sphereRotateTransformAnimation->setEndValue(QVariant::fromValue(360));
+ sphereRotateTransformAnimation->setDuration(10000);
+ sphereRotateTransformAnimation->setLoopCount(-1);
+ sphereRotateTransformAnimation->start();
+
+ sphereTransform->appendTransform(sphereTranslateTransform);
+ sphereTransform->appendTransform(sphereRotateTransform);
+
+ sphereEntity->addComponent(sphereMesh);
+ sphereEntity->addComponent(sphereTransform);
+ sphereEntity->addComponent(materialEntity);
+
+
+ // Put everything into the scene
+ rootEntity->addChild(cameraEntity);
+ rootEntity->addChild(frameGraph);
+ rootEntity->addChild(materialEntity);
+ rootEntity->addChild(cameraEntity);
+ rootEntity->addChild(torusEntity);
+ rootEntity->addChild(sphereEntity);
+
+ rootEntity->addComponent(frameGraph);
+
+ view.setRootObject(rootEntity);
+ view.show();
+
+ return app.exec();
+}
diff --git a/examples/simple-cpp/simple-cpp.pro b/examples/simple-cpp/simple-cpp.pro
new file mode 100644
index 000000000..9bf36fff7
--- /dev/null
+++ b/examples/simple-cpp/simple-cpp.pro
@@ -0,0 +1,5 @@
+TEMPLATE = app
+QT += 3dcore 3drenderer
+
+SOURCES += \
+ main.cpp