How can I change the position of the mouse cursor in OpenGL/Glut?

流过昼夜 提交于 2019-12-06 03:58:17

问题


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.

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


回答1:


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);



回答2:


Sorry for the late answer. What i meant was that after i use glutWrapPointer function, if i print out the x and y values, i could not catch the change on the cursor and it always prints out the values inside the glutWrapPointer function that i provided. What i did to fix it was to move this function inside the Animate function of openGl and it worked fine.



来源:https://stackoverflow.com/questions/784322/how-can-i-change-the-position-of-the-mouse-cursor-in-opengl-glut

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!