3D interface now launch when rules has been parsed + deleted useless rectangular prism

This commit is contained in:
Quentin Legot 2021-03-09 12:23:01 +01:00
parent dee7b8862a
commit 84f55b6ca4
9 changed files with 48 additions and 32 deletions

View File

@ -8,8 +8,6 @@ public class Main {
public static void main(String[] args) {
MainFrame frame = new MainFrame();
frame.setVisible(true);
GLCanvas canvas = new GLCanvas();
canvas.setVisible(true);
}
}

View File

@ -9,7 +9,7 @@ public class Main2D {
MainFrame frame = new MainFrame();
frame.setVisible(true);
SwingGLCanvas2D canvas = new SwingGLCanvas2D();
SwingGLCanvas2D canvas = new SwingGLCanvas2D(null);
canvas.setVisible(true);
}

View File

@ -127,6 +127,13 @@ public class Parser {
number = "";
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 {
for(char n : numbers) {
if(c == n) {
@ -134,13 +141,6 @@ public class Parser {
break;
}
}
if(c == '[') {
workingElement = lastCreatedElement;
bracket.add(lastCreatedElement);
}
if(c == ']') {
assert workingElement != null && !bracket.isEmpty();
workingElement = bracket.remove(bracket.size() - 1);
}
}
}

View File

@ -6,6 +6,7 @@ import com.jogamp.opengl.awt.GLCanvas;
import com.jogamp.opengl.glu.GLU;
import com.jogamp.opengl.util.FPSAnimator;
import com.jogamp.opengl.util.gl2.GLUT;
import lsystem.engine.Element;
import javax.swing.*;
import java.awt.*;
@ -14,6 +15,7 @@ import java.awt.event.WindowEvent;
public abstract class AbstractCanvas {
private final Element lsystem;
public JFrame frame;
protected FPSAnimator animator;
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)
protected AbstractCanvas() {
protected AbstractCanvas(Element parsed) {
this.lsystem = parsed;
GLProfile glProfile = GLProfile.getDefault();
GLCapabilities glCapabilities = new GLCapabilities(glProfile);
this.glCanvas = new GLCanvas(glCapabilities);

View File

@ -1,12 +1,13 @@
package lsystem.screen.gl2d;
import lsystem.engine.Element;
import lsystem.screen.AbstractCanvas;
public class SwingGLCanvas2D extends AbstractCanvas {
public SwingGLCanvas2D() {
super();
public SwingGLCanvas2D(Element parsed) {
super(parsed);
}
@Override

View File

@ -32,12 +32,12 @@ public class DrawHelper {
gl.glVertex3f(0f, 0f, 1f);
gl.glColor3f(255f, 255f, 255f);
for (int i = -25; i < 26; i++) {
gl.glVertex3f(-25f, 0f, i);
gl.glVertex3f(25f, 0f, i);
for (int i = -20; i < 21; i++) {
gl.glVertex3f(-20f, 0f, i);
gl.glVertex3f(20f, 0f, i);
gl.glVertex3f(i, 0, -25f);
gl.glVertex3f(i, 0, 25f);
gl.glVertex3f(i, 0, -20f);
gl.glVertex3f(i, 0, 20f);
}
gl.glEnd();
gl.glRasterPos3f(1.1f, 0.0f, 0.0f);
@ -71,6 +71,16 @@ public class DrawHelper {
gl.glVertex3f(rightUpX, leftBottomY, rightUpZ);
gl.glVertex3f(rightUpX, 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.glPopMatrix();
}

View File

@ -1,12 +1,13 @@
package lsystem.screen.gl3d;
import lsystem.engine.Element;
import lsystem.screen.AbstractCanvas;
public class GLCanvas extends AbstractCanvas {
public GLCanvas() {
super();
public GLCanvas(Element parsed) {
super(parsed);
}
@Override

View File

@ -104,15 +104,13 @@ public class GLEventListener implements com.jogamp.opengl.GLEventListener {
glut.glutSolidSphere(0.75f, 20, 20);
gl.glPopMatrix();
angle = (angle + 0.1f) % 360;
gl.glColor3f(0f, 0.5f, 1f);
gl.glPushMatrix();
for(Pair<Integer, Integer> pair : prismPosition) {
DrawHelper.drawRectangularPrism(gl, pair.getLeft(), 0f, pair.getRight(), pair.getLeft() + 1, 1f, pair.getRight() + 1);
}
gl.glColor3f(1f, 1f, 1f);
DrawHelper.drawRectangularPrism(gl, -3f, 0f, -2f, -2.5f, 1.5f, -1.5f);
glut.glutSolidCylinder(0.25f, 1.5f, 15, 2);
gl.glPopMatrix();
gl.glTranslatef(0f, 0f, 0f);
angle = (angle + 0.1f) % 360;
DrawHelper.drawAxes(gl, glut);
DrawHelper.drawDebugInformation(gl, glut, canvas);

View File

@ -3,6 +3,7 @@ package lsystem.screen.main;
import lsystem.engine.Element;
import lsystem.engine.Parser;
import lsystem.engine.Rewrite;
import lsystem.screen.gl3d.GLCanvas;
import javax.swing.*;
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");
new Listener(null, index, "Clear",tab);
} else {
new Thread(() -> {
Rewrite rewriter = new Rewrite(axiom, parser.parseRules(), tab.getNbIterations());
final String word = rewriter.rewrite();
System.out.println(word);
final Element parsed = Parser.parse(word);
GLCanvas canvas = new GLCanvas(parsed);
canvas.setVisible(true);
}).start();
}
break;