问题
I have an MFC appplication where the user have to move the mouse around a circle circonference with a dragging mouvement. I need to retrieve the number of degrees during this mouse drag "rotation" and I need to know if it's clockwise or counterclockwise.
At first, to determine the rotation direction, I was comparing x-coordinnate between the current mouse position and the mouse position where the user clicked to initiate the dragging. That works well until the user rotate over 180 degrees.
How can I handle the other half of the circle?
回答1:
You'll need at least three ordered points to determine whether someone is moving clockwise or counterclockwise over time. With only two points, it isn't obvious whether (for instance) someone rotated 90 degrees or -270 degrees. So simply taking the cross product of the start and end won't work.
Try sampling the mouse during the dragging to get the additional information you need, and then taking incremental cross products between each pair of consecutive points. That will tell you what you want to know. However, you'll need to sample fast enough that no rotation of more than 180 degrees could have occurred; otherwise you'll wind up in an ambiguous situation again.
回答2:
These might help you.
http://en.wikipedia.org/wiki/Atan2
http://www.phy.syr.edu/courses/java-suite/crosspro.html
And here is a simple example of recognizing gestures (it's in flash but the idea is the important bit)
http://www.bytearray.org/?p=91
回答3:
Read about cross products. Computing a cross product between the X and Y vectors (differences from the start point) will always reliably give the rotation direction.
来源:https://stackoverflow.com/questions/649177/how-to-determine-if-mouse-is-moving-clockwise-or-counterclockwise