java - FPS OpenGL 中的鼠标移动(甚至在窗口外)

标签 java opengl jogl

我正在创建一个简单的 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/

相关文章:

java - 如何与 Trackers 通信并获取 Peers 列表?

c++ - 仅当使用 opengl 3.2 上下文或更高版本时,glVertexAttribPointer 和 glDrawArrays 的 GL_ERROR == 1282

Java OpenGL 屏幕大小的纹理映射四边形

java - 3D相交测试

java - 微软图 : Updating a document with a Put request Java

java - 如何通过注解用 try-catch 包装一个方法?

java - Google Drive API - OAuth2.0 : How to Automate Authentication Process? 疑虑和问题

opengl - 了解 GPU/核心驱动程序的低级复杂性是否可以提高您使用图形 API 的技能?

c++ - 从相机旋转 openGL 中隔离 "Compass"

java - 在 java 中加载、更新和渲染 3d 建模