moved some constants to Constants.java + removed ROTATION_Z in ElementProperties.java + enhance window name
This commit is contained in:
parent
bbc74e1513
commit
7fcd7d4449
@ -5,8 +5,7 @@ public enum ElementProperties {
|
|||||||
DRAW('X'),
|
DRAW('X'),
|
||||||
NOTHING('Y'),
|
NOTHING('Y'),
|
||||||
ROTATION_X('x', (byte) 0),
|
ROTATION_X('x', (byte) 0),
|
||||||
ROTATION_Y('y', (byte) 1),
|
ROTATION_Y('y', (byte) 1);
|
||||||
ROTATION_Z('z', (byte) 2);
|
|
||||||
|
|
||||||
|
|
||||||
private final char ch4r;
|
private final char ch4r;
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package lsystem.engine;
|
package lsystem.engine;
|
||||||
|
|
||||||
import lsystem.Type;
|
import lsystem.Type;
|
||||||
|
import lsystem.screen.Constants;
|
||||||
import lsystem.utils.Pair;
|
import lsystem.utils.Pair;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -12,8 +13,6 @@ public class Parser {
|
|||||||
private final String axiom;
|
private final String axiom;
|
||||||
private final List<String> rules;
|
private final List<String> rules;
|
||||||
private final int nbIterations;
|
private final int nbIterations;
|
||||||
private final char[] validChars = {'=',']','[','.','+','-','X','Y','x','y','z','0','1','2','3','4','5','6','7','8','9',' '};
|
|
||||||
private static final float TWENTY_FIVE_DEGREES = 25/360f;
|
|
||||||
|
|
||||||
public Parser(String axiom, List<String> rules,int nbIterations) {
|
public Parser(String axiom, List<String> rules,int nbIterations) {
|
||||||
this.axiom = axiom;
|
this.axiom = axiom;
|
||||||
@ -64,12 +63,12 @@ public class Parser {
|
|||||||
}
|
}
|
||||||
if(old == '.'){
|
if(old == '.'){
|
||||||
for(int y = (type == Type.RULE ? 0 : 1); y < 12; y++){
|
for(int y = (type == Type.RULE ? 0 : 1); y < 12; y++){
|
||||||
if(temp == validChars[y])
|
if(temp == Constants.VALID_CHARS[y])
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
old = temp;
|
old = temp;
|
||||||
for(char validChar : validChars){
|
for(char validChar : Constants.VALID_CHARS){
|
||||||
if(temp == validChar)
|
if(temp == validChar)
|
||||||
break;
|
break;
|
||||||
if(validChar == ' ')
|
if(validChar == ' ')
|
||||||
@ -92,14 +91,13 @@ public class Parser {
|
|||||||
return rules;
|
return rules;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: 03/03/2021 to finish
|
|
||||||
public static Element parse(String word) throws NumberFormatException {
|
public static Element parse(String word) throws NumberFormatException {
|
||||||
char[] numbers = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '.', '+', '-'};
|
char[] numbers = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '.', '+', '-'};
|
||||||
Element root = null;
|
Element root = null;
|
||||||
Element workingElement = null;
|
Element workingElement = null;
|
||||||
String number = "";
|
String number = "";
|
||||||
List<Element> bracket = new ArrayList<>();
|
List<Element> bracket = new ArrayList<>();
|
||||||
float[] appliedRotation = new float[3];
|
float[] appliedRotation = new float[2];
|
||||||
Element lastCreatedElement = null;
|
Element lastCreatedElement = null;
|
||||||
|
|
||||||
for(int i = 0; i < word.length(); ++i) {
|
for(int i = 0; i < word.length(); ++i) {
|
||||||
@ -151,11 +149,10 @@ public class Parser {
|
|||||||
private static float getFloat(String number) throws NumberFormatException {
|
private static float getFloat(String number) throws NumberFormatException {
|
||||||
float n;
|
float n;
|
||||||
if(number.equals("") || number.equals("+"))
|
if(number.equals("") || number.equals("+"))
|
||||||
n = TWENTY_FIVE_DEGREES;
|
n = Constants.TWENTY_FIVE_DEGREES;
|
||||||
else if(number.equals("-")) {
|
else if(number.equals("-")) {
|
||||||
n = -TWENTY_FIVE_DEGREES;
|
n = -Constants.TWENTY_FIVE_DEGREES;
|
||||||
}else{
|
}else{
|
||||||
System.out.println(number);
|
|
||||||
n = Float.parseFloat(number);
|
n = Float.parseFloat(number);
|
||||||
}
|
}
|
||||||
return n;
|
return n;
|
||||||
|
@ -47,7 +47,7 @@ public abstract class AbstractCanvas {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
frame.getContentPane().add(glCanvas, BorderLayout.CENTER);
|
frame.getContentPane().add(glCanvas, BorderLayout.CENTER);
|
||||||
frame.setSize(Constants.WIDTH, Constants.HEIGHT);
|
frame.setSize(Constants.INITIAL_WIDTH, Constants.INITIAL_HEIGHT);
|
||||||
addEventsListeners();
|
addEventsListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,8 +2,14 @@
|
|||||||
|
|
||||||
public class Constants {
|
public class Constants {
|
||||||
|
|
||||||
public static final int WIDTH = 600;
|
public static final int INITIAL_WIDTH = 600;
|
||||||
public static final int HEIGHT = 400;
|
public static final int INITIAL_HEIGHT = 400;
|
||||||
|
public static final float TWENTY_FIVE_DEGREES = 25/360f;
|
||||||
|
public static final char[] VALID_CHARS = {'=',']','[','.','+','-','X','Y','x','y','0','1','2','3','4','5','6','7','8','9',' '};
|
||||||
|
public static final float[] light_0_ambient = {0.01f, 0.01f, 0.01f, 0.01f};
|
||||||
|
public static final float[] light_0_diffuse = {1.0f, 1.0f, 1.0f, 1.0f};
|
||||||
|
public static final float[] light_0_specular = {1.0f,1.0f, 1.0f, 1.0f};
|
||||||
|
public static final float[] material_specular = {0.8f, 0.8f, 0.8f, 0.8f};
|
||||||
public static final String HELP = "Alphabet{X,Y,Z}\r\n"
|
public static final String HELP = "Alphabet{X,Y,Z}\r\n"
|
||||||
+ "\r\n"
|
+ "\r\n"
|
||||||
+ "\r\n"
|
+ "\r\n"
|
||||||
|
@ -6,17 +6,12 @@ import com.jogamp.opengl.glu.GLU;
|
|||||||
import com.jogamp.opengl.util.gl2.GLUT;
|
import com.jogamp.opengl.util.gl2.GLUT;
|
||||||
import lsystem.engine.Element;
|
import lsystem.engine.Element;
|
||||||
import lsystem.engine.ElementProperties;
|
import lsystem.engine.ElementProperties;
|
||||||
|
import lsystem.screen.Constants;
|
||||||
|
|
||||||
public class GLEventListener implements com.jogamp.opengl.GLEventListener {
|
public class GLEventListener implements com.jogamp.opengl.GLEventListener {
|
||||||
|
|
||||||
private final GLCanvas canvas;
|
private final GLCanvas canvas;
|
||||||
private final float[] light_0_ambient = {0.01f, 0.01f, 0.01f, 0.01f};
|
|
||||||
private final float[] light_0_diffuse = {1.0f, 1.0f, 1.0f, 1.0f};
|
|
||||||
private final float[] light_0_specular = {1.0f,1.0f, 1.0f, 1.0f};
|
|
||||||
private final float[] light_0_position = {1000f, 1000f, 1000f, 1f};
|
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 GLU glu;
|
private final GLU glu;
|
||||||
private final GLUT glut;
|
private final GLUT glut;
|
||||||
private int fps;
|
private int fps;
|
||||||
@ -42,9 +37,9 @@ public class GLEventListener implements com.jogamp.opengl.GLEventListener {
|
|||||||
gl.glClearDepth(1.0f);
|
gl.glClearDepth(1.0f);
|
||||||
gl.glShadeModel(GL2.GL_SMOOTH);
|
gl.glShadeModel(GL2.GL_SMOOTH);
|
||||||
|
|
||||||
gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_AMBIENT, light_0_ambient, 0);
|
gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_AMBIENT, Constants.light_0_ambient, 0);
|
||||||
gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_DIFFUSE, light_0_diffuse, 0);
|
gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_DIFFUSE, Constants.light_0_diffuse, 0);
|
||||||
gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_SPECULAR, light_0_specular, 0);
|
gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_SPECULAR, Constants.light_0_specular, 0);
|
||||||
|
|
||||||
gl.glDepthFunc(GL2.GL_LEQUAL);
|
gl.glDepthFunc(GL2.GL_LEQUAL);
|
||||||
gl.glHint(GL2.GL_PERSPECTIVE_CORRECTION_HINT, GL2.GL_NICEST);
|
gl.glHint(GL2.GL_PERSPECTIVE_CORRECTION_HINT, GL2.GL_NICEST);
|
||||||
@ -120,7 +115,7 @@ public class GLEventListener implements com.jogamp.opengl.GLEventListener {
|
|||||||
gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_POSITION, light_0_position, 0);
|
gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_POSITION, light_0_position, 0);
|
||||||
gl.glColorMaterial(GL2.GL_FRONT_AND_BACK, GL2.GL_AMBIENT_AND_DIFFUSE);
|
gl.glColorMaterial(GL2.GL_FRONT_AND_BACK, GL2.GL_AMBIENT_AND_DIFFUSE);
|
||||||
gl.glMateriali(GL2.GL_FRONT_AND_BACK, GL2.GL_SHININESS, 90);
|
gl.glMateriali(GL2.GL_FRONT_AND_BACK, GL2.GL_SHININESS, 90);
|
||||||
gl.glMaterialfv(GL2.GL_FRONT_AND_BACK, GL2.GL_SPECULAR, material_specular, 0);
|
gl.glMaterialfv(GL2.GL_FRONT_AND_BACK, GL2.GL_SPECULAR, Constants.material_specular, 0);
|
||||||
|
|
||||||
gl.glMatrixMode(GL2.GL_MODELVIEW);
|
gl.glMatrixMode(GL2.GL_MODELVIEW);
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ package lsystem.screen.main;
|
|||||||
import lsystem.Main;
|
import lsystem.Main;
|
||||||
import lsystem.engine.Parser;
|
import lsystem.engine.Parser;
|
||||||
import lsystem.screen.AbstractCanvas;
|
import lsystem.screen.AbstractCanvas;
|
||||||
|
import lsystem.utils.Pair;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
@ -17,7 +18,7 @@ public class Listener implements ActionListener, KeyListener {
|
|||||||
MainFrame frame;
|
MainFrame frame;
|
||||||
Integer index;
|
Integer index;
|
||||||
String type;
|
String type;
|
||||||
Integer nbAxioms;
|
Integer nbAxioms = 0;
|
||||||
Thread parserThread = null;
|
Thread parserThread = null;
|
||||||
ImageIcon staticIcon = new ImageIcon(Toolkit.getDefaultToolkit().createImage(getClass().getClassLoader().getResource("loading-gif.gif")));
|
ImageIcon staticIcon = new ImageIcon(Toolkit.getDefaultToolkit().createImage(getClass().getClassLoader().getResource("loading-gif.gif")));
|
||||||
|
|
||||||
@ -27,7 +28,6 @@ public class Listener implements ActionListener, KeyListener {
|
|||||||
this.frame = frame;
|
this.frame = frame;
|
||||||
this.index = index;
|
this.index = index;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
nbAxioms = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -73,7 +73,18 @@ public class Listener implements ActionListener, KeyListener {
|
|||||||
tab.submitButton.setText("");
|
tab.submitButton.setText("");
|
||||||
parserThread = new Thread(() -> {
|
parserThread = new Thread(() -> {
|
||||||
try {
|
try {
|
||||||
Main.joglFrame.setLSystem(axiom, parser.parseRules(), tab.getNbIterations());
|
List<Pair<String, String>> lSystemRules = parser.parseRules();
|
||||||
|
Main.joglFrame.setLSystem(axiom, lSystemRules, tab.getNbIterations());
|
||||||
|
|
||||||
|
StringBuilder message = new StringBuilder("L-System 3D - {axiom:\"").append(axiom).append("\",rules:[");
|
||||||
|
for(int i = 0; i < lSystemRules.size(); ++i) {
|
||||||
|
Pair<String, String> rule = lSystemRules.get(i);
|
||||||
|
message.append("\"").append(rule.getLeft()).append("=").append(rule.getRight()).append("\"");
|
||||||
|
if(i + 1 != lSystemRules.size())
|
||||||
|
message.append(",");
|
||||||
|
}
|
||||||
|
Main.joglFrame.frame.setTitle(message.append("]} - Nombres d'itérations: ").append(tab.getNbIterations()).toString());
|
||||||
|
|
||||||
Main.joglFrame.setVisible(true);
|
Main.joglFrame.setVisible(true);
|
||||||
} catch (NumberFormatException err) {
|
} catch (NumberFormatException err) {
|
||||||
Main.joglFrame.parsedState = AbstractCanvas.State.FINISH_OR_NULL;
|
Main.joglFrame.parsedState = AbstractCanvas.State.FINISH_OR_NULL;
|
||||||
|
@ -15,11 +15,11 @@ public class MainFrame extends JFrame {
|
|||||||
private static final long serialVersionUID = -7898079642230075807L;
|
private static final long serialVersionUID = -7898079642230075807L;
|
||||||
private int nbTabs;
|
private int nbTabs;
|
||||||
boolean helpWindow = false;
|
boolean helpWindow = false;
|
||||||
private JPanel basePanel;
|
private final JPanel basePanel;
|
||||||
private JTabbedPane tabs;
|
private final JTabbedPane tabs;
|
||||||
private JButton newGen;
|
private final JButton newGen;
|
||||||
private JButton help;
|
private final JButton help;
|
||||||
private int nbRules;
|
private final int nbRules;
|
||||||
|
|
||||||
|
|
||||||
public MainFrame(){
|
public MainFrame(){
|
||||||
@ -40,11 +40,12 @@ public class MainFrame extends JFrame {
|
|||||||
|
|
||||||
this.setTitle("L-system interface");
|
this.setTitle("L-system interface");
|
||||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
this.setSize(Constants.WIDTH, Constants.HEIGHT);
|
Dimension windowDimension = new Dimension(Constants.INITIAL_WIDTH, Constants.INITIAL_HEIGHT);
|
||||||
|
this.setSize(windowDimension);
|
||||||
this.setLocationRelativeTo(null);
|
this.setLocationRelativeTo(null);
|
||||||
this.add(tabs);
|
this.add(tabs);
|
||||||
this.add(toolBar, BorderLayout.NORTH);
|
this.add(toolBar, BorderLayout.NORTH);
|
||||||
this.setPreferredSize(new Dimension(640,600));
|
this.setPreferredSize(windowDimension);
|
||||||
|
|
||||||
nbTabs++;
|
nbTabs++;
|
||||||
new Tab(nbTabs, nbRules, tabs,this);
|
new Tab(nbTabs, nbRules, tabs,this);
|
||||||
@ -97,11 +98,5 @@ public class MainFrame extends JFrame {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
public void closeTab() {
|
|
||||||
//TODO : Pour fermer un onglet, nécessite l'implémentation d'un button fermer grâce à la méthode newTab().
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user