From 26a118cfbce29014864f6cdddae66cccb65ffb4f Mon Sep 17 00:00:00 2001 From: Sean Harmer Date: Sat, 7 Nov 2015 19:02:14 +0000 Subject: Remove transforms property of QTransform Compound transformations are now built up using QMatrix4x4 in both QML and C++. Updating examples accordingly. Change-Id: I03c9abf1f6cdd1b56226dc0e16a7ad5ce84516dd Reviewed-by: Paul Lemire --- examples/qt3d/anaglyph-rendering/StereoCamera.qml | 17 +- examples/qt3d/anaglyph-rendering/main.qml | 101 +++---- examples/qt3d/assimp/main.cpp | 14 + examples/qt3d/assimp/main.qml | 76 +++-- examples/qt3d/basicshapes-cpp/scenemodifier.cpp | 65 ++--- examples/qt3d/bigmodel-qml/MyEntity.qml | 6 +- examples/qt3d/bigmodel-qml/main.qml | 5 +- examples/qt3d/bigscene-cpp/bigscene-cpp.pro | 6 +- examples/qt3d/bigscene-cpp/entity.cpp | 130 +++++++++ examples/qt3d/bigscene-cpp/entity.h | 97 +++++++ examples/qt3d/bigscene-cpp/main.cpp | 45 +-- examples/qt3d/clip-planes-qml/ClipPlaneEntity.qml | 16 +- examples/qt3d/clip-planes-qml/ClippingPlanes.qml | 2 +- examples/qt3d/clip-planes-qml/main.qml | 5 +- examples/qt3d/controls/Logo.qml | 23 +- examples/qt3d/cpp_example/main.cpp | 20 +- examples/qt3d/custom-mesh-cpp/main.cpp | 4 +- examples/qt3d/custom-mesh-qml/main.qml | 19 +- examples/qt3d/cylinder-cpp/main.cpp | 15 +- examples/qt3d/cylinder-qml/main.qml | 15 +- examples/qt3d/deferred-renderer-cpp/main.cpp | 15 +- examples/qt3d/deferred-renderer-qml/main.qml | 45 +-- examples/qt3d/dynamicscene-cpp/boxentity.cpp | 5 +- examples/qt3d/dynamicscene-cpp/boxentity.h | 4 - examples/qt3d/enabled-qml/main.qml | 43 ++- examples/qt3d/gltf/Wine.qml | 43 ++- examples/qt3d/gltf/main.qml | 8 +- examples/qt3d/gooch-qml/MyEntity.qml | 11 +- examples/qt3d/keyboardinput-qml/SphereEntity.qml | 17 +- examples/qt3d/keyboardinput-qml/main.qml | 5 +- examples/qt3d/loader-qml/CuboidEntity.qml | 19 +- examples/qt3d/loader-qml/SphereEntity.qml | 10 +- examples/qt3d/loader-qml/main.qml | 35 ++- examples/qt3d/materials-cpp/barrel.cpp | 2 +- examples/qt3d/materials-cpp/houseplant.cpp | 35 +-- examples/qt3d/materials-cpp/houseplant.h | 8 +- examples/qt3d/materials-cpp/main.cpp | 28 +- examples/qt3d/materials-cpp/planeentity.cpp | 14 - examples/qt3d/materials-cpp/planeentity.h | 6 - examples/qt3d/materials-cpp/renderableentity.cpp | 22 +- examples/qt3d/materials-cpp/renderableentity.h | 7 +- .../qt3d/materials-cpp/rotatingtrefoilknot.cpp | 8 +- examples/qt3d/materials-cpp/trefoilknot.cpp | 80 ++++-- examples/qt3d/materials-cpp/trefoilknot.h | 37 ++- examples/qt3d/materials/Barrel.qml | 7 +- examples/qt3d/materials/Chest.qml | 7 +- examples/qt3d/materials/HousePlant.qml | 7 +- examples/qt3d/materials/PlaneEntity.qml | 13 +- examples/qt3d/materials/RenderableEntity.qml | 23 +- examples/qt3d/materials/TrefoilKnot.qml | 15 +- examples/qt3d/materials/main.qml | 2 +- examples/qt3d/mouseinput-qml/main.qml | 4 +- .../qt3d/multiviewport/QuadViewportFrameGraph.qml | 80 ++++++ examples/qt3d/multiviewport/SimpleCamera.qml | 61 ++++ examples/qt3d/multiviewport/main.qml | 186 +++++------- examples/qt3d/multiviewport/multiviewport.qrc | 2 + examples/qt3d/picking-qml/main.qml | 26 +- examples/qt3d/planets-qml/SolarSystem.qml | 312 +++++++++------------ examples/qt3d/plasma/main.qml | 18 +- examples/qt3d/playground-qml/DetailView.qml | 29 +- examples/qt3d/playground-qml/MainView.qml | 34 ++- examples/qt3d/playground-qml/MyForwardRenderer.qml | 14 +- examples/qt3d/playground-qml/main.qml | 6 +- examples/qt3d/scene3d-loader/AnimatedEntity.qml | 35 ++- examples/qt3d/scene3d-loader/Scene2.qml | 12 +- examples/qt3d/scene3d/AnimatedEntity.qml | 33 ++- examples/qt3d/shadow-map-qml/AdsMaterial.qml | 2 +- examples/qt3d/shadow-map-qml/GroundPlane.qml | 4 +- examples/qt3d/shadow-map-qml/Light.qml | 2 +- .../qt3d/shadow-map-qml/ShadowMapFrameGraph.qml | 2 +- examples/qt3d/shadow-map-qml/Toyplane.qml | 47 ++-- examples/qt3d/shadow-map-qml/Trefoil.qml | 18 +- examples/qt3d/shadow-map-qml/main.qml | 1 + examples/qt3d/simple-cpp/main.cpp | 100 +++++-- examples/qt3d/simple-qml/main.qml | 34 ++- examples/qt3d/simple-shaders-qml/main.qml | 28 +- examples/qt3d/skybox/Skybox.qml | 3 +- examples/qt3d/tessellation-modes/BasicCamera.qml | 1 - .../qt3d/tessellation-modes/TessellatedQuad.qml | 15 +- .../TessellatedWireframeEffect.qml | 1 - .../TessellatedWireframeMaterial.qml | 2 - examples/qt3d/tessellation-modes/main.qml | 2 +- examples/qt3d/torus-qml/main.qml | 12 +- examples/qt3d/transparency-qml-scene3d/Scene.qml | 4 +- examples/qt3d/transparency-qml-scene3d/main.qml | 3 +- examples/qt3d/transparency-qml/main.qml | 4 +- examples/qt3d/wave/Background.qml | 12 +- examples/qt3d/wave/Wave.qml | 15 +- examples/qt3d/wave/main.qml | 1 + examples/qt3d/wireframe/TrefoilKnot.qml | 27 +- examples/qt3d/wireframe/main.qml | 2 +- 91 files changed, 1380 insertions(+), 1076 deletions(-) create mode 100644 examples/qt3d/bigscene-cpp/entity.cpp create mode 100644 examples/qt3d/bigscene-cpp/entity.h create mode 100644 examples/qt3d/multiviewport/QuadViewportFrameGraph.qml create mode 100644 examples/qt3d/multiviewport/SimpleCamera.qml (limited to 'examples/qt3d') diff --git a/examples/qt3d/anaglyph-rendering/StereoCamera.qml b/examples/qt3d/anaglyph-rendering/StereoCamera.qml index 4e0433883..c6218aee6 100644 --- a/examples/qt3d/anaglyph-rendering/StereoCamera.qml +++ b/examples/qt3d/anaglyph-rendering/StereoCamera.qml @@ -46,8 +46,8 @@ Entity { property real nearPlane: 10.0 property real farPlane: 10000.0 - property alias viewCenter: eyeLookAt.viewCenter - property alias position: eyeLookAt.position + property vector3d viewCenter: Qt.vector3d(0.0, 0.0, 0.0) + property vector3d position: Qt.vector3d(0.0, 0.0, 1.0) readonly property real _fov2: Math.tan(fieldOfView * Math.PI / 180 * 0.5) readonly property real top: nearPlane * _fov2 @@ -77,11 +77,14 @@ Entity { Transform { id: eyeTransform - LookAt { - id: eyeLookAt - upVector: Qt.vector3d(0.0, 1.0, 0.0) - viewCenter: root.viewCenter - position: root.position + + matrix: { + var m = Qt.matrix4x4(1, 0, 0, 0, + 0, 1, 0, 0, + 0, 0, 1, 0, + 0, 0, 0, 1); + m.lookAt(root.position, root.viewCenter, Qt.vector3d(0.0, 1.0, 0.0)); + return m; } } diff --git a/examples/qt3d/anaglyph-rendering/main.qml b/examples/qt3d/anaglyph-rendering/main.qml index 533b1118c..73a6bc59d 100644 --- a/examples/qt3d/anaglyph-rendering/main.qml +++ b/examples/qt3d/anaglyph-rendering/main.qml @@ -34,9 +34,9 @@ ** ****************************************************************************/ +import QtQuick 2.4 as QQ2 import Qt3D.Core 2.0 import Qt3D.Render 2.0 -import QtQuick 2.4 as QQ2 Entity { id: root @@ -56,7 +56,7 @@ Entity { readonly property real cameraRadius: obstaclesRepeater.radius - 50 readonly property vector3d circlePosition: Qt.vector3d(cameraRadius * Math.cos(circleRotation), 0.0, cameraRadius * Math.sin(circleRotation)) readonly property vector3d tan: circlePosition.crossProduct(Qt.vector3d(0, 1, 0).normalized()) - viewCenter: planeTranslation.translation + viewCenter: planeTransform.translation position: circlePosition.plus(Qt.vector3d(0, 45 * Math.sin(circleRotation * 2), 0)).plus(tan.times(-2)) QQ2.NumberAnimation { @@ -85,16 +85,20 @@ Entity { slices: 20 } property Transform transform: Transform { - Scale { id: cylinderScale; scale: 5 } - Rotate { - id: cylinderRotationTheta - angle: 45 - axis: Qt.vector3d(1, 0, 0) - } - Rotate { - id: cylinderRotationPhi - angle: 30 - axis: Qt.vector3d(1, 0, 0) + id: cylinderTransform + property real theta: 0.0 + property real phi: 0.0 + property real userScale: 1.0 + + matrix: { + var m = Qt.matrix4x4(1, 0, 0, 0, + 0, 1, 0, 0, + 0, 0, 1, 0, + 0, 0, 0, 1); + m.rotate(phi, Qt.vector3d(0.0, 1.0, 0.0)); + m.rotate(theta, Qt.vector3d(1.0, 0.0, 0.0)); + m.scale(userScale); + return m; } } property Material phong: PhongMaterial {} @@ -104,29 +108,29 @@ Entity { running: true QQ2.SequentialAnimation { QQ2.NumberAnimation { - target: cylinderScale - property: "scale" + target: cylinderTransform + property: "userScale" from: 5; to: 45 duration: 2000 easing.type: QQ2.Easing.OutInQuad } QQ2.NumberAnimation { - target: cylinderScale - property: "scale" + target: cylinderTransform + property: "userScale" from: 45; to: 5 duration: 2000 easing.type: QQ2.Easing.InOutQuart } } QQ2.NumberAnimation { - target: cylinderRotationPhi - property: "angle" + target: cylinderTransform + property: "phi" from: 0; to: 360 duration: 4000 } QQ2.NumberAnimation { - target: cylinderRotationTheta - property: "angle" + target: cylinderTransform + property: "theta" from: 0; to: 720 duration: 4000 } @@ -142,20 +146,20 @@ Entity { source: "assets/obj/toyplane.obj" }, Transform { - Rotate { // roll - id: roll - axis : Qt.vector3d(1, 0, 0) - angle : 30 - } - Rotate { - axis: Qt.vector3d(0, 1, 0) - angle: stereoCamera.circleRotation * -2 * 180 / Math.PI + 180 - } - Translate { - id: planeTranslation - dx: Math.sin(stereoCamera.circleRotation * -2) * obstaclesRepeater.radius - dy: 0 - dz: Math.cos(stereoCamera.circleRotation * -2) * obstaclesRepeater.radius + id: planeTransform + property real rollAngle: 0.0 + + matrix: { + var m = Qt.matrix4x4(1, 0, 0, 0, + 0, 1, 0, 0, + 0, 0, 1, 0, + 0, 0, 0, 1); + m.translate(Qt.vector3d(Math.sin(stereoCamera.circleRotation * -2) * obstaclesRepeater.radius, + 0.0, + Math.cos(stereoCamera.circleRotation * -2) * obstaclesRepeater.radius)) + m.rotate(stereoCamera.circleRotation * -2 * 180 / Math.PI + 180, Qt.vector3d(0.0, 1.0, 0.0)); + m.rotate(planeTransform.rollAngle, Qt.vector3d(1.0, 0.0, 0.0)); + return m; } }, PhongMaterial { @@ -169,20 +173,20 @@ Entity { loops: QQ2.Animation.Infinite QQ2.NumberAnimation { - target: roll - property: "angle" + target: planeTransform + property: "rollAngle" from: 30; to: 45 duration: 750 } QQ2.NumberAnimation { - target: roll - property: "angle" + target: planeTransform + property: "rollAngle" from: 45; to: 25 duration: 500 } QQ2.NumberAnimation { - target: roll - property: "angle" + target: planeTransform + property: "rollAngle" from: 25; to: 390 duration: 800 } @@ -206,13 +210,16 @@ Entity { Transform { id: transform readonly property real angle: Math.PI * 2.0 * index * obstaclesRepeater.det - Rotate { - angle: transform.angle * 180 / Math.PI - axis: Qt.vector3d(0.0, 1.0, 0.0) - } - Translate { - dx: obstaclesRepeater.radius * Math.cos(transform.angle) - dz: obstaclesRepeater.radius * Math.sin(transform.angle) + matrix: { + var m = Qt.matrix4x4(1, 0, 0, 0, + 0, 1, 0, 0, + 0, 0, 1, 0, + 0, 0, 0, 1); + m.translate(Qt.vector3d(obstaclesRepeater.radius * Math.cos(transform.angle), + 0.0, + obstaclesRepeater.radius * Math.sin(transform.angle))) + m.rotate(transform.angle * 180 / Math.PI, Qt.vector3d(0.0, 1.0, 0.0)); + return m; } }, PhongMaterial { diff --git a/examples/qt3d/assimp/main.cpp b/examples/qt3d/assimp/main.cpp index f0b8b6fbc..a637d47ae 100644 --- a/examples/qt3d/assimp/main.cpp +++ b/examples/qt3d/assimp/main.cpp @@ -50,6 +50,7 @@ class SceneHelper : public QObject public: Q_INVOKABLE QObject *findEntity(Qt3DRender::QSceneLoader *loader, const QString &name); + Q_INVOKABLE QObject *findComponent(Qt3DCore::QEntity *entity, const QString &componentMetatype); Q_INVOKABLE void addListEntry(const QVariant &list, QObject *entry); }; @@ -70,6 +71,19 @@ QObject *SceneHelper::findEntity(Qt3DRender::QSceneLoader *loader, const QString return root->findChild(name); } +QObject *SceneHelper::findComponent(Qt3DCore::QEntity *entity, const QString &componentMetatype) +{ + Q_ASSERT(entity); + Qt3DCore::QComponentList components = entity->components(); + Q_FOREACH (Qt3DCore::QComponent *component, components) { + qDebug() << component->metaObject()->className(); + if (component->metaObject()->className() == componentMetatype) { + return component; + } + } + return Q_NULLPTR; +} + void SceneHelper::addListEntry(const QVariant &list, QObject *entry) { QQmlListReference ref = list.value(); diff --git a/examples/qt3d/assimp/main.qml b/examples/qt3d/assimp/main.qml index 2b5f953ea..5210d2041 100644 --- a/examples/qt3d/assimp/main.qml +++ b/examples/qt3d/assimp/main.qml @@ -34,10 +34,10 @@ ** ****************************************************************************/ +import QtQuick 2.0 as Quick import Qt3D.Core 2.0 import Qt3D.Render 2.0 import Qt3D.Examples 2.0 -import QtQuick 2.0 as Quick Entity { @@ -93,16 +93,13 @@ Entity } } - Quick.Component { - id: rot90Comp - Rotate { axis: Qt.vector3d(1, 0, 0); angle: 90 } - } - Quick.Component { id: animRotComp - Rotate { - axis: Qt.vector3d(0, 0, 1) - Quick.NumberAnimation on angle { + Quick.QtObject { + id: rotationData + property real userAngle: 0.0 + property vector3d axis: Qt.vector3d(0, 0, 1) + Quick.NumberAnimation on userAngle { from: 0 to: 360 duration: 5000 @@ -112,12 +109,11 @@ Entity } Entity { - components : [ + components: [ Transform { Rotate {angle : 90; axis : Qt.vector3d(0, 1, 0)} }, - SceneLoader - { + SceneLoader { id: sceneLoader source: "qrc:/assets/test_scene.dae" onStatusChanged: { @@ -144,30 +140,54 @@ Entity } } - // Add an animated rotation transform. + // Add an animated rotation transform to make Suzanne orbit around. e = sceneHelper.findEntity(sceneLoader, "Suzanne"); - for (var i = 0; i < e.components.length; ++i) { - if (e.components[i].transforms !== undefined) { - var t = e.components[i].transforms; - sceneHelper.addListEntry(t, rot90Comp.createObject()); - sceneHelper.addListEntry(t, animRotComp.createObject()); - break; - } - } + var t = sceneHelper.findComponent(e, "Qt3DCore::QTransform"); + if (!t) + return; + + // Add object with animation data as a child + var suzanneAnim = animRotComp.createObject(t); + + // Query the existing transformation. We will use parts of this in + // the replacement animation + var origTranslation = t.translation; + var origRotation = t.rotation; + var origScale = t.scale; + console.log("origTranslation = " + origTranslation); + console.log("origRotation = " + origRotation); + console.log("origScale = " + origScale); + + // Make a deep copy of the original translation. This will not be updated when the + // transformation's translation property gets updated due to the animation. + var constantTranslation = Qt.vector3d(origTranslation.x, origTranslation.y, origTranslation.z); + + t.matrix = Qt.binding(function() { + var m = Qt.matrix4x4(1, 0, 0, 0, + 0, 1, 0, 0, + 0, 0, 1, 0, + 0, 0, 0, 1); + m.rotate(suzanneAnim.userAngle, suzanneAnim.axis); + m.translate(constantTranslation); + m.rotate(90, Qt.vector3d(1, 0, 0)); + m.scale(origScale); + return m; + }) } } - }] + } + ] } Entity { - components : [ + components: [ Transform { - Scale { scale: 0.2 } - Translate { dy: -15 } + scale: 0.2 + translation: Qt.vector3d(0.0, -15.0, 0.0) }, - SceneLoader - { + SceneLoader { source: "qrc:/assets/chest/Chest.obj" - }] + } + ] } } diff --git a/examples/qt3d/basicshapes-cpp/scenemodifier.cpp b/examples/qt3d/basicshapes-cpp/scenemodifier.cpp index d67e70902..48977fc0b 100644 --- a/examples/qt3d/basicshapes-cpp/scenemodifier.cpp +++ b/examples/qt3d/basicshapes-cpp/scenemodifier.cpp @@ -53,19 +53,10 @@ SceneModifier::SceneModifier(Qt3DCore::QEntity *rootEntity) // TorusMesh Transform //! [1] - Qt3DCore::QScaleTransform *torusScale = new Qt3DCore::QScaleTransform(); - Qt3DCore::QTranslateTransform *torusTranslation = new Qt3DCore::QTranslateTransform(); - Qt3DCore::QRotateTransform *torusRotation = new Qt3DCore::QRotateTransform(); - Qt3DCore::QTransform *torusTransforms = new Qt3DCore::QTransform(); - - torusScale->setScale3D(QVector3D(2.0f, 2.0f, 2.0f)); - torusTranslation->setTranslation(QVector3D(1.7f, 1.7f, 0.0f)); - torusRotation->setAngleDeg(25.0f); - torusRotation->setAxis(QVector3D(0, 1, 0)); - - torusTransforms->addTransform(torusRotation); - torusTransforms->addTransform(torusTranslation); - torusTransforms->addTransform(torusScale); + Qt3DCore::QTransform *torusTransform = new Qt3DCore::QTransform(); + torusTransform->setScale(2.0f); + torusTransform->setRotation(QQuaternion::fromAxisAndAngle(QVector3D(0.0f, 1.0f, 0.0f), 25.0f)); + torusTransform->setTranslation(QVector3D(4.0f, 4.0f, 0.0f)); //! [1] //! [2] @@ -78,7 +69,7 @@ SceneModifier::SceneModifier(Qt3DCore::QEntity *rootEntity) m_torusEntity = new Qt3DCore::QEntity(m_rootEntity); m_torusEntity->addComponent(m_torus); m_torusEntity->addComponent(torusMaterial); - m_torusEntity->addComponent(torusTransforms); + m_torusEntity->addComponent(torusTransform); //! [3] // Cylinder shape data @@ -89,19 +80,10 @@ SceneModifier::SceneModifier(Qt3DCore::QEntity *rootEntity) cylinder->setSlices(20); // CylinderMesh Transform - Qt3DCore::QScaleTransform *cylinderScale = new Qt3DCore::QScaleTransform(); - Qt3DCore::QRotateTransform *cylinderRotation = new Qt3DCore::QRotateTransform(); - Qt3DCore::QTranslateTransform *cylinderTranslation = new Qt3DCore::QTranslateTransform(); - Qt3DCore::QTransform *cylinderTransforms = new Qt3DCore::QTransform(); - - cylinderScale->setScale3D(QVector3D(1.5f, 1.5f, 1.5f)); - cylinderTranslation->setTranslation(QVector3D(-2.6f, 2.4f, -1.5)); - cylinderRotation->setAngleDeg(45.0f); - cylinderRotation->setAxis(QVector3D(1, 0, 0)); - - cylinderTransforms->addTransform(cylinderTranslation); - cylinderTransforms->addTransform(cylinderRotation); - cylinderTransforms->addTransform(cylinderScale); + Qt3DCore::QTransform *cylinderTransform = new Qt3DCore::QTransform(); + cylinderTransform->setScale(1.5f); + cylinderTransform->setRotation(QQuaternion::fromAxisAndAngle(QVector3D(1.0f, 0.0f, 0.0f), 45.0f)); + cylinderTransform->setTranslation(QVector3D(-4.0f, 4.0f, -1.5)); Qt3DRender::QPhongMaterial *cylinderMaterial = new Qt3DRender::QPhongMaterial(); cylinderMaterial->setDiffuse(QColor(QRgb(0x928327))); @@ -110,21 +92,15 @@ SceneModifier::SceneModifier(Qt3DCore::QEntity *rootEntity) m_cylinderEntity = new Qt3DCore::QEntity(m_rootEntity); m_cylinderEntity->addComponent(cylinder); m_cylinderEntity->addComponent(cylinderMaterial); - m_cylinderEntity->addComponent(cylinderTransforms); + m_cylinderEntity->addComponent(cylinderTransform); // Cuboid shape data Qt3DRender::QCuboidMesh *cuboid = new Qt3DRender::QCuboidMesh(); // CuboidMesh Transform - Qt3DCore::QScaleTransform *cuboidScale = new Qt3DCore::QScaleTransform(); - Qt3DCore::QTranslateTransform *cuboidTranslation = new Qt3DCore::QTranslateTransform(); - Qt3DCore::QTransform *cuboidTransforms = new Qt3DCore::QTransform(); - - cuboidScale->setScale3D(QVector3D(4.0f, 4.0f, 4.0f)); - cuboidTranslation->setTranslation(QVector3D(0.9f, -0.9f, 0.0f)); - - cuboidTransforms->addTransform(cuboidTranslation); - cuboidTransforms->addTransform(cuboidScale); + Qt3DCore::QTransform *cuboidTransform = new Qt3DCore::QTransform(); + cuboidTransform->setScale(4.0f); + cuboidTransform->setTranslation(QVector3D(4.0f, -4.0f, 0.0f)); Qt3DRender::QPhongMaterial *cuboidMaterial = new Qt3DRender::QPhongMaterial(); cuboidMaterial->setDiffuse(QColor(QRgb(0x665423))); @@ -133,7 +109,7 @@ SceneModifier::SceneModifier(Qt3DCore::QEntity *rootEntity) m_cuboidEntity = new Qt3DCore::QEntity(m_rootEntity); m_cuboidEntity->addComponent(cuboid); m_cuboidEntity->addComponent(cuboidMaterial); - m_cuboidEntity->addComponent(cuboidTransforms); + m_cuboidEntity->addComponent(cuboidTransform); // Sphere shape data Qt3DRender::QSphereMesh *sphereMesh = new Qt3DRender::QSphereMesh(); @@ -142,15 +118,10 @@ SceneModifier::SceneModifier(Qt3DCore::QEntity *rootEntity) sphereMesh->setRadius(2); // Sphere mesh transform - Qt3DCore::QScaleTransform *sphereScale = new Qt3DCore::QScaleTransform(); - Qt3DCore::QTranslateTransform *sphereTranslation = new Qt3DCore::QTranslateTransform(); - Qt3DCore::QTransform *sphereTransforms = new Qt3DCore::QTransform(); - - sphereScale->setScale3D(QVector3D(1.3f, 1.3f, 1.3f)); - sphereTranslation->setTranslation(QVector3D(-2.9f, -2.9f, 0.0f)); + Qt3DCore::QTransform *sphereTransform = new Qt3DCore::QTransform(); - sphereTransforms->addTransform(sphereTranslation); - sphereTransforms->addTransform(sphereScale); + sphereTransform->setScale(1.3f); + sphereTransform->setTranslation(QVector3D(-4.0f, -4.0f, 0.0f)); Qt3DRender::QPhongMaterial *sphereMaterial = new Qt3DRender::QPhongMaterial(); sphereMaterial->setDiffuse(QColor(QRgb(0xa69929))); @@ -159,7 +130,7 @@ SceneModifier::SceneModifier(Qt3DCore::QEntity *rootEntity) m_sphereEntity = new Qt3DCore::QEntity(m_rootEntity); m_sphereEntity->addComponent(sphereMesh); m_sphereEntity->addComponent(sphereMaterial); - m_sphereEntity->addComponent(sphereTransforms); + m_sphereEntity->addComponent(sphereTransform); } SceneModifier::~SceneModifier() diff --git a/examples/qt3d/bigmodel-qml/MyEntity.qml b/examples/qt3d/bigmodel-qml/MyEntity.qml index 3e30b2fd3..df0dbd13d 100644 --- a/examples/qt3d/bigmodel-qml/MyEntity.qml +++ b/examples/qt3d/bigmodel-qml/MyEntity.qml @@ -39,13 +39,11 @@ import Qt3D.Render 2.0 Entity { id: root - property alias x: translation.dx - property alias y: translation.dy - property alias z: translation.dz + property alias position: transform.translation property alias diffuse: material.diffuse components: [ - Transform { Translate { id: translation } }, + Transform { id: transform }, SphereMesh { radius: 2 }, PhongMaterial { id: material } ] diff --git a/examples/qt3d/bigmodel-qml/main.qml b/examples/qt3d/bigmodel-qml/main.qml index efb82375a..56081055e 100644 --- a/examples/qt3d/bigmodel-qml/main.qml +++ b/examples/qt3d/bigmodel-qml/main.qml @@ -76,8 +76,9 @@ Entity { id: myEntity property real _lightness: 0.2 + 0.7 / collection._rows * Math.floor(index / collection.cols) property real _hue: (index % collection.cols) / collection.cols - x: collection.spacing * (index % collection.cols - 0.5 * (collection.cols - 1)) - z: collection.spacing * (Math.floor(index / collection.cols) - 0.5 * collection._rows) + position: Qt.vector3d(collection.spacing * (index % collection.cols - 0.5 * (collection.cols - 1)), + 0.0, + collection.spacing * (Math.floor(index / collection.cols) - 0.5 * collection._rows)); diffuse: Qt.hsla( _hue, 0.5, _lightness, 1.0 ) } } diff --git a/examples/qt3d/bigscene-cpp/bigscene-cpp.pro b/examples/qt3d/bigscene-cpp/bigscene-cpp.pro index 640c9f5fc..5dcaf3d0f 100644 --- a/examples/qt3d/bigscene-cpp/bigscene-cpp.pro +++ b/examples/qt3d/bigscene-cpp/bigscene-cpp.pro @@ -5,5 +5,9 @@ QT += 3dcore 3drender 3dinput SOURCES += \ - main.cpp + main.cpp \ + entity.cpp + +HEADERS += \ + entity.h diff --git a/examples/qt3d/bigscene-cpp/entity.cpp b/examples/qt3d/bigscene-cpp/entity.cpp new file mode 100644 index 000000000..f42f6a18b --- /dev/null +++ b/examples/qt3d/bigscene-cpp/entity.cpp @@ -0,0 +1,130 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +#include "entity.h" + +#include +#include +#include +#include + +Entity::Entity(Qt3DCore::QNode *parent) + : QEntity(parent) + , m_transform(new Qt3DCore::QTransform()) + , m_mesh(new Qt3DRender::QCylinderMesh()) + , m_material(new Qt3DRender::QPhongMaterial()) +{ + m_mesh->setRings(50.0f); + m_mesh->setSlices(30.0f); + m_mesh->setRadius(2.5f); + m_mesh->setLength(5.0f); + + m_material->setAmbient(Qt::black); + m_material->setSpecular(Qt::white); + m_material->setShininess(150.0f); + + addComponent(m_mesh); + addComponent(m_transform); + addComponent(m_material); +} + +void Entity::updateTransform() +{ + QMatrix4x4 m; + m.translate(m_position); + m.rotate(m_phi, QVector3D(1.0f, 0.0f, 0.0f)); + m.rotate(m_theta, QVector3D(0.0f, 0.0f, 1.0f)); + m_transform->setMatrix(m); +} + +float Entity::theta() const +{ + return m_theta; +} + +float Entity::phi() const +{ + return m_phi; +} + +QVector3D Entity::position() const +{ + return m_position; +} + +QColor Entity::diffuseColor() const +{ + return m_material->diffuse(); +} + +void Entity::setTheta(float theta) +{ + if (m_theta == theta) + return; + + m_theta = theta; + emit thetaChanged(theta); + updateTransform(); +} + +void Entity::setPhi(float phi) +{ + if (m_phi == phi) + return; + + m_phi = phi; + emit phiChanged(phi); + updateTransform(); +} + +void Entity::setPosition(QVector3D position) +{ + if (m_position == position) + return; + + m_position = position; + emit positionChanged(position); + updateTransform(); +} + +void Entity::setDiffuseColor(QColor diffuseColor) +{ + if (m_material->diffuse() == diffuseColor) + return; + + m_material->setDiffuse(diffuseColor); + emit diffuseColorChanged(diffuseColor); +} diff --git a/examples/qt3d/bigscene-cpp/entity.h b/examples/qt3d/bigscene-cpp/entity.h new file mode 100644 index 000000000..932190324 --- /dev/null +++ b/examples/qt3d/bigscene-cpp/entity.h @@ -0,0 +1,97 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +#ifndef ENTITY_H +#define ENTITY_H + +#include +#include +#include + +QT_BEGIN_NAMESPACE + +namespace Qt3DCore { +class QTransform; +} + +namespace Qt3DRender { +class QCylinderMesh; +class QPhongMaterial; +} + +QT_END_NAMESPACE + +class Entity : public Qt3DCore::QEntity +{ + Q_OBJECT + Q_PROPERTY(float theta READ theta WRITE setTheta NOTIFY thetaChanged) + Q_PROPERTY(float phi READ phi WRITE setPhi NOTIFY phiChanged) + Q_PROPERTY(QVector3D position READ position WRITE setPosition NOTIFY positionChanged) + Q_PROPERTY(QColor diffuseColor READ diffuseColor WRITE setDiffuseColor NOTIFY diffuseColorChanged) + +public: + Entity(Qt3DCore::QNode *parent = 0); + + float theta() const; + float phi() const; + QVector3D position() const; + QColor diffuseColor() const; + +public slots: + void setTheta(float theta); + void setPhi(float phi); + void setPosition(QVector3D position); + void setDiffuseColor(QColor diffuseColor); + +signals: + void thetaChanged(float theta); + void phiChanged(float phi); + void positionChanged(QVector3D position); + void diffuseColorChanged(QColor diffuseColor); + +private: + void updateTransform(); + +private: + Qt3DCore::QTransform *m_transform; + Qt3DRender::QCylinderMesh *m_mesh; + Qt3DRender::QPhongMaterial *m_material; + float m_theta; + float m_phi; + QVector3D m_position; +}; + +#endif // ENTITY_H diff --git a/examples/qt3d/bigscene-cpp/main.cpp b/examples/qt3d/bigscene-cpp/main.cpp index e0dfee255..26eacb0d2 100644 --- a/examples/qt3d/bigscene-cpp/main.cpp +++ b/examples/qt3d/bigscene-cpp/main.cpp @@ -34,6 +34,8 @@ ** ****************************************************************************/ +#include "entity.h" + #include #include @@ -93,57 +95,34 @@ int main(int ac, char **av) frameGraph->setActiveFrameGraph(forwardRenderer); root->addComponent(frameGraph); - const float radius = 100.0f; const int max = 1000; const float det = 1.0f / max; + // Scene for (int i = 0; i < max; i++) { - QEntity *e = new QEntity(); - Qt3DCore::QTransform *transform = new Qt3DCore::QTransform(); - QTranslateTransform *translation = new QTranslateTransform(); - QRotateTransform *rotateX = new QRotateTransform(); - QRotateTransform *rotateZ = new QRotateTransform(); - QCylinderMesh *mesh = new QCylinderMesh(); - QPhongMaterial *material = new QPhongMaterial(); - mesh->setRings(50.0f); - mesh->setSlices(30.0f); - mesh->setRadius(2.5f); - mesh->setLength(5.0f); - + Entity *e = new Entity(); const float angle = M_PI * 2.0f * i * det * 10.; - material->setDiffuse(QColor(qFabs(qCos(angle)) * 255, 204, 75)); - material->setAmbient(Qt::black); - material->setSpecular(Qt::white); - material->setShininess(150.0f); - - translation->setTranslation(QVector3D(radius * qCos(angle), 200.* i * det, radius * qSin(angle))); - rotateX->setAxis(QVector3D(1.0f, 0.0f, 0.0f)); - rotateZ->setAxis(QVector3D(0.0f, 0.0f, 1.0f)); - rotateX->setAngleDeg(30.0f * i); - rotateZ->setAngleDeg(45.0f * i); + e->setDiffuseColor(QColor(qFabs(qCos(angle)) * 255, 204, 75)); + e->setPosition(QVector3D(radius * qCos(angle), 200.* i * det, radius * qSin(angle))); + e->setTheta(30.0f * i); + e->setPhi(45.0f * i); - QPropertyAnimation *animX = new QPropertyAnimation(rotateX, QByteArrayLiteral("angle")); - animX->setDuration(2400 * i); + QPropertyAnimation *animX = new QPropertyAnimation(e, QByteArrayLiteral("theta")); + animX->setDuration(2400 * (i + 1)); animX->setStartValue(QVariant::fromValue(i * 30.0f)); animX->setEndValue(QVariant::fromValue((i + 1) * 390.0f)); animX->setLoopCount(-1); animX->start(); - QPropertyAnimation *animZ = new QPropertyAnimation(rotateZ, QByteArrayLiteral("angle")); - animZ->setDuration(2400 * i); + QPropertyAnimation *animZ = new QPropertyAnimation(e, QByteArrayLiteral("phi")); + animZ->setDuration(2400 * (i + 1)); animZ->setStartValue(QVariant::fromValue(i * 20.0f)); animZ->setEndValue(QVariant::fromValue((i + 1) * 380.0f)); animZ->setLoopCount(-1); animZ->start(); - transform->addTransform(rotateX); - transform->addTransform(rotateZ); - transform->addTransform(translation); - e->addComponent(transform); - e->addComponent(mesh); - e->addComponent(material); e->setParent(root); } diff --git a/examples/qt3d/clip-planes-qml/ClipPlaneEntity.qml b/examples/qt3d/clip-planes-qml/ClipPlaneEntity.qml index fdd3f803e..cccab558c 100644 --- a/examples/qt3d/clip-planes-qml/ClipPlaneEntity.qml +++ b/examples/qt3d/clip-planes-qml/ClipPlaneEntity.qml @@ -40,9 +40,8 @@ import Qt3D.Render 2.0 Entity { id: root property Material visualMaterial; - property alias rotateAngle: _rotate.angle - property alias rotateAxis: _rotate.axis - + property real rotateAngle: 0.0 + property vector3d rotateAxis: Qt.vector3d(1.0, 0.0, 0.0) property vector3d center; property vector3d normal; readonly property vector4d equation: Qt.vector4d(normal.x, @@ -61,8 +60,15 @@ Entity { Transform { id: transform - Rotate { id: _rotate } - Translate { translation: root.center } + matrix: { + var m = Qt.matrix4x4(1, 0, 0, 0, + 0, 1, 0, 0, + 0, 0, 1, 0, + 0, 0, 0, 1); + m.translate(root.center); + m.rotate(root.rotateAngle, root.rotateAxis); + return m; + } } property Layer layer: Layer { diff --git a/examples/qt3d/clip-planes-qml/ClippingPlanes.qml b/examples/qt3d/clip-planes-qml/ClippingPlanes.qml index a5525f667..15ab76110 100644 --- a/examples/qt3d/clip-planes-qml/ClippingPlanes.qml +++ b/examples/qt3d/clip-planes-qml/ClippingPlanes.qml @@ -34,9 +34,9 @@ ** ****************************************************************************/ +import QtQuick 2.4 as QQ2 import Qt3D.Core 2.0 import Qt3D.Render 2.0 -import QtQuick 2.4 as QQ2 Entity { id: root diff --git a/examples/qt3d/clip-planes-qml/main.qml b/examples/qt3d/clip-planes-qml/main.qml index c4436a2df..b7bcd5adb 100644 --- a/examples/qt3d/clip-planes-qml/main.qml +++ b/examples/qt3d/clip-planes-qml/main.qml @@ -34,6 +34,7 @@ ** ****************************************************************************/ +import QtQuick 2.4 as QQ2 import Qt3D.Core 2.0 import Qt3D.Render 2.0 @@ -87,8 +88,8 @@ Entity { } property Transform transform: Transform { - Translate { dx: 0 } - Scale { scale: 3 } + translation: Qt.vector3d( 0.0, 0.0, 0.0 ) + scale: 3 } property Layer layer: Layer { diff --git a/examples/qt3d/controls/Logo.qml b/examples/qt3d/controls/Logo.qml index 1fe45340b..d4286ca7b 100644 --- a/examples/qt3d/controls/Logo.qml +++ b/examples/qt3d/controls/Logo.qml @@ -76,20 +76,15 @@ Entity { Transform { id: logoTransform - Rotate { - id: rotate_x - angle: rotation_x.value - axis: Qt.vector3d(1, 0, 0) - } - Rotate { - id: rotate_y - angle: rotation_y.value - axis: Qt.vector3d(0, 1, 0) - } - Rotate { - id: rotate_z - angle: rotation_z.value - axis: Qt.vector3d(0, 0, 1) + matrix: { + var m = Qt.matrix4x4(1, 0, 0, 0, + 0, 1, 0, 0, + 0, 0, 1, 0, + 0, 0, 0, 1); + m.rotate(rotation_z.value, Qt.vector3d(0, 0, 1)); + m.rotate(rotation_y.value, Qt.vector3d(0, 1, 0)); + m.rotate(rotation_x.value, Qt.vector3d(1, 0, 0)); + return m; } } diff --git a/examples/qt3d/cpp_example/main.cpp b/examples/qt3d/cpp_example/main.cpp index f02d716cc..3e47abc59 100644 --- a/examples/qt3d/cpp_example/main.cpp +++ b/examples/qt3d/cpp_example/main.cpp @@ -96,36 +96,24 @@ int main(int ac, char **av) torusEntity->addComponent(torus); // TorusMesh Transform - Qt3DCore::QTranslateTransform *torusTranslation = new Qt3DCore::QTranslateTransform(); - Qt3DCore::QRotateTransform *torusRotation = new Qt3DCore::QRotateTransform(); Qt3DCore::QTransform *torusTransforms = new Qt3DCore::QTransform(); - - torusTranslation->setTranslation(QVector3D(-5.0f, 3.5f, 2.0f)); - torusRotation->setAxis(QVector3D(1, 0, 0)); - torusRotation->setAngleDeg(35.0f); - torusTransforms->addTransform(torusTranslation); - torusTransforms->addTransform(torusRotation); + torusTransforms->setTranslation(QVector3D(-5.0f, 3.5f, 2.0f)); + torusTransforms->setRotation(QQuaternion::fromAxisAndAngle(QVector3D(1, 0, 0), 35.0f)); torusEntity->addComponent(torusTransforms); // Scene file Qt3DCore::QEntity *sceneEntity = new Qt3DCore::QEntity(rootEntity); - Qt3DRender::QSceneLoader *scene = new Qt3DRender::QSceneLoader(); + Qt3DRender::QSceneLoader *scene = new Qt3DRender::QSceneLoader(); scene->setObjectName(QStringLiteral("scene")); Qt3DCore::QTransform *sceneTransform = new Qt3DCore::QTransform(); - Qt3DCore::QTranslateTransform *sceneTranslateTransform = new Qt3DCore::QTranslateTransform(); - sceneTranslateTransform->setDx(2.5); - sceneTranslateTransform->setDy(0.5); - sceneTranslateTransform->setDz(-10); - sceneTransform->addTransform(sceneTranslateTransform); + sceneTransform->setTranslation(QVector3D(2.5f, 0.5f, -10.0f)); sceneEntity->addComponent(sceneTransform); -// scene->setSource(":/assets/gltf/wine/wine.json"); scene->setSource(QUrl("qrc:/assets/test_scene.dae")); sceneEntity->addComponent(scene); // Camera Qt3DCore::QCamera *cameraEntity = new Qt3DCore::QCamera(rootEntity); cameraEntity->setObjectName(QStringLiteral("cameraEntity")); - cameraEntity->lens()->setPerspectiveProjection(60.0f, 16.0f/9.0f, 0.1f, 1000.0f); cameraEntity->setPosition(QVector3D(-5, 0, -20.0f)); cameraEntity->setViewCenter(QVector3D(11, 0, 5)); diff --git a/examples/qt3d/custom-mesh-cpp/main.cpp b/examples/qt3d/custom-mesh-cpp/main.cpp index 61be657a4..ed94f96a5 100644 --- a/examples/qt3d/custom-mesh-cpp/main.cpp +++ b/examples/qt3d/custom-mesh-cpp/main.cpp @@ -104,9 +104,7 @@ int main(int argc, char* argv[]) // Transform Qt3DCore::QTransform *transform = new Qt3DCore::QTransform; - Qt3DCore::QScaleTransform *scaleTransform = new Qt3DCore::QScaleTransform; - scaleTransform->setScale(8.0f); - transform->addTransform(scaleTransform); + transform->setScale(8.0f); // Custom Mesh (TetraHedron) Qt3DRender::QGeometryRenderer *customMeshRenderer = new Qt3DRender::QGeometryRenderer; diff --git a/examples/qt3d/custom-mesh-qml/main.qml b/examples/qt3d/custom-mesh-qml/main.qml index 34d14aa5f..05b45f793 100644 --- a/examples/qt3d/custom-mesh-qml/main.qml +++ b/examples/qt3d/custom-mesh-qml/main.qml @@ -34,9 +34,9 @@ ** ****************************************************************************/ +import QtQuick 2.2 as QQ2 import Qt3D.Core 2.0 import Qt3D.Render 2.0 -import QtQuick 2.2 as QQ2 Entity { id: sceneRoot @@ -207,16 +207,21 @@ Entity { Transform { id: meshTransform - Scale { scale: 10 } - Rotate { - id: meshRotation - axis: Qt.vector3d(0, 1, 0) + property real userAngle: 0.0 + matrix: { + var m = Qt.matrix4x4(1, 0, 0, 0, + 0, 1, 0, 0, + 0, 0, 1, 0, + 0, 0, 0, 1); + m.rotate(userAngle, Qt.vector3d(0, 1, 0)); + m.scale(10); + return m; } } QQ2.NumberAnimation { - target: meshRotation - property: "angle" + target: meshTransform + property: "userAngle" duration: 10000 from: 0 to: 360 diff --git a/examples/qt3d/cylinder-cpp/main.cpp b/examples/qt3d/cylinder-cpp/main.cpp index e65554f92..b6441314e 100644 --- a/examples/qt3d/cylinder-cpp/main.cpp +++ b/examples/qt3d/cylinder-cpp/main.cpp @@ -108,21 +108,14 @@ int main(int argc, char **argv) cylinder->setSlices(20); // CylinderMesh Transform - Qt3DCore::QScaleTransform *cylinderScale = new Qt3DCore::QScaleTransform(); - Qt3DCore::QRotateTransform *cylinderRotation = new Qt3DCore::QRotateTransform(); - Qt3DCore::QTransform *cylinderTransforms = new Qt3DCore::QTransform(); - - cylinderScale->setScale3D(QVector3D(1.5f, 1.5f, 1.5f)); - cylinderRotation->setAngleDeg(45.0f); - cylinderRotation->setAxis(QVector3D(1, 0, 0)); - - cylinderTransforms->addTransform(cylinderScale); - cylinderTransforms->addTransform(cylinderRotation); + Qt3DCore::QTransform *cylinderTransform = new Qt3DCore::QTransform; + cylinderTransform->setScale(1.5f); + cylinderTransform->setRotation(QQuaternion::fromAxisAndAngle(QVector3D(1, 0, 0), 45.0f)); // Cylinder Qt3DCore::QEntity *cylinderEntity = new Qt3DCore::QEntity(rootEntity); cylinderEntity->addComponent(cylinder); - cylinderEntity->addComponent(cylinderTransforms); + cylinderEntity->addComponent(cylinderTransform); // Setting the FrameGraph rootEntity->addComponent(frameGraph); diff --git a/examples/qt3d/cylinder-qml/main.qml b/examples/qt3d/cylinder-qml/main.qml index 2eda44a26..82d535e83 100644 --- a/examples/qt3d/cylinder-qml/main.qml +++ b/examples/qt3d/cylinder-qml/main.qml @@ -76,17 +76,20 @@ Entity { Transform { id: transform - Scale { scale3D: Qt.vector3d(1.5, 1.5, 1.5) } - Rotate { - angle: 45 - axis: Qt.vector3d(1, 0, 0) + matrix: { + var m = Qt.matrix4x4(1, 0, 0, 0, + 0, 1, 0, 0, + 0, 0, 1, 0, + 0, 0, 0, 1); + m.rotate(45, Qt.vector3d(1, 0, 0)); + m.scale(1.5); + return m; } } Material { id: material - effect : Effect { - } + effect: Effect {} } Entity { diff --git a/examples/qt3d/deferred-renderer-cpp/main.cpp b/examples/qt3d/deferred-renderer-cpp/main.cpp index 086ba6677..111643ac4 100644 --- a/examples/qt3d/deferred-renderer-cpp/main.cpp +++ b/examples/qt3d/deferred-renderer-cpp/main.cpp @@ -138,16 +138,14 @@ int main(int ac, char **av) sphereOneMaterial->setEffect(sceneEffect); sphereOneMaterial->addParameter(new Qt3DRender::QParameter(QStringLiteral("meshColor"), QColor(Qt::blue))); - Qt3DCore::QTranslateTransform *sphereOneTranslate = new Qt3DCore::QTranslateTransform(); - sphereOneTranslate->setDx(-10.0f); - sphereOneTranslate->setDy(0.0f); - sphereOneTranslate->setDz(25.0f); + Qt3DCore::QTransform *sphereOneTransform = new Qt3DCore::QTransform; + sphereOneTransform->setTranslation(QVector3D(-10.0f, 0.0f, 25.0f)); Qt3DRender::QPointLight *light2 = new Qt3DRender::QPointLight(); light2->setColor(Qt::white); light2->setIntensity(1.5f); - sphereOne->addComponent(new Qt3DCore::QTransform(sphereOneTranslate)); + sphereOne->addComponent(sphereOneTransform); sphereOne->addComponent(sphereOneMaterial); sphereOne->addComponent(sphereMesh); sphereOne->addComponent(sceneLayer); @@ -183,12 +181,11 @@ int main(int ac, char **av) finalEffect->gl2Technique()->addParameter(new Qt3DRender::QParameter(QStringLiteral("pointLights"), QVariant::fromValue(lightsData))); screenQuadMaterial->setEffect(finalEffect); - Qt3DCore::QRotateTransform *screenPlaneRotation = new Qt3DCore::QRotateTransform(); - screenPlaneRotation->setAngleDeg(90); - screenPlaneRotation->setAxis(QVector3D(1.0f, 0.0f, 0.0f)); + Qt3DCore::QTransform *screenPlaneTransform = new Qt3DCore::QTransform; + screenPlaneTransform->setRotation(QQuaternion::fromAxisAndAngle(QVector3D(1.0f, 0.0f, 0.0f), 90.0f)); screenQuad->addComponent(quadLayer); - screenQuad->addComponent(new Qt3DCore::QTransform(screenPlaneRotation)); + screenQuad->addComponent(screenPlaneTransform); screenQuad->addComponent(screenQuadMaterial); screenQuad->addComponent(planeMesh); diff --git a/examples/qt3d/deferred-renderer-qml/main.qml b/examples/qt3d/deferred-renderer-qml/main.qml index d58bb6fab..304320c49 100644 --- a/examples/qt3d/deferred-renderer-qml/main.qml +++ b/examples/qt3d/deferred-renderer-qml/main.qml @@ -34,9 +34,9 @@ ** ****************************************************************************/ +import QtQuick 2.0 as QQ2 import Qt3D.Core 2.0 import Qt3D.Render 2.0 -import QtQuick 2.0 as QQ2 Entity { id : root @@ -69,9 +69,13 @@ Entity { meshResolution: Qt.size(2, 2) }, Transform { // We rotate the plane so that it faces us - Rotate { - axis : Qt.vector3d(1.0, 0.0, 0.0) - angle : 90 + matrix: { + var m = Qt.matrix4x4(1, 0, 0, 0, + 0, 1, 0, 0, + 0, 0, 1, 0, + 0, 0, 0, 1); + m.rotate(90, Qt.vector3d(1, 0, 0)); + return m; } }, Material { @@ -135,16 +139,17 @@ Entity { parameters : Parameter { name : "meshColor"; value : "dodgerblue" } } - property Transform transform : Transform { - Translate{ dx: -10; dy: 0; dz : 5 - id: sphere1Translate - } + property Transform transform: Transform { + id: sphere1Transform + property real x: -10.0 + translation: Qt.vector3d(x, 0, 5) } + QQ2.SequentialAnimation { loops: QQ2.Animation.Infinite running: false - QQ2.NumberAnimation {target: sphere1Translate; property: "dx"; to: 6; duration: 2000 } - QQ2.NumberAnimation {target: sphere1Translate; property: "dx"; to: -10; duration: 2000 } + QQ2.NumberAnimation { target: sphere1Transform; property: "x"; to: 6; duration: 2000 } + QQ2.NumberAnimation { target: sphere1Transform; property: "x"; to: -10; duration: 2000 } } property PointLight light : PointLight { @@ -174,8 +179,8 @@ Entity { intensity : 2.0 } - property Transform transform : Transform { - Translate{ dx: 5; dy: 0; dz : 5} + property Transform transform: Transform { + translation: Qt.vector3d(5, 0, 5) } components : [ @@ -199,15 +204,17 @@ Entity { parameters : Parameter { name : "meshColor"; value : "red" } } - property Transform transform : Transform { - Translate{ id: light3Translate; dx: 2; dy: 2; dz : 7 - } + property Transform transform: Transform { + id: light3Transform + property real y: 2.0 + translation: Qt.vector3d(2, y, 7) } + QQ2.SequentialAnimation { loops: QQ2.Animation.Infinite running: true - QQ2.NumberAnimation {target: light3Translate; property: "dy"; to: 6; duration: 1000; easing.type: QQ2.Easing.InOutQuad } - QQ2.NumberAnimation {target: light3Translate; property: "dy"; to: -6; duration: 1000; easing.type: QQ2.Easing.InOutQuint } + QQ2.NumberAnimation { target: light3Transform; property: "y"; to: 6; duration: 1000; easing.type: QQ2.Easing.InOutQuad } + QQ2.NumberAnimation { target: light3Transform; property: "y"; to: -6; duration: 1000; easing.type: QQ2.Easing.InOutQuint } } components: [ @@ -225,8 +232,8 @@ Entity { color : "white" intensity : 3.0 } - property Transform transform : Transform { - Translate{ dx: 5; dy: 2; dz : 7} + property Transform transform: Transform { + translation: Qt.vector3d(5, 2, 7) } components: [ diff --git a/examples/qt3d/dynamicscene-cpp/boxentity.cpp b/examples/qt3d/dynamicscene-cpp/boxentity.cpp index c6f1df33c..3ab25fed0 100644 --- a/examples/qt3d/dynamicscene-cpp/boxentity.cpp +++ b/examples/qt3d/dynamicscene-cpp/boxentity.cpp @@ -41,14 +41,11 @@ BoxEntity::BoxEntity(QNode *parent) : Qt3DCore::QEntity(parent) , m_transform(new Qt3DCore::QTransform()) - , m_translate(new Qt3DCore::QTranslateTransform()) , m_mesh(new Qt3DRender::QCuboidMesh()) , m_material(new Qt3DRender::QPhongMaterial()) , m_angle(0.0f) , m_radius(1.0f) { - m_transform->addTransform(m_translate); - connect(m_material, SIGNAL(diffuseChanged()), this, SIGNAL(diffuseColorChanged())); m_material->setAmbient(Qt::gray); m_material->setSpecular(Qt::white); @@ -101,7 +98,7 @@ float BoxEntity::radius() const void BoxEntity::updateTransformation() { - m_translate->setTranslation(QVector3D(qCos(m_angle) * m_radius, + m_transform->setTranslation(QVector3D(qCos(m_angle) * m_radius, 1.0f, qSin(m_angle) * m_radius)); } diff --git a/examples/qt3d/dynamicscene-cpp/boxentity.h b/examples/qt3d/dynamicscene-cpp/boxentity.h index 53253d038..cd12bad36 100644 --- a/examples/qt3d/dynamicscene-cpp/boxentity.h +++ b/examples/qt3d/dynamicscene-cpp/boxentity.h @@ -39,8 +39,6 @@ #include #include -#include -#include #include #include @@ -73,8 +71,6 @@ private: void updateTransformation(); Qt3DCore::QTransform *m_transform; - Qt3DCore::QTranslateTransform *m_translate; - Qt3DCore::QScaleTransform *m_scale; Qt3DRender::QCuboidMesh *m_mesh; Qt3DRender::QPhongMaterial *m_material; float m_angle; diff --git a/examples/qt3d/enabled-qml/main.qml b/examples/qt3d/enabled-qml/main.qml index 379c00d36..438491936 100644 --- a/examples/qt3d/enabled-qml/main.qml +++ b/examples/qt3d/enabled-qml/main.qml @@ -54,7 +54,7 @@ Entity { } CameraSelector { - camera: basicCamera + camera: camera enabled: counter !== 7 LayerFilter { @@ -76,28 +76,17 @@ Entity { } } - Entity { - id: basicCamera - - Transform { - id: basicCameraTransform - LookAt { - upVector: Qt.vector3d(0, 1, 0) - viewCenter: Qt.vector3d(0, 0, 0) - position: Qt.vector3d(0, 10, -10) - } - } - components: [basicCameraTransform, cameraLens] - } - - CameraLens { - id: cameraLens + Camera { + id: camera projectionType: CameraLens.PerspectiveProjection fieldOfView: 45 aspectRatio: 16/9 nearPlane : 0.1 farPlane : 1000.0 enabled: counter !== 4 + position: Qt.vector3d(0, 10, -10) + viewCenter: Qt.vector3d(0, 0, 0) + upVector: Qt.vector3d(0, 1, 0) } // Sphere @@ -123,48 +112,48 @@ Entity { Transform { id: transform + property real x: 0.0 + property real y: 0.0 + property real z: 0.0 + translation: Qt.vector3d(x, y, z) enabled: counter !== 3 - - Translate { - id: translate - } } QQ2.SequentialAnimation { running: true loops: QQ2.Animation.Infinite QQ2.NumberAnimation { - target: translate; property: "dx" + target: transform; property: "x" from: 0; to: 5; duration: 550 easing.type: QQ2.Easing.InOutQuad } QQ2.NumberAnimation { - target: translate; property: "dy" + target: transform; property: "y" from: 0; to: 5; duration: 650 easing.type: QQ2.Easing.InOutQuad } QQ2.NumberAnimation { - target: translate; property: "dz" + target: transform; property: "z" from: 0; to: 5; duration: 350 easing.type: QQ2.Easing.InOutQuad } QQ2.NumberAnimation { - target: translate; property: "dx" + target: transform; property: "x" from: 5; to: 0; duration: 550 easing.type: QQ2.Easing.InOutQuad } QQ2.NumberAnimation { - target: translate; property: "dy" + target: transform; property: "y" from: 5; to: 0; duration: 350 easing.type: QQ2.Easing.InOutQuad } QQ2.NumberAnimation { - target: translate; property: "dz" + target: transform; property: "z" from: 5; to: 0; duration: 650 easing.type: QQ2.Easing.InOutQuad diff --git a/examples/qt3d/gltf/Wine.qml b/examples/qt3d/gltf/Wine.qml index 6e9b1a4c9..7a1506ba5 100644 --- a/examples/qt3d/gltf/Wine.qml +++ b/examples/qt3d/gltf/Wine.qml @@ -40,37 +40,28 @@ import Qt3D.Render 2.0 Entity { id: root - property alias x: wineTranslate.dx - property alias y: wineTranslate.dy - property alias z: wineTranslate.dz - property alias angleX: rotateX.angle - property alias angleY: rotateY.angle - property alias angleZ: rotateZ.angle - property alias scale: wineScale.scale + property vector3d position: Qt.vector3d(0, 0, 0) + property real angleX: 0 + property real angleY: 0 + property real angleZ: 0 + property real scale: 1 components: [ Transform { - Rotate { - id: rotateX - axis: Qt.vector3d(1, 0, 0) - } - Rotate { - id: rotateY - axis: Qt.vector3d(0, 1, 0) - } - Rotate { - id: rotateZ - axis: Qt.vector3d(0, 0, 1) - } - Translate { - id: wineTranslate - } - Scale { - id: wineScale + matrix: { + var m = Qt.matrix4x4(1, 0, 0, 0, + 0, 1, 0, 0, + 0, 0, 1, 0, + 0, 0, 0, 1); + m.translate(root.position); + m.rotate(root.angleX, Qt.vector3d(1, 0, 0)) + m.rotate(root.angleY, Qt.vector3d(0, 1, 0)) + m.rotate(root.angleZ, Qt.vector3d(0, 0, 1)) + m.scale(root.scale); + return m; } }, - SceneLoader - { + SceneLoader { source: "qrc:/assets/gltf/wine/wine.gltf" } ] diff --git a/examples/qt3d/gltf/main.qml b/examples/qt3d/gltf/main.qml index 87a05c15d..c244c24f8 100644 --- a/examples/qt3d/gltf/main.qml +++ b/examples/qt3d/gltf/main.qml @@ -50,7 +50,7 @@ Entity { farPlane : 1000.0 position: Qt.vector3d( 0.0, 20.0, -120.0 ) upVector: Qt.vector3d( 0.0, 1.0, 0.0 ) - viewCenter: Qt.vector3d( 0.0, 0.0, 0.0 ) + viewCenter: Qt.vector3d( 0.0, 10.0, 0.0 ) } Configuration { @@ -79,11 +79,7 @@ Entity { Wine { id: wineRack - scale: 1 - x: -60.0 - y: -20.0 - z: 0.0 + position: Qt.vector3d(-60.0, 0.0, 50.0) angleX: 180 } - } diff --git a/examples/qt3d/gooch-qml/MyEntity.qml b/examples/qt3d/gooch-qml/MyEntity.qml index 49c5cf143..6e057c3ed 100644 --- a/examples/qt3d/gooch-qml/MyEntity.qml +++ b/examples/qt3d/gooch-qml/MyEntity.qml @@ -39,18 +39,13 @@ import Qt3D.Render 2.0 Entity { id: root - property alias x: translation.dx - property alias y: translation.dy - property alias z: translation.dz - property alias scale: scaleTransform.scale + property alias position: transform.translation + property alias scale: transform.scale property alias material: gooch property alias source: mesh.source components: [ - Transform { - Translate { id: translation } - Scale{ id: scaleTransform } - }, + Transform { id: transform }, Mesh { id: mesh }, GoochMaterial { id: gooch } ] diff --git a/examples/qt3d/keyboardinput-qml/SphereEntity.qml b/examples/qt3d/keyboardinput-qml/SphereEntity.qml index 4ed05dcd8..3f445cc2f 100644 --- a/examples/qt3d/keyboardinput-qml/SphereEntity.qml +++ b/examples/qt3d/keyboardinput-qml/SphereEntity.qml @@ -41,10 +41,7 @@ import QtQuick 2.3 as QQ2 Entity { id: root - - property alias x: translate.dx - property alias y: translate.dy - property alias z: translate.dz + property alias position: transform.translation property alias color: material.diffuse property alias input: input @@ -54,17 +51,13 @@ Entity { Transform { id: transform + scale: root.input.focus ? 2 : 1 - Scale { - scale: root.input.focus ? 2 : 1 - - QQ2.Behavior on scale { - QQ2.NumberAnimation { - duration: 250 - } + QQ2.Behavior on scale { + QQ2.NumberAnimation { + duration: 250 } } - Translate { id: translate } } KeyboardInput { id: input } diff --git a/examples/qt3d/keyboardinput-qml/main.qml b/examples/qt3d/keyboardinput-qml/main.qml index 65fbfe1f9..e943f190c 100644 --- a/examples/qt3d/keyboardinput-qml/main.qml +++ b/examples/qt3d/keyboardinput-qml/main.qml @@ -67,7 +67,7 @@ Entity { SphereEntity { id: sphere1 - x: -5 + position: Qt.vector3d(-5, 0, 0) color: "red" input.onTabPressed: sphere2.input.focus = true input.focus: true @@ -76,7 +76,6 @@ Entity { SphereEntity { id: sphere2 - x: 0 color: "green" input.onTabPressed: sphere3.input.focus = true input.controller: keyboardController @@ -84,7 +83,7 @@ Entity { SphereEntity { id: sphere3 - x: 5 + position: Qt.vector3d(5, 0, 0) color: "blue" input.onTabPressed: sphere1.input.focus = true input.controller: keyboardController diff --git a/examples/qt3d/loader-qml/CuboidEntity.qml b/examples/qt3d/loader-qml/CuboidEntity.qml index 71858e0f9..f355e30d3 100644 --- a/examples/qt3d/loader-qml/CuboidEntity.qml +++ b/examples/qt3d/loader-qml/CuboidEntity.qml @@ -34,9 +34,9 @@ ** ****************************************************************************/ +import QtQuick 2.4 as QQ2 import Qt3D.Core 2.0 import Qt3D.Render 2.0 -import QtQuick 2.4 as QQ2 Entity { components: [ mesh, phongMaterial, transform ] @@ -54,10 +54,15 @@ Entity { Transform { id: transform - Scale { scale: 4 } - Rotate { - id: _rotate - axis: Qt.vector3d(0.0, 1.0, 0.0) + property real userAngle: 0.0 + matrix: { + var m = Qt.matrix4x4(1, 0, 0, 0, + 0, 1, 0, 0, + 0, 0, 1, 0, + 0, 0, 0, 1); + m.rotate(userAngle, Qt.vector3d(0, 1, 0)); + m.scale(4); + return m; } } @@ -72,8 +77,8 @@ Entity { } QQ2.NumberAnimation { - target: _rotate - property: "angle" + target: transform + property: "userAngle" duration: 750 loops: QQ2.Animation.Infinite running: true diff --git a/examples/qt3d/loader-qml/SphereEntity.qml b/examples/qt3d/loader-qml/SphereEntity.qml index 9bad4c3a6..56be1eb07 100644 --- a/examples/qt3d/loader-qml/SphereEntity.qml +++ b/examples/qt3d/loader-qml/SphereEntity.qml @@ -34,9 +34,9 @@ ** ****************************************************************************/ +import QtQuick 2.4 as QQ2 import Qt3D.Core 2.0 import Qt3D.Render 2.0 -import QtQuick 2.4 as QQ2 Entity { components: [ mesh, material, transform ] @@ -48,11 +48,7 @@ Entity { Transform { id: transform - - Scale { - id: _scale - scale: 3 - } + scale: 3 } QQ2.ColorAnimation { @@ -66,7 +62,7 @@ Entity { } QQ2.NumberAnimation { - target: _scale + target: transform property: "scale" duration: 1500 loops: QQ2.Animation.Infinite diff --git a/examples/qt3d/loader-qml/main.qml b/examples/qt3d/loader-qml/main.qml index ee1efaf4f..b9dd2ca12 100644 --- a/examples/qt3d/loader-qml/main.qml +++ b/examples/qt3d/loader-qml/main.qml @@ -34,9 +34,9 @@ ** ****************************************************************************/ +import QtQuick 2.2 as QQ2 import Qt3D.Core 2.0 import Qt3D.Render 2.0 -import QtQuick 2.2 as QQ2 Entity { id: sceneRoot @@ -81,10 +81,14 @@ Entity { Transform { id: torusTransform - Scale { scale3D: Qt.vector3d(1.5, 1, 0.5) } - Rotate { - angle: 45 - axis: Qt.vector3d(1, 0, 0) + matrix: { + var m = Qt.matrix4x4(1, 0, 0, 0, + 0, 1, 0, 0, + 0, 0, 1, 0, + 0, 0, 0, 1); + m.rotate(45, Qt.vector3d(1, 0, 0)); + m.scale(Qt.vector3d(1.5, 1, 0.5)); + return m; } } @@ -112,18 +116,21 @@ Entity { Transform { id: revolutionTransform - Translate { - translation: Qt.vector3d(20, 0, 0) - } - - Rotate { - id: sphereRotation - axis: Qt.vector3d(0, 1, 0) + property real userAngle: 0.0 + matrix: { + var m = Qt.matrix4x4(1, 0, 0, 0, + 0, 1, 0, 0, + 0, 0, 1, 0, + 0, 0, 0, 1); + m.rotate(userAngle, Qt.vector3d(0, 1, 0)); + m.translate(Qt.vector3d(20, 0, 0)); + return m; } } + QQ2.NumberAnimation { - target: sphereRotation - property: "angle" + target: revolutionTransform + property: "userAngle" duration: 10000 from: 0 to: 360 diff --git a/examples/qt3d/materials-cpp/barrel.cpp b/examples/qt3d/materials-cpp/barrel.cpp index fc86a9ab2..96a5e0c35 100644 --- a/examples/qt3d/materials-cpp/barrel.cpp +++ b/examples/qt3d/materials-cpp/barrel.cpp @@ -71,7 +71,7 @@ Barrel::Barrel(Qt3DCore::QNode *parent) , m_specularTextureImage(new Qt3DRender::QTextureImage()) { mesh()->setSource(QUrl(QStringLiteral("qrc:/assets/metalbarrel/metal_barrel.obj"))); - scaleTransform()->setScale(0.03f); + transform()->setScale(0.03f); m_diffuseTexture->addTextureImage(m_diffuseTextureImage); m_normalTexture->addTextureImage(m_normalTextureImage); diff --git a/examples/qt3d/materials-cpp/houseplant.cpp b/examples/qt3d/materials-cpp/houseplant.cpp index 55ee27c2c..12ce2ba37 100644 --- a/examples/qt3d/materials-cpp/houseplant.cpp +++ b/examples/qt3d/materials-cpp/houseplant.cpp @@ -62,7 +62,6 @@ HousePlant::HousePlant(Qt3DCore::QNode *parent) , m_plantMaterial(new Qt3DRender::QNormalDiffuseMapAlphaMaterial()) , m_coverMaterial(new Qt3DRender::QNormalDiffuseMapMaterial()) , m_potImage(new Qt3DRender::QTextureImage()) - , m_potNormalImage(new Qt3DRender::QTextureImage()) , m_plantImage(new Qt3DRender::QTextureImage()) , m_plantNormalImage(new Qt3DRender::QTextureImage()) @@ -71,7 +70,7 @@ HousePlant::HousePlant(Qt3DCore::QNode *parent) , m_plantType(Bamboo) , m_potShape(Cross) { - m_pot->scaleTransform()->setScale(0.03f); + m_pot->transform()->setScale(0.03f); m_pot->addComponent(m_potMaterial); m_plant->addComponent(m_plantMaterial); m_cover->addComponent(m_coverMaterial); @@ -130,44 +129,24 @@ HousePlant::Plant HousePlant::plantType() const return m_plantType; } -void HousePlant::setX(float x) -{ - m_pot->translateTransform()->setDx(x); -} - -void HousePlant::setY(float y) -{ - m_pot->translateTransform()->setDy(y); -} - -void HousePlant::setZ(float z) +void HousePlant::setPosition(const QVector3D &pos) { - m_pot->translateTransform()->setDz(z); + m_pot->transform()->setTranslation(pos); } void HousePlant::setScale(float scale) { - m_pot->scaleTransform()->setScale(scale); -} - -float HousePlant::x() const -{ - return m_pot->translateTransform()->dx(); -} - -float HousePlant::y() const -{ - return m_pot->translateTransform()->dy(); + m_pot->transform()->setScale(scale); } -float HousePlant::z() const +QVector3D HousePlant::position() const { - return m_pot->translateTransform()->dz(); + return m_pot->transform()->translation(); } float HousePlant::scale() const { - return m_pot->scaleTransform()->scale(); + return m_pot->transform()->scale(); } void HousePlant::updatePotShape() diff --git a/examples/qt3d/materials-cpp/houseplant.h b/examples/qt3d/materials-cpp/houseplant.h index a49326dbd..15854d30a 100644 --- a/examples/qt3d/materials-cpp/houseplant.h +++ b/examples/qt3d/materials-cpp/houseplant.h @@ -71,14 +71,10 @@ public: PotShape potShape() const; Plant plantType() const; - void setX(float x); - void setY(float y); - void setZ(float z); + void setPosition(const QVector3D &pos); void setScale(float scale); - float x() const; - float y() const; - float z() const; + QVector3D position() const; float scale() const; private: diff --git a/examples/qt3d/materials-cpp/main.cpp b/examples/qt3d/materials-cpp/main.cpp index 41fcf563e..db24f96fe 100644 --- a/examples/qt3d/materials-cpp/main.cpp +++ b/examples/qt3d/materials-cpp/main.cpp @@ -117,7 +117,7 @@ int main(int argc, char* argv[]) // Chest RenderableEntity *chest = new RenderableEntity(sceneRoot); - chest->scaleTransform()->setScale(0.03f); + chest->transform()->setScale(0.03f); chest->mesh()->setSource(QUrl(QStringLiteral("qrc:/assets/chest/Chest.obj"))); Qt3DRender::QDiffuseMapMaterial *diffuseMapMaterial = new Qt3DRender::QDiffuseMapMaterial(); diffuseMapMaterial->setSpecular(QColor::fromRgbF(0.2f, 0.2f, 0.2f, 1.0f)); @@ -132,8 +132,8 @@ int main(int argc, char* argv[]) // TrefoilKnot RotatingTrefoilKnot *trefoil = new RotatingTrefoilKnot(sceneRoot); - trefoil->translateTransform()->setDy(3.5); - trefoil->scaleTransform()->setScale(0.5f); + trefoil->setPosition(QVector3D(0.0f, 3.5f, 0.0f)); + trefoil->setScale(0.5f); Qt3DRender::QPhongMaterial *phongMaterial = new Qt3DRender::QPhongMaterial(); phongMaterial->setDiffuse(QColor(204, 205, 75)); // Safari Yellow #cccd4b phongMaterial->setSpecular(Qt::white); @@ -141,58 +141,58 @@ int main(int argc, char* argv[]) // Barrels Barrel *basicBarrel = new Barrel(sceneRoot); - basicBarrel->translateTransform()->setDx(8.0f); + basicBarrel->transform()->setTranslation(QVector3D(8.0f, 0.0f, 0.0f)); Barrel *rustyBarrel = new Barrel(sceneRoot); rustyBarrel->setDiffuse(Barrel::RustDiffuse); rustyBarrel->setSpecular(Barrel::RustSpecular); rustyBarrel->setBumps(Barrel::HardBumps); - rustyBarrel->translateTransform()->setDx(10.0f); + rustyBarrel->transform()->setTranslation(QVector3D(10.0f, 0.0f, 0.0f)); Barrel *blueBarrel = new Barrel(sceneRoot); blueBarrel->setDiffuse(Barrel::Blue); blueBarrel->setBumps(Barrel::MiddleBumps); - blueBarrel->translateTransform()->setDx(12.0f); + blueBarrel->transform()->setTranslation(QVector3D(12.0f, 0.0f, 0.0f)); Barrel *greenBarrel = new Barrel(sceneRoot); greenBarrel->setDiffuse(Barrel::Green); greenBarrel->setBumps(Barrel::SoftBumps); - greenBarrel->translateTransform()->setDx(14.0f); + greenBarrel->transform()->setTranslation(QVector3D(14.0f, 0.0f, 0.0f)); Barrel *stainlessBarrel = new Barrel(sceneRoot); stainlessBarrel->setDiffuse(Barrel::StainlessSteelDiffuse); stainlessBarrel->setBumps(Barrel::NoBumps); stainlessBarrel->setSpecular(Barrel::StainlessSteelSpecular); stainlessBarrel->setShininess(150.0f); - stainlessBarrel->translateTransform()->setDx(16); + stainlessBarrel->transform()->setTranslation(QVector3D(16.0f, 0.0f, 0.0f)); // Plants HousePlant *squareBamboo = new HousePlant(sceneRoot); squareBamboo->setPotShape(HousePlant::Square); - squareBamboo->setX(4.0f); + squareBamboo->setPosition(QVector3D(4.0f, 0.0f, 0.0f)); HousePlant *trianglePalm = new HousePlant(sceneRoot); trianglePalm->setPlantType(HousePlant::Palm); trianglePalm->setPotShape(HousePlant::Triangle); - trianglePalm->setZ(4.0f); + trianglePalm->setPosition(QVector3D(0.0f, 0.0f, 4.0f)); HousePlant *spherePine = new HousePlant(sceneRoot); spherePine->setPlantType(HousePlant::Pine); spherePine->setPotShape(HousePlant::Sphere); - spherePine->setX(-4.0f); + spherePine->setPosition(QVector3D(-4.0f, 0.0f, 0.0f)); HousePlant *crossSpikes = new HousePlant(sceneRoot); crossSpikes->setPlantType(HousePlant::Spikes); - crossSpikes->setZ(-4.0f); + crossSpikes->setPosition(QVector3D(0.0f, 0.0f, -4.0f)); HousePlant *crossPalm = new HousePlant(sceneRoot); crossPalm->setPlantType(HousePlant::Palm); - crossPalm->setZ(-8.0f); + crossPalm->setPosition(QVector3D(0.0f, 0.0f, -8.0f)); crossPalm->setScale(0.05f); HousePlant *crossShrub = new HousePlant(sceneRoot); crossShrub->setPlantType(HousePlant::Shrub); - crossShrub->setZ(8.0f); + crossShrub->setPosition(QVector3D(0.0f, 0.0f, 8.0f)); crossShrub->setScale(0.05f); engine.setRootEntity(sceneRoot); diff --git a/examples/qt3d/materials-cpp/planeentity.cpp b/examples/qt3d/materials-cpp/planeentity.cpp index 5faa2186e..a3785bbf0 100644 --- a/examples/qt3d/materials-cpp/planeentity.cpp +++ b/examples/qt3d/materials-cpp/planeentity.cpp @@ -45,11 +45,7 @@ PlaneEntity::PlaneEntity(Qt3DCore::QNode *parent) : Qt3DCore::QEntity(new Qt3DCore::QEntity(parent)) , m_mesh(new Qt3DRender::QPlaneMesh()) , m_transform(new Qt3DCore::QTransform()) - , m_scaleTransform(new Qt3DCore::QScaleTransform()) - , m_translateTransform(new Qt3DCore::QTranslateTransform()) { - m_transform->addTransform(m_translateTransform); - m_transform->addTransform(m_scaleTransform); addComponent(m_mesh); addComponent(m_transform); } @@ -58,16 +54,6 @@ PlaneEntity::~PlaneEntity() { } -Qt3DCore::QScaleTransform *PlaneEntity::scaleTransform() const -{ - return m_scaleTransform; -} - -Qt3DCore::QTranslateTransform *PlaneEntity::translateTransform() const -{ - return m_translateTransform; -} - Qt3DRender::QPlaneMesh *PlaneEntity::mesh() const { return m_mesh; diff --git a/examples/qt3d/materials-cpp/planeentity.h b/examples/qt3d/materials-cpp/planeentity.h index 83f6b0213..768f9da5f 100644 --- a/examples/qt3d/materials-cpp/planeentity.h +++ b/examples/qt3d/materials-cpp/planeentity.h @@ -39,8 +39,6 @@ #include #include -#include -#include #include class PlaneEntity : public Qt3DCore::QEntity @@ -49,15 +47,11 @@ public: PlaneEntity(Qt3DCore::QNode *parent = 0); ~PlaneEntity(); - Qt3DCore::QScaleTransform *scaleTransform() const; - Qt3DCore::QTranslateTransform *translateTransform() const; Qt3DRender::QPlaneMesh *mesh() const; private: Qt3DRender::QPlaneMesh *m_mesh; Qt3DCore::QTransform *m_transform; - Qt3DCore::QScaleTransform *m_scaleTransform; - Qt3DCore::QTranslateTransform *m_translateTransform; }; #endif // PLANEENTITY_H diff --git a/examples/qt3d/materials-cpp/renderableentity.cpp b/examples/qt3d/materials-cpp/renderableentity.cpp index 1d100c686..8c4bad85c 100644 --- a/examples/qt3d/materials-cpp/renderableentity.cpp +++ b/examples/qt3d/materials-cpp/renderableentity.cpp @@ -40,20 +40,14 @@ RenderableEntity::RenderableEntity(Qt3DCore::QNode *parent) : Qt3DCore::QEntity(parent) , m_mesh(new Qt3DRender::QMesh()) , m_transform(new Qt3DCore::QTransform()) - , m_rotateTransform(new Qt3DCore::QRotateTransform()) - , m_scaleTransform(new Qt3DCore::QScaleTransform()) - , m_translateTransform(new Qt3DCore::QTranslateTransform()) { - m_transform->addTransform(m_rotateTransform); - m_transform->addTransform(m_scaleTransform); - m_transform->addTransform(m_translateTransform); addComponent(m_mesh); addComponent(m_transform); } RenderableEntity::~RenderableEntity() { - + QNode::cleanup(); } Qt3DRender::QMesh *RenderableEntity::mesh() const @@ -61,17 +55,7 @@ Qt3DRender::QMesh *RenderableEntity::mesh() const return m_mesh; } -Qt3DCore::QScaleTransform *RenderableEntity::scaleTransform() const -{ - return m_scaleTransform; -} - -Qt3DCore::QTranslateTransform *RenderableEntity::translateTransform() const -{ - return m_translateTransform; -} - -Qt3DCore::QRotateTransform *RenderableEntity::rotateTransform() const +Qt3DCore::QTransform *RenderableEntity::transform() const { - return m_rotateTransform; + return m_transform; } diff --git a/examples/qt3d/materials-cpp/renderableentity.h b/examples/qt3d/materials-cpp/renderableentity.h index 8d0b75215..85499226f 100644 --- a/examples/qt3d/materials-cpp/renderableentity.h +++ b/examples/qt3d/materials-cpp/renderableentity.h @@ -51,16 +51,11 @@ public: ~RenderableEntity(); Qt3DRender::QMesh *mesh() const; - Qt3DCore::QScaleTransform *scaleTransform() const; - Qt3DCore::QTranslateTransform *translateTransform() const; - Qt3DCore::QRotateTransform *rotateTransform() const; + Qt3DCore::QTransform *transform() const; private: Qt3DRender::QMesh *m_mesh; Qt3DCore::QTransform *m_transform; - Qt3DCore::QRotateTransform *m_rotateTransform; - Qt3DCore::QScaleTransform *m_scaleTransform; - Qt3DCore::QTranslateTransform *m_translateTransform; }; #endif // RENDERABLEENTITY_H diff --git a/examples/qt3d/materials-cpp/rotatingtrefoilknot.cpp b/examples/qt3d/materials-cpp/rotatingtrefoilknot.cpp index b27abcd36..bbe7f8161 100644 --- a/examples/qt3d/materials-cpp/rotatingtrefoilknot.cpp +++ b/examples/qt3d/materials-cpp/rotatingtrefoilknot.cpp @@ -45,16 +45,16 @@ RotatingTrefoilKnot::RotatingTrefoilKnot(Qt3DCore::QNode *parent) m_thetaAnimation->setStartValue(0.0f); m_thetaAnimation->setEndValue(360.0f); m_thetaAnimation->setLoopCount(-1); - m_thetaAnimation->setTargetObject(xaxisRotateTransform()); - m_thetaAnimation->setPropertyName("angle"); + m_thetaAnimation->setTargetObject(this); + m_thetaAnimation->setPropertyName("phi"); m_thetaAnimation->start(); m_phiAnimation->setDuration(2000); m_phiAnimation->setStartValue(0.0f); m_phiAnimation->setEndValue(360.0f); m_phiAnimation->setLoopCount(-1); - m_phiAnimation->setTargetObject(yaxisRotateTransform()); - m_phiAnimation->setPropertyName("angle"); + m_phiAnimation->setTargetObject(this); + m_phiAnimation->setPropertyName("theta"); m_phiAnimation->start(); } diff --git a/examples/qt3d/materials-cpp/trefoilknot.cpp b/examples/qt3d/materials-cpp/trefoilknot.cpp index 610a972bd..e0da64987 100644 --- a/examples/qt3d/materials-cpp/trefoilknot.cpp +++ b/examples/qt3d/materials-cpp/trefoilknot.cpp @@ -40,20 +40,10 @@ TrefoilKnot::TrefoilKnot(Qt3DCore::QNode *parent) : Qt3DCore::QEntity(parent) , m_mesh(new Qt3DRender::QMesh()) , m_transform(new Qt3DCore::QTransform()) - , m_scaleTransform(new Qt3DCore::QScaleTransform()) - , m_xaxisRotation(new Qt3DCore::QRotateTransform()) - , m_yaxisRotation(new Qt3DCore::QRotateTransform()) - , m_translateTransform(new Qt3DCore::QTranslateTransform()) + , m_position() + , m_scale(1.0f) { m_mesh->setSource(QUrl("qrc:/assets/obj/trefoil.obj")); - m_xaxisRotation->setAxis(QVector3D(1.0f, 0.0f, 0.0f)); - m_yaxisRotation->setAxis(QVector3D(0.0f, 1.0f, 0.0f)); - - m_transform->addTransform(m_scaleTransform); - m_transform->addTransform(m_xaxisRotation); - m_transform->addTransform(m_yaxisRotation); - m_transform->addTransform(m_translateTransform); - addComponent(m_mesh); addComponent(m_transform); } @@ -62,22 +52,72 @@ TrefoilKnot::~TrefoilKnot() { } -Qt3DCore::QScaleTransform *TrefoilKnot::scaleTransform() const +void TrefoilKnot::updateTransform() +{ + QMatrix4x4 m; + m.translate(m_position); + m.rotate(m_phi, QVector3D(1.0f, 0.0f, 0.0f)); + m.rotate(m_phi, QVector3D(0.0f, 1.0f, 0.0f)); + m.scale(m_scale); + m_transform->setMatrix(m); +} + +float TrefoilKnot::theta() const { - return m_scaleTransform; + return m_theta; } -Qt3DCore::QRotateTransform *TrefoilKnot::xaxisRotateTransform() const +float TrefoilKnot::phi() const { - return m_xaxisRotation; + return m_phi; } -Qt3DCore::QRotateTransform *TrefoilKnot::yaxisRotateTransform() const +QVector3D TrefoilKnot::position() const { - return m_yaxisRotation; + return m_position; } -Qt3DCore::QTranslateTransform *TrefoilKnot::translateTransform() const +float TrefoilKnot::scale() const { - return m_translateTransform; + return m_scale; +} + +void TrefoilKnot::setTheta(float theta) +{ + if (m_theta == theta) + return; + + m_theta = theta; + emit thetaChanged(theta); + updateTransform(); +} + +void TrefoilKnot::setPhi(float phi) +{ + if (m_phi == phi) + return; + + m_phi = phi; + emit phiChanged(phi); + updateTransform(); +} + +void TrefoilKnot::setPosition(QVector3D position) +{ + if (m_position == position) + return; + + m_position = position; + emit positionChanged(position); + updateTransform(); +} + +void TrefoilKnot::setScale(float scale) +{ + if (m_scale == scale) + return; + + m_scale = scale; + emit scaleChanged(scale); + updateTransform(); } diff --git a/examples/qt3d/materials-cpp/trefoilknot.h b/examples/qt3d/materials-cpp/trefoilknot.h index 1ffd1baf1..ff4e921da 100644 --- a/examples/qt3d/materials-cpp/trefoilknot.h +++ b/examples/qt3d/materials-cpp/trefoilknot.h @@ -46,22 +46,43 @@ class TrefoilKnot : public Qt3DCore::QEntity { + Q_OBJECT + Q_PROPERTY(float theta READ theta WRITE setTheta NOTIFY thetaChanged) + Q_PROPERTY(float phi READ phi WRITE setPhi NOTIFY phiChanged) + Q_PROPERTY(float scale READ scale WRITE setScale NOTIFY scaleChanged) + Q_PROPERTY(QVector3D position READ position WRITE setPosition NOTIFY positionChanged) + public: explicit TrefoilKnot(Qt3DCore::QNode *parent = 0); ~TrefoilKnot(); - Qt3DCore::QScaleTransform *scaleTransform() const; - Qt3DCore::QRotateTransform *xaxisRotateTransform() const; - Qt3DCore::QRotateTransform *yaxisRotateTransform() const; - Qt3DCore::QTranslateTransform *translateTransform() const; + float theta() const; + float phi() const; + QVector3D position() const; + float scale() const; + +public slots: + void setTheta(float theta); + void setPhi(float phi); + void setPosition(QVector3D position); + void setScale(float scale); + +signals: + void thetaChanged(float theta); + void phiChanged(float phi); + void positionChanged(QVector3D position); + void scaleChanged(float scale); + +protected: + void updateTransform(); private: Qt3DRender::QMesh *m_mesh; Qt3DCore::QTransform *m_transform; - Qt3DCore::QScaleTransform *m_scaleTransform; - Qt3DCore::QRotateTransform *m_xaxisRotation; - Qt3DCore::QRotateTransform *m_yaxisRotation; - Qt3DCore::QTranslateTransform *m_translateTransform; + float m_theta; + float m_phi; + QVector3D m_position; + float m_scale; }; #endif // TREFOILKNOT_H diff --git a/examples/qt3d/materials/Barrel.qml b/examples/qt3d/materials/Barrel.qml index ba703a998..02a7e4812 100644 --- a/examples/qt3d/materials/Barrel.qml +++ b/examples/qt3d/materials/Barrel.qml @@ -44,9 +44,9 @@ Entity { property string bump: "no_bumps" property string specular: "" - property alias x: barrel.x - property alias y: barrel.y - property alias z: barrel.z + property real x: 0 + property real y: 0 + property real z: 0 property alias shininess: material.shininess property real scale: 1.0 @@ -54,6 +54,7 @@ Entity { id: barrel source: "assets/metalbarrel/metal_barrel.obj" scale: 0.03 * root.scale + position: Qt.vector3d(root.x, root.y, root.z) material: NormalDiffuseSpecularMapMaterial { id: material diff --git a/examples/qt3d/materials/Chest.qml b/examples/qt3d/materials/Chest.qml index bc3fcd838..3e361cadb 100644 --- a/examples/qt3d/materials/Chest.qml +++ b/examples/qt3d/materials/Chest.qml @@ -40,14 +40,15 @@ import Qt3D.Render 2.0 Entity { id: root - property alias x: chest.x - property alias y: chest.y - property alias z: chest.z + property real x: 0 + property real y: 0 + property real z: 0 property real scale: 1.0 RenderableEntity { id: chest source: "assets/chest/Chest.obj" + position: Qt.vector3d(root.x, root.y, root.z) scale: 0.03 * root.scale material: DiffuseMapMaterial { diff --git a/examples/qt3d/materials/HousePlant.qml b/examples/qt3d/materials/HousePlant.qml index 9ed378e6a..c8d4693d3 100644 --- a/examples/qt3d/materials/HousePlant.qml +++ b/examples/qt3d/materials/HousePlant.qml @@ -43,15 +43,16 @@ Entity { property string potShape: "cross" property string plantType: "bamboo" - property alias x: pot.x - property alias y: pot.y - property alias z: pot.z + property real x: 0 + property real y: 0 + property real z: 0 property real scale: 1.0 RenderableEntity { id: pot source: "assets/houseplants/" + root.potShape + "-pot.obj" scale: 0.03 * root.scale + position: Qt.vector3d(root.x, root.y, root.z) material: NormalDiffuseMapMaterial { diffuse: "assets/houseplants/pot.webp" diff --git a/examples/qt3d/materials/PlaneEntity.qml b/examples/qt3d/materials/PlaneEntity.qml index e02318597..ce07db08b 100644 --- a/examples/qt3d/materials/PlaneEntity.qml +++ b/examples/qt3d/materials/PlaneEntity.qml @@ -39,11 +39,8 @@ import Qt3D.Render 2.0 Entity { id: root - - property alias x: translateTransform.dx - property alias y: translateTransform.dy - property alias z: translateTransform.dz - property alias scale: scaleTransform.scale + property alias position: transform.translation + property alias scale: transform.scale property alias width: mesh.width property alias height: mesh.height property alias resolution: mesh.meshResolution @@ -51,11 +48,7 @@ Entity { components: [ transform, mesh, root.material ] - Transform { - id: transform - Translate { id: translateTransform } - Scale { id: scaleTransform } - } + Transform { id: transform } PlaneMesh { id: mesh diff --git a/examples/qt3d/materials/RenderableEntity.qml b/examples/qt3d/materials/RenderableEntity.qml index 093ba24e5..e309ec8ba 100644 --- a/examples/qt3d/materials/RenderableEntity.qml +++ b/examples/qt3d/materials/RenderableEntity.qml @@ -40,12 +40,10 @@ import Qt3D.Render 2.0 Entity { id: root - property alias x: translateTransform.dx - property alias y: translateTransform.dy - property alias z: translateTransform.dz - property alias scale: scaleTransform.scale - property alias rotationAngle: rotateTransform.angle - property alias rotationAxis: rotateTransform.axis + property vector3d position: Qt.vector3d(0, 0, 0) + property real scale: 1.0 + property real rotationAngle: 0.0 + property vector3d rotationAxis: Qt.vector3d(1, 0, 0) property alias source: mesh.source property Material material @@ -53,9 +51,16 @@ Entity { Transform { id: transform - Rotate { id: rotateTransform } - Scale { id: scaleTransform } - Translate { id: translateTransform } + matrix: { + var m = Qt.matrix4x4(1, 0, 0, 0, + 0, 1, 0, 0, + 0, 0, 1, 0, + 0, 0, 0, 1); + m.translate(root.position); + m.rotate(root.rotationAngle, root.rotationAxis); + m.scale(root.scale); + return m; + } } Mesh { diff --git a/examples/qt3d/materials/TrefoilKnot.qml b/examples/qt3d/materials/TrefoilKnot.qml index 762ae5398..9440d7a85 100644 --- a/examples/qt3d/materials/TrefoilKnot.qml +++ b/examples/qt3d/materials/TrefoilKnot.qml @@ -52,10 +52,17 @@ Entity { Transform { id: transform - Scale { scale: root.scale } - Rotate{ angle: root.theta; axis: Qt.vector3d(1.0, 0.0, 0.0) } - Rotate{ angle: root.phi; axis: Qt.vector3d(0.0, 1.0, 0.0) } - Translate { dx: root.x; dy: root.y; dz: root.z } + matrix: { + var m = Qt.matrix4x4(1, 0, 0, 0, + 0, 1, 0, 0, + 0, 0, 1, 0, + 0, 0, 0, 1); + m.translate(Qt.vector3d(root.x, root.y, root.z)); + m.rotate(phi, Qt.vector3d(0, 1, 0)); + m.rotate(theta, Qt.vector3d(1, 0, 0)); + m.scale(root.scale); + return m; + } } Mesh { diff --git a/examples/qt3d/materials/main.qml b/examples/qt3d/materials/main.qml index c41126efa..de759209b 100644 --- a/examples/qt3d/materials/main.qml +++ b/examples/qt3d/materials/main.qml @@ -34,9 +34,9 @@ ** ****************************************************************************/ +import QtQuick 2.1 as QQ2 import Qt3D.Core 2.0 import Qt3D.Render 2.0 -import QtQuick 2.1 as QQ2 Entity { id: root diff --git a/examples/qt3d/mouseinput-qml/main.qml b/examples/qt3d/mouseinput-qml/main.qml index e05359ebf..2d9a8a138 100644 --- a/examples/qt3d/mouseinput-qml/main.qml +++ b/examples/qt3d/mouseinput-qml/main.qml @@ -85,9 +85,7 @@ Entity { property real scaleFactor: 1.0 property Transform transform: Transform { - Scale { - scale: sphere1.scaleFactor - } + scale: sphere1.scaleFactor } property MouseInput mouseInput : MouseInput { diff --git a/examples/qt3d/multiviewport/QuadViewportFrameGraph.qml b/examples/qt3d/multiviewport/QuadViewportFrameGraph.qml new file mode 100644 index 000000000..2011aaf4d --- /dev/null +++ b/examples/qt3d/multiviewport/QuadViewportFrameGraph.qml @@ -0,0 +1,80 @@ +/**************************************************************************** +** +** 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 + +FrameGraph { + id: quadViewportFrameGraph + + property alias topLeftCamera: cameraSelectorTopLeftViewport.camera; + property alias topRightCamera: cameraSelectorTopRightViewport.camera; + property alias bottomLeftCamera: cameraSelectorBottomLeftViewport.camera; + property alias bottomRightCamera: cameraSelectorBottomRightViewport.camera; + + Viewport { + id: mainViewport + rect: Qt.rect(0, 0, 1, 1) + + ClearBuffer { + buffers: ClearBuffer.ColorDepthBuffer + } + + Viewport { + id: topLeftViewport + rect: Qt.rect(0, 0, 0.5, 0.5) + CameraSelector { id: cameraSelectorTopLeftViewport } + } + + Viewport { + id: topRightViewport + rect: Qt.rect(0.5, 0, 0.5, 0.5) + CameraSelector { id: cameraSelectorTopRightViewport } + } + + Viewport { + id: bottomLeftViewport + rect: Qt.rect(0, 0.5, 0.5, 0.5) + CameraSelector { id: cameraSelectorBottomLeftViewport } + } + + Viewport { + id: bottomRightViewport + rect: Qt.rect(0.5, 0.5, 0.5, 0.5) + CameraSelector { id: cameraSelectorBottomRightViewport } + } + } +} diff --git a/examples/qt3d/multiviewport/SimpleCamera.qml b/examples/qt3d/multiviewport/SimpleCamera.qml new file mode 100644 index 000000000..cb570eb7b --- /dev/null +++ b/examples/qt3d/multiviewport/SimpleCamera.qml @@ -0,0 +1,61 @@ +/**************************************************************************** +** +** 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 position: Qt.vector3d(0.0, 0.0, 10.0) + property vector3d viewCenter: Qt.vector3d(0.0, 0.0, 0.0) + property vector3d upVector: Qt.vector3d(0.0, 1.0, 0.0) + property CameraLens lens: null + + components: [lens, transform] + + 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.position, root.viewCenter, root.upVector); + return m; + } + } +} diff --git a/examples/qt3d/multiviewport/main.qml b/examples/qt3d/multiviewport/main.qml index 69d6b98ca..9c4626eb4 100644 --- a/examples/qt3d/multiviewport/main.qml +++ b/examples/qt3d/multiviewport/main.qml @@ -38,150 +38,98 @@ import QtQuick 2.0 import Qt3D.Core 2.0 import Qt3D.Render 2.0 - Entity { - id : rootNode + id: rootNode + components: [quadViewportFrameGraph] - CameraLens { - id : cameraLens - projectionType: CameraLens.PerspectiveProjection - fieldOfView: 45 - aspectRatio: 16/9 - nearPlane : 0.01 - farPlane : 1000.0 - } // cameraLens + QuadViewportFrameGraph { + id: quadViewportFrameGraph + topLeftCamera: cameraSet.cameras[0] + topRightCamera: cameraSet.cameras[1] + bottomLeftCamera: cameraSet.cameras[2] + bottomRightCamera: cameraSet.cameras[3] + } Entity { - id : sceneRoot - components: [frameGraph] - property real rotationAngle : 0 - - SequentialAnimation { - running : true - loops: Animation.Infinite - NumberAnimation {target : sceneRoot; property : "rotationAngle"; to : 360; duration : 2000;} - } - - property var cameras : [cameraViewport1, cameraViewport2, cameraViewport3, cameraViewport4] + id: cameraSet + property var cameras: [camera1, camera2, camera3, camera4] Timer { - running : true - interval : 10000 - repeat : true - property int count : 0 - onTriggered: - { - cameraSelectorTopLeftViewport.camera = sceneRoot.cameras[count++ % 4]; - cameraSelectorTopRightViewport.camera = sceneRoot.cameras[count % 4]; - cameraSelectorBottomLeftViewport.camera = sceneRoot.cameras[(count + 1) % 4]; - cameraSelectorBottomRightViewport.camera = sceneRoot.cameras[(count + 2) % 4]; + running: true + interval: 10000 + repeat: true + property int count: 0 + onTriggered: { + quadViewportFrameGraph.topLeftCamera = cameraSet.cameras[count++ % 4]; + quadViewportFrameGraph.topRightCamera = cameraSet.cameras[count % 4]; + quadViewportFrameGraph.bottomLeftCamera = cameraSet.cameras[(count + 1) % 4]; + quadViewportFrameGraph.bottomRightCamera = cameraSet.cameras[(count + 2) % 4]; } } - FrameGraph { - id : frameGraph - - Viewport { - id : mainViewport - rect: Qt.rect(0, 0, 1, 1) - - ClearBuffer { - buffers : ClearBuffer.ColorDepthBuffer - } - - Viewport { - id : topLeftViewport - rect : Qt.rect(0, 0, 0.5, 0.5) - CameraSelector {id : cameraSelectorTopLeftViewport; camera : sceneRoot.cameras[0]} - } - - Viewport { - id : topRightViewport - rect : Qt.rect(0.5, 0, 0.5, 0.5) - CameraSelector {id : cameraSelectorTopRightViewport; camera : sceneRoot.cameras[1]} - } - - Viewport { - id : bottomLeftViewport - rect : Qt.rect(0, 0.5, 0.5, 0.5) - CameraSelector {id : cameraSelectorBottomLeftViewport; camera : sceneRoot.cameras[2]} - } + CameraLens { + id : cameraLens + projectionType: CameraLens.PerspectiveProjection + fieldOfView: 45 + aspectRatio: 16/9 + nearPlane : 0.01 + farPlane : 1000.0 + } - Viewport { - id : bottomRightViewport - rect : Qt.rect(0.5, 0.5, 0.5, 0.5) - CameraSelector {id : cameraSelectorBottomRightViewport; camera : sceneRoot.cameras[3]} - } + SimpleCamera { + id: camera1 + lens: cameraLens + position: Qt.vector3d( 0.0, 0.0, -20.0 ) + } - } // mainViewport - } // frameGraph + SimpleCamera { + id: camera2 + lens: cameraLens + position: Qt.vector3d( 0.0, 0.0, 20.0 ) + viewCenter: Qt.vector3d( -3.0, 0.0, 10.0 ) + } - Entity { - id : cameraViewport1 - property Transform transform : Transform { - LookAt { - position: Qt.vector3d( 0.0, 0.0, -20.0 ) - upVector: Qt.vector3d( 0.0, 1.0, 0.0 ) - viewCenter: Qt.vector3d( 0.0, 0.0, 0.0 ) - } - } - components : [cameraLens, transform] + SimpleCamera { + id: camera3 + lens: cameraLens + position: Qt.vector3d( 0.0, 30.0, 30.0 ) + viewCenter: Qt.vector3d( -5.0, -20.0, -10.0 ) } - Entity { - id : cameraViewport2 - property Transform transform : Transform { - Rotate { - angle : sceneRoot.rotationAngle - axis : Qt.vector3d(0, 1, 0) - } - LookAt { - position: Qt.vector3d( 0.0, 0.0, 20.0 ) - upVector: Qt.vector3d( 0.0, 1.0, 0.0 ) - viewCenter: Qt.vector3d( -3.0, 0.0, 10.0 ) - } - } - components : [cameraLens, transform] + SimpleCamera { + id: camera4 + lens: cameraLens + position: Qt.vector3d( 0.0, 15.0, 20.0 ) + viewCenter: Qt.vector3d( 0.0, -15.0, -20.0 ) } + } - Entity { - id : cameraViewport3 - property Transform transform : Transform { - LookAt { - position: Qt.vector3d( 0.0, 30.0, 30.0 ) - upVector: Qt.vector3d( 0.0, 1.0, 0.0 ) - viewCenter: Qt.vector3d( -5.0, -20.0, -10.0 ) - } - } - components : [cameraLens, transform] + Entity { + id: sceneRoot + property real rotationAngle: 0 + + SequentialAnimation { + running: true + loops: Animation.Infinite + NumberAnimation { target: sceneRoot; property: "rotationAngle"; to: 360; duration: 2000; } } Entity { - components : [ + components: [ Transform { - Rotate { - angle : -sceneRoot.rotationAngle - axis : Qt.vector3d(0, 0, 1) + matrix: { + var m = Qt.matrix4x4(1, 0, 0, 0, + 0, 1, 0, 0, + 0, 0, 1, 0, + 0, 0, 0, 1); + m.rotate(-sceneRoot.rotationAngle, Qt.vector3d(0, 0, 1)); + return m; } }, SceneLoader { source: "qrc:/assets/test_scene.dae" - }] - } - - Entity { - id : cameraViewport4 - property Transform transform : Transform { - LookAt { - position: Qt.vector3d( 0.0, 15.0, 20.0 ) - upVector: Qt.vector3d( 0.0, 0.0, 1.0 ) - viewCenter: Qt.vector3d( 0.0, -15.0, -20.0 ) } - } - components : [cameraLens, transform] + ] } - - } // sceneRoot - } // rootNode diff --git a/examples/qt3d/multiviewport/multiviewport.qrc b/examples/qt3d/multiviewport/multiviewport.qrc index 5f6483ac3..bd06fb169 100644 --- a/examples/qt3d/multiviewport/multiviewport.qrc +++ b/examples/qt3d/multiviewport/multiviewport.qrc @@ -1,5 +1,7 @@ main.qml + SimpleCamera.qml + QuadViewportFrameGraph.qml diff --git a/examples/qt3d/picking-qml/main.qml b/examples/qt3d/picking-qml/main.qml index 644e0f306..47bb97192 100644 --- a/examples/qt3d/picking-qml/main.qml +++ b/examples/qt3d/picking-qml/main.qml @@ -76,12 +76,8 @@ Entity { QQ2.Behavior on scaleFactor { QQ2.NumberAnimation { duration: 150; easing.type: QQ2.Easing.InQuad } } property Transform transform: Transform { - Scale { - scale: sphere1.scaleFactor - } - Translate { - dx: -8 - } + scale: sphere1.scaleFactor + translation: Qt.vector3d(-8, 0, 0) } property Material material: PhongMaterial { @@ -99,8 +95,6 @@ Entity { onExited: sphere1.material.ambient = "green" onClicked: console.log("Clicked Sphere 1") - - pickAttribute: sphereMesh.geometry.positionAttribute } components: [sphereMesh, material, transform, objectPicker] @@ -114,9 +108,7 @@ Entity { } property Transform transform: Transform { - Scale { - scale: 1.5 - } + scale: 1.5 } property ObjectPicker objectPicker: ObjectPicker { @@ -126,8 +118,6 @@ Entity { onReleased: sphere2.material.diffuse = "red" onClicked: console.log("Clicked Sphere 2") - - pickAttribute: sphereMesh.geometry.positionAttribute } components: [sphereMesh, material, transform, objectPicker] @@ -145,12 +135,8 @@ Entity { QQ2.Behavior on scaleFactor { QQ2.NumberAnimation { duration: 200; easing.type: QQ2.Easing.InQuad } } property Transform transform: Transform { - Scale { - scale: sphere3.scaleFactor - } - Translate { - dx: 8 - } + scale: sphere3.scaleFactor + translation: Qt.vector3d(8, 0, 0) } property ObjectPicker objectPicker: ObjectPicker { @@ -162,8 +148,6 @@ Entity { onExited: sphere3.material.ambient = "white" onClicked: console.log("Clicked Sphere 3") - - pickAttribute: sphereMesh.geometry.positionAttribute } components: [sphereMesh, material, transform, objectPicker] diff --git a/examples/qt3d/planets-qml/SolarSystem.qml b/examples/qt3d/planets-qml/SolarSystem.qml index bef982803..dc7437028 100644 --- a/examples/qt3d/planets-qml/SolarSystem.qml +++ b/examples/qt3d/planets-qml/SolarSystem.qml @@ -34,9 +34,9 @@ ** ****************************************************************************/ +import QtQuick 2.0 as QQ2 import Qt3D.Core 2.0 import Qt3D.Render 2.0 -import QtQuick 2.0 as QQ2 import "planets.js" as Planets @@ -467,12 +467,8 @@ Entity { } property Transform transformStarfield: Transform { - Scale { - scale: 8500000 - } - Translate { - translation: Qt.vector3d(0, 0, 0) - } + scale: 8500000 + translation: Qt.vector3d(0, 0, 0) } components: [ starfield, materialStarfield, transformStarfield ] @@ -499,19 +495,16 @@ Entity { } property Transform transformSun: Transform { - Scale { - scale: sun.r - } - Rotate { - axis: rollAxis - angle: sun.roll - } - Rotate { - axis: tiltAxis - angle: sun.tilt - } - Translate { - translation: Qt.vector3d(sun.x, sun.y, sun.z) + matrix: { + var m = Qt.matrix4x4(1, 0, 0, 0, + 0, 1, 0, 0, + 0, 0, 1, 0, + 0, 0, 0, 1); + m.translate(Qt.vector3d(sun.x, sun.y, sun.z)); + m.rotate(sun.tilt, tiltAxis); + m.rotate(sun.roll, rollAxis); + m.scale(sun.r); + return m; } } @@ -542,19 +535,16 @@ Entity { } property Transform transformMercury: Transform { - Scale { - scale: mercury.r - } - Rotate { - axis: rollAxis - angle: mercury.roll - } - Rotate { - axis: tiltAxis - angle: mercury.tilt - } - Translate { - translation: Qt.vector3d(mercury.x, mercury.y, mercury.z) + matrix: { + var m = Qt.matrix4x4(1, 0, 0, 0, + 0, 1, 0, 0, + 0, 0, 1, 0, + 0, 0, 0, 1); + m.translate(Qt.vector3d(mercury.x, mercury.y, mercury.z)); + m.rotate(mercury.tilt, tiltAxis); + m.rotate(mercury.roll, rollAxis); + m.scale(mercury.r); + return m; } } @@ -581,19 +571,16 @@ Entity { } property Transform transformVenus: Transform { - Scale { - scale: venus.r - } - Rotate { - axis: rollAxis - angle: venus.roll - } - Rotate { - axis: tiltAxis - angle: venus.tilt - } - Translate { - translation: Qt.vector3d(venus.x, venus.y, venus.z) + matrix: { + var m = Qt.matrix4x4(1, 0, 0, 0, + 0, 1, 0, 0, + 0, 0, 1, 0, + 0, 0, 0, 1); + m.translate(Qt.vector3d(venus.x, venus.y, venus.z)); + m.rotate(venus.tilt, tiltAxis); + m.rotate(venus.roll, rollAxis); + m.scale(venus.r); + return m; } } @@ -621,20 +608,16 @@ Entity { } property Transform transformEarth: Transform { - Scale { - scale: earth.r - } - Rotate { - axis: rollAxis - angle: earth.roll - } - Rotate { - axis: tiltAxis - angle: earth.tilt - } - Translate { - id: translationEarth - translation: Qt.vector3d(earth.x, earth.y, earth.z) + matrix: { + var m = Qt.matrix4x4(1, 0, 0, 0, + 0, 1, 0, 0, + 0, 0, 1, 0, + 0, 0, 0, 1); + m.translate(Qt.vector3d(earth.x, earth.y, earth.z)); + m.rotate(earth.tilt, tiltAxis); + m.rotate(earth.roll, rollAxis); + m.scale(earth.r); + return m; } } @@ -662,19 +645,16 @@ Entity { } property Transform transformEarthClouds: Transform { - Scale { - scale: earthClouds.r - } - Rotate { - axis: rollAxis - angle: earth.roll / 1.2 - } - Rotate { - axis: tiltAxis - angle: earth.tilt - } - Translate { - translation: translationEarth.translation + matrix: { + var m = Qt.matrix4x4(1, 0, 0, 0, + 0, 1, 0, 0, + 0, 0, 1, 0, + 0, 0, 0, 1); + m.translate(Qt.vector3d(earthClouds.x, earthClouds.y, earthClouds.z)); + m.rotate(earthClouds.tilt, tiltAxis); + m.rotate(earthClouds.roll / 1.2, rollAxis); + m.scale(earthClouds.r); + return m; } } @@ -701,19 +681,16 @@ Entity { } property Transform transformMoon: Transform { - Scale { - scale: moon.r - } - Rotate { - axis: rollAxis - angle: moon.roll - } - Rotate { - axis: tiltAxis - angle: moon.tilt - } - Translate { - translation: Qt.vector3d(moon.x, moon.y, moon.z) + matrix: { + var m = Qt.matrix4x4(1, 0, 0, 0, + 0, 1, 0, 0, + 0, 0, 1, 0, + 0, 0, 0, 1); + m.translate(Qt.vector3d(moon.x, moon.y, moon.z)); + m.rotate(moon.tilt, tiltAxis); + m.rotate(moon.roll, rollAxis); + m.scale(moon.r); + return m; } } @@ -740,19 +717,16 @@ Entity { } property Transform transformMars: Transform { - Scale { - scale: mars.r - } - Rotate { - axis: rollAxis - angle: mars.roll - } - Rotate { - axis: tiltAxis - angle: mars.tilt - } - Translate { - translation: Qt.vector3d(mars.x, mars.y, mars.z) + matrix: { + var m = Qt.matrix4x4(1, 0, 0, 0, + 0, 1, 0, 0, + 0, 0, 1, 0, + 0, 0, 0, 1); + m.translate(Qt.vector3d(mars.x, mars.y, mars.z)); + m.rotate(mars.tilt, tiltAxis); + m.rotate(mars.roll, rollAxis); + m.scale(mars.r); + return m; } } @@ -778,19 +752,16 @@ Entity { } property Transform transformJupiter: Transform { - Scale { - scale: jupiter.r - } - Rotate { - axis: rollAxis - angle: jupiter.roll - } - Rotate { - axis: tiltAxis - angle: jupiter.tilt - } - Translate { - translation: Qt.vector3d(jupiter.x, jupiter.y, jupiter.z) + matrix: { + var m = Qt.matrix4x4(1, 0, 0, 0, + 0, 1, 0, 0, + 0, 0, 1, 0, + 0, 0, 0, 1); + m.translate(Qt.vector3d(jupiter.x, jupiter.y, jupiter.z)); + m.rotate(jupiter.tilt, tiltAxis); + m.rotate(jupiter.roll, rollAxis); + m.scale(jupiter.r); + return m; } } @@ -816,20 +787,16 @@ Entity { } property Transform transformSaturn: Transform { - Scale { - scale: saturn.r - } - Rotate { - axis: rollAxis - angle: saturn.roll - } - Rotate { - axis: tiltAxis - angle: saturn.tilt - } - Translate { - id: translationSaturn - translation: Qt.vector3d(saturn.x, saturn.y, saturn.z) + matrix: { + var m = Qt.matrix4x4(1, 0, 0, 0, + 0, 1, 0, 0, + 0, 0, 1, 0, + 0, 0, 0, 1); + m.translate(Qt.vector3d(saturn.x, saturn.y, saturn.z)); + m.rotate(saturn.tilt, tiltAxis); + m.rotate(saturn.roll, rollAxis); + m.scale(saturn.r); + return m; } } @@ -857,19 +824,16 @@ Entity { } property Transform transformSaturnRing: Transform { - Scale { - scale: (saturnRing.innerRadius + saturnRing.outerRadius) / 1.75 - } - Rotate { - axis: rollAxis - angle: saturn.roll / 10 - } - Rotate { - axis: tiltAxis - angle: saturn.tilt - } - Translate { - translation: translationSaturn.translation + matrix: { + var m = Qt.matrix4x4(1, 0, 0, 0, + 0, 1, 0, 0, + 0, 0, 1, 0, + 0, 0, 0, 1); + m.translate(Qt.vector3d(saturn.x, saturn.y, saturn.z)); + m.rotate(saturn.tilt, tiltAxis); + m.rotate(saturn.roll / 10, rollAxis); + m.scale((saturnRing.innerRadius + saturnRing.outerRadius) / 1.75); + return m; } } @@ -895,20 +859,16 @@ Entity { } property Transform transformUranus: Transform { - Scale { - scale: uranus.r - } - Rotate { - axis: rollAxis - angle: uranus.roll - } - Rotate { - axis: tiltAxis - angle: uranus.tilt - } - Translate { - id: translationUranus - translation: Qt.vector3d(uranus.x, uranus.y, uranus.z) + matrix: { + var m = Qt.matrix4x4(1, 0, 0, 0, + 0, 1, 0, 0, + 0, 0, 1, 0, + 0, 0, 0, 1); + m.translate(Qt.vector3d(uranus.x, uranus.y, uranus.z)); + m.rotate(uranus.tilt, tiltAxis); + m.rotate(uranus.roll, rollAxis); + m.scale(uranus.r); + return m; } } @@ -936,19 +896,16 @@ Entity { } property Transform transformUranusRing: Transform { - Scale { - scale: (uranusRing.innerRadius + uranusRing.outerRadius) / 1.75 - } - Rotate { - axis: rollAxis - angle: uranus.roll / 10 - } - Rotate { - axis: tiltAxis - angle: uranus.tilt - } - Translate { - translation: translationUranus.translation + matrix: { + var m = Qt.matrix4x4(1, 0, 0, 0, + 0, 1, 0, 0, + 0, 0, 1, 0, + 0, 0, 0, 1); + m.translate(Qt.vector3d(uranus.x, uranus.y, uranus.z)); + m.rotate(uranus.tilt, tiltAxis); + m.rotate(uranus.roll / 10, rollAxis); + m.scale((uranusRing.innerRadius + uranusRing.outerRadius) / 1.75); + return m; } } @@ -974,19 +931,16 @@ Entity { } property Transform transformNeptune: Transform { - Scale { - scale: neptune.r - } - Rotate { - axis: rollAxis - angle: neptune.roll - } - Rotate { - axis: tiltAxis - angle: neptune.tilt - } - Translate { - translation: Qt.vector3d(neptune.x, neptune.y, neptune.z) + matrix: { + var m = Qt.matrix4x4(1, 0, 0, 0, + 0, 1, 0, 0, + 0, 0, 1, 0, + 0, 0, 0, 1); + m.translate(Qt.vector3d(neptune.x, neptune.y, neptune.z)); + m.rotate(neptune.tilt, tiltAxis); + m.rotate(neptune.roll, rollAxis); + m.scale(neptune.r); + return m; } } diff --git a/examples/qt3d/plasma/main.qml b/examples/qt3d/plasma/main.qml index 1c4cb45ea..a15287b41 100644 --- a/examples/qt3d/plasma/main.qml +++ b/examples/qt3d/plasma/main.qml @@ -38,14 +38,12 @@ import Qt3D.Core 2.0 import Qt3D.Render 2.0 Entity { - components: FrameGraph { ForwardRenderer {} } - Entity { - components : [ + components: [ PlaneMesh { width: 2.0 height: 2.0 @@ -53,14 +51,17 @@ Entity { }, Transform { // Rotate the plane so that it faces us - Rotate { - axis: Qt.vector3d(1.0, 0.0, 0.0) - angle: 90 + matrix: { + var m = Qt.matrix4x4(1, 0, 0, 0, + 0, 1, 0, 0, + 0, 0, 1, 0, + 0, 0, 0, 1); + m.rotate(90, Qt.vector3d(1.0, 0.0, 0.0)); + return m; } }, - Material - { + Material { parameters: Parameter { name: "winsize"; value: Qt.vector2d(_window.width, _window.height) } effect: Effect { @@ -77,7 +78,6 @@ Entity { shaderProgram: ShaderProgram { vertexShaderCode: loadSource("qrc:/plasma.vert") fragmentShaderCode: loadSource("qrc:/plasma.frag") - } } } diff --git a/examples/qt3d/playground-qml/DetailView.qml b/examples/qt3d/playground-qml/DetailView.qml index aa442278b..d3389bbd0 100644 --- a/examples/qt3d/playground-qml/DetailView.qml +++ b/examples/qt3d/playground-qml/DetailView.qml @@ -37,26 +37,15 @@ import Qt3D.Core 2.0 import Qt3D.Render 2.0 - Entity { - - property Entity camera : Entity { - components : [ - CameraLens { - projectionType: CameraLens.PerspectiveProjection - fieldOfView: 60 - aspectRatio: 16/9 - nearPlane: 0.001 - farPlane: 10000.0 - }, - Transform { - LookAt { - position: Qt.vector3d( 10.0, 10.0, -25.0 ) - upVector: Qt.vector3d( 0.0, 1.0, 0.0 ) - viewCenter: Qt.vector3d( 0.0, 0.0, 10.0 ) - } - } - ] + property Entity camera: Camera { + projectionType: CameraLens.PerspectiveProjection + fieldOfView: 60 + aspectRatio: 16/9 + nearPlane: 0.001 + farPlane: 10000.0 + position: Qt.vector3d( 10.0, 10.0, -25.0 ) + upVector: Qt.vector3d( 0.0, 1.0, 0.0 ) + viewCenter: Qt.vector3d( 0.0, 0.0, 10.0 ) } - } diff --git a/examples/qt3d/playground-qml/MainView.qml b/examples/qt3d/playground-qml/MainView.qml index 9cfab2900..3333c28fe 100644 --- a/examples/qt3d/playground-qml/MainView.qml +++ b/examples/qt3d/playground-qml/MainView.qml @@ -85,16 +85,15 @@ Entity { mesh: ballMesh material: animatedMaterial transform: Transform { - Translate { - dx: 0; dy: -10; dz : 25 - QQ2.SequentialAnimation on dz { - running : true - loops: QQ2.Animation.Infinite - QQ2.NumberAnimation { to : -1000; duration : 5000 } - QQ2.NumberAnimation { to : 1000; duration : 3000 } - } + property real z: 25 + translation: Qt.vector3d( 0, -10, z ) + scale: 0.3 + QQ2.SequentialAnimation on z { + running: true + loops: QQ2.Animation.Infinite + QQ2.NumberAnimation { to: -1000; duration: 5000 } + QQ2.NumberAnimation { to: 1000; duration: 3000 } } - Scale {scale : 0.3} } } @@ -102,16 +101,15 @@ Entity { mesh: cubeMesh material: animatedMaterial transform: Transform { - Translate { - dx: 0; dy: -10; dz : 25 - QQ2.SequentialAnimation on dx { - running : true - loops: QQ2.Animation.Infinite - QQ2.NumberAnimation { to : -100; duration : 10000 } - QQ2.NumberAnimation { to : 100; duration : 5000 } - } + property real x: 0 + translation: Qt.vector3d( x, -10, 25 ) + scale: 0.3 + QQ2.SequentialAnimation on x { + running : true + loops: QQ2.Animation.Infinite + QQ2.NumberAnimation { to : -100; duration : 10000 } + QQ2.NumberAnimation { to : 100; duration : 5000 } } - Scale {scale : 0.3} } } } diff --git a/examples/qt3d/playground-qml/MyForwardRenderer.qml b/examples/qt3d/playground-qml/MyForwardRenderer.qml index 8ed767e84..51e9c9cf0 100644 --- a/examples/qt3d/playground-qml/MyForwardRenderer.qml +++ b/examples/qt3d/playground-qml/MyForwardRenderer.qml @@ -49,8 +49,8 @@ TechniqueFilter { // Using this as a building block for a larger framegraph would // allow a scene to be rendered multiple times to different // viewports using different cameras for e.g. - property alias mainCameraViewport: mainCamera.camera - property alias detailCameraViewport: detailCamera.camera + property alias mainCamera: mainCameraSelector.camera + property alias detailCamera: detailCameraSelector.camera property alias layerFilters: layerFilter.layers property alias clearColor: viewport.clearColor @@ -68,7 +68,7 @@ TechniqueFilter { rect: Qt.rect(0.0, 0, 1.0, 1.0) CameraSelector { - id : mainCamera + id: mainCameraSelector LayerFilter { id: layerFilter @@ -81,12 +81,14 @@ TechniqueFilter { } Viewport { - id : detailViewport + id: detailViewport rect: Qt.rect(0.75, 0.0, 0.25, 0.25) CameraSelector { - id: detailCamera - RenderPassFilter { includes : [Annotation {name : "Name"; value : "ColorMaterial";}] } + id: detailCameraSelector + RenderPassFilter { + includes: [ Annotation { name: "Name"; value: "ColorMaterial"; } ] + } } } } diff --git a/examples/qt3d/playground-qml/main.qml b/examples/qt3d/playground-qml/main.qml index 86cb0f03d..852fe03c4 100644 --- a/examples/qt3d/playground-qml/main.qml +++ b/examples/qt3d/playground-qml/main.qml @@ -47,8 +47,8 @@ Entity { FrameGraph { id : external_forward_renderer activeFrameGraph: MyForwardRenderer { - mainCameraViewport: mainView.camera - detailCameraViewport: detailCamera ? detailView.camera : mainView.camera + mainCamera: mainView.camera + detailCamera: root.detailCamera ? detailView.camera : mainView.camera clearColor: "black" } } @@ -59,7 +59,7 @@ Entity { id: keyboardInput controller: keyboardController focus: true - onTabPressed: detailCamera = !detailCamera; + onTabPressed: root.detailCamera = !root.detailCamera; } components: [external_forward_renderer, keyboardInput] diff --git a/examples/qt3d/scene3d-loader/AnimatedEntity.qml b/examples/qt3d/scene3d-loader/AnimatedEntity.qml index bf73d6df4..5431db8ea 100644 --- a/examples/qt3d/scene3d-loader/AnimatedEntity.qml +++ b/examples/qt3d/scene3d-loader/AnimatedEntity.qml @@ -36,6 +36,7 @@ import Qt3D.Core 2.0 import Qt3D.Render 2.0 + import QtQuick 2.0 as QQ2 @@ -63,7 +64,7 @@ Entity { activeFrameGraph: Viewport { id: viewport rect: Qt.rect(0.0, 0.0, 1.0, 1.0) // From Top Left - clearColor: Qt.rgba(0, 0.5, 1, 1) + clearColor: "transparent" CameraSelector { id : cameraSelector @@ -91,10 +92,14 @@ Entity { Transform { id: torusTransform - Scale { scale3D: Qt.vector3d(1.5, 1, 0.5) } - Rotate { - angle: 45 - axis: Qt.vector3d(1, 0, 0) + matrix: { + var m = Qt.matrix4x4(1, 0, 0, 0, + 0, 1, 0, 0, + 0, 0, 1, 0, + 0, 0, 0, 1); + m.rotate(45, Qt.vector3d(1, 0, 0)) + m.scale(Qt.vector3d(1.5, 1, 0.5)); + return m; } } @@ -110,19 +115,21 @@ Entity { Transform { id: sphereTransform - Translate { - translation: Qt.vector3d(20, 0, 0) - } - - Rotate { - id: sphereRotation - axis: Qt.vector3d(0, 1, 0) + property real userAngle: 0.0 + matrix: { + var m = Qt.matrix4x4(1, 0, 0, 0, + 0, 1, 0, 0, + 0, 0, 1, 0, + 0, 0, 0, 1); + m.translate(Qt.vector3d(20, 0, 0)); + m.rotate(userAngle, Qt.vector3d(0, 1, 0)) + return m; } } QQ2.NumberAnimation { - target: sphereRotation - property: "angle" + target: sphereTransform + property: "userAngle" duration: 10000 from: 0 to: 360 diff --git a/examples/qt3d/scene3d-loader/Scene2.qml b/examples/qt3d/scene3d-loader/Scene2.qml index 34e339395..8280b1bb3 100644 --- a/examples/qt3d/scene3d-loader/Scene2.qml +++ b/examples/qt3d/scene3d-loader/Scene2.qml @@ -82,10 +82,14 @@ Scene3D { Transform { id: transform - Scale { scale3D: Qt.vector3d(1.5, 1, 0.5) } - Rotate { - angle: 45 - axis: Qt.vector3d(1, 0, 0) + matrix: { + var m = Qt.matrix4x4(1, 0, 0, 0, + 0, 1, 0, 0, + 0, 0, 1, 0, + 0, 0, 0, 1); + m.rotate(45, Qt.vector3d(1, 0, 0)) + m.scale(Qt.vector3d(1.5, 1, 0.5)); + return m; } } diff --git a/examples/qt3d/scene3d/AnimatedEntity.qml b/examples/qt3d/scene3d/AnimatedEntity.qml index b0070db68..5431db8ea 100644 --- a/examples/qt3d/scene3d/AnimatedEntity.qml +++ b/examples/qt3d/scene3d/AnimatedEntity.qml @@ -92,10 +92,14 @@ Entity { Transform { id: torusTransform - Scale { scale3D: Qt.vector3d(1.5, 1, 0.5) } - Rotate { - angle: 45 - axis: Qt.vector3d(1, 0, 0) + matrix: { + var m = Qt.matrix4x4(1, 0, 0, 0, + 0, 1, 0, 0, + 0, 0, 1, 0, + 0, 0, 0, 1); + m.rotate(45, Qt.vector3d(1, 0, 0)) + m.scale(Qt.vector3d(1.5, 1, 0.5)); + return m; } } @@ -111,18 +115,21 @@ Entity { Transform { id: sphereTransform - Translate { - translation: Qt.vector3d(20, 0, 0) - } - - Rotate { - id: sphereRotation - axis: Qt.vector3d(0, 1, 0) + property real userAngle: 0.0 + matrix: { + var m = Qt.matrix4x4(1, 0, 0, 0, + 0, 1, 0, 0, + 0, 0, 1, 0, + 0, 0, 0, 1); + m.translate(Qt.vector3d(20, 0, 0)); + m.rotate(userAngle, Qt.vector3d(0, 1, 0)) + return m; } } + QQ2.NumberAnimation { - target: sphereRotation - property: "angle" + target: sphereTransform + property: "userAngle" duration: 10000 from: 0 to: 360 diff --git a/examples/qt3d/shadow-map-qml/AdsMaterial.qml b/examples/qt3d/shadow-map-qml/AdsMaterial.qml index 4e02e23e6..184189074 100644 --- a/examples/qt3d/shadow-map-qml/AdsMaterial.qml +++ b/examples/qt3d/shadow-map-qml/AdsMaterial.qml @@ -34,9 +34,9 @@ ** ****************************************************************************/ +import QtQuick 2.1 import Qt3D.Core 2.0 import Qt3D.Render 2.0 -import QtQuick 2.1 Material { id: root diff --git a/examples/qt3d/shadow-map-qml/GroundPlane.qml b/examples/qt3d/shadow-map-qml/GroundPlane.qml index 6ccef86ae..3cade62b7 100644 --- a/examples/qt3d/shadow-map-qml/GroundPlane.qml +++ b/examples/qt3d/shadow-map-qml/GroundPlane.qml @@ -50,9 +50,7 @@ Entity { Transform { id: groundTransform - Translate { - dy: -5 - } + translation: Qt.vector3d(0, -5, 0) } components: [ diff --git a/examples/qt3d/shadow-map-qml/Light.qml b/examples/qt3d/shadow-map-qml/Light.qml index 493cf6acf..a0e0306b0 100644 --- a/examples/qt3d/shadow-map-qml/Light.qml +++ b/examples/qt3d/shadow-map-qml/Light.qml @@ -44,7 +44,7 @@ Entity { property vector3d lightIntensity: Qt.vector3d(1.0, 1.0, 1.0) readonly property Camera lightCamera: lightCamera - readonly property matrix4x4 lightViewProjection: lightCamera.projectionMatrix.times(lightCamera.matrix) + readonly property matrix4x4 lightViewProjection: lightCamera.projectionMatrix.times(lightCamera.viewMatrix) Camera { id: lightCamera diff --git a/examples/qt3d/shadow-map-qml/ShadowMapFrameGraph.qml b/examples/qt3d/shadow-map-qml/ShadowMapFrameGraph.qml index 2038d9f9c..63cbfae82 100644 --- a/examples/qt3d/shadow-map-qml/ShadowMapFrameGraph.qml +++ b/examples/qt3d/shadow-map-qml/ShadowMapFrameGraph.qml @@ -34,9 +34,9 @@ ** ****************************************************************************/ +import QtQuick 2.2 as QQ2 import Qt3D.Core 2.0 import Qt3D.Render 2.0 -import QtQuick 2.2 as QQ2 FrameGraph { id: root diff --git a/examples/qt3d/shadow-map-qml/Toyplane.qml b/examples/qt3d/shadow-map-qml/Toyplane.qml index 3bc1c0d53..1f883f2bb 100644 --- a/examples/qt3d/shadow-map-qml/Toyplane.qml +++ b/examples/qt3d/shadow-map-qml/Toyplane.qml @@ -34,9 +34,9 @@ ** ****************************************************************************/ +import QtQuick 2.1 as QQ2 import Qt3D.Core 2.0 import Qt3D.Render 2.0 -import QtQuick 2.1 as QQ2 Entity { id: root @@ -50,40 +50,27 @@ Entity { Transform { id: toyplaneTransform - property real rollAngle : 0 - property real pitchAngle : 15 - property real altitude : 5 + property real rollAngle: 0 + property real pitchAngle: 15 + property real altitude: 5 property real angle: 0 property real scaleFactor: 10 QQ2.Behavior on rollAngle { QQ2.SpringAnimation { spring: 2; damping: 0.2} } - Scale { - scale: 1.0 / toyplaneTransform.scaleFactor - } - - Rotate { // roll - axis : Qt.vector3d(1, 0, 0) - angle : toyplaneTransform.rollAngle - } - - Rotate { // pitch - axis : Qt.vector3d(0, 0, 1) - angle : toyplaneTransform.pitchAngle - } - - Rotate { - id: toyplaneRotation - axis: Qt.vector3d(0, 1, 0) - angle: toyplaneTransform.angle - } - - Translate { - property real translation: 1 - - dx: Math.sin(toyplaneTransform.angle * Math.PI / 180) * translation * toyplaneTransform.scaleFactor - dy: toyplaneTransform.altitude - dz: Math.cos(toyplaneTransform.angle * Math.PI / 180) * translation * toyplaneTransform.scaleFactor + matrix: { + var m = Qt.matrix4x4(1, 0, 0, 0, + 0, 1, 0, 0, + 0, 0, 1, 0, + 0, 0, 0, 1); + m.translate(Qt.vector3d(Math.sin(angle * Math.PI / 180) * scaleFactor, + altitude, + Math.cos(angle * Math.PI / 180) * scaleFactor)); + m.rotate(angle, Qt.vector3d(0, 1, 0)); + m.rotate(pitchAngle, Qt.vector3d(0, 0, 1)); + m.rotate(rollAngle, Qt.vector3d(1, 0, 0)); + m.scale(1.0 / toyplaneTransform.scaleFactor); + return m; } } diff --git a/examples/qt3d/shadow-map-qml/Trefoil.qml b/examples/qt3d/shadow-map-qml/Trefoil.qml index 68a334ef8..4691adbd3 100644 --- a/examples/qt3d/shadow-map-qml/Trefoil.qml +++ b/examples/qt3d/shadow-map-qml/Trefoil.qml @@ -34,9 +34,9 @@ ** ****************************************************************************/ +import QtQuick 2.1 as QQ2 import Qt3D.Core 2.0 import Qt3D.Render 2.0 -import QtQuick 2.1 as QQ2 Entity { id: root @@ -49,20 +49,24 @@ Entity { Transform { id: trefoilMeshTransform - - Rotate { - id: trefoilMeshRotation - axis: Qt.vector3d(0, 1, 0) + property real userAngle: 0.0 + matrix: { + var m = Qt.matrix4x4(1, 0, 0, 0, + 0, 1, 0, 0, + 0, 0, 1, 0, + 0, 0, 0, 1); + m.rotate(userAngle, Qt.vector3d(0, 1, 0)); + return m; } } QQ2.NumberAnimation { - target: trefoilMeshRotation + target: trefoilMeshTransform running: true loops: QQ2.Animation.Infinite - property: "angle" + property: "userAngle" duration: 5000 from: 360 to: 0 diff --git a/examples/qt3d/shadow-map-qml/main.qml b/examples/qt3d/shadow-map-qml/main.qml index 3b79213a8..f05bbbc8a 100644 --- a/examples/qt3d/shadow-map-qml/main.qml +++ b/examples/qt3d/shadow-map-qml/main.qml @@ -34,6 +34,7 @@ ** ****************************************************************************/ +import QtQuick 2.1 as QQ2 import Qt3D.Core 2.0 import Qt3D.Render 2.0 diff --git a/examples/qt3d/simple-cpp/main.cpp b/examples/qt3d/simple-cpp/main.cpp index cb01cac8a..3a24867e7 100644 --- a/examples/qt3d/simple-cpp/main.cpp +++ b/examples/qt3d/simple-cpp/main.cpp @@ -60,6 +60,76 @@ #include +class OrbitTransformController : public QObject +{ + Q_OBJECT + Q_PROPERTY(Qt3DCore::QTransform* target READ target WRITE setTarget NOTIFY targetChanged) + Q_PROPERTY(float radius READ radius WRITE setRadius NOTIFY radiusChanged) + Q_PROPERTY(float angle READ angle WRITE setAngle NOTIFY angleChanged) + +public: + OrbitTransformController(QObject *parent = 0) + : QObject(parent) + , m_target(Q_NULLPTR) + , m_matrix() + , m_radius(1.0f) + , m_angle(0.0f) + { + } + + void setTarget(Qt3DCore::QTransform *target) + { + if (m_target != target) { + m_target = target; + emit targetChanged(); + } + } + + Qt3DCore::QTransform *target() const { return m_target; } + + void setRadius(float radius) + { + if (!qFuzzyCompare(radius, m_radius)) { + m_radius = radius; + updateMatrix(); + emit radiusChanged(); + } + } + + float radius() const { return m_radius; } + + void setAngle(float angle) + { + if (!qFuzzyCompare(angle, m_angle)) { + m_angle = angle; + updateMatrix(); + emit angleChanged(); + } + } + + float angle() const { return m_angle; } + +signals: + void targetChanged(); + void radiusChanged(); + void angleChanged(); + +protected: + void updateMatrix() + { + m_matrix.setToIdentity(); + m_matrix.rotate(m_angle, QVector3D(0.0f, 1.0f, 0.0f)); + m_matrix.translate(m_radius, 0.0f, 0.0f); + m_target->setMatrix(m_matrix); + } + +private: + Qt3DCore::QTransform *m_target; + QMatrix4x4 m_matrix; + float m_radius; + float m_angle; +}; + int main(int argc, char* argv[]) { QGuiApplication app(argc, argv); @@ -91,16 +161,8 @@ int main(int argc, char* argv[]) torusMesh->setSlices(20); Qt3DCore::QTransform *torusTransform = new Qt3DCore::QTransform; - Qt3DCore::QScaleTransform *torusScaleTransform = new Qt3DCore::QScaleTransform; - torusScaleTransform->setScale3D(QVector3D(1.5, 1, 0.5)); - - Qt3DCore::QRotateTransform *torusRotateTransform = new Qt3DCore::QRotateTransform; - torusRotateTransform->setAxis(QVector3D(1, 0, 0)); - torusRotateTransform->setAngleDeg(45); - - torusTransform->addTransform(torusScaleTransform); - torusTransform->addTransform(torusRotateTransform); - + torusTransform->setScale3D(QVector3D(1.5, 1, 0.5)); + torusTransform->setRotation(QQuaternion::fromAxisAndAngle(QVector3D(1, 0, 0), 45.0f)); torusEntity->addComponent(torusMesh); torusEntity->addComponent(torusTransform); @@ -112,12 +174,12 @@ int main(int argc, char* argv[]) sphereMesh->setRadius(3); Qt3DCore::QTransform *sphereTransform = new Qt3DCore::QTransform; - Qt3DCore::QTranslateTransform *sphereTranslateTransform = new Qt3DCore::QTranslateTransform; - sphereTranslateTransform->setTranslation(QVector3D(20, 0, 0)); + OrbitTransformController *controller = new OrbitTransformController(sphereTransform); + controller->setTarget(sphereTransform); + controller->setRadius(20.0f); - Qt3DCore::QRotateTransform *sphereRotateTransform = new Qt3DCore::QRotateTransform; - QPropertyAnimation *sphereRotateTransformAnimation = new QPropertyAnimation(sphereRotateTransform); - sphereRotateTransformAnimation->setTargetObject(sphereRotateTransform); + QPropertyAnimation *sphereRotateTransformAnimation = new QPropertyAnimation(sphereTransform); + sphereRotateTransformAnimation->setTargetObject(controller); sphereRotateTransformAnimation->setPropertyName("angle"); sphereRotateTransformAnimation->setStartValue(QVariant::fromValue(0)); sphereRotateTransformAnimation->setEndValue(QVariant::fromValue(360)); @@ -125,12 +187,6 @@ int main(int argc, char* argv[]) sphereRotateTransformAnimation->setLoopCount(-1); sphereRotateTransformAnimation->start(); - sphereRotateTransform->setAxis(QVector3D(0, 1, 0)); - sphereRotateTransform->setAngleDeg(0); - - sphereTransform->addTransform(sphereTranslateTransform); - sphereTransform->addTransform(sphereRotateTransform); - sphereEntity->addComponent(sphereMesh); sphereEntity->addComponent(sphereTransform); sphereEntity->addComponent(material); @@ -140,3 +196,5 @@ int main(int argc, char* argv[]) return app.exec(); } + +#include "main.moc" diff --git a/examples/qt3d/simple-qml/main.qml b/examples/qt3d/simple-qml/main.qml index 517ffa3a5..559aec1e8 100644 --- a/examples/qt3d/simple-qml/main.qml +++ b/examples/qt3d/simple-qml/main.qml @@ -34,9 +34,9 @@ ** ****************************************************************************/ +import QtQuick 2.2 as QQ2 import Qt3D.Core 2.0 import Qt3D.Render 2.0 -import QtQuick 2.2 as QQ2 Entity { id: sceneRoot @@ -80,10 +80,14 @@ Entity { Transform { id: torusTransform - Scale { scale3D: Qt.vector3d(1.5, 1, 0.5) } - Rotate { - angle: 45 - axis: Qt.vector3d(1, 0, 0) + matrix: { + var m = Qt.matrix4x4(1, 0, 0, 0, + 0, 1, 0, 0, + 0, 0, 1, 0, + 0, 0, 0, 1); + m.scale(Qt.vector3d(1.5, 1, 0.5)); + m.rotate(45, Qt.vector3d(1, 0, 0)); + return m; } } @@ -99,19 +103,21 @@ Entity { Transform { id: sphereTransform - Translate { - translation: Qt.vector3d(20, 0, 0) - } - - Rotate { - id: sphereRotation - axis: Qt.vector3d(0, 1, 0) + property real userAngle: 0.0 + matrix: { + var m = Qt.matrix4x4(1, 0, 0, 0, + 0, 1, 0, 0, + 0, 0, 1, 0, + 0, 0, 0, 1); + m.rotate(userAngle, Qt.vector3d(0, 1, 0)); + m.translate(Qt.vector3d(20, 0, 0)); + return m; } } QQ2.NumberAnimation { - target: sphereRotation - property: "angle" + target: sphereTransform + property: "userAngle" duration: 10000 from: 0 to: 360 diff --git a/examples/qt3d/simple-shaders-qml/main.qml b/examples/qt3d/simple-shaders-qml/main.qml index ce83c01a9..93f7d031c 100644 --- a/examples/qt3d/simple-shaders-qml/main.qml +++ b/examples/qt3d/simple-shaders-qml/main.qml @@ -34,9 +34,9 @@ ** ****************************************************************************/ +import QtQuick 2.2 as QQ2 import Qt3D.Core 2.0 import Qt3D.Render 2.0 -import QtQuick 2.2 as QQ2 Entity { id: sceneRoot @@ -78,10 +78,14 @@ Entity { id: torusEntityInlineShader property Transform transform: Transform { - Translate { translation: Qt.vector3d(-2.0, 0.0, 0.0) } - Rotate { - angle: 45 - axis: Qt.vector3d(1, 0, 0) + matrix: { + var m = Qt.matrix4x4(1, 0, 0, 0, + 0, 1, 0, 0, + 0, 0, 1, 0, + 0, 0, 0, 1); + m.rotate(45, Qt.vector3d(1, 0, 0)); + m.translate(Qt.vector3d(-2.0, 0.0, 0.0)); + return m; } } @@ -157,11 +161,15 @@ Entity { Entity { id: torusEntitySeparateShader - property Transform transform: Transform { - Translate { translation: Qt.vector3d(2.0, 0.0, 0.0) } - Rotate { - angle: 15 - axis: Qt.vector3d(1, 0, 0) + property Transform transform: Transform { + matrix: { + var m = Qt.matrix4x4(1, 0, 0, 0, + 0, 1, 0, 0, + 0, 0, 1, 0, + 0, 0, 0, 1); + m.rotate(15, Qt.vector3d(1, 0, 0)); + m.translate(Qt.vector3d(2.0, 0.0, 0.0)); + return m; } } diff --git a/examples/qt3d/skybox/Skybox.qml b/examples/qt3d/skybox/Skybox.qml index 0d69c3434..f040ba5a7 100644 --- a/examples/qt3d/skybox/Skybox.qml +++ b/examples/qt3d/skybox/Skybox.qml @@ -39,7 +39,7 @@ import Qt3D.Render 2.0 Entity { - property alias cameraPosition: cameraTranslate.translation; + property alias cameraPosition: transform.translation; property string sourceDirectory: ""; property string extension: ".webp" @@ -80,7 +80,6 @@ Entity { Transform { id: transform - Translate { id: cameraTranslate } } Material { diff --git a/examples/qt3d/tessellation-modes/BasicCamera.qml b/examples/qt3d/tessellation-modes/BasicCamera.qml index a06f1562c..79ff51822 100644 --- a/examples/qt3d/tessellation-modes/BasicCamera.qml +++ b/examples/qt3d/tessellation-modes/BasicCamera.qml @@ -36,7 +36,6 @@ import Qt3D.Core 2.0 import Qt3D.Render 2.0 -import QtQuick 2.1 as QQ2 Camera { id: mainCamera diff --git a/examples/qt3d/tessellation-modes/TessellatedQuad.qml b/examples/qt3d/tessellation-modes/TessellatedQuad.qml index 63962edb9..b5945ed6c 100644 --- a/examples/qt3d/tessellation-modes/TessellatedQuad.qml +++ b/examples/qt3d/tessellation-modes/TessellatedQuad.qml @@ -34,10 +34,10 @@ ** ****************************************************************************/ +import QtQuick 2.1 as QQ2 import Qt3D.Core 2.0 import Qt3D.Render 2.0 import Qt3D.Examples 1.0 -import QtQuick 2.1 as QQ2 Entity { id: root @@ -53,9 +53,16 @@ Entity { Transform { id: transform - Translate { dx: root.x; dy: root.y; dz: root.z } - Scale { scale: root.scale } - Rotate{ angle: root.theta; axis: Qt.vector3d(0.0, 1.0, 0.0) } + matrix: { + var m = Qt.matrix4x4(1, 0, 0, 0, + 0, 1, 0, 0, + 0, 0, 1, 0, + 0, 0, 0, 1); + m.translate(Qt.vector3d(root.x, root.y, root.z)); + m.rotate(root.theta, Qt.vector3d(0, 1, 0)); + m.scale(root.scale) + return m; + } } TessellatedQuadMesh { diff --git a/examples/qt3d/tessellation-modes/TessellatedWireframeEffect.qml b/examples/qt3d/tessellation-modes/TessellatedWireframeEffect.qml index f3cfb942c..9a4a5002c 100644 --- a/examples/qt3d/tessellation-modes/TessellatedWireframeEffect.qml +++ b/examples/qt3d/tessellation-modes/TessellatedWireframeEffect.qml @@ -36,7 +36,6 @@ import Qt3D.Core 2.0 import Qt3D.Render 2.0 -import QtQuick 2.1 Effect { id: root diff --git a/examples/qt3d/tessellation-modes/TessellatedWireframeMaterial.qml b/examples/qt3d/tessellation-modes/TessellatedWireframeMaterial.qml index fcaa37d58..98c5b4a7d 100644 --- a/examples/qt3d/tessellation-modes/TessellatedWireframeMaterial.qml +++ b/examples/qt3d/tessellation-modes/TessellatedWireframeMaterial.qml @@ -36,7 +36,6 @@ import Qt3D.Core 2.0 import Qt3D.Render 2.0 -import QtQuick 2.1 as QQ2 Material { id: root @@ -50,7 +49,6 @@ Material { property var innerTessLevel: [1.0, 1.0 ] property var outerTessLevel: [1.0, 1.0, 1.0, 1.0] - parameters: [ Parameter { name: "ambient"; value: Qt.vector3d(root.ambient.r, root.ambient.g, root.ambient.b) }, Parameter { name: "diffuse"; value: Qt.vector3d(root.diffuse.r, root.diffuse.g, root.diffuse.b) }, diff --git a/examples/qt3d/tessellation-modes/main.qml b/examples/qt3d/tessellation-modes/main.qml index 33cfd3732..e75664364 100644 --- a/examples/qt3d/tessellation-modes/main.qml +++ b/examples/qt3d/tessellation-modes/main.qml @@ -34,9 +34,9 @@ ** ****************************************************************************/ +import QtQuick 2.1 as QQ2 import Qt3D.Core 2.0 import Qt3D.Render 2.0 -import QtQuick 2.1 as QQ2 Entity { id: root diff --git a/examples/qt3d/torus-qml/main.qml b/examples/qt3d/torus-qml/main.qml index e7c4cc32e..59023189d 100644 --- a/examples/qt3d/torus-qml/main.qml +++ b/examples/qt3d/torus-qml/main.qml @@ -76,10 +76,14 @@ Entity { Transform { id: transform - Scale { scale3D: Qt.vector3d(1.5, 1, 0.5) } - Rotate { - angle: 45 - axis: Qt.vector3d(1, 0, 0) + matrix: { + var m = Qt.matrix4x4(1, 0, 0, 0, + 0, 1, 0, 0, + 0, 0, 1, 0, + 0, 0, 0, 1); + m.rotate(45, Qt.vector3d(1, 0, 0)); + m.scale(Qt.vector3d(1.5, 1, 0.5)) + return m; } } diff --git a/examples/qt3d/transparency-qml-scene3d/Scene.qml b/examples/qt3d/transparency-qml-scene3d/Scene.qml index 51cc79d7a..6b9b4683d 100644 --- a/examples/qt3d/transparency-qml-scene3d/Scene.qml +++ b/examples/qt3d/transparency-qml-scene3d/Scene.qml @@ -72,12 +72,12 @@ Entity { Transform { id: sphereTransform - Translate { dx: 10 } + translation: Qt.vector3d(10, 0, 0) } Transform { id: cylinderTransform - Translate { dx: -10 } + translation: Qt.vector3d(-10, 0, 0) } Entity { diff --git a/examples/qt3d/transparency-qml-scene3d/main.qml b/examples/qt3d/transparency-qml-scene3d/main.qml index 14b69a40a..d1460c8fe 100644 --- a/examples/qt3d/transparency-qml-scene3d/main.qml +++ b/examples/qt3d/transparency-qml-scene3d/main.qml @@ -38,8 +38,7 @@ import QtQuick 2.4 import QtQuick.Window 2.2 import QtQuick.Scene3D 2.0 -Window -{ +Window { visible: true width: 800 height: 600 diff --git a/examples/qt3d/transparency-qml/main.qml b/examples/qt3d/transparency-qml/main.qml index d9639f819..8d104ab76 100644 --- a/examples/qt3d/transparency-qml/main.qml +++ b/examples/qt3d/transparency-qml/main.qml @@ -72,12 +72,12 @@ Entity { Transform { id: sphereTransform - Translate { dx: 10 } + translation: Qt.vector3d(10, 0, 0) } Transform { id: cylinderTransform - Translate { dx: -10 } + translation: Qt.vector3d(-10, 0, 0) } Entity { diff --git a/examples/qt3d/wave/Background.qml b/examples/qt3d/wave/Background.qml index 64468209b..7c6ed4952 100644 --- a/examples/qt3d/wave/Background.qml +++ b/examples/qt3d/wave/Background.qml @@ -34,9 +34,9 @@ ** ****************************************************************************/ +import QtQuick 2.1 as QQ2 import Qt3D.Core 2.0 import Qt3D.Render 2.0 -import QtQuick 2.1 as QQ2 Entity { id: root @@ -72,9 +72,13 @@ Entity { Transform { // Rotate the plane so that it faces us - Rotate { - axis: Qt.vector3d( 1.0, 0.0, 0.0 ) - angle: 90 + matrix: { + var m = Qt.matrix4x4(1, 0, 0, 0, + 0, 1, 0, 0, + 0, 0, 1, 0, + 0, 0, 0, 1); + m.rotate(90, Qt.vector3d(1, 0, 0)); + return m; } }, diff --git a/examples/qt3d/wave/Wave.qml b/examples/qt3d/wave/Wave.qml index 708e35775..9bbb707a9 100644 --- a/examples/qt3d/wave/Wave.qml +++ b/examples/qt3d/wave/Wave.qml @@ -59,10 +59,17 @@ Entity { Transform { id: transform - Translate { dx: root.x; dy: root.y; dz: root.z } - Scale { scale: root.scale } - Rotate{ angle: root.theta; axis: Qt.vector3d(1.0, 0.0, 0.0) } - Rotate{ angle: root.phi; axis: Qt.vector3d(0.0, 1.0, 0.0) } + matrix: { + var m = Qt.matrix4x4(1, 0, 0, 0, + 0, 1, 0, 0, + 0, 0, 1, 0, + 0, 0, 0, 1); + m.translate(Qt.vector3d(root.x, root.y, root.z)); + m.rotate(root.phi, Qt.vector3d(0, 1, 0)); + m.rotate(root.theta, Qt.vector3d(1, 0, 0)); + m.scale(root.scale); + return m; + } } WaveMaterial { diff --git a/examples/qt3d/wave/main.qml b/examples/qt3d/wave/main.qml index a81a6c38a..6f7aaddb9 100644 --- a/examples/qt3d/wave/main.qml +++ b/examples/qt3d/wave/main.qml @@ -34,6 +34,7 @@ ** ****************************************************************************/ +import QtQuick 2.1 as QQ2 import Qt3D.Core 2.0 import Qt3D.Render 2.0 import Qt3D.Input 2.0 diff --git a/examples/qt3d/wireframe/TrefoilKnot.qml b/examples/qt3d/wireframe/TrefoilKnot.qml index 8b05c8ab9..4d51e067b 100644 --- a/examples/qt3d/wireframe/TrefoilKnot.qml +++ b/examples/qt3d/wireframe/TrefoilKnot.qml @@ -40,22 +40,29 @@ import Qt3D.Render 2.0 Entity { id: root - property alias x: translation.dx - property alias y: translation.dy - property alias z: translation.dz - property alias scale: scaleTransform.scale - property alias theta: thetaRotation.angle - property alias phi: phiRotation.angle + property real x: 0.0 + property real y: 0.0 + property real z: 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 - Translate { id: translation } - Scale { id: scaleTransform } - Rotate{ id: thetaRotation; axis: Qt.vector3d( 1.0, 0.0, 0.0 ) } - Rotate{ id: phiRotation; axis: Qt.vector3d( 0.0, 1.0, 0.0 ) } + matrix: { + var m = Qt.matrix4x4(1, 0, 0, 0, + 0, 1, 0, 0, + 0, 0, 1, 0, + 0, 0, 0, 1); + m.translate(Qt.vector3d(root.x, root.y, root.z)); + m.rotate(root.phi, Qt.vector3d(0, 1, 0)); + m.rotate(root.theta, Qt.vector3d(1, 0, 0)); + m.scale(root.scale); + return m; + } } Mesh { diff --git a/examples/qt3d/wireframe/main.qml b/examples/qt3d/wireframe/main.qml index 8e06a8b19..ed3f2899f 100644 --- a/examples/qt3d/wireframe/main.qml +++ b/examples/qt3d/wireframe/main.qml @@ -34,9 +34,9 @@ ** ****************************************************************************/ +import QtQuick 2.1 as QQ2 import Qt3D.Core 2.0 import Qt3D.Render 2.0 -import QtQuick 2.1 as QQ2 Entity { id: root -- cgit v1.2.3