I think maybe you should use the SmoothedAnimation velocity property, which woud be degrees per second? You'll also have to change the Easing to linear.
 
 
 
 
Sent: Wednesday, April 27, 2016 at 1:38 PM
From: "Ramy Atalla via Interest" <interest@qt-project.org>
To: "Qt Project" <interest@qt-project.org>
Subject: Re: [Interest] [Qt3d] Does the duration of NumberAnimation update when you change its value?
Hi DR. Sean
Thanks 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:2000
QQ2.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.5
import 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.har...@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
 
 
}
 
Thanks
Ramy



 
_______________________________________________ Interest mailing list Interest@qt-project.org http://lists.qt-project.org/mailman/listinfo/interest
_______________________________________________
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest

Reply via email to