3D interface now launch when rules has been parsed + deleted useless rectangular prism
This commit is contained in:
parent
dee7b8862a
commit
84f55b6ca4
@ -8,8 +8,6 @@ public class Main {
|
|||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
MainFrame frame = new MainFrame();
|
MainFrame frame = new MainFrame();
|
||||||
frame.setVisible(true);
|
frame.setVisible(true);
|
||||||
GLCanvas canvas = new GLCanvas();
|
|
||||||
canvas.setVisible(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@ public class Main2D {
|
|||||||
|
|
||||||
MainFrame frame = new MainFrame();
|
MainFrame frame = new MainFrame();
|
||||||
frame.setVisible(true);
|
frame.setVisible(true);
|
||||||
SwingGLCanvas2D canvas = new SwingGLCanvas2D();
|
SwingGLCanvas2D canvas = new SwingGLCanvas2D(null);
|
||||||
canvas.setVisible(true);
|
canvas.setVisible(true);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -127,6 +127,13 @@ public class Parser {
|
|||||||
number = "";
|
number = "";
|
||||||
appliedRotation[property.getDirection()] = n;
|
appliedRotation[property.getDirection()] = n;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
if(c == '[') {
|
||||||
|
workingElement = lastCreatedElement;
|
||||||
|
bracket.add(lastCreatedElement);
|
||||||
|
} else if(c == ']') {
|
||||||
|
assert workingElement != null && !bracket.isEmpty();
|
||||||
|
workingElement = bracket.remove(bracket.size() - 1);
|
||||||
} else {
|
} else {
|
||||||
for(char n : numbers) {
|
for(char n : numbers) {
|
||||||
if(c == n) {
|
if(c == n) {
|
||||||
@ -134,13 +141,6 @@ public class Parser {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(c == '[') {
|
|
||||||
workingElement = lastCreatedElement;
|
|
||||||
bracket.add(lastCreatedElement);
|
|
||||||
}
|
|
||||||
if(c == ']') {
|
|
||||||
assert workingElement != null && !bracket.isEmpty();
|
|
||||||
workingElement = bracket.remove(bracket.size() - 1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@ import com.jogamp.opengl.awt.GLCanvas;
|
|||||||
import com.jogamp.opengl.glu.GLU;
|
import com.jogamp.opengl.glu.GLU;
|
||||||
import com.jogamp.opengl.util.FPSAnimator;
|
import com.jogamp.opengl.util.FPSAnimator;
|
||||||
import com.jogamp.opengl.util.gl2.GLUT;
|
import com.jogamp.opengl.util.gl2.GLUT;
|
||||||
|
import lsystem.engine.Element;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
@ -14,6 +15,7 @@ import java.awt.event.WindowEvent;
|
|||||||
|
|
||||||
public abstract class AbstractCanvas {
|
public abstract class AbstractCanvas {
|
||||||
|
|
||||||
|
private final Element lsystem;
|
||||||
public JFrame frame;
|
public JFrame frame;
|
||||||
protected FPSAnimator animator;
|
protected FPSAnimator animator;
|
||||||
public final GLCanvas glCanvas;
|
public final GLCanvas glCanvas;
|
||||||
@ -23,7 +25,8 @@ public abstract class AbstractCanvas {
|
|||||||
0f, 0f, 0f}; // camera rotation yaw(x-axis), pitch(y-axis), roll(z-axis)
|
0f, 0f, 0f}; // camera rotation yaw(x-axis), pitch(y-axis), roll(z-axis)
|
||||||
|
|
||||||
|
|
||||||
protected AbstractCanvas() {
|
protected AbstractCanvas(Element parsed) {
|
||||||
|
this.lsystem = parsed;
|
||||||
GLProfile glProfile = GLProfile.getDefault();
|
GLProfile glProfile = GLProfile.getDefault();
|
||||||
GLCapabilities glCapabilities = new GLCapabilities(glProfile);
|
GLCapabilities glCapabilities = new GLCapabilities(glProfile);
|
||||||
this.glCanvas = new GLCanvas(glCapabilities);
|
this.glCanvas = new GLCanvas(glCapabilities);
|
||||||
|
@ -1,12 +1,13 @@
|
|||||||
package lsystem.screen.gl2d;
|
package lsystem.screen.gl2d;
|
||||||
|
|
||||||
|
import lsystem.engine.Element;
|
||||||
import lsystem.screen.AbstractCanvas;
|
import lsystem.screen.AbstractCanvas;
|
||||||
|
|
||||||
|
|
||||||
public class SwingGLCanvas2D extends AbstractCanvas {
|
public class SwingGLCanvas2D extends AbstractCanvas {
|
||||||
|
|
||||||
public SwingGLCanvas2D() {
|
public SwingGLCanvas2D(Element parsed) {
|
||||||
super();
|
super(parsed);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -32,12 +32,12 @@ public class DrawHelper {
|
|||||||
gl.glVertex3f(0f, 0f, 1f);
|
gl.glVertex3f(0f, 0f, 1f);
|
||||||
|
|
||||||
gl.glColor3f(255f, 255f, 255f);
|
gl.glColor3f(255f, 255f, 255f);
|
||||||
for (int i = -25; i < 26; i++) {
|
for (int i = -20; i < 21; i++) {
|
||||||
gl.glVertex3f(-25f, 0f, i);
|
gl.glVertex3f(-20f, 0f, i);
|
||||||
gl.glVertex3f(25f, 0f, i);
|
gl.glVertex3f(20f, 0f, i);
|
||||||
|
|
||||||
gl.glVertex3f(i, 0, -25f);
|
gl.glVertex3f(i, 0, -20f);
|
||||||
gl.glVertex3f(i, 0, 25f);
|
gl.glVertex3f(i, 0, 20f);
|
||||||
}
|
}
|
||||||
gl.glEnd();
|
gl.glEnd();
|
||||||
gl.glRasterPos3f(1.1f, 0.0f, 0.0f);
|
gl.glRasterPos3f(1.1f, 0.0f, 0.0f);
|
||||||
@ -71,6 +71,16 @@ public class DrawHelper {
|
|||||||
gl.glVertex3f(rightUpX, leftBottomY, rightUpZ);
|
gl.glVertex3f(rightUpX, leftBottomY, rightUpZ);
|
||||||
gl.glVertex3f(rightUpX, rightUpY, rightUpZ);
|
gl.glVertex3f(rightUpX, rightUpY, rightUpZ);
|
||||||
gl.glVertex3f(leftBottomX, rightUpY, rightUpZ);
|
gl.glVertex3f(leftBottomX, rightUpY, rightUpZ);
|
||||||
|
|
||||||
|
gl.glVertex3f(leftBottomX, leftBottomY, leftBottomZ);
|
||||||
|
gl.glVertex3f(rightUpX, leftBottomY, leftBottomZ);
|
||||||
|
gl.glVertex3f(rightUpX, leftBottomY, rightUpZ);
|
||||||
|
gl.glVertex3f(leftBottomX, leftBottomY, rightUpZ);
|
||||||
|
|
||||||
|
gl.glVertex3f(leftBottomX, rightUpY, leftBottomZ);
|
||||||
|
gl.glVertex3f(rightUpX, rightUpY, leftBottomZ);
|
||||||
|
gl.glVertex3f(rightUpX, rightUpY, rightUpZ);
|
||||||
|
gl.glVertex3f(leftBottomX, rightUpY, rightUpZ);
|
||||||
gl.glEnd();
|
gl.glEnd();
|
||||||
gl.glPopMatrix();
|
gl.glPopMatrix();
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,13 @@
|
|||||||
package lsystem.screen.gl3d;
|
package lsystem.screen.gl3d;
|
||||||
|
|
||||||
|
import lsystem.engine.Element;
|
||||||
import lsystem.screen.AbstractCanvas;
|
import lsystem.screen.AbstractCanvas;
|
||||||
|
|
||||||
|
|
||||||
public class GLCanvas extends AbstractCanvas {
|
public class GLCanvas extends AbstractCanvas {
|
||||||
|
|
||||||
public GLCanvas() {
|
public GLCanvas(Element parsed) {
|
||||||
super();
|
super(parsed);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -104,15 +104,13 @@ public class GLEventListener implements com.jogamp.opengl.GLEventListener {
|
|||||||
glut.glutSolidSphere(0.75f, 20, 20);
|
glut.glutSolidSphere(0.75f, 20, 20);
|
||||||
gl.glPopMatrix();
|
gl.glPopMatrix();
|
||||||
|
|
||||||
angle = (angle + 0.1f) % 360;
|
|
||||||
|
|
||||||
gl.glColor3f(0f, 0.5f, 1f);
|
|
||||||
gl.glPushMatrix();
|
gl.glPushMatrix();
|
||||||
for(Pair<Integer, Integer> pair : prismPosition) {
|
gl.glColor3f(1f, 1f, 1f);
|
||||||
DrawHelper.drawRectangularPrism(gl, pair.getLeft(), 0f, pair.getRight(), pair.getLeft() + 1, 1f, pair.getRight() + 1);
|
DrawHelper.drawRectangularPrism(gl, -3f, 0f, -2f, -2.5f, 1.5f, -1.5f);
|
||||||
}
|
glut.glutSolidCylinder(0.25f, 1.5f, 15, 2);
|
||||||
gl.glPopMatrix();
|
gl.glPopMatrix();
|
||||||
gl.glTranslatef(0f, 0f, 0f);
|
|
||||||
|
angle = (angle + 0.1f) % 360;
|
||||||
|
|
||||||
DrawHelper.drawAxes(gl, glut);
|
DrawHelper.drawAxes(gl, glut);
|
||||||
DrawHelper.drawDebugInformation(gl, glut, canvas);
|
DrawHelper.drawDebugInformation(gl, glut, canvas);
|
||||||
|
@ -3,6 +3,7 @@ package lsystem.screen.main;
|
|||||||
import lsystem.engine.Element;
|
import lsystem.engine.Element;
|
||||||
import lsystem.engine.Parser;
|
import lsystem.engine.Parser;
|
||||||
import lsystem.engine.Rewrite;
|
import lsystem.engine.Rewrite;
|
||||||
|
import lsystem.screen.gl3d.GLCanvas;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
@ -52,10 +53,14 @@ public class Listener implements ActionListener, KeyListener {
|
|||||||
JOptionPane.showMessageDialog(null, "Vos règles ou votre axiome ne sont pas correctement écrites, veuillez recommencer");
|
JOptionPane.showMessageDialog(null, "Vos règles ou votre axiome ne sont pas correctement écrites, veuillez recommencer");
|
||||||
new Listener(null, index, "Clear",tab);
|
new Listener(null, index, "Clear",tab);
|
||||||
} else {
|
} else {
|
||||||
|
new Thread(() -> {
|
||||||
Rewrite rewriter = new Rewrite(axiom, parser.parseRules(), tab.getNbIterations());
|
Rewrite rewriter = new Rewrite(axiom, parser.parseRules(), tab.getNbIterations());
|
||||||
final String word = rewriter.rewrite();
|
final String word = rewriter.rewrite();
|
||||||
System.out.println(word);
|
System.out.println(word);
|
||||||
final Element parsed = Parser.parse(word);
|
final Element parsed = Parser.parse(word);
|
||||||
|
GLCanvas canvas = new GLCanvas(parsed);
|
||||||
|
canvas.setVisible(true);
|
||||||
|
}).start();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user