0
\$\begingroup\$

would anyone know a method or algorithm (js) to calculate and detect if a mouse is moving by a circle around a target? Example if a rotate mouse *4 time around a specific XY point, i would like to re-center my camera (in my context i need algoritme for a camera engine)

I search i little bit on the web, but no found good formula to perform this.

Maybe a will need a special api ?

thank.

\$\endgroup\$
  • \$\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 May 23 '18 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 May 23 '18 at 2:59
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.

| improve this answer | |
\$\endgroup\$
  • \$\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 May 23 '18 at 18:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.