如果 CPU 使用率不是 100%,鼠标坐标就会滞后 - 真的很奇怪!
当我让我的程序仅使用 0-2% cpu(删除了一些 CPU 密集型 opengl 函数)时,我的鼠标坐标开始滞后!当我使用 100% CPU 时(启用 opengl 函数时),我会得到漂亮且平滑的鼠标坐标,请注意 opengl 函数对我的鼠标坐标没有任何作用。看下图,我使用鼠标坐标记录了我的旋转函数值:
这是 100% cpu 使用率(正如它应该看起来的那样): 无延迟 http://img15.imageshack.us/img15/1304/mousecursorsmoothcoords.png< /a>
-
这是 2% cpu 使用率的情况: 滞后 http://img5.imageshack.us/img5/5514/mousecursorlaggedcoords.png
这确实是一个烦人的问题,因为我使用鼠标光标位置来改变旋转角度,并且在上面的图像情况下,它看起来真的很滞后旋转。
我也许可以进行自己的插值或其他操作,但我想知道是什么原因造成的以及如何修复它。
我通过 WM_MOUSEMOVE 消息获取鼠标坐标,并且我还尝试在旋转代码之前的每一帧上使用 GetCursorPos() ,但它没有区别。
编辑:我注意到CPU使用率不一定要100%才能流畅,但CPU只需要被“唤醒”,然后即使CPU使用率较低也能保持流畅。
When i make my program to use only 0-2% cpu (removed some CPU intensive opengl function), my mouse coordinates starts to lag! and when i use 100% CPU (when enabling the opengl function) i get nice and smooth mouse coordinates, note that the opengl function does nothing to my mouse coordinates. look at below image i recorded my rotation function values by using mouse coordinates:
This is with 100% cpu usage (as it should look):
no lag http://img15.imageshack.us/img15/1304/mousecursorsmoothcoords.png
-
This is with 2% cpu usage:
lag http://img5.imageshack.us/img5/5514/mousecursorlaggedcoords.png
It is really annoying problem, because i am using mouse cursor position to change the rotation angle, and with the above image case, it looks really laggy rotation.
I might be able to make own interpolation or something, but i want to know what is causing this and how to fix it.
Im getting mouse coordinates with WM_MOUSEMOVE message and i also tried to use GetCursorPos() on every frame before my rotation code, but it has no difference.
Edit: I noticed that the CPU usage doesnt have to be 100% to get smooth, but the CPU just needs to be "waken up" and then it stays smooth even with low CPU usage.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你的第二张图看起来像是“捆绑”更新。 Y 轴上的跳跃似乎在 X 轴上以固定频率进行。
推测:
http://www.geisswerks.com/ryan/FAQS/timing.html
Your second graph seems like it is "bunching" updates. Jumps on the Y axis seem to be at a fixed frequency on the X axis.
Speculation:
http://www.geisswerks.com/ryan/FAQS/timing.html
您可以使用
获得有关鼠标运动的更好信息GetMouseMovePointsEx()
API。旁注:由于某种原因我只能看到你的第一个图形
You might be able to get better information about the mouse motion by using the
GetMouseMovePointsEx()
API.Sidenote: for some reason I can only see your first graphic