如何获得更精确的鼠标移动

发布于 2024-11-07 01:40:44 字数 345 浏览 0 评论 0原文

操作系统:: windows xp sp3 Qt:: 4.6

我正在玩一些 3D 的东西,需要实现鼠标移动。我尝试使用 Qt mouseMoveEvent 但发现这不好,因为 mouseMoveEvent 在鼠标移动时不会处理每个像素。我需要一些东西来记录运动的每个像素。 为了寻找解决方案,我检查了 Qt 在线文档 &&找到 QCursor 类 &&它的成员 pos()。

问题:: QCursor::pos() 是否记录运动中的每个像素?有人有更好的想法来精确处理 3d 中的相机视图(我没有使用 openGL ,构建我的画家引擎(这是为了乐趣和爱好))?

os:: windows xp sp3
Qt:: 4.6

I am playing with some 3D stuff and need to implement mouse moving. I tried with Qt mouseMoveEvent but found that is not good because mouseMoveEvent does not handle with every pixel when mouse is moved. I need somethig that register EVERY pixel of movement.
Searching for solution I cheked Qt online documentation && found QCursor class && its member pos().

Questions:: Does QCursor::pos() register every pixel in movement? Have somebody better idea for precise handling of camera wiew in 3d (i am not using openGL , building my engine in painter(it is for fun && hoby) ) ?

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

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

发布评论

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

评论(4

给不了的爱 2024-11-14 01:40:44

不,鼠标可以一次移动几个像素。
如果您需要某件事的中间点,请计算它们。计算鼠标两个位置之间直线上的所有点。我仍然不清楚为什么你需要这些积分,但这应该有帮助。

No, mouse may move several pixels at once.
If you need the midway points for something then calculate them. Calculate all points on line between two positions of mouse. It is still unclear to me why you need the points, but that should help.

‖放下 2024-11-14 01:40:44

这很可能与 Qt 没有太大关系,而是与鼠标轮询率有关。您可能需要参考这篇内容丰富的博客文章 编码恐怖

This most likely does not have much to do with Qt, but with your mouse polling rate. You might want to refer to this quite informative blog post on Coding Horror.

好久不见√ 2024-11-14 01:40:44

前段时间我也遇到过类似的问题(我没有使用QT)。您的系统没有那么精确的信息。

我所做的是计算鼠标位置变化(dx,dy)并使用该信息来移动相机。在许多框架中,您不必计算 (dx,dy),因为您通过事件(例如 SDL)获取该信息。

或者,您可以计算位置变化,然后在当前和上一个鼠标位置之间插入位置 - 然后您可以使用这些位置来移动相机。

如果您想在屏幕上绘制鼠标移动,您也会遇到同样的问题。然后,您可以使用 Bresenham 算法 http://en.wikipedia.org/wiki/Bresenham's_line_algorithm 生成两个给定点之间的像素

Some time ago I had similar issue (I didn't use QT). Your system does not have that precise information.

What I did, was computing mouse position change (dx, dy) and using that information to move the camera. In many frameworks you don't have to compute (dx,dy) as you get that information with the event (for example SDL).

Alternatively you could compute position change and then interpolate positions between current and previous mouse position - then you could use those positions to move your camera.

You would have the same problem if you wanted to draw mouse movement on the screen. You can then use Bresenham's algorithm http://en.wikipedia.org/wiki/Bresenham's_line_algorithm to generate pixels between two given points

翻了热茶 2024-11-14 01:40:44

不,QCursor 不提供该信息,因为它没有信号向您提供该信息。您必须显式查询其位置,并在 mouseMoveEvent 中执行此操作再次限制精度。底层窗口系统无法提供这种精度。就像其他人所说的那样,只需处理任意广泛的运动或自己计算中间点即可。

No, QCursor does not prvide that information, as it has no signal giving you this. You have to explicitly query its position and doing that in the mouseMoveEvent limits the precision again. The underlying window system just does not deliver that precision. Like the others said, just work with arbitrary wide movements or compute the intermediary points yourself.

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