improve example tab + improve camera when generate l system

This commit is contained in:
Quentin Legot 2021-04-19 11:50:33 +02:00
parent 11529aaf18
commit 4b34a788b2
7 changed files with 53 additions and 18 deletions

View File

@ -65,6 +65,7 @@ public abstract class AbstractCanvas {
// -XX:+UseG1GC to force jre 1.8 to use G1GC (G1GC is default on jre 11+), if you have jre 15+ you should use
// ZGC which is very quick compared to G1GC and have a lower CPU usage
System.gc();
camera = new float[]{0f, 1f, 5f, 0f, 0f, 0f}; // reset default camera position
}
});
frame.getContentPane().add(glCanvas, BorderLayout.CENTER);

View File

@ -92,8 +92,8 @@ public class GLEventListener extends AbstractListener {
if(element.property == ElementProperties.DRAW) {
if(firstGen) {
canvas.camera[1] += 0.10f;
canvas.camera[2] += 0.10f;
canvas.camera[1] = (float) Math.min(50f, canvas.camera[1] + 0.10f-Math.sin(element.rotation[1]));
canvas.camera[2] = Math.min(50f, canvas.camera[2] + 0.10f);
}
glut.glutSolidCylinder(0.25f, 1f, 10, 10);
gl.glTranslatef(0f, 0f, 1f);

View File

@ -0,0 +1,17 @@
package lsystem.screen.main;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionListener;
public abstract class AbstractListener implements ActionListener {
protected final String type;
protected ImageIcon staticIcon = new ImageIcon(Toolkit.getDefaultToolkit().createImage(getClass().getClassLoader().getResource("./loading-gif.gif")));
public AbstractListener(String type) {
this.type = type;
}
public abstract void openDialog(String message);
}

View File

@ -1,37 +1,55 @@
package lsystem.screen.main;
import lsystem.engine.Parser;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Arrays;
import java.util.List;
public class Example extends JPanel {
private final MainFrame frame;
private final JButton a;
private final JButton b;
public Example(MainFrame frame) {
this.frame = frame;
JPanel list = new JPanel();
list.setLayout(new GridBagLayout());
JButton a = new JButton("{axiom=\"Y\",rules:[\"Y=X+[[Y]-Y]-X[-XY]+Y\", \"X=XX\"]}");
a = new JButton("{axiom=\"Y\",rules:[\"Y=X+[[Y]-Y]-X[-XY]+Y\", \"X=XX\"]}");
a.addActionListener(new ExampleListener("a"));
JPanel aboveComponents = new JPanel();
this.add(a);
b = new JButton("{axiom=\"X\",rules:[\"X=XY\",\"Y=X\"]}");
b.addActionListener(new ExampleListener("b"));
this.add(b);
this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
}
private class ExampleListener implements ActionListener {
private final String type;
private class ExampleListener extends AbstractListener {
public ExampleListener(String type) {
this.type = type;
super(type);
}
@Override
public void openDialog(String message) {
JOptionPane.showMessageDialog(null, message);
new ExampleListener("Clear");
}
@Override
public void actionPerformed(ActionEvent e) {
Parser parser;
switch(type) {
case "a":
parser = new Parser("Y", Arrays.asList("Y=X+[[Y]-Y]-X[-XY]+Y", "X=XX"), 5);
frame.generateLSystem(this, parser, a);
break;
case "b":
parser = new Parser("X", Arrays.asList("X=XY", "Y=X"), 5);
frame.generateLSystem(this, parser , b);
}
}

View File

@ -7,20 +7,18 @@ import java.awt.*;
import java.awt.event.*;
import java.util.List;
public class Listener implements ActionListener, KeyListener, MouseWheelListener {
public class Listener extends AbstractListener implements KeyListener, MouseWheelListener {
Tab tab;
MainFrame frame;
Integer index;
String type;
Integer nbAxioms= 0;
ImageIcon staticIcon = new ImageIcon(Toolkit.getDefaultToolkit().createImage(getClass().getClassLoader().getResource("./loading-gif.gif")));
public Listener(MainFrame frame, Integer index, String type, Tab tab){
super(type);
this.tab = tab;
this.frame = frame;
this.index = index;
this.type = type;
}
@Override
@ -64,7 +62,8 @@ public class Listener implements ActionListener, KeyListener, MouseWheelListener
}
void openDialog(String message) {
@Override
public void openDialog(String message) {
JOptionPane.showMessageDialog(null, message);
new Listener(null, index, "Clear", tab);
}

View File

@ -133,7 +133,7 @@ public class MainFrame extends JFrame {
}
}
public void generateLSystem(Listener listener, Parser parser, JButton submitButton) {
public void generateLSystem(AbstractListener listener, Parser parser, JButton submitButton) {
if(Main.joglFrame.frame.isVisible()) {
listener.openDialog("Veuillez fermer la fenêtre 2D ou 3D avant de lancer une nouvelle génération");
} else if(Main.joglFrame.parsedState == AbstractCanvas.State.LOAD) {