checkpoint
authoradam <adam@megacz.com>
Tue, 18 Dec 2007 01:43:52 +0000 (17:43 -0800)
committeradam <adam@megacz.com>
Tue, 18 Dec 2007 01:43:52 +0000 (17:43 -0800)
darcs-hash:20071218014352-5007d-312834fbd2fa9a4263bca8f1d7a75fde05fc0c14.gz

src/edu/berkeley/qfat/Main.java
src/edu/berkeley/qfat/Mesh.java
src/edu/berkeley/qfat/MeshViewer.java
src/edu/berkeley/qfat/geom/BindingGroup.java [new file with mode: 0644]
src/edu/berkeley/qfat/geom/HasBindingGroup.java [new file with mode: 0644]

index 83bf281..0c9e521 100644 (file)
@@ -281,7 +281,7 @@ public class Main extends MeshViewer {
             Mesh.E e = es.poll();
             verts++;
             //System.out.println("shatter " + e);
-            e.shatter();
+            e.shatter(e.midpoint(), null, null, true, true);
             Thread.yield();
             repaint();
         }
index 68e9c23..fa6b80f 100644 (file)
@@ -357,6 +357,9 @@ public class Mesh implements Iterable<Mesh.T> {
         public Point shatter() { return shatter(true); }
         public Point shatter(boolean triangles) { return shatter(midpoint(), null, null, triangles); }
         public Point shatter(Point mid, BindingGroup bg1, BindingGroup bg2, boolean triangles) {
+            return shatter(mid, bg1, bg2, triangles, false);
+        }
+        public Point shatter(Point mid, BindingGroup bg1, BindingGroup bg2, boolean triangles, boolean leader) {
             if (shattered || destroyed) return mid;
             shattered = true;
 
@@ -382,6 +385,7 @@ public class Mesh implements Iterable<Mesh.T> {
                 newT(r.p, mid, p2.p, null, old_colorclass);
                 bg1.add(p1.getE(mid));
                 bg2.add(p2.getE(mid).pair);
+                if (leader) p1.getE(mid).shatter();
             }
             return mid;
         }
index 29919a4..a886aa4 100644 (file)
@@ -21,7 +21,7 @@ public class MeshViewer implements GLEventListener, MouseListener, MouseMotionLi
     public boolean tileon = true;
     public boolean tilemeshon = false;
     public boolean goalon = false;
-    public boolean anneal = true;
+    public boolean anneal = false;
 
     public int breaks = 0;
     boolean alt = false;
@@ -226,7 +226,7 @@ public class MeshViewer implements GLEventListener, MouseListener, MouseMotionLi
             green -= .12f;
             blue -= .15f;
 
-            if (triangles) switch(t.colorclass) {
+            if (triangles) switch(t.color/*class*/) {
                 case 0: gl.glColor4f((float)0.25, (float)0.25, (float)0.75, (float)0.3); break;
                 case 1: gl.glColor4f((float)0.25, (float)0.75, (float)0.25, (float)0.3); break;
                 case 2: gl.glColor4f((float)0.75, (float)0.25, (float)0.25, (float)0.3); break;
@@ -235,7 +235,7 @@ public class MeshViewer implements GLEventListener, MouseListener, MouseMotionLi
                 case 5: gl.glColor4f((float)0.25, (float)0.75, (float)0.75, (float)0.3); break;
                 case 6: gl.glColor4f((float)0.75, (float)0.25, (float)0.75, (float)0.3); break;
             }
-            gl.glColor4f((float)0.75, (float)0.25, (float)0.25, (float)0.3);
+            //gl.glColor4f((float)0.75, (float)0.25, (float)0.25, (float)0.3);
             //gl.glBegin(GL.GL_LINES);
 
             if (triangles) {
diff --git a/src/edu/berkeley/qfat/geom/BindingGroup.java b/src/edu/berkeley/qfat/geom/BindingGroup.java
new file mode 100644 (file)
index 0000000..ca07312
--- /dev/null
@@ -0,0 +1,35 @@
+package edu.berkeley.qfat.geom;
+import javax.media.opengl.*;
+import java.util.*;
+
+public class BindingGroup<T extends HasBindingGroup> {
+
+    private T                  master   = null;
+    private HashMap<T,Matrix>  matrices = new HashMap<T,Matrix>();
+
+    public BindingGroup(T master) {
+        this.master = master;
+        matrices.put(master, Matrix.ONE);
+    }
+
+    public void merge(BindingGroup<T> bg, Matrix m) {
+        for(HasBindingGroup hbg : bg.matrices.keySet()) {
+            matrices.put((T)hbg, bg.matrices.get(hbg).times(m));
+            hbg.bindingGroup = this;
+        }
+        bg.matrices.clear();
+        bg.master = null;
+    }
+
+    public T getMaster() { return master; }
+    public Matrix getMatrix(T t) { return matrices.get(t); }
+
+    //                    t1 = getMatrix(t1) * master
+    // getMatrix(t2)^-1 * t2 =                 master
+    //                    t1 = getMatrix(t1) * getMatrix(t2)^-1 * t2
+    /** t1 = getMatrix(t1, t2) * t2 */
+    public Matrix getMatrix(T t1, T t2) {
+        return getMatrix(t1).times(getMatrix(t2).inverse());
+    }
+
+}
diff --git a/src/edu/berkeley/qfat/geom/HasBindingGroup.java b/src/edu/berkeley/qfat/geom/HasBindingGroup.java
new file mode 100644 (file)
index 0000000..cf72a08
--- /dev/null
@@ -0,0 +1,33 @@
+package edu.berkeley.qfat.geom;
+import javax.media.opengl.*;
+import java.util.*;
+
+public abstract class HasBindingGroup {
+
+    BindingGroup bindingGroup;
+
+    // know:      self   = bindingGroup[self] * master
+    // know:      other  = other.bindingGroup[other] * other.bindingGroup.master
+    // want:      self   = bindingMatrix * other
+    // therefore: master = bindingGroup[self]^-1 * bindingMatrix * other
+    // therefore:        = bindingGroup[self]^-1 * bindingMatrix * other.bindingGroup[other] * other.bindingGroup.master
+    public void bindTo(HasBindingGroup other, Matrix bindingMatrix) {
+        if (other.bindingGroup == this.bindingGroup)
+            throw new Error("rebind attempt");
+
+        bindingMatrix =
+            getBindingMatrix()
+            .times(bindingMatrix)
+            .times(other.getBindingMatrix());
+        other.bindingGroup.merge(bindingGroup, bindingMatrix);
+    }
+
+    public Matrix getBindingMatrix() {
+        return bindingGroup.getMatrix(this);
+    }
+
+    public HasBindingGroup getMaster() {
+        return bindingGroup.getMaster();
+    }
+
+}