From 4878df85f7a62d3ae6d57e0cbbb1427891cf9e8c Mon Sep 17 00:00:00 2001 From: Arthur <78031901+Arthur7770@users.noreply.github.com> Date: Tue, 2 Mar 2021 17:49:59 +0100 Subject: [PATCH] Control key update but still an acceleration problem --- .../screen/listener/JoglMouseListener.java | 2 +- .../screen/listener/KeyboardListener.java | 32 ++++++++++++++++--- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/src/lsystem/screen/listener/JoglMouseListener.java b/src/lsystem/screen/listener/JoglMouseListener.java index c9790bd..90a6d3d 100644 --- a/src/lsystem/screen/listener/JoglMouseListener.java +++ b/src/lsystem/screen/listener/JoglMouseListener.java @@ -53,7 +53,7 @@ public class JoglMouseListener implements MouseListener, MouseMotionListener, Mo if(origine != null) { double xDiff = origine.getX() - e.getPoint().getX(); double yDiff = origine.getY() - e.getPoint().getY(); - /* if(button == 2) { + /* if(button == 1) { canvas.camera[0] += Math.cos(canvas.camera[3]) * xDiff * 0.01; canvas.camera[1] += Math.cos(canvas.camera[4]) * yDiff * 0.01; canvas.camera[2] += Math.sin(canvas.camera[3]) * xDiff * 0.01; diff --git a/src/lsystem/screen/listener/KeyboardListener.java b/src/lsystem/screen/listener/KeyboardListener.java index dcd8d26..07ebda9 100644 --- a/src/lsystem/screen/listener/KeyboardListener.java +++ b/src/lsystem/screen/listener/KeyboardListener.java @@ -19,16 +19,40 @@ public class KeyboardListener implements KeyListener { switch (e.getKeyChar()) { case 'z': - canvas.camera[2] -= 0.1f; + if(Math.abs(canvas.camera[3]) < 90 || Math.abs(canvas.camera[3])>270 ){ + canvas.camera[2] -= 0.1f; + canvas.camera[0] += 0.1f*Math.tan(Math.toRadians(canvas.camera[3])); + }else{ + canvas.camera[2] += 0.1f; + canvas.camera[0] -= 0.1f*Math.tan(Math.toRadians(canvas.camera[3])); + } break; case 's': - canvas.camera[2] += 0.1f; + if(Math.abs(canvas.camera[3]) < 90 || Math.abs(canvas.camera[3])>270 ){ + canvas.camera[2] += 0.1f; + canvas.camera[0] -= 0.1f*Math.tan(Math.toRadians(canvas.camera[3])); + }else{ + canvas.camera[2] -= 0.1f; + canvas.camera[0] += 0.1f*Math.tan(Math.toRadians(canvas.camera[3])); + } break; case 'q': - canvas.camera[0] -= 0.1f; + if(Math.abs(canvas.camera[3]) < 90 || Math.abs(canvas.camera[3])>270 ){ + canvas.camera[0] -= 0.1f; + canvas.camera[2] -= 0.1f*Math.tan(Math.toRadians(canvas.camera[3])); + }else{ + canvas.camera[0] += 0.1f; + canvas.camera[2] -= 0.1f*Math.tan(Math.toRadians(canvas.camera[3])); + } break; case 'd': - canvas.camera[0] += 0.1f; + if(Math.abs(canvas.camera[3]) < 180 || Math.abs(canvas.camera[3])>0 ){ + canvas.camera[0] += 0.1f; + canvas.camera[2] += 0.1f*Math.tan(Math.toRadians(canvas.camera[3])); + }else{ + canvas.camera[0] -= 0.1f; + canvas.camera[2] += 0.1f*Math.tan(Math.toRadians(canvas.camera[3])); + } break; case 'a': canvas.camera[3] -= 1;