Merge branch 'master' of https://forge.info.unicaen.fr/git/l-system
This commit is contained in:
commit
a4bd08dc4f
57
src/lsystem/screen/AbstractListener.java
Normal file
57
src/lsystem/screen/AbstractListener.java
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
package lsystem.screen;
|
||||||
|
|
||||||
|
import com.jogamp.opengl.GL2;
|
||||||
|
import com.jogamp.opengl.GLAutoDrawable;
|
||||||
|
import com.jogamp.opengl.GLEventListener;
|
||||||
|
import com.jogamp.opengl.glu.GLU;
|
||||||
|
import com.jogamp.opengl.util.gl2.GLUT;
|
||||||
|
import lsystem.engine.Element;
|
||||||
|
|
||||||
|
public abstract class AbstractListener implements GLEventListener {
|
||||||
|
|
||||||
|
protected final AbstractCanvas canvas;
|
||||||
|
protected final GLU glu;
|
||||||
|
protected final GLUT glut;
|
||||||
|
protected int fps;
|
||||||
|
|
||||||
|
public AbstractListener(AbstractCanvas swingGLCanvas) {
|
||||||
|
this.canvas = swingGLCanvas;
|
||||||
|
this.glu = canvas.glu;
|
||||||
|
this.glut = canvas.glut;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void init(GLAutoDrawable glAutoDrawable) {
|
||||||
|
GL2 gl = glAutoDrawable.getGL().getGL2();
|
||||||
|
|
||||||
|
gl.glClearColor(0f, 0f, 0f, 1.0f);
|
||||||
|
|
||||||
|
new Thread(() -> {
|
||||||
|
while (canvas.frame.isVisible()) {
|
||||||
|
try {
|
||||||
|
Thread.sleep(1000);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
System.out.println(fps);
|
||||||
|
fps = 0;
|
||||||
|
}
|
||||||
|
}).start();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void dispose(GLAutoDrawable glAutoDrawable) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void reshape(GLAutoDrawable glAutoDrawable, int x, int y, int width, int height) {
|
||||||
|
GL2 gl = glAutoDrawable.getGL().getGL2();
|
||||||
|
gl.glViewport(x, y, width, height);
|
||||||
|
|
||||||
|
gl.glMatrixMode(GL2.GL_PROJECTION);
|
||||||
|
gl.glLoadIdentity();
|
||||||
|
glu.gluPerspective(60.0f, (float) width / height, 0.1f, 1000.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract void drawLSystem(GL2 gl, Element element);
|
||||||
|
}
|
@ -2,51 +2,24 @@ package lsystem.screen.gl2d;
|
|||||||
|
|
||||||
import com.jogamp.opengl.GL2;
|
import com.jogamp.opengl.GL2;
|
||||||
import com.jogamp.opengl.GLAutoDrawable;
|
import com.jogamp.opengl.GLAutoDrawable;
|
||||||
import com.jogamp.opengl.GLEventListener;
|
|
||||||
import com.jogamp.opengl.glu.GLU;
|
|
||||||
import com.jogamp.opengl.util.gl2.GLUT;
|
|
||||||
|
|
||||||
import lsystem.engine.Element;
|
import lsystem.engine.Element;
|
||||||
import lsystem.engine.ElementProperties;
|
import lsystem.engine.ElementProperties;
|
||||||
|
import lsystem.screen.AbstractListener;
|
||||||
import lsystem.screen.gl3d.DrawHelper;
|
import lsystem.screen.gl3d.DrawHelper;
|
||||||
public class JoglEventListener2D implements GLEventListener {
|
|
||||||
|
|
||||||
private final SwingGLCanvas2D canvas;
|
public class JoglEventListener2D extends AbstractListener {
|
||||||
|
|
||||||
private final GLU glu;
|
|
||||||
private final GLUT glut;
|
|
||||||
private int fps;
|
|
||||||
|
|
||||||
public JoglEventListener2D(SwingGLCanvas2D swingGLCanvas) {
|
public JoglEventListener2D(SwingGLCanvas2D swingGLCanvas) {
|
||||||
this.canvas = swingGLCanvas;
|
super(swingGLCanvas);
|
||||||
this.glu = canvas.glu;
|
|
||||||
this.glut = canvas.glut;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void init(GLAutoDrawable glAutoDrawable) {
|
public void drawLSystem(GL2 gl, Element element) {
|
||||||
GL2 gl = glAutoDrawable.getGL().getGL2();
|
drawAll(gl, element, new lsystem.screen.gl2d.Point2(-1.0f, -1.0f));
|
||||||
|
|
||||||
gl.glClearColor(0f, 0f, 0f, 1.0f);
|
|
||||||
|
|
||||||
new Thread(() -> {
|
|
||||||
while (canvas.frame.isVisible()) {
|
|
||||||
try {
|
|
||||||
Thread.sleep(1000);
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
System.out.println(fps);
|
|
||||||
fps = 0;
|
|
||||||
}
|
|
||||||
}).start();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private void drawAll(GL2 gl, Element actual, lsystem.screen.gl2d.Point2 origin) {
|
||||||
public void dispose(GLAutoDrawable glAutoDrawable) {
|
|
||||||
}
|
|
||||||
|
|
||||||
public void drawAll(GL2 gl, Element actual, lsystem.screen.gl2d.Point2 origin) {
|
|
||||||
if (actual.property == ElementProperties.DRAW) {
|
if (actual.property == ElementProperties.DRAW) {
|
||||||
System.out.println("DESSIN");
|
System.out.println("DESSIN");
|
||||||
lsystem.screen.gl2d.Point2 newOrigin = new lsystem.screen.gl2d.Point2(origin, actual.getRotation2D());
|
lsystem.screen.gl2d.Point2 newOrigin = new lsystem.screen.gl2d.Point2(origin, actual.getRotation2D());
|
||||||
@ -61,25 +34,11 @@ public class JoglEventListener2D implements GLEventListener {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void display(GLAutoDrawable glAutoDrawable) {
|
public void display(GLAutoDrawable glAutoDrawable) {
|
||||||
/*
|
|
||||||
* Element str = new Element(ElementProperties.DRAW, null, new int[]{0, 0, 0});
|
|
||||||
*
|
|
||||||
* Element child1 = new Element(ElementProperties.DRAW, str, new int[]{0, 0,
|
|
||||||
* 0}); Element child2 = new Element(ElementProperties.DRAW, str, new int[]{45,
|
|
||||||
* 0, 0}); str.children.add(child1); str.children.add(child2); Element child11 =
|
|
||||||
* new Element(ElementProperties.DRAW, child1, new int[]{225, 0, 0}); Element
|
|
||||||
* child12 = new Element(ElementProperties.DRAW, child1, new int[]{270, 0, 0});
|
|
||||||
* child1.children.add(child11); child1.children.add(child12);
|
|
||||||
*/
|
|
||||||
|
|
||||||
GL2 gl = glAutoDrawable.getGL().getGL2();
|
GL2 gl = glAutoDrawable.getGL().getGL2();
|
||||||
|
|
||||||
|
drawLSystem(gl, canvas.getLSystem());
|
||||||
drawAll(gl, canvas.getLSystem(), new lsystem.screen.gl2d.Point2(-1.0f, -1.0f));
|
drawAll(gl, canvas.getLSystem(), new lsystem.screen.gl2d.Point2(-1.0f, -1.0f));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void reshape(GLAutoDrawable glAutoDrawable, int x, int y, int width, int height) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,87 +0,0 @@
|
|||||||
package lsystem.screen.gl2d;
|
|
||||||
|
|
||||||
import com.jogamp.opengl.glu.GLU;
|
|
||||||
|
|
||||||
import java.awt.*;
|
|
||||||
import java.awt.event.*;
|
|
||||||
|
|
||||||
public class JoglMouseListener2D implements MouseListener, MouseMotionListener, MouseWheelListener {
|
|
||||||
|
|
||||||
private final GLU glu;
|
|
||||||
private final SwingGLCanvas2D canvas;
|
|
||||||
private int button = 0;
|
|
||||||
private Point origine;
|
|
||||||
|
|
||||||
public JoglMouseListener2D(SwingGLCanvas2D canvas) {
|
|
||||||
this.canvas = canvas;
|
|
||||||
this.glu = canvas.glu;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void mouseClicked(MouseEvent e) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void mousePressed(MouseEvent e) {
|
|
||||||
if(button == 0) {
|
|
||||||
button = e.getButton();
|
|
||||||
origine = e.getPoint();
|
|
||||||
} else {
|
|
||||||
button = 0;
|
|
||||||
origine = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void mouseReleased(MouseEvent e) {
|
|
||||||
button = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void mouseEntered(MouseEvent e) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void mouseExited(MouseEvent e) {
|
|
||||||
System.out.println("exited " + canvas.camera[0] + ", " + canvas.camera[1]);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void mouseDragged(MouseEvent e) {
|
|
||||||
if(origine != null) {
|
|
||||||
double xDiff = origine.getX() - e.getPoint().getX();
|
|
||||||
double yDiff = origine.getY() - e.getPoint().getY();
|
|
||||||
/* if(button == 2) {
|
|
||||||
canvas.camera[0] += Math.cos(canvas.camera[3]) * xDiff * 0.01;
|
|
||||||
canvas.camera[1] += Math.cos(canvas.camera[4]) * yDiff * 0.01;
|
|
||||||
canvas.camera[2] += Math.sin(canvas.camera[3]) * xDiff * 0.01;
|
|
||||||
} */
|
|
||||||
if(button == 3) {
|
|
||||||
canvas.camera[3] += xDiff * 0.1;
|
|
||||||
canvas.camera[4] += yDiff * 0.1;
|
|
||||||
}
|
|
||||||
origine = e.getPoint();
|
|
||||||
}
|
|
||||||
for (int i = 0; i < canvas.camera.length; i++) {
|
|
||||||
canvas.camera[i] = canvas.camera[i] % 360;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void mouseMoved(MouseEvent e) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void mouseWheelMoved(MouseWheelEvent e) {
|
|
||||||
if( 45 > Math.abs(canvas.camera[3]) && 45>Math.abs(canvas.camera[4]))
|
|
||||||
canvas.camera[0] += e.getWheelRotation() * Math.tan(Math.toRadians(-canvas.camera[3])) * 0.25;
|
|
||||||
else
|
|
||||||
canvas.camera[0] += e.getWheelRotation() * Math.tan(Math.toRadians(canvas.camera[3])) * 0.25;
|
|
||||||
canvas.camera[1] += e.getWheelRotation() * Math.tan(Math.toRadians(canvas.camera[4])) * 0.25;
|
|
||||||
if( 45 < Math.abs(canvas.camera[3]) || 45 < Math.abs(canvas.camera[4]))
|
|
||||||
canvas.camera[2] += -e.getWheelRotation()*0.25;
|
|
||||||
else
|
|
||||||
canvas.camera[2] += e.getWheelRotation()*0.25;
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,56 +0,0 @@
|
|||||||
package lsystem.screen.gl2d;
|
|
||||||
|
|
||||||
import java.awt.event.KeyEvent;
|
|
||||||
import java.awt.event.KeyListener;
|
|
||||||
|
|
||||||
public class KeyboardListener2D implements KeyListener {
|
|
||||||
|
|
||||||
private final SwingGLCanvas2D canvas;
|
|
||||||
|
|
||||||
|
|
||||||
public KeyboardListener2D(SwingGLCanvas2D swingGLCanvas) {
|
|
||||||
this.canvas = swingGLCanvas;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void keyTyped(KeyEvent e) {
|
|
||||||
|
|
||||||
switch (e.getKeyChar()) {
|
|
||||||
case 'z':
|
|
||||||
canvas.camera[2] -= 0.1f;
|
|
||||||
break;
|
|
||||||
case 's':
|
|
||||||
canvas.camera[2] += 0.1f;
|
|
||||||
break;
|
|
||||||
case 'q':
|
|
||||||
canvas.camera[0] -= 0.1f;
|
|
||||||
break;
|
|
||||||
case 'd':
|
|
||||||
canvas.camera[0] += 0.1f;
|
|
||||||
break;
|
|
||||||
case 'a':
|
|
||||||
canvas.camera[3] -= 1;
|
|
||||||
break;
|
|
||||||
case 'e':
|
|
||||||
canvas.camera[3] += 1;
|
|
||||||
break;
|
|
||||||
case 'w':
|
|
||||||
canvas.camera[1] += 0.1f;
|
|
||||||
break;
|
|
||||||
case 'x':
|
|
||||||
canvas.camera[1] -= 0.1f;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void keyPressed(KeyEvent e) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void keyReleased(KeyEvent e) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
@ -7,12 +7,6 @@ public class SwingGLCanvas2D extends AbstractCanvas {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void addEventsListeners() {
|
protected void addEventsListeners() {
|
||||||
|
|
||||||
glCanvas.addGLEventListener(new JoglEventListener2D(this));
|
glCanvas.addGLEventListener(new JoglEventListener2D(this));
|
||||||
JoglMouseListener2D mouse = new JoglMouseListener2D(this);
|
|
||||||
glCanvas.addMouseListener(mouse);
|
|
||||||
glCanvas.addMouseMotionListener(mouse);
|
|
||||||
glCanvas.addMouseWheelListener(mouse);
|
|
||||||
glCanvas.addKeyListener(new KeyboardListener2D(this));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,18 +2,12 @@ package lsystem.screen.gl3d;
|
|||||||
|
|
||||||
import com.jogamp.opengl.GL2;
|
import com.jogamp.opengl.GL2;
|
||||||
import com.jogamp.opengl.util.gl2.GLUT;
|
import com.jogamp.opengl.util.gl2.GLUT;
|
||||||
|
import lsystem.screen.AbstractCanvas;
|
||||||
import lsystem.screen.gl2d.Point2;
|
import lsystem.screen.gl2d.Point2;
|
||||||
import lsystem.screen.gl2d.SwingGLCanvas2D;
|
|
||||||
|
|
||||||
public class DrawHelper {
|
public class DrawHelper {
|
||||||
|
|
||||||
public static void placeCamera(GL2 gl, GLCanvas canvas) {
|
public static void placeCamera(GL2 gl, AbstractCanvas canvas) {
|
||||||
gl.glRotatef(canvas.camera[4], 1f, 0f, 0f);
|
|
||||||
gl.glRotatef(canvas.camera[3], 0f, 1f, 0f);
|
|
||||||
gl.glRotatef(canvas.camera[5], 0f, 0f, 1f);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void placeCamera(GL2 gl, SwingGLCanvas2D canvas) {
|
|
||||||
gl.glRotatef(canvas.camera[4], 1f, 0f, 0f);
|
gl.glRotatef(canvas.camera[4], 1f, 0f, 0f);
|
||||||
gl.glRotatef(canvas.camera[3], 0f, 1f, 0f);
|
gl.glRotatef(canvas.camera[3], 0f, 1f, 0f);
|
||||||
gl.glRotatef(canvas.camera[5], 0f, 0f, 1f);
|
gl.glRotatef(canvas.camera[5], 0f, 0f, 1f);
|
||||||
@ -33,12 +27,13 @@ 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 = -20; i < 21; i++) {
|
int limit = 20;
|
||||||
gl.glVertex3f(-20f, 0f, i);
|
for (int i = -limit; i < limit + 1; i++) {
|
||||||
gl.glVertex3f(20f, 0f, i);
|
gl.glVertex3f(-limit, 0f, i);
|
||||||
|
gl.glVertex3f(limit, 0f, i);
|
||||||
|
|
||||||
gl.glVertex3f(i, 0, -20f);
|
gl.glVertex3f(i, 0, -limit);
|
||||||
gl.glVertex3f(i, 0, 20f);
|
gl.glVertex3f(i, 0, limit);
|
||||||
}
|
}
|
||||||
gl.glEnd();
|
gl.glEnd();
|
||||||
gl.glRasterPos3f(1.1f, 0.0f, 0.0f);
|
gl.glRasterPos3f(1.1f, 0.0f, 0.0f);
|
||||||
@ -86,15 +81,7 @@ public class DrawHelper {
|
|||||||
gl.glPopMatrix();
|
gl.glPopMatrix();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void drawDebugInformation(GL2 gl, GLUT glut, GLCanvas canvas) {
|
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);
|
|
||||||
glut.glutBitmapString(GLUT.BITMAP_HELVETICA_18,
|
|
||||||
"x=" + canvas.camera[0] + ", y=" + canvas.camera[1] + ", z=" + canvas.camera[2] + "\n yaw = "
|
|
||||||
+ canvas.camera[3] + " pitch = " + canvas.camera[4] + " roll = " + canvas.camera[5]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void drawDebugInformation(GL2 gl, GLUT glut, SwingGLCanvas2D canvas) {
|
|
||||||
gl.glRasterPos3f(canvas.camera[0], canvas.camera[1], canvas.camera[2] - 1);
|
gl.glRasterPos3f(canvas.camera[0], canvas.camera[1], canvas.camera[2] - 1);
|
||||||
gl.glColor3f(1f, 1f, 1f);
|
gl.glColor3f(1f, 1f, 1f);
|
||||||
glut.glutBitmapString(GLUT.BITMAP_HELVETICA_18,
|
glut.glutBitmapString(GLUT.BITMAP_HELVETICA_18,
|
||||||
|
@ -2,24 +2,18 @@ package lsystem.screen.gl3d;
|
|||||||
|
|
||||||
import com.jogamp.opengl.GL2;
|
import com.jogamp.opengl.GL2;
|
||||||
import com.jogamp.opengl.GLAutoDrawable;
|
import com.jogamp.opengl.GLAutoDrawable;
|
||||||
import com.jogamp.opengl.glu.GLU;
|
|
||||||
import com.jogamp.opengl.util.gl2.GLUT;
|
|
||||||
import lsystem.engine.Element;
|
import lsystem.engine.Element;
|
||||||
import lsystem.engine.ElementProperties;
|
import lsystem.engine.ElementProperties;
|
||||||
import lsystem.screen.Constants;
|
import lsystem.screen.Constants;
|
||||||
|
import lsystem.screen.AbstractListener;
|
||||||
|
|
||||||
public class GLEventListener implements com.jogamp.opengl.GLEventListener {
|
public class GLEventListener extends AbstractListener {
|
||||||
|
|
||||||
private final GLCanvas canvas;
|
|
||||||
private final float[] light_0_position = {1000f, 1000f, 1000f, 1f};
|
private final float[] light_0_position = {1000f, 1000f, 1000f, 1f};
|
||||||
private final GLU glu;
|
|
||||||
private final GLUT glut;
|
|
||||||
private int fps;
|
|
||||||
|
|
||||||
public GLEventListener(GLCanvas swingGLCanvas) {
|
public GLEventListener(GLCanvas swingGLCanvas) {
|
||||||
this.canvas = swingGLCanvas;
|
super(swingGLCanvas);
|
||||||
this.glu = canvas.glu;
|
|
||||||
this.glut = canvas.glut;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -43,21 +37,7 @@ public class GLEventListener implements com.jogamp.opengl.GLEventListener {
|
|||||||
|
|
||||||
gl.glDepthFunc(GL2.GL_LEQUAL);
|
gl.glDepthFunc(GL2.GL_LEQUAL);
|
||||||
gl.glHint(GL2.GL_PERSPECTIVE_CORRECTION_HINT, GL2.GL_NICEST);
|
gl.glHint(GL2.GL_PERSPECTIVE_CORRECTION_HINT, GL2.GL_NICEST);
|
||||||
new Thread(() -> {
|
super.init(glAutoDrawable);
|
||||||
while (canvas.frame.isVisible()) {
|
|
||||||
try {
|
|
||||||
Thread.sleep(1000);
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
System.out.println(fps);
|
|
||||||
fps = 0;
|
|
||||||
}
|
|
||||||
}).start();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void dispose(GLAutoDrawable glAutoDrawable) {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -74,7 +54,7 @@ public class GLEventListener implements com.jogamp.opengl.GLEventListener {
|
|||||||
gl.glPushMatrix();
|
gl.glPushMatrix();
|
||||||
gl.glRotatef(90f, -1f, 0f, 0f);
|
gl.glRotatef(90f, -1f, 0f, 0f);
|
||||||
gl.glColor3f(0f, 1f, 0f);
|
gl.glColor3f(0f, 1f, 0f);
|
||||||
displayLSystem(gl, glut, canvas.getLSystem());
|
drawLSystem(gl, canvas.getLSystem());
|
||||||
gl.glPopMatrix();
|
gl.glPopMatrix();
|
||||||
|
|
||||||
DrawHelper.drawAxes(gl, glut);
|
DrawHelper.drawAxes(gl, glut);
|
||||||
@ -82,8 +62,8 @@ public class GLEventListener implements com.jogamp.opengl.GLEventListener {
|
|||||||
gl.glFlush();
|
gl.glFlush();
|
||||||
fps++;
|
fps++;
|
||||||
}
|
}
|
||||||
|
@Override
|
||||||
private void displayLSystem(GL2 gl, GLUT glut, Element element) {
|
public void drawLSystem(GL2 gl, 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);
|
||||||
@ -93,25 +73,19 @@ public class GLEventListener implements com.jogamp.opengl.GLEventListener {
|
|||||||
if(element.property == ElementProperties.DRAW) {
|
if(element.property == ElementProperties.DRAW) {
|
||||||
glut.glutSolidCylinder(0.25f, 1f, 10, 10);
|
glut.glutSolidCylinder(0.25f, 1f, 10, 10);
|
||||||
gl.glTranslatef(0f, 0f, 1f);
|
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);
|
drawLSystem(gl, child);
|
||||||
}
|
}
|
||||||
gl.glPopMatrix();
|
gl.glPopMatrix();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void reshape(GLAutoDrawable glAutoDrawable, int x, int y, int width, int height) {
|
public void reshape(GLAutoDrawable glAutoDrawable, int x, int y, int width, int height) {
|
||||||
|
super.reshape(glAutoDrawable, x, y, width, height);
|
||||||
GL2 gl = glAutoDrawable.getGL().getGL2();
|
GL2 gl = glAutoDrawable.getGL().getGL2();
|
||||||
gl.glViewport(x, y, width, height);
|
|
||||||
|
|
||||||
gl.glMatrixMode(GL2.GL_PROJECTION);
|
|
||||||
gl.glLoadIdentity();
|
|
||||||
glu.gluPerspective(60.0f, (float) width / height, 0.1f, 1000.0f);
|
|
||||||
|
|
||||||
gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_POSITION, light_0_position, 0);
|
gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_POSITION, light_0_position, 0);
|
||||||
gl.glColorMaterial(GL2.GL_FRONT_AND_BACK, GL2.GL_AMBIENT_AND_DIFFUSE);
|
gl.glColorMaterial(GL2.GL_FRONT_AND_BACK, GL2.GL_AMBIENT_AND_DIFFUSE);
|
||||||
gl.glMateriali(GL2.GL_FRONT_AND_BACK, GL2.GL_SHININESS, 90);
|
gl.glMateriali(GL2.GL_FRONT_AND_BACK, GL2.GL_SHININESS, 90);
|
||||||
|
@ -1,14 +1,16 @@
|
|||||||
package lsystem.screen.gl3d;
|
package lsystem.screen.gl3d;
|
||||||
|
|
||||||
import com.jogamp.opengl.glu.GLU;
|
import com.jogamp.opengl.glu.GLU;
|
||||||
|
import lsystem.screen.AbstractCanvas;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.event.*;
|
import java.awt.event.*;
|
||||||
|
|
||||||
public class GLMouseListener implements MouseListener, MouseMotionListener, MouseWheelListener {
|
public class GLMouseListener implements MouseListener, MouseMotionListener, MouseWheelListener {
|
||||||
|
|
||||||
private final GLU glu;
|
protected final GLU glu;
|
||||||
private final GLCanvas canvas;
|
protected final GLCanvas canvas;
|
||||||
|
|
||||||
private int button = 0;
|
private int button = 0;
|
||||||
private Point origine;
|
private Point origine;
|
||||||
private final float MULTIPLIER = 0.25f;
|
private final float MULTIPLIER = 0.25f;
|
||||||
@ -45,7 +47,6 @@ public class GLMouseListener implements MouseListener, MouseMotionListener, Mous
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void mouseExited(MouseEvent e) {
|
public void mouseExited(MouseEvent e) {
|
||||||
System.out.println("exited " + canvas.camera[0] + ", " + canvas.camera[1]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -53,11 +54,6 @@ public class GLMouseListener implements MouseListener, MouseMotionListener, Mous
|
|||||||
if(origine != null) {
|
if(origine != null) {
|
||||||
double xDiff = origine.getX() - e.getPoint().getX();
|
double xDiff = origine.getX() - e.getPoint().getX();
|
||||||
double yDiff = origine.getY() - e.getPoint().getY();
|
double yDiff = origine.getY() - e.getPoint().getY();
|
||||||
/* if(button == 1) {
|
|
||||||
canvas.camera[0] += Math.cos(canvas.camera[3]) * xDiff * 0.01;
|
|
||||||
canvas.camera[1] += Math.cos(canvas.camera[4]) * yDiff * 0.01;
|
|
||||||
canvas.camera[2] += Math.sin(canvas.camera[3]) * xDiff * 0.01;
|
|
||||||
} */
|
|
||||||
if(button == 3) {
|
if(button == 3) {
|
||||||
canvas.camera[3] += xDiff * 0.1;
|
canvas.camera[3] += xDiff * 0.1;
|
||||||
canvas.camera[4] += yDiff * 0.1;
|
canvas.camera[4] += yDiff * 0.1;
|
||||||
@ -75,6 +71,5 @@ public class GLMouseListener implements MouseListener, MouseMotionListener, Mous
|
|||||||
canvas.camera[2] += Math.cos(Math.toRadians(canvas.camera[4]))*MULTIPLIER* e.getWheelRotation()*Math.cos(Math.toRadians(Math.abs(360-canvas.camera[3])));
|
canvas.camera[2] += Math.cos(Math.toRadians(canvas.camera[4]))*MULTIPLIER* e.getWheelRotation()*Math.cos(Math.toRadians(Math.abs(360-canvas.camera[3])));
|
||||||
canvas.camera[0] -= Math.cos(Math.toRadians(canvas.camera[4]))*MULTIPLIER* e.getWheelRotation()*Math.cos(Math.toRadians(Math.abs(450-canvas.camera[3])));
|
canvas.camera[0] -= Math.cos(Math.toRadians(canvas.camera[4]))*MULTIPLIER* e.getWheelRotation()*Math.cos(Math.toRadians(Math.abs(450-canvas.camera[3])));
|
||||||
canvas.camera[1] += (1-Math.cos(Math.toRadians(canvas.camera[4])))*MULTIPLIER* e.getWheelRotation()*Math.cos(Math.toRadians(Math.abs(360-canvas.camera[4])));
|
canvas.camera[1] += (1-Math.cos(Math.toRadians(canvas.camera[4])))*MULTIPLIER* e.getWheelRotation()*Math.cos(Math.toRadians(Math.abs(360-canvas.camera[4])));
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,13 +7,10 @@ import lsystem.utils.Pair;
|
|||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.*;
|
||||||
import java.awt.event.ActionListener;
|
|
||||||
import java.awt.event.KeyEvent;
|
|
||||||
import java.awt.event.KeyListener;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class Listener implements ActionListener, KeyListener {
|
public class Listener implements ActionListener, KeyListener, MouseWheelListener {
|
||||||
Tab tab;
|
Tab tab;
|
||||||
MainFrame frame;
|
MainFrame frame;
|
||||||
Integer index;
|
Integer index;
|
||||||
@ -57,26 +54,26 @@ public class Listener implements ActionListener, KeyListener {
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "Generate":
|
case "Generate 2D":
|
||||||
String axiom = tab.getAxiom();
|
String axiom2D = tab.getAxiom();
|
||||||
List<String> rules = tab.getRules();
|
List<String> rules2D = tab.getRules();
|
||||||
Parser parser = new Parser(axiom, rules, tab.getNbIterations());
|
Parser parser2D = new Parser(axiom2D, rules2D, tab.getNbIterations());
|
||||||
if(Main.joglFrame.frame.isVisible()) {
|
if(Main.joglFrame.frame.isVisible()) {
|
||||||
openDialog("Veuillez fermer la fenêtre 3D avant de lancer une nouvelle génération");
|
openDialog("Veuillez fermer la fenêtre 2D ou 3D avant de lancer une nouvelle génération");
|
||||||
} else if(Main.joglFrame.parsedState == AbstractCanvas.State.LOAD) {
|
} else if(Main.joglFrame.parsedState == AbstractCanvas.State.LOAD) {
|
||||||
openDialog("Une génération est actuellement en cours, impossible d'en relancer un autre");
|
openDialog("Une génération est actuellement en cours, impossible d'en relancer un autre");
|
||||||
openDialog("Une génération est actuellement en cours, impossible d'en relancer un autre");
|
openDialog("Une génération est actuellement en cours, impossible d'en relancer un autre");
|
||||||
} else if (!parser.isCorrect()) {
|
} else if (!parser2D.isCorrect()) {
|
||||||
openDialog("Vos règles ou votre axiome ne sont pas correctement écrites, veuillez recommencer");
|
openDialog("Vos règles ou votre axiome ne sont pas correctement écrites, veuillez recommencer");
|
||||||
} else {
|
} else {
|
||||||
tab.submitButton.setIcon(staticIcon);
|
tab.submitButton2D.setIcon(staticIcon);
|
||||||
tab.submitButton.setText("");
|
tab.submitButton2D.setText("");
|
||||||
parserThread = new Thread(() -> {
|
parserThread = new Thread(() -> {
|
||||||
try {
|
try {
|
||||||
List<Pair<String, String>> lSystemRules = parser.parseRules();
|
List<Pair<String, String>> lSystemRules = parser2D.parseRules();
|
||||||
Main.joglFrame.setLSystem(axiom, lSystemRules, tab.getNbIterations());
|
Main.joglFrame.setLSystem(axiom2D, lSystemRules, tab.getNbIterations());
|
||||||
|
|
||||||
StringBuilder message = new StringBuilder("L-System 3D - {axiom:\"").append(axiom).append("\",rules:[");
|
StringBuilder message = new StringBuilder("L-System 2D - {axiom:\"").append(axiom2D).append("\",rules:[");
|
||||||
for(int i = 0; i < lSystemRules.size(); ++i) {
|
for(int i = 0; i < lSystemRules.size(); ++i) {
|
||||||
Pair<String, String> rule = lSystemRules.get(i);
|
Pair<String, String> rule = lSystemRules.get(i);
|
||||||
message.append("\"").append(rule.getLeft()).append("=").append(rule.getRight()).append("\"");
|
message.append("\"").append(rule.getLeft()).append("=").append(rule.getRight()).append("\"");
|
||||||
@ -90,8 +87,48 @@ public class Listener implements ActionListener, KeyListener {
|
|||||||
Main.joglFrame.parsedState = AbstractCanvas.State.FINISH_OR_NULL;
|
Main.joglFrame.parsedState = AbstractCanvas.State.FINISH_OR_NULL;
|
||||||
openDialog("Une erreur de type " + err.getClass().getSimpleName() + " est survenue lors de l'execution du parser: " + err.getMessage());
|
openDialog("Une erreur de type " + err.getClass().getSimpleName() + " est survenue lors de l'execution du parser: " + err.getMessage());
|
||||||
}
|
}
|
||||||
tab.submitButton.setIcon(null);
|
tab.submitButton2D.setIcon(null);
|
||||||
tab.submitButton.setText("Générer");
|
tab.submitButton2D.setText("Générer en 2D");
|
||||||
|
});
|
||||||
|
parserThread.start();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "Generate 3D":
|
||||||
|
String axiom3D = tab.getAxiom();
|
||||||
|
List<String> rules3D = tab.getRules();
|
||||||
|
Parser parser3D = new Parser(axiom3D, rules3D, tab.getNbIterations());
|
||||||
|
if(Main.joglFrame.frame.isVisible()) {
|
||||||
|
openDialog("Veuillez fermer la fenêtre 2D ou 3D avant de lancer une nouvelle génération");
|
||||||
|
} else if(Main.joglFrame.parsedState == AbstractCanvas.State.LOAD) {
|
||||||
|
openDialog("Une génération est actuellement en cours, impossible d'en relancer un autre");
|
||||||
|
openDialog("Une génération est actuellement en cours, impossible d'en relancer un autre");
|
||||||
|
} else if (!parser3D.isCorrect()) {
|
||||||
|
openDialog("Vos règles ou votre axiome ne sont pas correctement écrites, veuillez recommencer");
|
||||||
|
} else {
|
||||||
|
tab.submitButton3D.setIcon(staticIcon);
|
||||||
|
tab.submitButton3D.setText("");
|
||||||
|
parserThread = new Thread(() -> {
|
||||||
|
try {
|
||||||
|
List<Pair<String, String>> lSystemRules = parser3D.parseRules();
|
||||||
|
Main.joglFrame.setLSystem(axiom3D, lSystemRules, tab.getNbIterations());
|
||||||
|
|
||||||
|
StringBuilder message = new StringBuilder("L-System 3D - {axiom:\"").append(axiom3D).append("\",rules:[");
|
||||||
|
for(int i = 0; i < lSystemRules.size(); ++i) {
|
||||||
|
Pair<String, String> rule = lSystemRules.get(i);
|
||||||
|
message.append("\"").append(rule.getLeft()).append("=").append(rule.getRight()).append("\"");
|
||||||
|
if(i + 1 != lSystemRules.size())
|
||||||
|
message.append(",");
|
||||||
|
}
|
||||||
|
Main.joglFrame.frame.setTitle(message.append("]} - Nombres d'itérations: ").append(tab.getNbIterations()).toString());
|
||||||
|
|
||||||
|
Main.joglFrame.setVisible(true);
|
||||||
|
} catch (NumberFormatException err) {
|
||||||
|
Main.joglFrame.parsedState = AbstractCanvas.State.FINISH_OR_NULL;
|
||||||
|
openDialog("Une erreur de type " + err.getClass().getSimpleName() + " est survenue lors de l'execution du parser: " + err.getMessage());
|
||||||
|
}
|
||||||
|
tab.submitButton3D.setIcon(null);
|
||||||
|
tab.submitButton3D.setText("Générer en 3D");
|
||||||
});
|
});
|
||||||
parserThread.start();
|
parserThread.start();
|
||||||
}
|
}
|
||||||
@ -145,4 +182,12 @@ public class Listener implements ActionListener, KeyListener {
|
|||||||
public void resetNbAxioms(){
|
public void resetNbAxioms(){
|
||||||
nbAxioms = 0;
|
nbAxioms = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseWheelMoved(MouseWheelEvent e) {
|
||||||
|
if(e.getWheelRotation() < 0)
|
||||||
|
tab.itSpinner.setValue(tab.itSpinner.getNextValue());
|
||||||
|
else
|
||||||
|
tab.itSpinner.setValue(tab.itSpinner.getPreviousValue());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,10 +8,10 @@ public class Tab extends JPanel{
|
|||||||
|
|
||||||
int nbTabs;
|
int nbTabs;
|
||||||
int nbRules;
|
int nbRules;
|
||||||
JSpinner nbIterations,itSpinner;
|
public JSpinner itSpinner;
|
||||||
JTextField axiomeField,rulesField;
|
JTextField axiomeField,rulesField;
|
||||||
JTextArea axiomList,rulesList;;
|
JTextArea axiomList,rulesList;;
|
||||||
JButton submitButton, close;
|
JButton submitButton2D, submitButton3D, close;
|
||||||
|
|
||||||
public Tab(int nbTabs,int nbRules,JTabbedPane tabs,MainFrame frame) {
|
public Tab(int nbTabs,int nbRules,JTabbedPane tabs,MainFrame frame) {
|
||||||
this.nbRules = nbRules;
|
this.nbRules = nbRules;
|
||||||
@ -22,12 +22,10 @@ public class Tab extends JPanel{
|
|||||||
axiomList = textArea("Axiome : \n",nbTabs);
|
axiomList = textArea("Axiome : \n",nbTabs);
|
||||||
rulesList = textArea("Règles : \n",nbTabs+10);
|
rulesList = textArea("Règles : \n",nbTabs+10);
|
||||||
|
|
||||||
nbIterations = new JSpinner();
|
|
||||||
nbIterations.setModel(new SpinnerNumberModel(1, 1, 15, 1));
|
|
||||||
|
|
||||||
JLabel itLabel = new JLabel("Nombre d'itérations : ");
|
JLabel itLabel = new JLabel("Nombre d'itérations : ");
|
||||||
itSpinner = new JSpinner(new SpinnerNumberModel(1, 1, 30, 1));
|
itSpinner = new JSpinner(new SpinnerNumberModel(1, 1, 30, 1));
|
||||||
((JSpinner.DefaultEditor) itSpinner.getEditor()).getTextField().setEditable(false);
|
((JSpinner.DefaultEditor) itSpinner.getEditor()).getTextField().setEditable(false);
|
||||||
|
itSpinner.addMouseWheelListener(new Listener(null,null,"Spinner",this));
|
||||||
|
|
||||||
JLabel axiome = new JLabel("Axiome :");
|
JLabel axiome = new JLabel("Axiome :");
|
||||||
JLabel rules = new JLabel("Règle "+ nbRules+" :");
|
JLabel rules = new JLabel("Règle "+ nbRules+" :");
|
||||||
@ -40,11 +38,14 @@ public class Tab extends JPanel{
|
|||||||
rulesField.addKeyListener(new Listener(null,nbTabs+10,"Règles",this));
|
rulesField.addKeyListener(new Listener(null,nbTabs+10,"Règles",this));
|
||||||
rulesField.setPreferredSize(new Dimension(120,20));
|
rulesField.setPreferredSize(new Dimension(120,20));
|
||||||
|
|
||||||
submitButton = new JButton("Générer");
|
submitButton2D = new JButton("Générer en 2D");
|
||||||
|
submitButton3D = new JButton("Générer en 3D");
|
||||||
JButton clearButton = new JButton("Clear");
|
JButton clearButton = new JButton("Clear");
|
||||||
clearButton.addActionListener(new Listener(null,nbTabs,"Clear",this));
|
clearButton.addActionListener(new Listener(null,nbTabs,"Clear",this));
|
||||||
submitButton.addActionListener(new Listener(null,nbTabs,"Generate",this));
|
submitButton2D.addActionListener(new Listener(null,nbTabs,"Generate 2D",this));
|
||||||
JPanel southComponents = subPanel(clearButton,submitButton,null);
|
submitButton3D.addActionListener(new Listener(null,nbTabs,"Generate 3D",this));
|
||||||
|
JPanel southComponents = subPanel(submitButton2D,submitButton3D, null);
|
||||||
|
JPanel southComponents2 = subPanel(clearButton, southComponents, null);
|
||||||
|
|
||||||
GridBagConstraints gc = new GridBagConstraints();
|
GridBagConstraints gc = new GridBagConstraints();
|
||||||
gc.gridx = 0;
|
gc.gridx = 0;
|
||||||
@ -66,7 +67,7 @@ public class Tab extends JPanel{
|
|||||||
|
|
||||||
aboveComponents.setLayout(new GridLayout(1,4));
|
aboveComponents.setLayout(new GridLayout(1,4));
|
||||||
tab.add(aboveComponents);
|
tab.add(aboveComponents);
|
||||||
tab.add(southComponents);
|
tab.add(southComponents2);
|
||||||
tab.setLayout(new BoxLayout(tab,1));
|
tab.setLayout(new BoxLayout(tab,1));
|
||||||
|
|
||||||
close = new JButton("Close");
|
close = new JButton("Close");
|
||||||
|
Loading…
Reference in New Issue
Block a user