0
\$\begingroup\$

How can I detect if the mouse cursor is moving in a circle around a target, and calculate how many turns it's done?

For example, if I rotate the mouse 4 times around a specific XY point on the screen, I would like to re-center my camera (in my context, I need this algorithm for a camera system)

\$\endgroup\$
2
  • \$\begingroup\$ Do you know the target point in advance, and need to detect when the mouse has circled it? Or do you need to infer a variable center from the circular motion itself? \$\endgroup\$
    – DMGregory
    Commented May 23, 2018 at 2:51
  • \$\begingroup\$ yes the target are know , i need to find a way to check if mouse do multiple circle rotation around the Target with example a laps time (1000 or 2000 ms) \$\endgroup\$
    – jon
    Commented May 23, 2018 at 2:59

1 Answer 1

0
\$\begingroup\$

Just take the mouse position in the last frame, subtract the center position from it and using atan2, get the angle of the vector. Then do the same for the current mouse position, subtract the first result from the second and you get the amount of rotation in that frame.

You need to save the total rotation in a variable. Divide it by 2 * pi to get the number of circles the mouse did around the point. To stop this from firing even if the player didn't intend to center the camera, specify a minimum speed for the mouse. If it goes slower, than that, reset the total rotation variable.

So now that that's done, let's go over some problems. The biggest problem with this problem is accessibility. Some people have discomfort or some disability, that prevents them from doing fast and precise movements. This mechanic would put a big barrier in front of them.

The other thing is that doing precise circular movements using the mouse is still pretty hard. You can see this if you try drawing circles with it. This becomes a bigger problem, if the player has pointer acceleration turned on, which makes the task even harder.

\$\endgroup\$
1
  • \$\begingroup\$ hey thank it a good approach. I use the pointer lock mouse api, so it will be able to setup the mouse and activate this option. \$\endgroup\$
    – jon
    Commented May 23, 2018 at 18:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .