Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
a943ff5442
@ -1,4 +1,4 @@
|
||||
package lsystem.screen;
|
||||
package lsystem.screen.gl3d;
|
||||
|
||||
import com.jogamp.opengl.GLCapabilities;
|
||||
import com.jogamp.opengl.GLProfile;
|
||||
@ -9,6 +9,7 @@ import com.jogamp.opengl.util.gl2.GLUT;
|
||||
import lsystem.engine.Element;
|
||||
import lsystem.engine.Parser;
|
||||
import lsystem.engine.Rewrite;
|
||||
import lsystem.screen.Constants;
|
||||
import lsystem.utils.Pair;
|
||||
|
||||
import javax.swing.*;
|
@ -1,4 +1,4 @@
|
||||
package lsystem.screen;
|
||||
package lsystem.screen.gl3d;
|
||||
|
||||
import com.jogamp.opengl.GL2;
|
||||
import com.jogamp.opengl.GLAutoDrawable;
|
||||
@ -13,6 +13,7 @@ public abstract class AbstractListener implements GLEventListener {
|
||||
protected final GLU glu;
|
||||
protected final GLUT glut;
|
||||
protected int fps;
|
||||
boolean firstGen;
|
||||
|
||||
public AbstractListener(AbstractCanvas swingGLCanvas) {
|
||||
this.canvas = swingGLCanvas;
|
||||
@ -50,7 +51,7 @@ public abstract class AbstractListener implements GLEventListener {
|
||||
|
||||
gl.glMatrixMode(GL2.GL_PROJECTION);
|
||||
gl.glLoadIdentity();
|
||||
glu.gluPerspective(60.0f, (float) width / height, 0.1f, 1000.0f);
|
||||
glu.gluPerspective(60.0f, ((float) width) / height, 0.1f, 1000.0f);
|
||||
}
|
||||
|
||||
public abstract void drawLSystem(GL2 gl, Element element);
|
@ -2,7 +2,8 @@ package lsystem.screen.gl3d;
|
||||
|
||||
import com.jogamp.opengl.GL2;
|
||||
import com.jogamp.opengl.util.gl2.GLUT;
|
||||
import lsystem.screen.AbstractCanvas;
|
||||
import lsystem.engine.Element;
|
||||
import lsystem.engine.ElementProperties;
|
||||
|
||||
public class DrawHelper {
|
||||
|
||||
@ -43,43 +44,29 @@ public class DrawHelper {
|
||||
glut.glutBitmapCharacter(GLUT.BITMAP_HELVETICA_18, 'Z'); // draw the z axis
|
||||
}
|
||||
|
||||
public static void drawRectangularPrism(GL2 gl, float leftBottomX, float leftBottomY, float leftBottomZ,
|
||||
float rightUpX, float rightUpY, float rightUpZ) {
|
||||
public static void drawLSystem(AbstractListener listener, GL2 gl, GLUT glut, Element element) {
|
||||
gl.glPushMatrix();
|
||||
gl.glBegin(GL2.GL_QUADS);
|
||||
gl.glVertex3f(leftBottomX, leftBottomY, leftBottomZ);
|
||||
gl.glVertex3f(rightUpX, leftBottomY, leftBottomZ);
|
||||
gl.glVertex3f(rightUpX, rightUpY, leftBottomZ);
|
||||
gl.glVertex3f(leftBottomX, rightUpY, leftBottomZ);
|
||||
gl.glRotatef(element.rotation[0] * 360, 1f, 0f, 0f);
|
||||
gl.glRotatef(element.rotation[1] * 360, 0f, 1f, 0f);
|
||||
gl.glRotated(-Math.sin(element.rotation[0]) * 180 - 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.glVertex3f(leftBottomX, leftBottomY, leftBottomZ);
|
||||
gl.glVertex3f(leftBottomX, leftBottomY, rightUpZ);
|
||||
gl.glVertex3f(leftBottomX, rightUpY, rightUpZ);
|
||||
gl.glVertex3f(leftBottomX, rightUpY, leftBottomZ);
|
||||
if(element.property == ElementProperties.DRAW) {
|
||||
if(listener.firstGen) {
|
||||
listener.canvas.camera[1] += 0.10f;
|
||||
listener.canvas.camera[2] += 0.10f;
|
||||
}
|
||||
glut.glutSolidCylinder(0.25f, 1f, 10, 10);
|
||||
gl.glTranslatef(0f, 0f, 1f);
|
||||
}
|
||||
|
||||
gl.glVertex3f(rightUpX, leftBottomY, leftBottomZ);
|
||||
gl.glVertex3f(rightUpX, leftBottomY, rightUpZ);
|
||||
gl.glVertex3f(rightUpX, rightUpY, rightUpZ);
|
||||
gl.glVertex3f(rightUpX, rightUpY, leftBottomZ);
|
||||
|
||||
gl.glVertex3f(leftBottomX, leftBottomY, rightUpZ);
|
||||
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();
|
||||
for(Element child : element.children) {
|
||||
drawLSystem(listener, gl, glut, child);
|
||||
}
|
||||
gl.glPopMatrix();
|
||||
}
|
||||
|
||||
|
||||
public static void drawDebugInformation(GL2 gl, GLUT glut, AbstractCanvas canvas) {
|
||||
gl.glRasterPos3f(canvas.camera[0], canvas.camera[1], canvas.camera[2] - 1);
|
||||
gl.glColor3f(1f, 1f, 1f);
|
||||
|
@ -1,7 +1,5 @@
|
||||
package lsystem.screen.gl3d;
|
||||
|
||||
import lsystem.screen.AbstractCanvas;
|
||||
|
||||
|
||||
public class GLCanvas extends AbstractCanvas {
|
||||
|
||||
|
@ -3,14 +3,11 @@ package lsystem.screen.gl3d;
|
||||
import com.jogamp.opengl.GL2;
|
||||
import com.jogamp.opengl.GLAutoDrawable;
|
||||
import lsystem.engine.Element;
|
||||
import lsystem.engine.ElementProperties;
|
||||
import lsystem.screen.Constants;
|
||||
import lsystem.screen.AbstractListener;
|
||||
|
||||
public class GLEventListener extends AbstractListener {
|
||||
|
||||
private final float[] light_0_position = {1000f, 1000f, 1000f, 1f};
|
||||
private boolean firstGen;
|
||||
|
||||
|
||||
public GLEventListener(GLCanvas swingGLCanvas) {
|
||||
@ -67,26 +64,7 @@ public class GLEventListener extends AbstractListener {
|
||||
}
|
||||
@Override
|
||||
public void drawLSystem(GL2 gl, Element element) {
|
||||
gl.glPushMatrix();
|
||||
gl.glRotatef(element.rotation[0] * 360, 1f, 0f, 0f);
|
||||
gl.glRotatef(element.rotation[1] * 360, 0f, 1f, 0f);
|
||||
gl.glRotated(-Math.sin(element.rotation[0]) * 180 - 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]));
|
||||
|
||||
if(element.property == ElementProperties.DRAW) {
|
||||
if(firstGen) {
|
||||
canvas.camera[1] += 0.10f;
|
||||
canvas.camera[2] += 0.10f;
|
||||
}
|
||||
glut.glutSolidCylinder(0.25f, 1f, 10, 10);
|
||||
gl.glTranslatef(0f, 0f, 1f);
|
||||
}
|
||||
|
||||
|
||||
for(Element child : element.children) {
|
||||
drawLSystem(gl, child);
|
||||
}
|
||||
gl.glPopMatrix();
|
||||
DrawHelper.drawLSystem(this, gl, glut, element);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,7 +1,6 @@
|
||||
package lsystem.screen.gl3d;
|
||||
|
||||
import com.jogamp.opengl.glu.GLU;
|
||||
import lsystem.screen.AbstractCanvas;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
|
@ -2,7 +2,7 @@ package lsystem.screen.main;
|
||||
|
||||
import lsystem.Main;
|
||||
import lsystem.engine.Parser;
|
||||
import lsystem.screen.AbstractCanvas;
|
||||
import lsystem.screen.gl3d.AbstractCanvas;
|
||||
import lsystem.utils.Pair;
|
||||
|
||||
import javax.swing.*;
|
||||
|
@ -38,7 +38,7 @@ public class Pair<U, K> {
|
||||
return false;
|
||||
}
|
||||
final Pair<?, ?> other = (Pair<?, ?>) obj;
|
||||
return this.left.equals(other.getLeft()) && this.left.equals(other.getRight());
|
||||
return this.left.equals(other.getLeft()) && this.right.equals(other.getRight());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user