From 44250cd124a346923a606f70eacd24fc0d5f5808 Mon Sep 17 00:00:00 2001 From: Arthur <78031901+Arthur7770@users.noreply.github.com> Date: Tue, 2 Mar 2021 17:13:43 +0100 Subject: [PATCH] Scroll works --- src/lsystem/Main.java | 4 +- .../screen/listener/JoglEventListener.java | 3 ++ .../screen/listener/JoglMouseListener.java | 41 +++++++++++++++---- 3 files changed, 38 insertions(+), 10 deletions(-) diff --git a/src/lsystem/Main.java b/src/lsystem/Main.java index 0aaf338..77ce7a1 100644 --- a/src/lsystem/Main.java +++ b/src/lsystem/Main.java @@ -3,10 +3,12 @@ package lsystem; import lsystem.screen.MainFrame; import lsystem.screen.SwingGLCanvas; +import java.util.Arrays; + public class Main { public static void main(String[] args) { - + System.out.println(-180%360); MainFrame frame = new MainFrame(); frame.setVisible(true); SwingGLCanvas canvas = new SwingGLCanvas(); diff --git a/src/lsystem/screen/listener/JoglEventListener.java b/src/lsystem/screen/listener/JoglEventListener.java index 680f400..7019b91 100644 --- a/src/lsystem/screen/listener/JoglEventListener.java +++ b/src/lsystem/screen/listener/JoglEventListener.java @@ -84,6 +84,9 @@ public class JoglEventListener implements GLEventListener { @Override public void display(GLAutoDrawable glAutoDrawable) { + for (int i = 0; i < canvas.camera.length; i++) { + canvas.camera[i] = canvas.camera[i] % 360; + } GL2 gl = glAutoDrawable.getGL().getGL2(); gl.glClear(GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT); gl.glLoadIdentity(); diff --git a/src/lsystem/screen/listener/JoglMouseListener.java b/src/lsystem/screen/listener/JoglMouseListener.java index ced2645..c9790bd 100644 --- a/src/lsystem/screen/listener/JoglMouseListener.java +++ b/src/lsystem/screen/listener/JoglMouseListener.java @@ -64,9 +64,6 @@ public class JoglMouseListener implements MouseListener, MouseMotionListener, Mo } origine = e.getPoint(); } - for (int i = 0; i < canvas.camera.length; i++) { - canvas.camera[i] = canvas.camera[i] % 360; - } } @Override @@ -75,15 +72,41 @@ public class JoglMouseListener implements MouseListener, MouseMotionListener, Mo @Override public void mouseWheelMoved(MouseWheelEvent e) { - if( 45 > Math.abs(canvas.camera[3]) && 45>Math.abs(canvas.camera[4])) + // Gestion de la position x: + if(Math.abs(canvas.camera[3]) < 90 || Math.abs(canvas.camera[3]) > 270 ) { canvas.camera[0] += e.getWheelRotation() * Math.tan(Math.toRadians(-canvas.camera[3])) * 0.25; - else + } + else if(Math.abs(canvas.camera[3]) > 90 || Math.abs(canvas.camera[3]) < 270){ canvas.camera[0] += e.getWheelRotation() * Math.tan(Math.toRadians(canvas.camera[3])) * 0.25; - canvas.camera[1] += e.getWheelRotation() * Math.tan(Math.toRadians(canvas.camera[4])) * 0.25; - if( 45 < Math.abs(canvas.camera[3]) || 45 < Math.abs(canvas.camera[4])) - canvas.camera[2] += -e.getWheelRotation()*0.25; - else + } + // Gestion de la position y: + if(Math.abs(canvas.camera[4]) < 90 || Math.abs(canvas.camera[4]) > 270) { + canvas.camera[1] += e.getWheelRotation() * Math.tan(Math.toRadians(canvas.camera[4])) * 0.25; + } + else if(Math.abs(canvas.camera[4]) > 90 || Math.abs(canvas.camera[4]) < 270){ + canvas.camera[1] += e.getWheelRotation() * Math.tan(Math.toRadians(-canvas.camera[4])) * 0.25; + } + + if( 90 == canvas.camera[3]){ + canvas.camera[0] +=e.getWheelRotation()*0.25; + canvas.camera[2] += 0; + } + if( 90 == canvas.camera[4]){ + canvas.camera[1] +=e.getWheelRotation()*0.25; + canvas.camera[2] += 0; + } + if( -90 == canvas.camera[3]){ + canvas.camera[0] +=-e.getWheelRotation()*0.25; + canvas.camera[2] += 0; + } + if( -90 == canvas.camera[4]){ + canvas.camera[1] +=e.getWheelRotation()*0.25; + canvas.camera[2] += 0; + } + if(Math.abs(canvas.camera[3]) < 90 || Math.abs(canvas.camera[3]) > 270 && Math.abs(canvas.camera[4]) < 90 || Math.abs(canvas.camera[4]) > 270){ canvas.camera[2] += e.getWheelRotation()*0.25; + }else + canvas.camera[2] += -e.getWheelRotation()*0.25; } }