From 41fc399f7084b6eb59630843e6948306256132a9 Mon Sep 17 00:00:00 2001 From: Arthur <78031901+Arthur7770@users.noreply.github.com> Date: Mon, 1 Mar 2021 12:41:47 +0100 Subject: [PATCH] Scroll Camera Works --- src/lsystem/Main.java | 2 +- src/lsystem/screen/DrawHelper.java | 2 +- .../screen/listener/JoglMouseListener.java | 16 +++++++++++++--- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/lsystem/Main.java b/src/lsystem/Main.java index 50cfe09..0aaf338 100644 --- a/src/lsystem/Main.java +++ b/src/lsystem/Main.java @@ -9,7 +9,7 @@ public class Main { MainFrame frame = new MainFrame(); frame.setVisible(true); - //SwingGLCanvas canvas = new SwingGLCanvas(); + SwingGLCanvas canvas = new SwingGLCanvas(); } diff --git a/src/lsystem/screen/DrawHelper.java b/src/lsystem/screen/DrawHelper.java index c900b4e..e3f8c6d 100644 --- a/src/lsystem/screen/DrawHelper.java +++ b/src/lsystem/screen/DrawHelper.java @@ -71,6 +71,6 @@ public class DrawHelper { gl.glRasterPos3f(canvas.camera[0], canvas.camera[1], canvas.camera[2] - 1); gl.glColor3f(1f,1f, 1f); glut.glutBitmapString(GLUT.BITMAP_HELVETICA_18, - "x=" + canvas.camera[0] + ", y=" + canvas.camera[1] + ", z=" + canvas.camera[2]); + "x=" + canvas.camera[0] + ", y=" + canvas.camera[1] + ", z=" + canvas.camera[2]+"\n yaw = " + canvas.camera[3] + " pitch = " + canvas.camera[4] + " roll = " + canvas.camera[5]); } } diff --git a/src/lsystem/screen/listener/JoglMouseListener.java b/src/lsystem/screen/listener/JoglMouseListener.java index 8838e25..f9888f1 100644 --- a/src/lsystem/screen/listener/JoglMouseListener.java +++ b/src/lsystem/screen/listener/JoglMouseListener.java @@ -75,9 +75,19 @@ public class JoglMouseListener implements MouseListener, MouseMotionListener, Mo @Override public void mouseWheelMoved(MouseWheelEvent e) { - canvas.camera[0] += e.getWheelRotation() * 0.25 * canvas.camera[3]; - canvas.camera[1] += e.getWheelRotation() * 0.25 * canvas.camera[4]; + if( 45 > Math.abs(canvas.camera[3])) + canvas.camera[0] += e.getWheelRotation()*Math.tan(Math.toRadians(-canvas.camera[3]))*0.25; + else + canvas.camera[0] += e.getWheelRotation()*Math.tan(Math.toRadians(canvas.camera[3]))*0.25; + if(45>Math.abs(canvas.camera[4])) + canvas.camera[1] += e.getWheelRotation()*Math.tan(Math.toRadians(canvas.camera[4]))*0.25; + else + canvas.camera[1] += e.getWheelRotation()*Math.tan(Math.toRadians(-canvas.camera[4]))*0.25; + + if( 45 < Math.abs(canvas.camera[3]) || 45