diff options
author | Sean Harmer <sean.harmer@kdab.com> | 2015-10-26 15:34:58 +0000 |
---|---|---|
committer | Paul Lemire <paul.lemire@kdab.com> | 2015-11-20 16:34:07 +0000 |
commit | 3d1727dc60e9c9a72160e785243a7be7a68fc60e (patch) | |
tree | d0fa4f8b42012592609cd34dc45df17c0c04af2a /examples/qt3d/transforms-qml | |
parent | a08ece5caee4ba7a793173e18b04e3c88263c5ec (diff) |
Add a simple example showing how to use the new transform
Will be used to prove out the API. Perhaps we can extend this into a
more complete example to show how the scene hierarchy leads to
propagation of transformations.
Change-Id: I06ed5fdd8f38043d1b4a296e9fa8a07c54a736af
Reviewed-by: Paul Lemire <paul.lemire@kdab.com>
Diffstat (limited to 'examples/qt3d/transforms-qml')
-rw-r--r-- | examples/qt3d/transforms-qml/RenderableEntity.qml | 58 | ||||
-rw-r--r-- | examples/qt3d/transforms-qml/TemporaryCamera.qml | 70 | ||||
-rw-r--r-- | examples/qt3d/transforms-qml/TrefoilKnot.qml | 73 | ||||
-rw-r--r-- | examples/qt3d/transforms-qml/main.cpp | 66 | ||||
-rw-r--r-- | examples/qt3d/transforms-qml/main.qml | 100 | ||||
-rw-r--r-- | examples/qt3d/transforms-qml/transforms-qml.pro | 18 | ||||
-rw-r--r-- | examples/qt3d/transforms-qml/transforms-qml.qrc | 8 |
7 files changed, 393 insertions, 0 deletions
diff --git a/examples/qt3d/transforms-qml/RenderableEntity.qml b/examples/qt3d/transforms-qml/RenderableEntity.qml new file mode 100644 index 000000000..7a11f69b2 --- /dev/null +++ b/examples/qt3d/transforms-qml/RenderableEntity.qml @@ -0,0 +1,58 @@ +/**************************************************************************** +** +** Copyright (C) 2015 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:LGPL3$ +** 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 The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/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 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later 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 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import Qt3D.Core 2.0 +import Qt3D.Render 2.0 + +Entity { + id: root + + property Material material: null + property alias meshSource: mesh.source + property alias translation: transform.translation + property alias rotation: transform.rotation + property alias scale: transform.scale + + components: [ transform, mesh, material ] + + Transform { + id: transform + } + + Mesh { + id: mesh + } +} diff --git a/examples/qt3d/transforms-qml/TemporaryCamera.qml b/examples/qt3d/transforms-qml/TemporaryCamera.qml new file mode 100644 index 000000000..6c2862ee7 --- /dev/null +++ b/examples/qt3d/transforms-qml/TemporaryCamera.qml @@ -0,0 +1,70 @@ +/**************************************************************************** +** +** Copyright (C) 2015 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:LGPL3$ +** 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 The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/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 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later 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 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import Qt3D.Core 2.0 +import Qt3D.Render 2.0 + +Entity { + id: root + + property vector3d pos: Qt.vector3d(0.0, 0.0, 0.0) + property vector3d viewCenter: Qt.vector3d(0.0, 0.0, -10.0) + property vector3d up: Qt.vector3d(0.0, 1.0, 0.0) + + components: [ transform, lens ] + + Transform { + id: transform + + matrix: { + var m = Qt.matrix4x4(1,0,0,0, + 0,1,0,0, + 0,0,1,0, + 0,0,0,1); + m.lookAt( root.pos, root.viewCenter, root.up ); + return m; + } + } + + CameraLens { + id: lens + projectionType: CameraLens.PerspectiveProjection + fieldOfView: 45 + aspectRatio: _view.width / _view.height + nearPlane: 0.1 + farPlane: 1000.0 + } +} diff --git a/examples/qt3d/transforms-qml/TrefoilKnot.qml b/examples/qt3d/transforms-qml/TrefoilKnot.qml new file mode 100644 index 000000000..7152c6af8 --- /dev/null +++ b/examples/qt3d/transforms-qml/TrefoilKnot.qml @@ -0,0 +1,73 @@ +/**************************************************************************** +** +** Copyright (C) 2015 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:LGPL3$ +** 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 The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/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 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later 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 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import Qt3D.Core 2.0 +import Qt3D.Render 2.0 + +Entity { + id: root + + property vector3d translation: Qt.vector3d(0.0, 0.0, 0.0) + property real scale: 1.0 + property real theta: 0.0 + property real phi: 0.0 + property Material material + + components: [ transform, mesh, root.material ] + + Transform { + id: transform + + matrix: { + // TODO: Adapt QtObject::method_matrix4x4() in qqmlbuiltinfunctions.cpp to + // work with 0 arguments such that it creates an identity matrix + var m = Qt.matrix4x4(1,0,0,0, + 0,1,0,0, + 0,0,1,0, + 0,0,0,1); + m.translate( root.translation ); + m.rotate( root.theta, Qt.vector3d( 1.0, 0.0, 0.0 ) ); + m.rotate( root.phi, Qt.vector3d( 0.0, 1.0, 0.0 ) ); + m.scale( root.scale ); + return m; + } + } + + Mesh { + id: mesh + source: "assets/obj/trefoil.obj" + } +} diff --git a/examples/qt3d/transforms-qml/main.cpp b/examples/qt3d/transforms-qml/main.cpp new file mode 100644 index 000000000..b08758b49 --- /dev/null +++ b/examples/qt3d/transforms-qml/main.cpp @@ -0,0 +1,66 @@ +/**************************************************************************** +** +** 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:LGPL3$ +** 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 The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/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 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later 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 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <window.h> +#include <Qt3DRender/QRenderAspect> +#include <Qt3DInput/QInputAspect> +#include <Qt3DQuick/QQmlAspectEngine> + +#include <QtQml> + +#include <QGuiApplication> + +int main(int argc, char* argv[]) +{ + QGuiApplication app(argc, argv); + + Window view; + Qt3DCore::Quick::QQmlAspectEngine engine; + + engine.aspectEngine()->registerAspect(new Qt3DRender::QRenderAspect()); + engine.aspectEngine()->registerAspect(new Qt3DInput::QInputAspect()); + engine.aspectEngine()->initialize(); + QVariantMap data; + data.insert(QStringLiteral("surface"), QVariant::fromValue(static_cast<QSurface *>(&view))); + data.insert(QStringLiteral("eventSource"), QVariant::fromValue(&view)); + engine.aspectEngine()->setData(data); + engine.qmlEngine()->rootContext()->setContextProperty("_view", &view); + engine.setSource(QUrl("qrc:/main.qml")); + + view.show(); + + return app.exec(); +} diff --git a/examples/qt3d/transforms-qml/main.qml b/examples/qt3d/transforms-qml/main.qml new file mode 100644 index 000000000..acb264351 --- /dev/null +++ b/examples/qt3d/transforms-qml/main.qml @@ -0,0 +1,100 @@ +/**************************************************************************** +** +** 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:LGPL3$ +** 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 The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/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 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later 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 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import Qt3D.Core 2.0 +import Qt3D.Render 2.0 + +Entity { + id: sceneRoot + + components: [ + FrameGraph { + activeFrameGraph: ForwardRenderer { + clearColor: Qt.rgba(0, 0.5, 1, 1) + camera: camera + } + } + ] + + TemporaryCamera { + id: camera + pos: Qt.vector3d( 0.0, 0.0, 120.0 ) + viewCenter: Qt.vector3d( 0.0, 0.0, 0.0 ) + up: Qt.vector3d( 0.0, 1.0, 0.0 ) + } + + RenderableEntity { + id: rootEntity + + meshSource: "assets/obj/toyplane.obj" + material: PhongMaterial { + diffuse: "red" + } + + RenderableEntity { + id: trefoil + + translation: Qt.vector3d( 0.0, 20.0, 0.0 ) + scale: Qt.vector3d(4, 4, 4) + + meshSource: "assets/obj/trefoil.obj" + material: PhongMaterial { + diffuse: "green" + } + + RenderableEntity { + id: ball + + translation: Qt.vector3d( 0.0, 5.0, 0.0 ) + scale: Qt.vector3d(0.2, 0.2, 0.2) + + meshSource: "assets/obj/ball.obj" + material: PhongMaterial { + diffuse: "purple" + } + } + } + } + + TrefoilKnot { + translation: Qt.vector3d( 20, 0, 0 ) + scale: 6.0 + phi: 60.0 + material: PhongMaterial { + diffuse: "grey" + } + } +} diff --git a/examples/qt3d/transforms-qml/transforms-qml.pro b/examples/qt3d/transforms-qml/transforms-qml.pro new file mode 100644 index 000000000..18dd6fa43 --- /dev/null +++ b/examples/qt3d/transforms-qml/transforms-qml.pro @@ -0,0 +1,18 @@ +!include( ../examples.pri ) { + error( "Couldn't find the examples.pri file!" ) +} + +QT += 3dcore 3drender 3dinput 3dquick qml quick + +SOURCES += \ + main.cpp + +OTHER_FILES += \ + main.qml \ + RenderableEntity.qml \ + TemporaryCamera.qml \ + TrefoilKnot.qml + +RESOURCES += \ + transforms-qml.qrc \ + ../exampleresources/obj.qrc diff --git a/examples/qt3d/transforms-qml/transforms-qml.qrc b/examples/qt3d/transforms-qml/transforms-qml.qrc new file mode 100644 index 000000000..9035959d9 --- /dev/null +++ b/examples/qt3d/transforms-qml/transforms-qml.qrc @@ -0,0 +1,8 @@ +<RCC> + <qresource prefix="/"> + <file>main.qml</file> + <file>RenderableEntity.qml</file> + <file>TemporaryCamera.qml</file> + <file>TrefoilKnot.qml</file> + </qresource> +</RCC> |