Improved l-system draw in 3d
This commit is contained in:
parent
6242618413
commit
32303c22ba
5
.gitignore
vendored
5
.gitignore
vendored
@ -1,7 +1,7 @@
|
|||||||
# ide files (eclipse, intellij...)
|
# ide files (eclipse, intellij...)
|
||||||
.idea/
|
.idea/
|
||||||
out/
|
out/
|
||||||
/bin/
|
bin/
|
||||||
.project
|
.project
|
||||||
.classpath
|
.classpath
|
||||||
.bin
|
.bin
|
||||||
@ -9,6 +9,9 @@ out/
|
|||||||
.metadata
|
.metadata
|
||||||
*.iml
|
*.iml
|
||||||
|
|
||||||
|
# don't commit jre fatal errors
|
||||||
|
hs_err_pid*.log
|
||||||
|
|
||||||
# log files
|
# log files
|
||||||
rapport/
|
rapport/
|
||||||
!rapport/rapport.tex
|
!rapport/rapport.tex
|
||||||
|
@ -13,6 +13,7 @@ public class Parser {
|
|||||||
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 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;
|
||||||
@ -150,9 +151,9 @@ 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 = 0.25f;
|
n = TWENTY_FIVE_DEGREES;
|
||||||
else if(number.equals("-")) {
|
else if(number.equals("-")) {
|
||||||
n = -0.25f;
|
n = -TWENTY_FIVE_DEGREES;
|
||||||
}else{
|
}else{
|
||||||
System.out.println(number);
|
System.out.println(number);
|
||||||
n = Float.parseFloat(number);
|
n = Float.parseFloat(number);
|
||||||
|
@ -31,7 +31,9 @@ public class Rewrite {
|
|||||||
rewritten = replaceIDByRuleApplication(toRewrite, rules);
|
rewritten = replaceIDByRuleApplication(toRewrite, rules);
|
||||||
System.out.println(i + " / " + recurrences + " : " + rewritten.length());
|
System.out.println(i + " / " + recurrences + " : " + rewritten.length());
|
||||||
}
|
}
|
||||||
return rewritten.replace("[", "Y[");
|
rewritten = rewritten.replace("[", "Y[");
|
||||||
|
System.out.println(rewritten);
|
||||||
|
return rewritten;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ import com.jogamp.opengl.GLAutoDrawable;
|
|||||||
import com.jogamp.opengl.glu.GLU;
|
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;
|
||||||
|
|
||||||
public class GLEventListener implements com.jogamp.opengl.GLEventListener {
|
public class GLEventListener implements com.jogamp.opengl.GLEventListener {
|
||||||
|
|
||||||
@ -77,7 +78,7 @@ public class GLEventListener implements com.jogamp.opengl.GLEventListener {
|
|||||||
glu.gluLookAt(canvas.camera[0], canvas.camera[1], canvas.camera[2], canvas.camera[0], canvas.camera[1], canvas.camera[2] - 1, 0f, 1f, 0f);
|
glu.gluLookAt(canvas.camera[0], canvas.camera[1], canvas.camera[2], canvas.camera[0], canvas.camera[1], canvas.camera[2] - 1, 0f, 1f, 0f);
|
||||||
gl.glPushMatrix();
|
gl.glPushMatrix();
|
||||||
gl.glRotatef(90f, -1f, 0f, 0f);
|
gl.glRotatef(90f, -1f, 0f, 0f);
|
||||||
|
gl.glColor3f(0f, 1f, 0f);
|
||||||
displayLSystem(gl, glut, canvas.getLSystem());
|
displayLSystem(gl, glut, canvas.getLSystem());
|
||||||
gl.glPopMatrix();
|
gl.glPopMatrix();
|
||||||
|
|
||||||
@ -89,12 +90,18 @@ public class GLEventListener implements com.jogamp.opengl.GLEventListener {
|
|||||||
|
|
||||||
private void displayLSystem(GL2 gl, GLUT glut, Element element) {
|
private void displayLSystem(GL2 gl, GLUT glut, Element element) {
|
||||||
gl.glPushMatrix();
|
gl.glPushMatrix();
|
||||||
gl.glRotatef(element.rotation[0] * 360 , 1f, 0f, 0f);
|
gl.glRotatef(element.rotation[0] * 360, 1f, 0f, 0f);
|
||||||
gl.glRotatef(element.rotation[1] * 360, 0f, 1f, 0f);
|
gl.glRotatef(element.rotation[1] * 360, 0f, 1f, 0f);
|
||||||
gl.glRotatef((element.rotation[0] + element.rotation[1]) * 360, 0f, 0f, 1f);
|
gl.glRotated(-Math.sin(element.rotation[0]) * 180, 0f, 0f, 1f);
|
||||||
|
gl.glRotated(-Math.sin(element.rotation[1]) * 180, 0f, 0f, 1f);
|
||||||
gl.glTranslated(-Math.sin(element.rotation[0]), -Math.sin(element.rotation[1]), -Math.sin(element.rotation[0] + element.rotation[1]));
|
gl.glTranslated(-Math.sin(element.rotation[0]), -Math.sin(element.rotation[1]), -Math.sin(element.rotation[0] + element.rotation[1]));
|
||||||
glut.glutSolidCylinder(0.25f, 1f, 10, 10);
|
if(element.property == ElementProperties.DRAW) {
|
||||||
gl.glTranslatef(0f, 0f, 1f);
|
glut.glutSolidCylinder(0.25f, 1f, 10, 10);
|
||||||
|
gl.glTranslatef(0f, 0f, 1f);
|
||||||
|
//gl.glTranslated(Math.cos(element.rotation[0] * Math.PI), Math.sin(element.rotation[1] * Math.PI), Math.cos(element.rotation[2] * Math.PI));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
for(Element child : element.children) {
|
for(Element child : element.children) {
|
||||||
displayLSystem(gl, glut, child);
|
displayLSystem(gl, glut, child);
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@ import java.awt.event.KeyListener;
|
|||||||
public class GLKeyboardListener implements KeyListener {
|
public class GLKeyboardListener implements KeyListener {
|
||||||
|
|
||||||
private final GLCanvas canvas;
|
private final GLCanvas canvas;
|
||||||
|
private final float MULTIPLIER = 0.2f;
|
||||||
|
|
||||||
|
|
||||||
public GLKeyboardListener(GLCanvas swingGLCanvas) {
|
public GLKeyboardListener(GLCanvas swingGLCanvas) {
|
||||||
@ -17,20 +18,20 @@ public class GLKeyboardListener implements KeyListener {
|
|||||||
|
|
||||||
switch (e.getKeyChar()) {
|
switch (e.getKeyChar()) {
|
||||||
case 'z':
|
case 'z':
|
||||||
canvas.camera[2] -= 0.1f*Math.cos(Math.toRadians(canvas.camera[3]));
|
canvas.camera[2] -= MULTIPLIER * Math.cos(Math.toRadians(canvas.camera[3]));
|
||||||
canvas.camera[0] += 0.1f*Math.cos(Math.toRadians(90-canvas.camera[3]));
|
canvas.camera[0] += MULTIPLIER * Math.cos(Math.toRadians(90 - canvas.camera[3]));
|
||||||
break;
|
break;
|
||||||
case 's':
|
case 's':
|
||||||
canvas.camera[2] += 0.1f*Math.cos(Math.toRadians(canvas.camera[3]));
|
canvas.camera[2] += MULTIPLIER * Math.cos(Math.toRadians(canvas.camera[3]));
|
||||||
canvas.camera[0] -= 0.1f*Math.cos(Math.toRadians(90-canvas.camera[3]));
|
canvas.camera[0] -= MULTIPLIER * Math.cos(Math.toRadians(90 - canvas.camera[3]));
|
||||||
break;
|
break;
|
||||||
case 'q':
|
case 'q':
|
||||||
canvas.camera[2] += 0.1f*Math.cos(Math.toRadians(canvas.camera[3]+90));
|
canvas.camera[2] += MULTIPLIER * Math.cos(Math.toRadians(canvas.camera[3] + 90));
|
||||||
canvas.camera[0] += 0.1f*Math.cos(Math.toRadians(180-canvas.camera[3]));
|
canvas.camera[0] += MULTIPLIER * Math.cos(Math.toRadians(180 - canvas.camera[3]));
|
||||||
break;
|
break;
|
||||||
case 'd':
|
case 'd':
|
||||||
canvas.camera[2] -= 0.1f*Math.cos(Math.toRadians(canvas.camera[3]+90));
|
canvas.camera[2] -= MULTIPLIER * Math.cos(Math.toRadians(canvas.camera[3] + 90));
|
||||||
canvas.camera[0] -= 0.1f*Math.cos(Math.toRadians(180-canvas.camera[3]));
|
canvas.camera[0] -= MULTIPLIER * Math.cos(Math.toRadians(180 - canvas.camera[3]));
|
||||||
break;
|
break;
|
||||||
case 'a':
|
case 'a':
|
||||||
canvas.camera[3] -= 1;
|
canvas.camera[3] -= 1;
|
||||||
@ -39,10 +40,10 @@ public class GLKeyboardListener implements KeyListener {
|
|||||||
canvas.camera[3] += 1;
|
canvas.camera[3] += 1;
|
||||||
break;
|
break;
|
||||||
case 'w':
|
case 'w':
|
||||||
canvas.camera[1] += 0.1f;
|
canvas.camera[1] += MULTIPLIER;
|
||||||
break;
|
break;
|
||||||
case 'x':
|
case 'x':
|
||||||
canvas.camera[1] -= 0.1f;
|
canvas.camera[1] -= MULTIPLIER;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user