Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QML smooth movement
Forum Updated to NodeBB v4.3 + New Features

QML smooth movement

Scheduled Pinned Locked Moved Unsolved General and Desktop
14 Posts 5 Posters 4.7k Views 3 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    MartinD
    wrote on last edited by
    #1

    Hi,
    I have a QML object which moves on the screen at constant speed. This is done by adding constant numbers to current x and y coordinates of the QML object 45 times per second.

    The problem is that the movement is not smooth.

    I also tried to use QElapsedTimer to find time that passed from the last position update and using this time I adapted position change. Still no smooth movement.

    Obviously, it is possible to have smooth movements in Qt as Qt animations work smoothly on my PC. So, how to make smooth movement (without using Qt animations)?

    A jsulmJ 2 Replies Last reply
    0
    • M MartinD

      Hi,
      I have a QML object which moves on the screen at constant speed. This is done by adding constant numbers to current x and y coordinates of the QML object 45 times per second.

      The problem is that the movement is not smooth.

      I also tried to use QElapsedTimer to find time that passed from the last position update and using this time I adapted position change. Still no smooth movement.

      Obviously, it is possible to have smooth movements in Qt as Qt animations work smoothly on my PC. So, how to make smooth movement (without using Qt animations)?

      A Offline
      A Offline
      ambershark
      wrote on last edited by
      #2

      @MartinD Can we see the code for the movement? Also if you could do a small screencast of the non-smooth movement that would help understanding as well.

      My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

      M 1 Reply Last reply
      0
      • M MartinD

        Hi,
        I have a QML object which moves on the screen at constant speed. This is done by adding constant numbers to current x and y coordinates of the QML object 45 times per second.

        The problem is that the movement is not smooth.

        I also tried to use QElapsedTimer to find time that passed from the last position update and using this time I adapted position change. Still no smooth movement.

        Obviously, it is possible to have smooth movements in Qt as Qt animations work smoothly on my PC. So, how to make smooth movement (without using Qt animations)?

        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #3

        @MartinD 45 times per second? 24 would already be enough.

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • A ambershark

          @MartinD Can we see the code for the movement? Also if you could do a small screencast of the non-smooth movement that would help understanding as well.

          M Offline
          M Offline
          MartinD
          wrote on last edited by
          #4

          @ambershark Here si a video http://gaminn.sweb.cz/v.mp4

          And the code is simple. On QTimer expiration (45 times per second) we update position of the ball - we add constant number to x and y coordinates.

          The application consumes 3 - 5 % of CPU, so the CPU is not overloaded.

          1 Reply Last reply
          0
          • ? Offline
            ? Offline
            A Former User
            wrote on last edited by
            #5

            On QTimer expiration (45 times per second) we update position of the ball - we add constant number to x and y coordinates.

            Can't work this way as the frame rate is never 100% constant. You need to synchronize with the renderer, and compute the ball's position for that point in time when it actually gets drawn.

            M 1 Reply Last reply
            1
            • ? A Former User

              On QTimer expiration (45 times per second) we update position of the ball - we add constant number to x and y coordinates.

              Can't work this way as the frame rate is never 100% constant. You need to synchronize with the renderer, and compute the ball's position for that point in time when it actually gets drawn.

              M Offline
              M Offline
              MartinD
              wrote on last edited by MartinD
              #6

              @Wieland How can I synchronize with the renderer in Qt? The renderer is QML engine. In my application I use QML items (Item, Rectangle, Image, ..).

              1 Reply Last reply
              0
              • ? Offline
                ? Offline
                A Former User
                wrote on last edited by
                #7

                QQuickWindow emits a number of signals for syncing, choose the one that fits your needs best:

                • afterAnimating
                • afterRendering
                • afterSynchronizing
                • beforeRendering
                • beforeSynchronizing
                1 Reply Last reply
                3
                • ? Offline
                  ? Offline
                  A Former User
                  wrote on last edited by
                  #8

                  I've thought about it again. Given the low velocity of the ball, the jumps between the observed positions seem far too extreme to be caused by what I first thought. Now I think the problem must be something else. The Timer you're using, it is a QML Timer or a QTimer in C++?

                  M 1 Reply Last reply
                  2
                  • ? A Former User

                    I've thought about it again. Given the low velocity of the ball, the jumps between the observed positions seem far too extreme to be caused by what I first thought. Now I think the problem must be something else. The Timer you're using, it is a QML Timer or a QTimer in C++?

                    M Offline
                    M Offline
                    MartinD
                    wrote on last edited by
                    #9

                    @Wieland Thanks for getting back to me. I tried synchronization using the signals you mentioned and moving the ball depending on the time that passed between the two signal invokes but it doesn't help.

                    I use QTimer in C++. All computation is done in C++ (the movement is computed by Box2D engine). There are approx. 30 objects on the scene (as you can see, some bricks, ball, paddle). Box2D computation routine takes 20 to 200 us every frame (measured by QElapsedTimer). I don't know if it is acceptable or not...

                    A 1 Reply Last reply
                    0
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      Hi,

                      Not an answer but you might be interested by the QML-Box2D project.

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      1 Reply Last reply
                      0
                      • M MartinD

                        @Wieland Thanks for getting back to me. I tried synchronization using the signals you mentioned and moving the ball depending on the time that passed between the two signal invokes but it doesn't help.

                        I use QTimer in C++. All computation is done in C++ (the movement is computed by Box2D engine). There are approx. 30 objects on the scene (as you can see, some bricks, ball, paddle). Box2D computation routine takes 20 to 200 us every frame (measured by QElapsedTimer). I don't know if it is acceptable or not...

                        A Offline
                        A Offline
                        ambershark
                        wrote on last edited by
                        #11

                        @MartinD said in QML smooth movement:

                        Box2D computation routine takes 20 to 200 us every frame (measured by QElapsedTimer).

                        Are you saying that it takes 20 to 200 milliseconds to calculate? If that is the case there is no way you are going to be able to update 45 times per second. I'm assuming "ms" as you put "us" and not sure what you meant there? Could be nanoseconds maybe? I dunno, hence the assumption. Or maybe you meant microseconds which looks like a u in it's symbol representation, in which case ignore my comment. ;)

                        I don't have any good ideas on what might be going on to offer right now either, but I'll keep thinking about it.

                        My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

                        M 1 Reply Last reply
                        0
                        • A ambershark

                          @MartinD said in QML smooth movement:

                          Box2D computation routine takes 20 to 200 us every frame (measured by QElapsedTimer).

                          Are you saying that it takes 20 to 200 milliseconds to calculate? If that is the case there is no way you are going to be able to update 45 times per second. I'm assuming "ms" as you put "us" and not sure what you meant there? Could be nanoseconds maybe? I dunno, hence the assumption. Or maybe you meant microseconds which looks like a u in it's symbol representation, in which case ignore my comment. ;)

                          I don't have any good ideas on what might be going on to offer right now either, but I'll keep thinking about it.

                          M Offline
                          M Offline
                          MartinD
                          wrote on last edited by
                          #12

                          @ambershark Hi. I'm used (and I think many other people) to use us for microseconds... The routine takes 20 to 200 microseconds.

                          1 Reply Last reply
                          1
                          • M Offline
                            M Offline
                            MartinD
                            wrote on last edited by MartinD
                            #13

                            I made a simple test project - http://gaminn.sweb.cz/MoveTest.zip. The red ball is moved by Qt animation, the black ball is moved by updating its position on afterAnimating signal.

                            It seems that both balls experience glitches.

                            I did QML profiling and I can see periodic gaps in rendering (purple "signal"):

                            alt text

                            Is there anything I can do with this issue. I use Qt 5.7.1 on Win and on Android.

                            A 1 Reply Last reply
                            0
                            • M MartinD

                              I made a simple test project - http://gaminn.sweb.cz/MoveTest.zip. The red ball is moved by Qt animation, the black ball is moved by updating its position on afterAnimating signal.

                              It seems that both balls experience glitches.

                              I did QML profiling and I can see periodic gaps in rendering (purple "signal"):

                              alt text

                              Is there anything I can do with this issue. I use Qt 5.7.1 on Win and on Android.

                              A Offline
                              A Offline
                              ambershark
                              wrote on last edited by
                              #14

                              @MartinD I wish I was better in QML and could help here, but I just started learning QML a month or so ago. So I just don't have a good answer on something you can try.

                              I've done Qt for 16 years, but I'm really new to QML. :(

                              You said your computer isn't running at high CPU so it really shouldn't have those gaps in processing. Is there a correlation between those gaps and something on your PC using a burst of resources? Like anti virus or something else that hogs up the CPU?

                              My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

                              1 Reply Last reply
                              0

                              • Login

                              • Login or register to search.
                              • First post
                                Last post
                              0
                              • Categories
                              • Recent
                              • Tags
                              • Popular
                              • Users
                              • Groups
                              • Search
                              • Get Qt Extensions
                              • Unsolved