[Interest] [Qt3d] Does the duration of NumberAnimation update when you change its value?
Ramy Atalla
ramitix at yahoo.com
Wed Apr 27 19:38:58 CEST 2016
Hi DR. SeanThanks for reply.I tried both methods none of them works, Overall I think I have a problem controlling the animation (start/stop/restart).I have a slider which generates a value between 0-5000 for the duration of the animation, On value change of the slider it calls a function which does the follow:(1)stops the animation(doesn't work,however console log for animation.running updates to false). (2)updates the value of the property "carspeed".(3) restarts the animation(doesn't work,however console log for animation.running updates to true).
I know there is something implemented wrong.If I initialize the animation running:true it won't stop and if I initialize it to running:false it won't start.
Car.qml (one wheel and one rim transform)
Transform { id: wheel1Transform property real userAngle: 0.0 translation:Qt.vector3d(-1.35, 0.368, 1.8) rotation: fromAxisAndAngle(Qt.vector3d(1, 0, 0), userAngle)}Transform { id: rim1Transform property real userAngle: 0.0 translation:Qt.vector3d(-1.40, 0.368, 1.8) rotation: fromAxisAndAngle(Qt.vector3d(1, 0, 0), userAngle)}
Car.qml (wheeling and rim rotation animation)
property alias wheelanimationControl : wheelanimationMain property real carspeed:2000QQ2.SequentialAnimation { id :wheelanimationMain running: false loops: QQ2.Animation.Infinite
QQ2.NumberAnimation { id:wheelanimation targets:[ wheel1Transform, rim1Transform,wheel2Transform , rim2Transform,wheel3Transform , rim3Transform,wheel4Transform , rim4Transform] properties: "userAngle" duration: carspeed from: 0 to: 360 alwaysRunToEnd:false // onDurationChanged: wheelanimationMain.restart()}}
Car.qml (the function that the slider will use)
function sliderValue(){ console.log("before",wheel1Transform.userAngle,wheelanimationMain.running,slider.value, rootcar.carspeed) wheelanimationMain.stop(); wheelanimationMain.running=false; // redundant step
rootcar.carspeed = slider.value; wheelanimationMain.restart(); wheelanimationMain.running=true; // redundant step console.log("after",wheel1Transform.userAngle,wheelanimationMain.running,slider.value, rootcar.carspeed)
}
Slider.qml
import QtQuick 2.5import QtQuick.Controls 1.4
Item { id :root width: 300 height: 80
Rectangle { id: rectangle1 x: 696 y: 30 width: 300 height: 80 color: "#202020" radius: 1 border.color: "#ffffff" opacity: 0.5 } Text { id: text1 x: 705 y: 33 color: "#ffffff" text: qsTr("Speed") horizontalAlignment: Text.AlignHCenter verticalAlignment: Text.AlignVCenter font.pixelSize: 13 }
MouseArea { id: mouseArea1 x: 696 y: 30 width: 300 height: 80 onClicked: root.visible=false cursorShape: Qt.PointingHandCursor } Car{ id:car }
Slider{ id:slider x: 716 y: 68 width: 263 height: 22 maximumValue: 5000 stepSize: 100 updateValueWhileDragging :true onValueChanged: car.sliderValue() } Label { x: 910 y: 45 width: 63 height: 16 color: "#ffffff" text: Math.floor(slider.value/10)+" MPH" horizontalAlignment: Text.AlignHCenter }
Rectangle { id: rectangle2 x: 600 y: 30 width: 80 height: 80 color: "#202020" radius: 1 border.color: "#ffffff" opacity: 0.5 } Text { id: text2 x: 600 y: 33 color: "#ffffff" text: qsTr("run") horizontalAlignment: Text.AlignHCenter verticalAlignment: Text.AlignVCenter font.pixelSize: 13 }
MouseArea { id: mouseArea2 x: 600 y: 30 width: 80 height: 80 onClicked: car.wheelanimationControl.running=true; cursorShape: Qt.PointingHandCursor }}Thanks,Ramy
---------------------------------------------------------------
Hi,I don't think this works unless you stop/restart the animation which is not
ideal. A work around is to have a simple NumberAnimation changing a "progress"
value, then in your actual property that you wish to animate, multiply this
progress property by your rotationSpeed property. It requires some extra
gymnastics to cope with non-integer numbers of rotations per cycle of the
progress property.
Something like this should do it (not tested):
Entity {
id: root
property real progress: 0.0
property real rotationSpeed: 10.0
property real angle: previousAngle + ( progress * rotationSpeed )
property real previousAngle: 0.0
function updatePreviousRotation() {
root.previousAngle = root.angle;
}
SequentialAnimation {
running: true
loops: Animation.Infinite
NumberAnimation {
from: 0; to: 1
duration: 1000
}
ScriptAction { script: updatePreviousRotation() }
}
}
This is a limitation of what can be expressed with the Qt Quick 2 animation
framework at present. When we look at adding an animation aspect to Qt 3D for
Qt 5.8 or 5.9, this is one of the things I want to address along with morph
target, key frame and skeletal animations. More likely for 5.9 given we're
already well into the development cycle for 5.8 and we're still putting all
efforts into 5.7.
Hope this helps,
Sean
--
Dr Sean Harmer | sean.harmer at kdab.com | Managing Director UK
Klarälvdalens Datakonsult AB, a KDAB Group company
Tel. UK +44 (0)1625 809908, Sweden (HQ) +46-563-540090
KDAB - Qt Experts - Platform-independent software solutions
---------------------------------------------------------------Hi,I am trying to do a rotation animation and control the rotation speed by changing the value of the duration, But it doesn't work . My question is it feasible or there another way ?
QQ2.NumberAnimation { id:wheelanimation property int carspeed:0 targets: [wheel1Transform , rim1Transform,wheel2Transform , rim2Transform,wheel3Transform , rim3Transform,wheel4Transform , rim4Transform] property: "userAngle" duration: carspeed from: 0 to: 360 loops: QQ2.Animation.Infinite running: true
}
QQ2.NumberAnimation { duration: 100 loops: QQ2.Animation.Infinite target: wheelanimation property: "carspeed" from: 0.0 to: 3000 running: true
}
ThanksRamy
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20160427/73e460aa/attachment.html>
More information about the Interest
mailing list