From 9a60e73a7339e38ca07ead4a1d4b8880eea34854 Mon Sep 17 00:00:00 2001 From: adam Date: Tue, 1 Jul 2008 11:41:16 -0700 Subject: [PATCH] checkpoint darcs-hash:20080701184116-5007d-1a5fbf6ced7110203432fc52abe9ef44fde246f8.gz --- src/edu/berkeley/qfat/InteractiveMeshViewer.java | 45 ++++++++++++++++------ src/edu/berkeley/qfat/Main.java | 25 ++++++++++++ src/edu/berkeley/qfat/Mesh.java | 21 ++++++++++ src/edu/berkeley/qfat/MeshViewer.java | 9 ++++- 4 files changed, 87 insertions(+), 13 deletions(-) diff --git a/src/edu/berkeley/qfat/InteractiveMeshViewer.java b/src/edu/berkeley/qfat/InteractiveMeshViewer.java index e024d04..d162677 100644 --- a/src/edu/berkeley/qfat/InteractiveMeshViewer.java +++ b/src/edu/berkeley/qfat/InteractiveMeshViewer.java @@ -11,36 +11,53 @@ import java.util.*; import edu.berkeley.qfat.geom.*; import edu.berkeley.qfat.geom.Point; -public class InteractiveMeshViewer extends JPanel { +public class InteractiveMeshViewer extends JPanel implements KeyListener { public Mesh tile; public Mesh goal; - private MeshViewer mv; + private HashSet mvs = new HashSet(); public InteractiveMeshViewer(JFrame f) { - mv = new MeshViewer(); - setLayout(new BorderLayout()); - this.add(mv, BorderLayout.CENTER); + MeshViewer mv1 = new MeshViewer(); + MeshViewer mv2 = new MeshViewer(); + MeshViewer mv3 = new MeshViewer(); + MeshViewer mv4 = new MeshViewer(); + mvs.add(mv1); + mvs.add(mv2); + mvs.add(mv3); + mvs.add(mv4); + addKeyListener(this); + mv1.addKeyListener(this); + mv2.addKeyListener(this); + mv3.addKeyListener(this); + mv4.addKeyListener(this); + setLayout(new GridLayout(2,2)); + this.add(mv1); + this.add(mv2); + this.add(mv3); + this.add(mv4); setTile(new Mesh(false)); setGoal(new Mesh(false)); } public void repaint() { - if (mv != null) mv.repaint(); + if (mvs != null) + for(MeshViewer mv : mvs) + mv.repaint(); } public void setTile(Mesh tile) { - mv.removeMesh(this.tile); + for(MeshViewer mv : mvs) mv.removeMesh(this.tile); this.tile = tile; - mv.addMesh(this.tile); + for(MeshViewer mv : mvs) mv.addMesh(this.tile); } public void setGoal(Mesh goal) { - mv.removeMesh(this.goal); + for(MeshViewer mv : mvs) mv.removeMesh(this.goal); this.goal = goal; goal.option_selectable = false; goal.option_wireframe = true; - mv.addMesh(this.goal); + for(MeshViewer mv : mvs) mv.addMesh(this.goal); } public synchronized void dump() { @@ -83,10 +100,16 @@ public class InteractiveMeshViewer extends JPanel { public int accepts; public int vertss; + public void keyTyped(KeyEvent e) { } + public void keyReleased(KeyEvent e) { } public void keyPressed(KeyEvent e) { //super.keyPressed(e); switch(e.getKeyCode()) { - case KeyEvent.VK_SPACE: breaks++; force = true; break; + case KeyEvent.VK_SPACE: + synchronized(this) { + tile.subdivide(); + } + //case KeyEvent.VK_SPACE: breaks++; force = true; break; case KeyEvent.VK_UP: temp = temp * 2; break; case KeyEvent.VK_ENTER: temp = 10; break; case KeyEvent.VK_LEFT: whichNeighbor--; break; diff --git a/src/edu/berkeley/qfat/Main.java b/src/edu/berkeley/qfat/Main.java index 75b3f12..e4abd5a 100644 --- a/src/edu/berkeley/qfat/Main.java +++ b/src/edu/berkeley/qfat/Main.java @@ -11,6 +11,31 @@ import edu.berkeley.qfat.geom.Point; import edu.berkeley.qfat.geom.Polygon; // TO DO: +// +// - Implement "real" constraints (plane, line, point) +// +// - Constrained surface subdivision +// - Edge.flip() gets us the triforce subdivision +// - Edge.delete() gets us the catmull-clark subdivision +// - Catmull-Clark: just don't move points if we can't. Need to average the influence of the points on a binding group. +// +// - Ability to snap three views to orthgonal +// - SLIDE UI +// - left button -> crystal ball +// - translate +// - rightbutton/mousewheel zoom +// - v+click to select vertex +// - show: constraints, bindings, faces +// +// Editing: +// - fracture edge, face +// - change aspect ratio +// - ability to select a point, rotate the model, then move the point +// - when moving a vertex in one window, show that window's axes in all other windows +// + + +// TO DO: // - real anneal // - solve self-intersection problem // - get a better test model? diff --git a/src/edu/berkeley/qfat/Mesh.java b/src/edu/berkeley/qfat/Mesh.java index 7c38672..f7143f0 100644 --- a/src/edu/berkeley/qfat/Mesh.java +++ b/src/edu/berkeley/qfat/Mesh.java @@ -115,6 +115,22 @@ public class Mesh implements Iterable { } + public void subdivide() { + for (T t : this) t.old = true; + for (Vertex v : vertices()) v.original = true; + OUTER: while(true) { + for (T t : this) + if (t.old) { + Point p = t.e1.midpoint(); + System.out.println("shatter " + t.e1); + t.e1.shatter(); + nearest(p).edge = true; + continue OUTER; + } + break; + } + } + // Vertexices ////////////////////////////////////////////////////////////////////////////// /** a vertex in the mesh */ @@ -123,6 +139,9 @@ public class Mesh implements Iterable { public Point oldp; E e; // some edge *leaving* this point + public boolean original = false; + public boolean edge = false; + private boolean illegal = false; public boolean visible = false; @@ -752,6 +771,8 @@ public class Mesh implements Iterable { public final int color; public final int colorclass; + public boolean old; + public final int serial = max_serial++; public boolean occluded; diff --git a/src/edu/berkeley/qfat/MeshViewer.java b/src/edu/berkeley/qfat/MeshViewer.java index 7a9fcd5..f7fa9c1 100644 --- a/src/edu/berkeley/qfat/MeshViewer.java +++ b/src/edu/berkeley/qfat/MeshViewer.java @@ -24,6 +24,7 @@ public class MeshViewer extends JPanel implements GLEventListener, MouseListener private Point clickPoint = null; private GLCanvas glcanvas; private boolean updateVisibilities = false; + private boolean mouseInside = false; private HashSet meshes = new HashSet(); @@ -75,6 +76,10 @@ public class MeshViewer extends JPanel implements GLEventListener, MouseListener GL gl = glcanvas.getGL();//drawable.getGL(); GLU glu = new GLU(); + + if (!mouseInside) gl.glClearColor(0.1f, 0.1f, 0.1f, 1.0f); + else gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f); + gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); gl.glPointSize(5.0f); gl.glLoadIdentity(); @@ -185,8 +190,8 @@ public class MeshViewer extends JPanel implements GLEventListener, MouseListener public void keyReleased(KeyEvent e) { } public void mouseClicked(MouseEvent e) { } - public void mouseEntered(MouseEvent e) { } - public void mouseExited(MouseEvent e) { } + public void mouseEntered(MouseEvent e) { mouseInside = true; } + public void mouseExited(MouseEvent e) { mouseInside = false; } public void mousePressed(MouseEvent e) { clickPoint = getMouse(); } -- 1.7.10.4