Prevent camera from going through blocks.

Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
origin
sigonasr2, Sig, Sigo 3 years ago
parent b0f0961260
commit 6f48971a74
  1. 21
      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;

Loading…
Cancel
Save