diff --git a/src/lsystem/engine/Element.java b/src/lsystem/engine/Element.java index a1941cf..1aed8ab 100644 --- a/src/lsystem/engine/Element.java +++ b/src/lsystem/engine/Element.java @@ -1,13 +1,13 @@ package lsystem.engine; -import java.util.LinkedList; +import java.util.ArrayList; public class Element { public final ElementProperties property; public final Element parent; public final float[] rotation; - public final LinkedList children = new LinkedList<>(); + public final ArrayList children = new ArrayList<>(); public Element(ElementProperties property, Element parent) { this(property, parent, new float[]{0f, 0f, 0f}); diff --git a/src/lsystem/engine/Parser.java b/src/lsystem/engine/Parser.java index d0987ae..2992737 100644 --- a/src/lsystem/engine/Parser.java +++ b/src/lsystem/engine/Parser.java @@ -92,7 +92,7 @@ public class Parser { } // TODO: 03/03/2021 to finish - public static Element parse(String word) { + public static Element parse(String word) throws NumberFormatException { char[] numbers = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '.', '+', '-'}; Element root = null; Element workingElement = null; diff --git a/src/lsystem/screen/AbstractCanvas.java b/src/lsystem/screen/AbstractCanvas.java index 0c3917d..d3c13e7 100644 --- a/src/lsystem/screen/AbstractCanvas.java +++ b/src/lsystem/screen/AbstractCanvas.java @@ -65,7 +65,7 @@ public abstract class AbstractCanvas { return lSystem; } - public void setLSystem(String axiom, List> rules, int iterations) { + public void setLSystem(String axiom, List> rules, int iterations) throws NumberFormatException { parsedState = State.LOAD; this.lSystem = Parser.parse(Rewrite.rewrite(axiom, rules, iterations)); parsedState = State.FINISH_OR_NULL; diff --git a/src/lsystem/screen/gl3d/GLEventListener.java b/src/lsystem/screen/gl3d/GLEventListener.java index 6292ab1..d15efe5 100644 --- a/src/lsystem/screen/gl3d/GLEventListener.java +++ b/src/lsystem/screen/gl3d/GLEventListener.java @@ -5,10 +5,6 @@ import com.jogamp.opengl.GLAutoDrawable; import com.jogamp.opengl.glu.GLU; import com.jogamp.opengl.util.gl2.GLUT; import lsystem.engine.Element; -import lsystem.utils.Pair; - -import java.util.LinkedList; -import java.util.Random; public class GLEventListener implements com.jogamp.opengl.GLEventListener { @@ -19,7 +15,6 @@ public class GLEventListener implements com.jogamp.opengl.GLEventListener { private final float[] light_0_position = {1000f, 1000f, 1000f, 1f}; private final float[] material_specular = {0.8f, 0.8f, 0.8f, 0.8f}; - private final LinkedList> prismPosition = new LinkedList<>(); private final GLU glu; private final GLUT glut; @@ -52,14 +47,6 @@ public class GLEventListener implements com.jogamp.opengl.GLEventListener { gl.glDepthFunc(GL2.GL_LEQUAL); gl.glHint(GL2.GL_PERSPECTIVE_CORRECTION_HINT, GL2.GL_NICEST); - for(int i = -50; i < 51; ++i) { - for(int j = -50; j < 51; ++j) { - if(new Random().nextFloat() < 0.05) { - prismPosition.add(new Pair<>(i, j)); - } - } - } - System.out.println(prismPosition.size() * 8); new Thread(() -> { while (canvas.frame.isVisible()) { try { @@ -90,6 +77,7 @@ public class GLEventListener implements com.jogamp.opengl.GLEventListener { glu.gluLookAt(canvas.camera[0], canvas.camera[1], canvas.camera[2], canvas.camera[0], canvas.camera[1], canvas.camera[2] - 1, 0f, 1f, 0f); gl.glPushMatrix(); gl.glRotatef(90f, -1f, 0f, 0f); + displayLSystem(gl, glut, canvas.getLSystem()); gl.glPopMatrix(); @@ -105,9 +93,7 @@ public class GLEventListener implements com.jogamp.opengl.GLEventListener { gl.glRotatef(element.rotation[1] * 360, 0f, 1f, 0f); gl.glRotatef((element.rotation[0] + element.rotation[1]) * 360, 0f, 0f, 1f); gl.glTranslated(-Math.sin(element.rotation[0]), -Math.sin(element.rotation[1]), -Math.sin(element.rotation[0] + element.rotation[1])); - gl.glBegin(GL2.GL_LINES); - glut.glutSolidCylinder(0.25f, 1f, 20, 20); - gl.glEnd(); + glut.glutSolidCylinder(0.25f, 1f, 10, 10); gl.glTranslatef(0f, 0f, 1f); for(Element child : element.children) { displayLSystem(gl, glut, child); diff --git a/src/lsystem/screen/main/Listener.java b/src/lsystem/screen/main/Listener.java index d0b3008..d37e9a4 100644 --- a/src/lsystem/screen/main/Listener.java +++ b/src/lsystem/screen/main/Listener.java @@ -59,8 +59,13 @@ public class Listener implements ActionListener, KeyListener { openDialog("Vos règles ou votre axiome ne sont pas correctement écrites, veuillez recommencer"); } else { parserThread = new Thread(() -> { - Main.joglFrame.setLSystem(axiom, parser.parseRules(), tab.getNbIterations()); - Main.joglFrame.setVisible(true); + try { + Main.joglFrame.setLSystem(axiom, parser.parseRules(), tab.getNbIterations()); + Main.joglFrame.setVisible(true); + } catch (NumberFormatException err) { + Main.joglFrame.parsedState = AbstractCanvas.State.FINISH_OR_NULL; + openDialog("Une erreur de type " + err.getClass().getSimpleName() + " est survenue lors de l'execution du parser: " + err.getMessage()); + } }); parserThread.start(); }