如何判断鼠标是顺时针还是逆时针移动? [英] How to determine if mouse is moving clockwise or counterclockwise?

查看:24
本文介绍了如何判断鼠标是顺时针还是逆时针移动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 MFC 应用程序,在该应用程序中,用户必须通过拖动运动将鼠标绕着一个圆圈移动.我需要在鼠标拖动旋转"期间检索度数,我需要知道它是顺时针还是逆时针.

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.

首先,为了确定旋转方向,我比较了当前鼠标位置和用户单击以启动拖动的鼠标位置之间的 x 坐标.在用户旋转超过 180 度之前效果很好.

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?

推荐答案

您需要至少三个有序点来确定某人随着时间的推移是顺时针还是逆时针移动.只有两点,(例如)某人是否旋转 90 度或 -270 度并不明显.所以简单地取 start 和 end 的叉积是行不通的.

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.

尝试在拖动过程中对鼠标进行采样以获得所需的附加信息,然后在每对连续点之间进行增量叉积.这会告诉你你想知道什么.但是,您需要足够快地进行采样,以便不会发生超过 180 度的旋转;否则你会再次陷入模棱两可的境地.

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.

这篇关于如何判断鼠标是顺时针还是逆时针移动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆