lwjgl将mouseLook转换为键

时间:2014-03-11 12:41:10

标签: java lwjgl

嘿,我正在使用lwjgl从事3D项目。此时,玩家的摄像机视图被鼠标移动。使用箭头键和&我想将鼠标视图转换为w,a,s,d,这样您就不必再使用鼠标。

为什么我这样做?我有一个我无法使用的界面系统,因为应用程序当前抓住鼠标移动视图,因此播放器无法与界面交互。

我得到了什么:

public void cameraView() {
    if (Mouse.isGrabbed()) {
        float mouseDX = Mouse.getDX() * 0.8f * 0.16f;
        float mouseDY = Mouse.getDY() * 0.8f * 0.16f;
        if (rotation.y + mouseDX >= 360) {
            rotation.y = rotation.y + mouseDX - 360;
        } else if (rotation.y + mouseDX < 0) {
            rotation.y = 360 - rotation.y + mouseDX;
        } else {
            rotation.y += mouseDX;
        }
        if (rotation.x - mouseDY >= -89 && rotation.x - mouseDY <= 89) {
            rotation.x += -mouseDY;
        } else if (rotation.x - mouseDY < -89) {
            rotation.x = -89;
        } else if (rotation.x - mouseDY > 89) {
            rotation.x = 89;
        }
    }
}

如果有人能帮助我,那就太棒了。提前谢谢!

1 个答案:

答案 0 :(得分:0)

if(Keyboard.isKeyDown(Keyboard.KEY_A)) {rotation.y -= 1;}
if(Keyboard.isKeyDown(Keyboard.KEY_D)) {rotation.y += 1;}

这应该与Mouse.getDX()相同 或者,您可以使用:

while(Keyboard.next()) {
  if(Keyboard.getEventKey() == Keyboard.KEY_ESCAPE) {
    if(Keyboard.getEventKeyState()) {
      Mouse.setGrabbed(!Mouse.isGrabbed());
      Mouse.setCursorPosition(Display.getWidth()/2, Display.getHeight()/2);
}}}

if(Mouse.isGrabbed()) {
//Use mouse for moving
} else {
//Use mouse for interface
}
相关问题