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'),
|
||||
NOTHING('Y'),
|
||||
ROTATION_X('x', (byte) 0),
|
||||
ROTATION_Y('y', (byte) 1),
|
||||
ROTATION_Z('z', (byte) 2);
|
||||
ROTATION_Y('y', (byte) 1);
|
||||
|
||||
|
||||
private final char ch4r;
|
||||
|
@ -1,6 +1,7 @@
|
||||
package lsystem.engine;
|
||||
|
||||
import lsystem.Type;
|
||||
import lsystem.screen.Constants;
|
||||
import lsystem.utils.Pair;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -12,8 +13,6 @@ public class Parser {
|
||||
private final String axiom;
|
||||
private final List<String> rules;
|
||||
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) {
|
||||
this.axiom = axiom;
|
||||
@ -64,12 +63,12 @@ public class Parser {
|
||||
}
|
||||
if(old == '.'){
|
||||
for(int y = (type == Type.RULE ? 0 : 1); y < 12; y++){
|
||||
if(temp == validChars[y])
|
||||
if(temp == Constants.VALID_CHARS[y])
|
||||
return false;
|
||||
}
|
||||
}
|
||||
old = temp;
|
||||
for(char validChar : validChars){
|
||||
for(char validChar : Constants.VALID_CHARS){
|
||||
if(temp == validChar)
|
||||
break;
|
||||
if(validChar == ' ')
|
||||
@ -92,14 +91,13 @@ public class Parser {
|
||||
return rules;
|
||||
}
|
||||
|
||||
// TODO: 03/03/2021 to finish
|
||||
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;
|
||||
String number = "";
|
||||
List<Element> bracket = new ArrayList<>();
|
||||
float[] appliedRotation = new float[3];
|
||||
float[] appliedRotation = new float[2];
|
||||
Element lastCreatedElement = null;
|
||||
|
||||
for(int i = 0; i < word.length(); ++i) {
|
||||
@ -151,11 +149,10 @@ public class Parser {
|
||||
private static float getFloat(String number) throws NumberFormatException {
|
||||
float n;
|
||||
if(number.equals("") || number.equals("+"))
|
||||
n = TWENTY_FIVE_DEGREES;
|
||||
n = Constants.TWENTY_FIVE_DEGREES;
|
||||
else if(number.equals("-")) {
|
||||
n = -TWENTY_FIVE_DEGREES;
|
||||
n = -Constants.TWENTY_FIVE_DEGREES;
|
||||
}else{
|
||||
System.out.println(number);
|
||||
n = Float.parseFloat(number);
|
||||
}
|
||||
return n;
|
||||
|
@ -47,7 +47,7 @@ public abstract class AbstractCanvas {
|
||||
}
|
||||
});
|
||||
frame.getContentPane().add(glCanvas, BorderLayout.CENTER);
|
||||
frame.setSize(Constants.WIDTH, Constants.HEIGHT);
|
||||
frame.setSize(Constants.INITIAL_WIDTH, Constants.INITIAL_HEIGHT);
|
||||
addEventsListeners();
|
||||
}
|
||||
|
||||
|
@ -2,8 +2,14 @@
|
||||
|
||||
public class Constants {
|
||||
|
||||
public static final int WIDTH = 600;
|
||||
public static final int HEIGHT = 400;
|
||||
public static final int INITIAL_WIDTH = 600;
|
||||
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"
|
||||
+ "\r\n"
|
||||
+ "\r\n"
|
||||
|
@ -6,17 +6,12 @@ import com.jogamp.opengl.glu.GLU;
|
||||
import com.jogamp.opengl.util.gl2.GLUT;
|
||||
import lsystem.engine.Element;
|
||||
import lsystem.engine.ElementProperties;
|
||||
import lsystem.screen.Constants;
|
||||
|
||||
public class GLEventListener implements com.jogamp.opengl.GLEventListener {
|
||||
|
||||
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[] material_specular = {0.8f, 0.8f, 0.8f, 0.8f};
|
||||
|
||||
private final GLU glu;
|
||||
private final GLUT glut;
|
||||
private int fps;
|
||||
@ -42,9 +37,9 @@ public class GLEventListener implements com.jogamp.opengl.GLEventListener {
|
||||
gl.glClearDepth(1.0f);
|
||||
gl.glShadeModel(GL2.GL_SMOOTH);
|
||||
|
||||
gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_AMBIENT, light_0_ambient, 0);
|
||||
gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_DIFFUSE, light_0_diffuse, 0);
|
||||
gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_SPECULAR, light_0_specular, 0);
|
||||
gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_AMBIENT, Constants.light_0_ambient, 0);
|
||||
gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_DIFFUSE, Constants.light_0_diffuse, 0);
|
||||
gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_SPECULAR, Constants.light_0_specular, 0);
|
||||
|
||||
gl.glDepthFunc(GL2.GL_LEQUAL);
|
||||
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.glColorMaterial(GL2.GL_FRONT_AND_BACK, GL2.GL_AMBIENT_AND_DIFFUSE);
|
||||
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);
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package lsystem.screen.main;
|
||||
import lsystem.Main;
|
||||
import lsystem.engine.Parser;
|
||||
import lsystem.screen.AbstractCanvas;
|
||||
import lsystem.utils.Pair;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
@ -17,7 +18,7 @@ public class Listener implements ActionListener, KeyListener {
|
||||
MainFrame frame;
|
||||
Integer index;
|
||||
String type;
|
||||
Integer nbAxioms;
|
||||
Integer nbAxioms = 0;
|
||||
Thread parserThread = null;
|
||||
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.index = index;
|
||||
this.type = type;
|
||||
nbAxioms = 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -73,7 +73,18 @@ public class Listener implements ActionListener, KeyListener {
|
||||
tab.submitButton.setText("");
|
||||
parserThread = new Thread(() -> {
|
||||
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);
|
||||
} catch (NumberFormatException err) {
|
||||
Main.joglFrame.parsedState = AbstractCanvas.State.FINISH_OR_NULL;
|
||||
|
@ -15,11 +15,11 @@ public class MainFrame extends JFrame {
|
||||
private static final long serialVersionUID = -7898079642230075807L;
|
||||
private int nbTabs;
|
||||
boolean helpWindow = false;
|
||||
private JPanel basePanel;
|
||||
private JTabbedPane tabs;
|
||||
private JButton newGen;
|
||||
private JButton help;
|
||||
private int nbRules;
|
||||
private final JPanel basePanel;
|
||||
private final JTabbedPane tabs;
|
||||
private final JButton newGen;
|
||||
private final JButton help;
|
||||
private final int nbRules;
|
||||
|
||||
|
||||
public MainFrame(){
|
||||
@ -40,11 +40,12 @@ public class MainFrame extends JFrame {
|
||||
|
||||
this.setTitle("L-system interface");
|
||||
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.add(tabs);
|
||||
this.add(toolBar, BorderLayout.NORTH);
|
||||
this.setPreferredSize(new Dimension(640,600));
|
||||
this.setPreferredSize(windowDimension);
|
||||
|
||||
nbTabs++;
|
||||
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