Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Game Development
  4. Rotation based on Mouse-Position
Forum Updated to NodeBB v4.3 + New Features

Rotation based on Mouse-Position

Scheduled Pinned Locked Moved Game Development
6 Posts 3 Posters 4.3k Views 1 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.
  • N Offline
    N Offline
    nor0x
    wrote on last edited by
    #1

    Hello Community ;)

    I am working on a little game (similar to frozen bubble), and I have a problem with the rotation of the Arrow, which shows the direction to shoot.
    The arrow on the bottom of the image, should alwas point to the current position of the mouse-cursor.

    !http://www.abload.de/img/box2d_rotationinuli.png(rotation)!

    I already search in this forum, right now I have this code to rotate the arrow, but the rotation-behavior is quite strange.

    @var a1 = mouseX - arrowBody.x;
    var b1 = mousey - arrowBody.y;
    var angle = Math.atan2(a1,b1);
    // var angle = angle / (Math.PI / 180);
    arrow.rotation = angle;@

    As you can see in the code, I also tried to work with degrees, but nothing worked for me.

    I hope you can help me!
    Thank you,
    nor0x

    1 Reply Last reply
    0
    • S Offline
      S Offline
      steno
      wrote on last edited by
      #2

      If you are using qt 4.8.4 or older, you might be experiencing this bug.

      "qAtan2 bug":https://bugreports.qt-project.org/browse/QTBUG-27090

      1 Reply Last reply
      0
      • N Offline
        N Offline
        nor0x
        wrote on last edited by
        #3

        Thank you very much,

        I am using V-Play-Engine with QT 4.7.4 - i will update my Installation, and post if it helped

        1 Reply Last reply
        0
        • S Offline
          S Offline
          steno
          wrote on last edited by
          #4

          I think just reversing your parameters and converting to degres should be enough.

          1 Reply Last reply
          0
          • N Offline
            N Offline
            nor0x
            wrote on last edited by
            #5

            bq. I think just reversing your parameters and converting to degres should be enough.

            Thanks for the reply, i changed my code to:

            @var angle = Math.atan2(b1,a1)
            arrowBody.rotation = angle * 180 / Math.PI@

            The rotation works better than before but it starts at a wrong point.

            The picture shows the behavior of my arrow, when I click near the orange-point the arrow changes from straight vertical to an incorrect angle!
            !http://www.abload.de/img/rotation2bguhu.png(Rotation)!

            Thank you

            1 Reply Last reply
            0
            • V Offline
              V Offline
              vishu
              wrote on last edited by
              #6

              hi,,,
              i am beginner to QML i too have same problem i am creating small applications in that whenever i change the cursor position all my fishes has to come to eat the cursor point.. i am able to move it with cursor position but unable to move with direction.

              kindly help me

              Thanku

              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