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) {
|
||||
MainFrame frame = new MainFrame();
|
||||
frame.setVisible(true);
|
||||
GLCanvas canvas = new GLCanvas();
|
||||
canvas.setVisible(true);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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);
|
||||
|
||||
}
|
||||
|
@ -128,19 +128,19 @@ public class Parser {
|
||||
appliedRotation[property.getDirection()] = n;
|
||||
}
|
||||
} else {
|
||||
for(char n : numbers) {
|
||||
if(c == n) {
|
||||
number += c;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(c == '[') {
|
||||
workingElement = lastCreatedElement;
|
||||
bracket.add(lastCreatedElement);
|
||||
}
|
||||
if(c == ']') {
|
||||
} else if(c == ']') {
|
||||
assert workingElement != null && !bracket.isEmpty();
|
||||
workingElement = bracket.remove(bracket.size() - 1);
|
||||
} else {
|
||||
for(char n : numbers) {
|
||||
if(c == n) {
|
||||
number += c;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
|
@ -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 {
|
||||
Rewrite rewriter = new Rewrite(axiom, parser.parseRules(), tab.getNbIterations());
|
||||
final String word = rewriter.rewrite();
|
||||
System.out.println(word);
|
||||
final Element parsed = Parser.parse(word);
|
||||
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;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user