如何在 OpenGL 窗口模式下扩展鼠标空间

发布于 2024-09-02 04:02:04 字数 90 浏览 2 评论 0原文

如何延长鼠标在 OpenGL 窗口中的移动距离?

我希望实现的是类似 fps 的界面,其中光标被隐藏,并且相机旋转不受鼠标必须保留在窗口边界内的限制。

How do I extend the distance the mouse can move in an OpenGL window?

What I wish to achieve is an fps like interface where the cursor is hidden and camera rotations are not limited by the mouse having to remain inside the window boundaries.

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

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

发布评论

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

评论(4

黯淡〆 2024-09-09 04:02:04

每次鼠标移动后,使用 glutWarpPointer 将鼠标移回到屏幕中间(这将在 glutMotionFunc、glutPassiveMotionFunc 中)。
使用 glutsetcursor 更改或隐藏光标的外观。

Use glutWarpPointer to move the mouse back to the middle of the screen after every mouse move(that would be in glutMotionFunc, glutPassiveMotionFunc).
Use glutsetcursor to change or hide what the cursor looks like.

晨与橙与城 2024-09-09 04:02:04

在 Linux 中,这通常是通过将鼠标“变形”回屏幕中心来实现的。 这里是一个关于此问题的论坛主题,使用流行的 SDL库进行实际的鼠标读取。

在 Windows 中,考虑使用较低级别的输入 API,例如 XInput。

This is often implemented by "warping" the mouse back to the center of the screen, in Linux. Here is a forum thread on this, using the popular SDL library to do the actual mouse reading.

In Windows, look into using lower-level input API:s, such as XInput.

感悟人生的甜 2024-09-09 04:02:04

执行此操作的某些代码可能需要特定于平台。例如,在 Windows 上,您通常会在用户拖动鼠标时旋转相机。您可以通过捕获鼠标并在捕获鼠标时响应 WM_MOUSEMOVE 消息来处理它。捕获鼠标时,即使光标位置超出窗口边界,您也将继续收到鼠标移动消息。

看起来unwind已经很好地涵盖了X,所以这里不再重复。

Some of the code to do this will probably need to be platform specific. On Windows, for example, you'd typically do your camera rotations when the user drags the mouse. You'd handle it by capturing the mouse and responding to WM_MOUSEMOVE messages while it's captured. While the mouse is captured, you'll continue to receive the mouse move messages even if the cursor position goes outside the boundaries of your window.

It looks like unwind has already covered X pretty well, so I won't repeat it here.

七颜 2024-09-09 04:02:04

根据您使用的平台和工具,您可以让鼠标移动,然后计算距离,然后将其移回到屏幕(或 OpenGl 窗口)的中心。

int x,y;
GetMousePosition(&x,&y);
int deltaX = x-SCREEN_WIDTH/2;
int deltaY = y-SCREEN_WIDTH/2;
MoveMouse(SCREEN_WIDTH/2,SCREEN_HEIGHT/2);

这样您就可以轻松地移动鼠标,同时将鼠标保持在同一位置,从而避免出现问题。请注意,GetMousePositionMoveMouse 是通用函数名称,因为这取决于您使用的操作系统和/或库。

Depending on what platform and tools you use you can just let the mouse move, then calculate the distance and then move it back in the center of the screen(or OpenGl window).

int x,y;
GetMousePosition(&x,&y);
int deltaX = x-SCREEN_WIDTH/2;
int deltaY = y-SCREEN_WIDTH/2;
MoveMouse(SCREEN_WIDTH/2,SCREEN_HEIGHT/2);

This way you easily get the mouse movement while keeping the mouse in the same place and thus avoiding the problem. Note that the GetMousePosition and MoveMouse are generic function names as this depends on the OS and/or libraries you use.

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