lwjgl将鼠标线转换为键

eimct9ow  于 2021-07-09  发布在  Java
关注(0)|答案(1)|浏览(233)

嘿,伙计,我在用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;
        }
    }
}

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

iqjalb3h

iqjalb3h1#

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
}

相关问题