如何在OpenGL/Glut中更改鼠标光标的位置? [英] How can I change the position of the mouse cursor in OpenGL/Glut?

查看:415
本文介绍了如何在OpenGL/Glut中更改鼠标光标的位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个简单的游戏,我将用鼠标控制摄像头(使用GlutPassiveMotionFunc).

I'm writing a simple game and I'm going to have the mouse control the camera (using GlutPassiveMotionFunc).

我将基于回调之间的鼠标差异来进行俯仰和偏航,但是,我认为每当他们尝试移动鼠标时,将其强制"回到屏幕中心是个好主意.这样,他们的光标就不会在屏幕的边缘,并且他们也无法在该方向上进一步移动.

I'm going to pitch and yaw based off the mouse difference between callbacks, however I think it would be a good idea to "force" the mouse back to the center of the screen every time they tried to move it. This way their cursor won't be at the edge of the screen and they can't move any further in that direction.

我可以使用什么Glut/OpenGL命令来强制更改鼠标的位置?

What Glut / OpenGL command can I use to force the position of the mouse to change?

推荐答案

使用glutWarpPointer(x, y),其中xy(均为int s)以像素为单位(相对于窗口的原点).例如:

Use glutWarpPointer(x, y), where x and y (both ints) are in pixels (relative to the window's origin). For example:

glutWarpPointer(windowWidth / 2, windowHeight / 2);

这篇关于如何在OpenGL/Glut中更改鼠标光标的位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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