From 4f172ccb982e939989d35f20fa0772742ba8568e Mon Sep 17 00:00:00 2001 From: Andrew Lalis Date: Fri, 29 Jul 2022 00:24:43 +0200 Subject: [PATCH] Improved gravity slightly. --- .../java/nl/andrewl/aos2_client/Camera.java | 8 ++++++++ .../aos2_client/render/GameRenderer.java | 6 +++--- .../java/nl/andrewl/aos_core/model/Player.java | 17 ++++++++++++++--- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/client/src/main/java/nl/andrewl/aos2_client/Camera.java b/client/src/main/java/nl/andrewl/aos2_client/Camera.java index d90beb8..3f92e7e 100644 --- a/client/src/main/java/nl/andrewl/aos2_client/Camera.java +++ b/client/src/main/java/nl/andrewl/aos2_client/Camera.java @@ -52,6 +52,14 @@ public class Camera { velocity.set(p.getVelocity()); } + public void setToPlayerScopeView(Player p) { + Vector3f pos = new Vector3f(); + Matrix4f tx = p.getHeldItemTransform(); + tx.transformPosition(pos); + position.set(pos); + velocity.set(p.getVelocity()); + } + public void setOrientationToPlayer(Player p) { orientation.set(p.getOrientation()); } diff --git a/client/src/main/java/nl/andrewl/aos2_client/render/GameRenderer.java b/client/src/main/java/nl/andrewl/aos2_client/render/GameRenderer.java index 7477c1c..74d3a0a 100644 --- a/client/src/main/java/nl/andrewl/aos2_client/render/GameRenderer.java +++ b/client/src/main/java/nl/andrewl/aos2_client/render/GameRenderer.java @@ -137,7 +137,7 @@ public class GameRenderer { throw new RuntimeException(e); } log.debug("Initialized model renderer."); - updatePerspective(); + updatePerspective(config.fov); } public float getAspectRatio() { @@ -147,8 +147,8 @@ public class GameRenderer { /** * Updates the rendering perspective used to render the game. */ - private void updatePerspective() { - float fovRad = (float) Math.toRadians(config.fov); + public void updatePerspective(float fov) { + float fovRad = (float) Math.toRadians(fov); if (fovRad >= Math.PI) { fovRad = (float) (Math.PI - 0.01f); } else if (fovRad <= 0) { diff --git a/core/src/main/java/nl/andrewl/aos_core/model/Player.java b/core/src/main/java/nl/andrewl/aos_core/model/Player.java index 7ba55c8..79f6c7c 100644 --- a/core/src/main/java/nl/andrewl/aos_core/model/Player.java +++ b/core/src/main/java/nl/andrewl/aos_core/model/Player.java @@ -1,10 +1,9 @@ package nl.andrewl.aos_core.model; +import nl.andrewl.aos_core.Directions; import nl.andrewl.aos_core.MathUtils; +import org.joml.*; import org.joml.Math; -import org.joml.Vector2f; -import org.joml.Vector3f; -import org.joml.Vector3i; import java.util.ArrayList; import java.util.List; @@ -168,6 +167,18 @@ public class Player { return crouching ? HEIGHT_CROUCH : HEIGHT; } + /** + * Gets a transformation that transforms a position to the position of the + * player's held gun. + * @return The gun transform. + */ + public Matrix4f getHeldItemTransform() { + return new Matrix4f() + .translate(position) + .rotate(orientation.x + (float) Math.PI, Directions.UPf) + .translate(-0.35f, getEyeHeight() - 0.4f, 0.35f); + } + public List getBlockSpaceOccupied() { float playerBodyMinZ = position.z - RADIUS; float playerBodyMaxZ = position.z + RADIUS;