Commit eec0dca3 authored by Andy Nichols's avatar Andy Nichols
Browse files

Use Quaternions for rotation in Node API



This should solve several problems and remove the need for a rotation
order API. This does break the existing code though.

[ChangeLog] Node.rotation is now a quaternion, Node.eulerRotation a
vector3d of euler angles. Node.rotationOrder has been removed.

Fixes: QTBUG-77609
Change-Id: Ib1f4f3e173512cefb7f6863d2b431581e98587e2
Reviewed-by: default avatarChristian Strømme <christian.stromme@qt.io>
parent 4c1f4780
......@@ -20,9 +20,9 @@ make install
You may also need the qtquicktimeline module if you want to convert existing projects or assets that use keyframe animations. That is found [here](https://code.qt.io/cgit/qt/qtquicktimeline.git/)
```
import QtQuick 2.12
import QtQuick 2.15
import QtQuick.Window 2.12
import QtQuick3D 1.0
import QtQuick3D 1.15
Window {
id: window
......
......@@ -48,8 +48,8 @@
**
****************************************************************************/
import QtQuick 2.14
import QtQuick3D 1.14
import QtQuick 2.15
import QtQuick3D 1.15
View3D {
//! [background]
......@@ -69,7 +69,7 @@ View3D {
Model {
source: "#Cube"
rotation: Qt.vector3d(45, 45, 22.5)
rotation: Quaternion.fromEulerAngles(45, 45, 22.5)
materials: DefaultMaterial {
diffuseColor: "#a8171a"
}
......
......@@ -48,9 +48,9 @@
**
****************************************************************************/
import QtQuick 2.14
import QtQuick3D 1.14
import QtQuick3D.Materials 1.14
import QtQuick 2.15
import QtQuick3D 1.15
import QtQuick3D.Materials 1.15
View3D {
//! [foreground]
......@@ -64,7 +64,7 @@ View3D {
NumberAnimation {
target: orbiter
property: "rotation.y"
property: "eulerRotation.y"
duration: 5000
from: 0
to: 360
......@@ -92,7 +92,7 @@ View3D {
Model {
id: cone1
y: -100
rotation.x: -45
eulerRotation.x: -45
source: "#Cone"
materials: CopperMaterial {}
......
......@@ -48,7 +48,7 @@
**
****************************************************************************/
import QtQuick 2.14
import QtQuick 2.15
import QtQuick.Window 2.14
//! [extra import]
import QtGraphicalEffects 1.14
......
......@@ -48,9 +48,9 @@
**
****************************************************************************/
import QtQuick 2.14
import QtQuick3D 1.14
import QtQuick3D.Materials 1.14
import QtQuick 2.15
import QtQuick3D 1.15
import QtQuick3D.Materials 1.15
Node {
id: weirdShape
......@@ -64,9 +64,9 @@ Node {
Model {
source: "weirdShape.mesh"
scale: Qt.vector3d(150, 150, 150)
rotation: Qt.vector3d(-90, 0, 0)
rotation: Quaternion.fromEulerAngles(-90, 0, 0)
SequentialAnimation on rotation {
SequentialAnimation on eulerRotation {
loops: Animation.Infinite
PropertyAnimation {
duration: Math.random() * (10000 - 1) + 1
......
......@@ -48,10 +48,10 @@
**
****************************************************************************/
import QtQuick 2.14
import QtQuick 2.15
import QtQuick.Window 2.14
import QtQuick3D 1.14
import QtQuick3D.Materials 1.14
import QtQuick3D 1.15
import QtQuick3D.Materials 1.15
Window {
width: 1280
......
......@@ -48,9 +48,9 @@
**
****************************************************************************/
import QtQuick 2.12
import QtQuick3D 1.14
import QtQuick3D.Materials 1.14
import QtQuick 2.15
import QtQuick3D 1.15
import QtQuick3D.Materials 1.15
//! [implementation]
CustomMaterial {
......
......@@ -48,7 +48,7 @@
**
****************************************************************************/
import QtQuick 2.12
import QtQuick 2.15
import QtQuick.Controls 2.12
import QtQuick.Layouts 1.12
......
......@@ -48,9 +48,9 @@
**
****************************************************************************/
import QtQuick 2.12
import QtQuick 2.15
import QtQuick.Window 2.11
import QtQuick3D 1.14
import QtQuick3D 1.15
import QtQuick.Controls 2.4
Window {
......@@ -73,7 +73,7 @@ Window {
PerspectiveCamera {
id: camera
position: Qt.vector3d(0, 200, 300)
rotation: Qt.vector3d(-30, 0, 0)
eulerRotation.x: -30
}
//! [use]
......
......@@ -48,9 +48,9 @@
**
****************************************************************************/
import QtQuick 2.14
import QtQuick3D 1.14
import QtQuick3D.Materials 1.14
import QtQuick 2.15
import QtQuick3D 1.15
import QtQuick3D.Materials 1.15
Node {
id: weirdShape
......@@ -62,9 +62,9 @@ Node {
Model {
source: "weirdShape.mesh"
scale: Qt.vector3d(150, 150, 150)
rotation: Qt.vector3d(90, 0, 0)
eulerRotation.x: 90
SequentialAnimation on rotation {
SequentialAnimation on eulerRotation {
loops: Animation.Infinite
PropertyAnimation {
duration: Math.random() * (10000 - 1) + 1
......
......@@ -48,10 +48,10 @@
**
****************************************************************************/
import QtQuick 2.14
import QtQuick 2.15
import QtQuick.Window 2.14
import QtQuick.Controls 2.14
import QtQuick3D 1.14
import QtQuick3D 1.15
Window {
id: window
......@@ -141,14 +141,14 @@ Window {
position: Qt.vector3d(0, 0, 600)
}
rotation: Qt.vector3d(0, -90, 0)
eulerRotation.y: -90
SequentialAnimation on rotation {
SequentialAnimation on eulerRotation.y {
loops: Animation.Infinite
PropertyAnimation {
duration: 5000
to: Qt.vector3d(0, 360, 0)
from: Qt.vector3d(0, 0, 0)
to: 360
from: 0
}
}
}
......
......@@ -48,7 +48,7 @@
**
****************************************************************************/
import QtQuick 2.14
import QtQuick 2.15
import "content"
Rectangle {
......
......@@ -48,12 +48,11 @@
**
****************************************************************************/
import QtQuick3D 1.14
import QtQuick 2.14
import QtQuick3D 1.15
import QtQuick 2.15
Node {
id: doorRoot
rotationOrder: Node.XYZr
property PerspectiveCamera activeCamera: camera
PointLight {
......@@ -72,11 +71,10 @@ Node {
x: 180.067
y: 225.598
z: -411.521
rotation.x: -15.4614
eulerRotation.x: -15.4614
rotation.y: 171.605
eulerRotation.y: 171.605
rotationOrder: Node.XYZr
fieldOfViewOrientation: Camera.Horizontal
}
......@@ -88,7 +86,6 @@ Node {
scale.x: 2
scale.y: 3.5
scale.z: 0.5
rotationOrder: Node.XYZr
source: "meshes/door1.mesh"
pickable: true
......@@ -110,14 +107,14 @@ Node {
name: "opened"
PropertyChanges {
target: door1
rotation: Qt.vector3d(0, 90, 0)
eulerRotation.y: 90
}
}
transitions: Transition {
to: "opened"
reversible: true
SequentialAnimation {
PropertyAnimation { property: "rotation"; duration: 2000 }
PropertyAnimation { property: "eulerRotation"; duration: 2000 }
}
}
//! [state]
......@@ -129,7 +126,6 @@ Node {
scale.x: 400
scale.y: 100
scale.z: 10
rotationOrder: Node.XYZr
source: "meshes/wall.mesh"
DefaultMaterial {
......@@ -149,7 +145,6 @@ Node {
scale.y: 3.5
scale.z: 0.5
pivot.x: -20
rotationOrder: Node.XYZr
source: "meshes/door2.mesh"
pickable: true
materials: [
......@@ -159,14 +154,14 @@ Node {
name: "opened"
PropertyChanges {
target: door2
rotation: Qt.vector3d(0, -90, 0)
eulerRotation.y: -90
}
}
transitions: Transition {
to: "opened"
reversible: true
SequentialAnimation {
PropertyAnimation { property: "rotation"; duration: 2000 }
PropertyAnimation { property: "eulerRotation"; duration: 2000 }
}
}
}
......
......@@ -48,7 +48,7 @@
**
****************************************************************************/
import QtQuick 2.14
import QtQuick 2.15
Component {
Item {
......
......@@ -48,10 +48,10 @@
**
****************************************************************************/
import QtQuick 2.14
import QtQuick 2.15
import QtQuick.Window 2.14
import QtQuick3D 1.14
import QtQuick3D.Helpers 1.14
import QtQuick3D 1.15
import QtQuick3D.Helpers 1.15
Window {
id: window
......
......@@ -48,7 +48,7 @@
**
****************************************************************************/
import QtQuick 2.14
import QtQuick 2.15
import QtQuick.Window 2.14
import QtQuick3D 1.15
import QtQuick3D.Effects 1.15
......@@ -75,14 +75,15 @@ Window {
//! [camera]
PerspectiveCamera {
position: Qt.vector3d(0, 200, -300)
rotation: Qt.vector3d(30, 0, 0)
position: Qt.vector3d(0, 200, 300)
eulerRotation.x: -30
}
//! [camera]
//! [light]
DirectionalLight {
rotation: Qt.vector3d(30, 70, 0)
eulerRotation.x: -30
eulerRotation.y: -70
}
//! [light]
......
......@@ -48,9 +48,9 @@
**
****************************************************************************/
import QtQuick 2.14
import QtQuick 2.15
import QtQuick.Window 2.14
import QtQuick3D 1.14
import QtQuick3D 1.15
Window {
id: window
......@@ -128,11 +128,11 @@ Window {
PerspectiveCamera {
id: camera
position: Qt.vector3d(0, 200, 300)
rotation: Qt.vector3d(-30, 0, 0)
eulerRotation.x: -30
}
DirectionalLight {
rotation: Qt.vector3d(-30, 0, 0)
eulerRotation.x: -30
}
Model {
......@@ -149,15 +149,15 @@ Window {
}
}
]
rotation: Qt.vector3d(0, 90, 0)
eulerRotation.y: 90
//! [3dcube]
SequentialAnimation on rotation {
SequentialAnimation on eulerRotation {
loops: Animation.Infinite
PropertyAnimation {
duration: 5000
to: Qt.vector3d(360, 0, 360)
from: Qt.vector3d(0, 0, 0)
to: Qt.vector3d(360, 0, 360)
}
}
}
......
......@@ -48,7 +48,7 @@
**
****************************************************************************/
import QtQuick 2.14
import QtQuick 2.15
import QtQuick.Controls 2.4
import QtQuick.Layouts 1.14
......
......@@ -48,7 +48,7 @@
**
****************************************************************************/
import QtQuick 2.14
import QtQuick 2.15
import QtQuick.Controls 2.4
import QtQuick.Layouts 1.14
......
......@@ -48,7 +48,7 @@
**
****************************************************************************/
import QtQuick 2.14
import QtQuick 2.15
import QtQuick.Window 2.12
import QtQuick3D 1.15
......@@ -69,7 +69,7 @@ Window {
PerspectiveCamera {
position: Qt.vector3d(0, 400, 600)
rotation: Qt.vector3d(-30, 0, 0)
eulerRotation.x: -30
clipFar: 2000
}
......@@ -79,20 +79,20 @@ Window {
color: Qt.rgba(1.0, 0.1, 0.1, 1.0)
ambientColor: Qt.rgba(0.1, 0.1, 0.1, 1.0)
position: Qt.vector3d(0, 200, 0)
rotation: Qt.vector3d(135, 90, 0)
rotation: Quaternion.fromEulerAngles(135, 90, 0)
shadowMapQuality: Light.ShadowMapQualityHigh
visible: checkBox1.checked
castsShadow: checkBoxShadows.checked
brightness: slider1.sliderValue
SequentialAnimation on rotation {
loops: Animation.Infinite
PropertyAnimation {
to: Qt.vector3d(45, 90, 0)
QuaternionAnimation {
to: Quaternion.fromEulerAngles(45, 90, 0)
duration: 2000
easing.type: Easing.InOutQuad
}
PropertyAnimation {
to: Qt.vector3d(135, 90, 0)
QuaternionAnimation {
to: Quaternion.fromEulerAngles(135, 90, 0)
duration: 2000
easing.type: Easing.InOutQuad
}
......@@ -133,7 +133,7 @@ Window {
color: Qt.rgba(0.1, 0.1, 1.0, 1.0)
ambientColor: Qt.rgba(0.1, 0.1, 0.1, 1.0)
position: Qt.vector3d(-50, 250, -150)
rotation: Qt.vector3d(-90, 0, 0)
eulerRotation.x: -90
width: 1000
height: 200
shadowMapFar: 2000
......@@ -163,7 +163,7 @@ Window {
color: Qt.rgba(1.0, 0.9, 0.7, 1.0)
ambientColor: Qt.rgba(0.0, 0.0, 0.0, 0.0)
position: Qt.vector3d(0, 250, 0)
rotation: Qt.vector3d(-45, 0, 0)
eulerRotation.x: -45
shadowMapFar: 2000
shadowMapQuality: Light.ShadowMapQualityHigh
visible: checkBox4.checked
......@@ -172,8 +172,8 @@ Window {
coneAngle: 50
Vector3dAnimation on rotation {
loops: Animation.Infinite
from: Qt.vector3d(-45, 0, 0)
to: Qt.vector3d(-45, 360, 0)
from: Quaternion.fromEulerAngles(-45, 0, 0)
to: Quaternion.fromEulerAngles(-45, 360, 0)
duration: 10000
}
}
......@@ -184,7 +184,7 @@ Window {
source: "#Rectangle"
y: -200
scale: Qt.vector3d(15, 15, 15)
rotation: Qt.vector3d(-90, 0, 0)
eulerRotation.x: -90
materials: [
DefaultMaterial {
diffuseColor: Qt.rgba(0.8, 0.6, 0.4, 1.0)
......@@ -214,7 +214,7 @@ Window {
}
]
NumberAnimation on rotation.y {
NumberAnimation on eulerRotation.y {
loops: Animation.Infinite
duration: 5000
from: 0
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment