如何判断鼠标是顺时针还是逆时针移动?

发布于 2024-07-15 12:39:58 字数 188 浏览 9 评论 0原文

我有一个 MFC 应用程序,用户必须通过拖动移动鼠标围绕圆弧移动。 我需要检索鼠标拖动“旋转”期间的度数,并且我需要知道它是顺时针还是逆时针。

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

我该如何处理圆的另一半?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

葬シ愛 2024-07-22 12:39:58

您需要至少三个有序点来确定某人随着时间的推移是顺时针还是逆时针移动。 只有两个点,(例如)某人旋转了 90 度还是 -270 度并不明显。 因此,简单地采用开始和结束的叉积是行不通的。

尝试在拖动过程中对鼠标进行采样以获得所需的附加信息,然后在每对连续点之间获取增量叉积。 那会告诉你你想知道什么。 但是,您需要足够快的采样速度,不会发生超过 180 度的旋转; 不然你又会陷入暧昧的境地。

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.

此刻的回忆 2024-07-22 12:39:58

这些可能对你有帮助。

http://en.wikipedia.org/wiki/Atan2

http://www.phy.syr.edu/courses/java-suite/crosspro.html

这是一个识别手势的简单示例(它是在 Flash 中,但想法很重要)

http://www.bytearray.org/?p=91

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

遗忘曾经 2024-07-22 12:39:58

了解交叉产品。 计算 X 和 Y 向量(与起点的差值)之间的叉积将始终可靠地给出旋转方向。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文