public void doInput() { // inputManager.pollInput(); // One Mouse.getDX() to rule them all // TODO move this a plugin if (activePlayer == null) { return; } if (Mouse.isGrabbed()) { Transform ts = activePlayer.getTransform().getTransform(); float pitch = ts.getRotation().getPitch(); float yaw = ts.getRotation().getYaw(); float mouseDX = -Mouse.getDX() * 0.16f; float mouseDY = Mouse.getDY() * 0.16f; if (yaw + mouseDX >= 360) yaw += mouseDX - 360; else if (yaw + mouseDX < 0) yaw += mouseDX + 360; else yaw += mouseDX; if (pitch + mouseDY >= -80 && pitch + mouseDY <= 80) pitch += mouseDY; else if (pitch + mouseDY < -80) pitch = -80; else if (pitch + mouseDY > 80) pitch = 80; // System.out.println("yaw: "+yaw+" pitch: "+pitch); ts.setRotation(MathHelper.rotation(pitch, yaw, ts.getRotation().getRoll())); activePlayer.getTransform().setTransform(ts); // System.out.println(activePlayer.getTransform().getTransform().toMatrix().toString()); } boolean keyUp = Keyboard.isKeyDown(Keyboard.KEY_UP) || Keyboard.isKeyDown(Keyboard.KEY_Z); boolean keyDown = Keyboard.isKeyDown(Keyboard.KEY_DOWN) || Keyboard.isKeyDown(Keyboard.KEY_S); boolean keyLeft = Keyboard.isKeyDown(Keyboard.KEY_LEFT) || Keyboard.isKeyDown(Keyboard.KEY_Q); boolean keyRight = Keyboard.isKeyDown(Keyboard.KEY_RIGHT) || Keyboard.isKeyDown(Keyboard.KEY_D); boolean flyUp = Keyboard.isKeyDown(Keyboard.KEY_SPACE); boolean flyDown = Keyboard.isKeyDown(Keyboard.KEY_LSHIFT); Point point = new Point(Point.ONE, activePlayer.getWorld()); if (keyUp) { point = point.multiply(activePlayer.getTransform().getTransform().forwardVector()); // activePlayer.getTransform().setPosition(activePlayer.getTransform().getPosition().subtract(activePlayer.getTransform().getTransform().forwardVector())); } if (keyDown) { point = point.multiply(activePlayer.getTransform().getTransform().forwardVector().multiply(-1)); // activePlayer.getTransform().setPosition(activePlayer.getTransform().getPosition().add(activePlayer.getTransform().getTransform().forwardVector())); } if (keyLeft) { point = point.multiply(activePlayer.getTransform().getTransform().rightVector()); // activePlayer.getTransform().setPosition(activePlayer.getTransform().getPosition().subtract(activePlayer.getTransform().getTransform().rightVector())); } if (keyRight) { point = point.multiply(activePlayer.getTransform().getTransform().rightVector().multiply(-1)); // activePlayer.getTransform().setPosition(activePlayer.getTransform().getPosition().add(activePlayer.getTransform().getTransform().rightVector())); } if (flyUp) { point = point.multiply(activePlayer.getTransform().getTransform().upVector()); // activePlayer.getTransform().setPosition(activePlayer.getTransform().getPosition().add(activePlayer.getTransform().getTransform().upVector())); } if (flyDown) { point = point.multiply(activePlayer.getTransform().getTransform().upVector().multiply(-1)); // activePlayer.getTransform().setPosition(activePlayer.getTransform().getPosition().subtract(activePlayer.getTransform().getTransform().upVector())); } if (keyUp || keyDown || keyLeft || keyRight || flyUp || flyDown) { // point = new Point(point.normalize(),activePlayer.getWorld()); System.out.println("Translation : " + point.getX() + "/" + point.getY() + "/" + point.getZ()); System.out.println( "Position : " + activePlayer.getTransform().getPosition().getX() + "/" + activePlayer.getTransform().getPosition().getY() + "/" + activePlayer.getTransform().getPosition().getZ()); activePlayer.getTransform().setPosition(activePlayer.getTransform().getPosition().add(point)); } /*for (Flags f : activePlayer.input().getFlagSet()) { switch(f) { case FORWARD: activePlayer.getTransform().setPosition(activePlayer.getTransform().getPosition().add(activePlayer.getTransform().getTransform().forwardVector())); break; case BACKWARD: activePlayer.getTransform().setPosition(activePlayer.getTransform().getPosition().subtract(activePlayer.getTransform().getTransform().forwardVector())); break; case LEFT: activePlayer.getTransform().setPosition(activePlayer.getTransform().getPosition().add(activePlayer.getTransform().getTransform().rightVector())); break; case RIGHT: activePlayer.getTransform().setPosition(activePlayer.getTransform().getPosition().subtract(activePlayer.getTransform().getTransform().rightVector())); break; case CROUCH: case FIRE_1: case FIRE_2: case INTERACT: case JUMP: case SELECT_DOWN: case SELECT_UP: } }*/ }
private void setAxisAngles(float pitch, float yaw, float roll, String errorMessage) { if (activeThreadIsValid(errorMessage)) { setRotation(MathHelper.rotation(pitch, yaw, roll)); } }