From 6f48971a7461d7e83f891c23a69083f3f0bdc85e Mon Sep 17 00:00:00 2001 From: "sigonasr2, Sig, Sigo" Date: Tue, 9 Nov 2021 05:13:49 +0000 Subject: [PATCH] Prevent camera from going through blocks. Co-authored-by: sigonasr2 --- src/sig/SigRenderer.java | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/sig/SigRenderer.java b/src/sig/SigRenderer.java index d0e53ee..6b16eec 100644 --- a/src/sig/SigRenderer.java +++ b/src/sig/SigRenderer.java @@ -80,11 +80,28 @@ public class SigRenderer implements KeyListener,MouseListener,MouseMotionListene if (wHeld||sHeld) { Vector forward = Vector.multiply(vLookDir,MOVESPEED); if (wHeld) { - vCamera = Vector.add(vCamera,forward); + if (!blockGrid.containsKey((float)Math.floor(vCamera.x+forward.x)+"_"+(float)Math.floor(vCamera.y)+"_"+(float)Math.floor(vCamera.z))) { + vCamera.x+=forward.x; + } + if (!blockGrid.containsKey((float)Math.floor(vCamera.x)+"_"+(float)Math.floor(vCamera.y+forward.y)+"_"+(float)Math.floor(vCamera.z))) { + vCamera.y+=forward.y; + } + if (!blockGrid.containsKey((float)Math.floor(vCamera.x)+"_"+(float)Math.floor(vCamera.y)+"_"+(float)Math.floor(vCamera.z+forward.z))) { + vCamera.z+=forward.z; + } } if (sHeld) { - vCamera = Vector.subtract(vCamera,forward); + if (!blockGrid.containsKey((float)Math.floor(vCamera.x-forward.x)+"_"+(float)Math.floor(vCamera.y)+"_"+(float)Math.floor(vCamera.z))) { + vCamera.x-=forward.x; + } + if (!blockGrid.containsKey((float)Math.floor(vCamera.x)+"_"+(float)Math.floor(vCamera.y-forward.y)+"_"+(float)Math.floor(vCamera.z))) { + vCamera.y-=forward.y; + } + if (!blockGrid.containsKey((float)Math.floor(vCamera.x)+"_"+(float)Math.floor(vCamera.y)+"_"+(float)Math.floor(vCamera.z-forward.z))) { + vCamera.z-=forward.z; + } } + System.out.println(vCamera); } if (aHeld) { yaw-=TURNSPEED;