walkingSpeed /= 10f;
}
if (keyUp && keyRight && !keyLeft && !keyDown) {
float angle = rotation.y + 45;
Vector3f newPosition = new Vector3f(position);
float hypotenuse = (walkingSpeed * 0.0002f) * delta;
float adjacent = hypotenuse * (float) Math.cos(Math.toRadians(angle));
float opposite = (float) (Math.sin(Math.toRadians(angle)) * hypotenuse);
newPosition.z += adjacent;
newPosition.x -= opposite;
position.z = newPosition.z;
position.x = newPosition.x;
}
if (keyUp && keyLeft && !keyRight && !keyDown) {
float angle = rotation.y - 45;
Vector3f newPosition = new Vector3f(position);
float hypotenuse = (walkingSpeed * 0.0002f) * delta;
float adjacent = hypotenuse * (float) Math.cos(Math.toRadians(angle));
float opposite = (float) (Math.sin(Math.toRadians(angle)) * hypotenuse);
newPosition.z += adjacent;
newPosition.x -= opposite;
position.z = newPosition.z;
position.x = newPosition.x;
}
if (keyUp && !keyLeft && !keyRight && !keyDown) {
float angle = rotation.y;
Vector3f newPosition = new Vector3f(position);
float hypotenuse = (walkingSpeed * 0.0002f) * delta;
float adjacent = hypotenuse * (float) Math.cos(Math.toRadians(angle));
float opposite = (float) (Math.sin(Math.toRadians(angle)) * hypotenuse);
newPosition.z += adjacent;
newPosition.x -= opposite;
position.z = newPosition.z;
position.x = newPosition.x;
}
if (keyDown && keyLeft && !keyRight && !keyUp) {
float angle = rotation.y - 135;
Vector3f newPosition = new Vector3f(position);
float hypotenuse = (walkingSpeed * 0.0002f) * delta;
float adjacent = hypotenuse * (float) Math.cos(Math.toRadians(angle));
float opposite = (float) (Math.sin(Math.toRadians(angle)) * hypotenuse);
newPosition.z += adjacent;
newPosition.x -= opposite;
position.z = newPosition.z;
position.x = newPosition.x;
}
if (keyDown && keyRight && !keyLeft && !keyUp) {
float angle = rotation.y + 135;
Vector3f newPosition = new Vector3f(position);
float hypotenuse = (walkingSpeed * 0.0002f) * delta;
float adjacent = hypotenuse * (float) Math.cos(Math.toRadians(angle));
float opposite = (float) (Math.sin(Math.toRadians(angle)) * hypotenuse);
newPosition.z += adjacent;
newPosition.x -= opposite;
position.z = newPosition.z;
position.x = newPosition.x;
}
if (keyDown && !keyUp && !keyLeft && !keyRight) {
float angle = rotation.y;
Vector3f newPosition = new Vector3f(position);
float hypotenuse = -(walkingSpeed * 0.0002f) * delta;
float adjacent = hypotenuse * (float) Math.cos(Math.toRadians(angle));
float opposite = (float) (Math.sin(Math.toRadians(angle)) * hypotenuse);
newPosition.z += adjacent;
newPosition.x -= opposite;
position.z = newPosition.z;
position.x = newPosition.x;
}
if (keyLeft && !keyRight && !keyUp && !keyDown) {
float angle = rotation.y - 90;
Vector3f newPosition = new Vector3f(position);
float hypotenuse = (walkingSpeed * 0.0002f) * delta;
float adjacent = hypotenuse * (float) Math.cos(Math.toRadians(angle));
float opposite = (float) (Math.sin(Math.toRadians(angle)) * hypotenuse);
newPosition.z += adjacent;
newPosition.x -= opposite;
position.z = newPosition.z;
position.x = newPosition.x;
}
if (keyRight && !keyLeft && !keyUp && !keyDown) {
float angle = rotation.y + 90;
Vector3f newPosition = new Vector3f(position);
float hypotenuse = (walkingSpeed * 0.0002f) * delta;
float adjacent = hypotenuse * (float) Math.cos(Math.toRadians(angle));
float opposite = (float) (Math.sin(Math.toRadians(angle)) * hypotenuse);
newPosition.z += adjacent;
newPosition.x -= opposite;
position.z = newPosition.z;
position.x = newPosition.x;
}
if (flyUp && !flyDown) {
double newPositionY = (walkingSpeed * 0.0002) * delta;
position.y -= newPositionY;
}
if (flyDown && !flyUp) {
double newPositionY = (walkingSpeed * 0.0002) * delta;
position.y += newPositionY;
}
if (moveFaster && !moveSlower) {
walkingSpeed /= 4f;
}
if (moveSlower && !moveFaster) {
walkingSpeed *= 10f;
}
while (Mouse.next()) {
if (Mouse.isButtonDown(0)) {
Mouse.setGrabbed(true);
}
if (Mouse.isButtonDown(1)) {
Mouse.setGrabbed(false);
}
}
while (Keyboard.next()) {
if (Keyboard.isKeyDown(Keyboard.KEY_C)) {
position = new Vector3f(0, 0, 0);
rotation = new Vector3f(0, 0, 0);
}
if (Keyboard.isKeyDown(Keyboard.KEY_O)) {
mouseSpeed += 1;
System.out.println("Mouse speed changed to " + mouseSpeed + ".");
}