我正在创建一个简单的 FPS 游戏,其中摄像机的移动由鼠标控制。当相机位于窗口内时,用鼠标移动相机非常简单。但是即使我在窗外,我怎样才能让这项工作正常进行呢?
我听说过一些关于将鼠标固定在屏幕中央的事情,但我不确定如何让它发挥作用。
我目前有以下内容:
public void mouseMoved(MouseEvent event) {
x = X;
y = Y;
X = event.getX();
Y = event.getY();
}
public void update() {
dX = X - x;
dY = Y - y;
x = X;
y = Y;
}
最佳答案
I've heard some thing about fixing the mouse in the center of the screen, but I'm not sure how to get this to work.
这是一种非常常见的方法。检查完鼠标移动了多少并使用该信息进行相机移动后,只需将光标移回屏幕中心即可。
考虑这样的事情:
Vec2 mouseDelta = getMousePosition();
camera.CalculateMovement(mouseDelta);
setMousePosition(0, 0);
关于java - FPS OpenGL 中的鼠标移动(甚至在窗口外),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20126019/