checkpoint autogen tile
authoradam <adam@megacz.com>
Thu, 20 Dec 2007 11:53:49 +0000 (03:53 -0800)
committeradam <adam@megacz.com>
Thu, 20 Dec 2007 11:53:49 +0000 (03:53 -0800)
darcs-hash:20071220115349-5007d-a873fd4586ed29fe4a553c632252c6bc3742b20c.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
src/edu/berkeley/qfat/geom/HasBindingGroup.java
src/edu/berkeley/qfat/geom/Plane.java
src/edu/berkeley/qfat/geom/Polygon.java
src/edu/berkeley/qfat/geom/Vec.java

index 5d86d71..8b5b51f 100644 (file)
@@ -57,9 +57,11 @@ public class Main extends MeshViewer {
     
     /** magnification factor */
     private static final float MAG = 1;
     
     /** magnification factor */
     private static final float MAG = 1;
-    public static final float MATCHING_EPSILON = 0.0001f;
+    public static final float MATCHING_EPSILON = 0.001f;
 
 
+    private static boolean small(float f) { return Math.abs(f) < 0.001; }
     public void generateTile(Matrix[] matrices, Mesh mesh) {
     public void generateTile(Matrix[] matrices, Mesh mesh) {
+        mesh.coalesce = true;
         HashSet<HalfSpace> halfSpaces = new HashSet<HalfSpace>();
         HashSet<Polygon> polygons = new HashSet<Polygon>();
         for(Matrix m : matrices) {
         HashSet<HalfSpace> halfSpaces = new HashSet<HalfSpace>();
         HashSet<Polygon> polygons = new HashSet<Polygon>();
         for(Matrix m : matrices) {
@@ -67,7 +69,25 @@ public class Main extends MeshViewer {
             if (v.mag() < 0.0001) continue;
             v = v.times(0.5f);
             Point p = Point.ORIGIN.plus(v);
             if (v.mag() < 0.0001) continue;
             v = v.times(0.5f);
             Point p = Point.ORIGIN.plus(v);
-            HalfSpace hs = new HalfSpace(p, Point.ORIGIN.minus(p).norm());
+            Vec v0 = v;
+            /*
+            if      (small(v.x) && small(v.y)) v = new Vec(0,0,1);
+            else if (small(v.y) && small(v.z)) v = new Vec(1,0,0);
+            else if (small(v.z) && small(v.x)) v = new Vec(0,1,0);
+            else if (small(v.x))               v = new Vec(0,v.y,0).minus(new Vec(0,0,v.z)).cross(new Vec(1,0,0));
+            else if (small(v.y))               v = new Vec(0,0,v.z).minus(new Vec(v.x,0,0)).cross(new Vec(0,1,0));
+            else if (small(v.z))               v = new Vec(v.x,0,0).minus(new Vec(0,v.y,0)).cross(new Vec(0,0,1));
+            else {
+                Point v1 = new Point(v.x, 0,   0);
+                Point v2 = new Point(0,   v.y, 0);
+                Point v3 = new Point(0,   0,   v.z);
+                v = v3.minus(v2).cross(v1.minus(v2));
+            }
+            */
+            if (v.dot(Point.ORIGIN.minus(p)) < 0) v = v.times(-1);
+
+            System.out.println(v);
+            HalfSpace hs = new HalfSpace(p, v.norm());
             halfSpaces.add(hs);
             polygons.add(new Polygon(hs));
         }
             halfSpaces.add(hs);
             polygons.add(new Polygon(hs));
         }
@@ -108,7 +128,7 @@ public class Main extends MeshViewer {
 
         // rotate to align major axis -- this probably needs to be done by a human.
         //goal.transform(Matrix.rotate(new Vec(0, 0, 1), (float)(Math.PI/2)));
 
         // rotate to align major axis -- this probably needs to be done by a human.
         //goal.transform(Matrix.rotate(new Vec(0, 0, 1), (float)(Math.PI/2)));
-        goal.transform(Matrix.rotate(new Vec(0, 1, 0), (float)(Math.PI/2)));
+
 
         float goal_width  = goal.diagonal().dot(new Vec(1, 0, 0));
         float goal_height = goal.diagonal().dot(new Vec(0, 1, 0));
 
         float goal_width  = goal.diagonal().dot(new Vec(1, 0, 0));
         float goal_height = goal.diagonal().dot(new Vec(0, 1, 0));
@@ -120,30 +140,48 @@ public class Main extends MeshViewer {
           float depth  = (float)0.3;
         */
         
           float depth  = (float)0.3;
         */
         
-        float width  = (float)0.7;
+        float width  = (float)0.8;
         float depth  = (float)0.08;
         float height = (float)0.4;
 
         float rshift =   width/2;
         float lshift = -(width/2);
         float depth  = (float)0.08;
         float height = (float)0.4;
 
         float rshift =   width/2;
         float lshift = -(width/2);
-
-        //float halfup = height/2;
         float halfup = 0;
         float halfup = 0;
-
+        //float shift = height/2;
+        //width = (width*2)/3;
+        float shift = 0;
         translations = new Matrix[] {
 
         translations = new Matrix[] {
 
-            //Matrix.translate(new Vec(lshift,  depth,    0)),
-            //Matrix.translate(new Vec(rshift,  depth,    0)),
-            //Matrix.translate(new Vec(lshift, -depth,    0)),
-            //Matrix.translate(new Vec(rshift, -depth,    0)),
-
+            Matrix.translate(new Vec(lshift/2,  depth,    -shift)),
+            Matrix.translate(new Vec(rshift/2,  depth,    -shift)),
+            Matrix.translate(new Vec(lshift/2, -depth,    -shift)),
+            Matrix.translate(new Vec(rshift/2, -depth,    -shift)),
+
+            Matrix.translate(new Vec(lshift,  depth/2,    -shift)),
+            Matrix.translate(new Vec(rshift,  depth/2,    -shift)),
+            Matrix.translate(new Vec(lshift, -depth/2,    -shift)),
+            Matrix.translate(new Vec(rshift, -depth/2,    -shift)),
+
+
+            /*
+            Matrix.translate(new Vec(lshift,  depth,    -shift)),
+            Matrix.translate(new Vec(rshift,  depth,    -shift)),
+            Matrix.translate(new Vec(lshift, -depth,    -shift)),
+            Matrix.translate(new Vec(rshift, -depth,    -shift)),
+            */
+            /*
+            Matrix.translate(new Vec(lshift,  depth,    shift)),
+            Matrix.translate(new Vec(rshift,  depth,    shift)),
+            Matrix.translate(new Vec(lshift, -depth,    shift)),
+            Matrix.translate(new Vec(rshift, -depth,    shift)),
+            */
             //Matrix.translate(new Vec(0,  depth,    0)).times(Matrix.rotate(new Vec(0, 0, 1), (float)Math.PI)),
             //Matrix.translate(new Vec(0, -depth,    0)).times(Matrix.rotate(new Vec(0, 0, 1), (float)Math.PI)),
             //Matrix.translate(new Vec(0,   0,    height)).times(Matrix.rotate(new Vec(0, 0, 1), (float)Math.PI)),
             //Matrix.translate(new Vec(0,   0,   -height)).times(Matrix.rotate(new Vec(0, 0, 1), (float)Math.PI)),
 
             //Matrix.translate(new Vec(0,  depth,    0)).times(Matrix.rotate(new Vec(0, 0, 1), (float)Math.PI)),
             //Matrix.translate(new Vec(0, -depth,    0)).times(Matrix.rotate(new Vec(0, 0, 1), (float)Math.PI)),
             //Matrix.translate(new Vec(0,   0,    height)).times(Matrix.rotate(new Vec(0, 0, 1), (float)Math.PI)),
             //Matrix.translate(new Vec(0,   0,   -height)).times(Matrix.rotate(new Vec(0, 0, 1), (float)Math.PI)),
 
-            Matrix.translate(new Vec(0,  depth, 0)),
-            Matrix.translate(new Vec(0, -depth, 0)),
+            //Matrix.translate(new Vec(0,  depth, 0)),
+            //Matrix.translate(new Vec(0, -depth, 0)),
             Matrix.translate(new Vec(0,      0,  height)),
             Matrix.translate(new Vec(0,      0, -height)),
 
             Matrix.translate(new Vec(0,      0,  height)),
             Matrix.translate(new Vec(0,      0, -height)),
 
@@ -157,9 +195,43 @@ public class Main extends MeshViewer {
             Matrix.translate(new Vec( width,           0,    0)),
             Matrix.translate(new Vec(-width,           0,    0)),
 
             Matrix.translate(new Vec( width,           0,    0)),
             Matrix.translate(new Vec(-width,           0,    0)),
 
+            Matrix.ONE
+        };
+
+        float unit = 0.1f;
+        float r = unit/2;
+        float sin = (float)(unit * Math.sin(Math.PI/3));
+        float cos = (float)(unit * Math.cos(Math.PI/3));
+        float x = (float)(r*Math.tan(Math.PI/6));
+        float z = (float)(r/Math.cos(Math.PI/6));
+        height = 2*r*(float)Math.sqrt(2f/3f);
+
+
+        r *= 0.3f;
+        cos *= 0.3f;
+        unit *= 0.3f;
+
+
+        /*
+        sin *= 0.3f;
+        x *= 0.3f;
+        z *= 0.3f;
+        */
+        translations = new Matrix[] {
+            Matrix.translate(new Vec(-unit, 0, 0)),
+            Matrix.translate(new Vec( unit, 0, 0)),
+            Matrix.translate(new Vec(-cos,  0,  sin)),
+            Matrix.translate(new Vec( cos,  0,  sin)),
+            Matrix.translate(new Vec(-cos,  0, -sin)),
+            Matrix.translate(new Vec( cos,  0, -sin)),
+            Matrix.translate(new Vec( 0,  height, z)),
+            Matrix.translate(new Vec(-r,  height, -x)),
+            Matrix.translate(new Vec( r,  height, -x)),
+            Matrix.translate(new Vec( 0, -height, -z)),
+            Matrix.translate(new Vec(-r, -height, x)),
+            Matrix.translate(new Vec( r, -height, x)),
         };
 
         };
 
-        generateTile(translations, tile);
 
         /*
         translations = new Matrix[] {
 
         /*
         translations = new Matrix[] {
@@ -192,10 +264,11 @@ public class Main extends MeshViewer {
             Matrix.translate(new Vec(-width,           0,    0)),
 
         };
             Matrix.translate(new Vec(-width,           0,    0)),
 
         };
-
+        */
         //   
 
 
         //   
 
 
+        //generateTile(translations, tile);
 
         Point ltf = new Point(lshift,  (depth/2),  (height/2));
         Point mtf = new Point( 0.0,    (depth/2),  (height/2));
 
         Point ltf = new Point(lshift,  (depth/2),  (height/2));
         Point mtf = new Point( 0.0,    (depth/2),  (height/2));
@@ -241,7 +314,7 @@ public class Main extends MeshViewer {
             mbn,
             rbn
         };
             mbn,
             rbn
         };
-
+        /*
 
         // top
         tile.newT(ltf, mtf, mtc, null, 1);
 
         // top
         tile.newT(ltf, mtf, mtc, null, 1);
@@ -290,7 +363,8 @@ public class Main extends MeshViewer {
         tile.newT(mbf, ltf, lbf, null, 6);
         tile.newT(rtf, mtf, rbf, null, 6);
         tile.newT(rbf, mtf, mbf, null, 6);
         tile.newT(mbf, ltf, lbf, null, 6);
         tile.newT(rtf, mtf, rbf, null, 6);
         tile.newT(rbf, mtf, mbf, null, 6);
-
+*/
+        /*
         HashSet<Mesh.E> es = new HashSet<Mesh.E>();
         for(Mesh.T t : tile) {
             es.add(t.e1());
         HashSet<Mesh.E> es = new HashSet<Mesh.E>();
         for(Mesh.T t : tile) {
             es.add(t.e1());
@@ -305,7 +379,7 @@ public class Main extends MeshViewer {
         }
         */
 
         }
         */
 
-        /*
+
          height = 4;
          width  = 4;
          depth  = 1;
          height = 4;
          width  = 4;
          depth  = 1;
@@ -379,22 +453,32 @@ public class Main extends MeshViewer {
              new Point(-1, -1,  1),
              new Point(-1, -1, -1));
 
              new Point(-1, -1,  1),
              new Point(-1, -1, -1));
 
-        float factor = (float)Math.pow(tile.volume() / goal.volume(), 1.0/3.0);
-        goal.transform(Matrix.scale(factor/2.4f));
 
 
-        /*        
-        translations = new Matrix[] {
 
 
+        translations = new Matrix[] {
+            /*
             Matrix.translate(new Vec(0, 0.2f,0))
             .times(Matrix.rotate(new Vec(0,1,0), (float)( 1*Math.PI/2))),
 
             Matrix.translate(new Vec(0,-0.2f,0))
             .times(Matrix.rotate(new Vec(0,1,0), (float)(-1*Math.PI/2))),
 
             Matrix.translate(new Vec(0, 0.2f,0))
             .times(Matrix.rotate(new Vec(0,1,0), (float)( 1*Math.PI/2))),
 
             Matrix.translate(new Vec(0,-0.2f,0))
             .times(Matrix.rotate(new Vec(0,1,0), (float)(-1*Math.PI/2))),
 
-            //Matrix.translate(new Vec( 0.2f,0,0))
-            //.times(Matrix.rotate(new Vec(1,0,0), (float)( 1*Math.PI/2))),
-            //Matrix.translate(new Vec(-0.2f,0,0))
-            //.times(Matrix.rotate(new Vec(1,0,0), (float)(-1*Math.PI/2))),
+            Matrix.translate(new Vec( 0.2f,0,0))
+            .times(Matrix.rotate(new Vec(1,0,0), (float)( 1*Math.PI/2))),
+
+            Matrix.translate(new Vec(-0.2f,0,0))
+            .times(Matrix.rotate(new Vec(1,0,0), (float)(-1*Math.PI/2))),
+            */
+
+            /*
+            Matrix.rotate(new Vec(0,0,1), (float)(1*Math.PI/2)),
+            Matrix.rotate(new Vec(0,0,1), (float)(2*Math.PI/2)),
+            Matrix.rotate(new Vec(0,0,1), (float)(3*Math.PI/2)),
+            */
+            Matrix.rotate(new Vec(1,0,0), (float)(2*Math.PI/2)),
+
+            //Matrix.rotate(new Vec(0,0,1), (float)(2*Math.PI/2)),
+            //Matrix.scale(1,-1,1),
 
             //Matrix.translate(new Vec( 0.2f, 0,0))
             //.times(Matrix.rotate(new Vec(0,0,1), (float)( 1*Math.PI/2)))
 
             //Matrix.translate(new Vec( 0.2f, 0,0))
             //.times(Matrix.rotate(new Vec(0,0,1), (float)( 1*Math.PI/2)))
@@ -420,8 +504,9 @@ public class Main extends MeshViewer {
 
             Matrix.ONE,
         };
 
             Matrix.ONE,
         };
-        */
-            
+
+
+           
         for(Matrix m1 : translations) {
         for(Matrix m2 : translations) {
             for(Mesh.T t1 : tile) {
         for(Matrix m1 : translations) {
         for(Matrix m2 : translations) {
             for(Mesh.T t1 : tile) {
@@ -451,6 +536,28 @@ public class Main extends MeshViewer {
                         t2.e1().bindEdge(t1.e2(), m);
                     }
 
                         t2.e1().bindEdge(t1.e2(), m);
                     }
 
+                    if ((t1.v1().p.times(m).minus(t2.v1().p).mag() < MATCHING_EPSILON) &&
+                        (t1.v2().p.times(m).minus(t2.v2().p).mag() < MATCHING_EPSILON) &&
+                        (t1.v3().p.times(m).minus(t2.v3().p).mag() < MATCHING_EPSILON)) {
+                        t2.e1().bindEdge(t1.e1().pair, m);
+                        t2.e2().bindEdge(t1.e2().pair, m);
+                        t2.e3().bindEdge(t1.e3().pair, m);
+                    }
+                    if ((t1.v2().p.times(m).minus(t2.v1().p).mag() < MATCHING_EPSILON) &&
+                        (t1.v3().p.times(m).minus(t2.v2().p).mag() < MATCHING_EPSILON) &&
+                        (t1.v1().p.times(m).minus(t2.v3().p).mag() < MATCHING_EPSILON)) {
+                        t2.e2().bindEdge(t1.e1().pair, m);
+                        t2.e3().bindEdge(t1.e2().pair, m);
+                        t2.e1().bindEdge(t1.e3().pair, m);
+                    }
+                    if ((t1.v3().p.times(m).minus(t2.v1().p).mag() < MATCHING_EPSILON) &&
+                        (t1.v1().p.times(m).minus(t2.v2().p).mag() < MATCHING_EPSILON) &&
+                        (t1.v2().p.times(m).minus(t2.v3().p).mag() < MATCHING_EPSILON)) {
+                        t2.e3().bindEdge(t1.e1().pair, m);
+                        t2.e1().bindEdge(t1.e2().pair, m);
+                        t2.e2().bindEdge(t1.e3().pair, m);
+                    }
+
                 }
             }
         }
                 }
             }
         }
@@ -461,6 +568,9 @@ public class Main extends MeshViewer {
         // rescale to match volume
 
 
         // rescale to match volume
 
 
+        float factor = (float)Math.pow(tile.volume() / goal.volume(), 1.0/3.0);
+        goal.transform(Matrix.scale(factor/2.4f));
+        goal.transform(Matrix.rotate(new Vec(0, 1, 0), (float)(Math.PI/2)));
 
         // translate to match centroid
         goal.transform(Matrix.translate(tile.centroid().minus(goal.centroid())));
 
         // translate to match centroid
         goal.transform(Matrix.translate(tile.centroid().minus(goal.centroid())));
index 774c7f9..0d7a96a 100644 (file)
@@ -169,6 +169,20 @@ public class Mesh implements Iterable<Mesh.T> {
             //     t2' = t2.getMatrix(t1) * M * t1
             //     t1 =     t1.getMatrix(t2) * t2
             // M * t1 = M * t1.getMatrix(t2) * t2
             //     t2' = t2.getMatrix(t1) * M * t1
             //     t1 =     t1.getMatrix(t2) * t2
             // M * t1 = M * t1.getMatrix(t2) * t2
+            if (bindingGroup!=null && this != bindingGroup.getMaster()) {
+                Matrix v = getBindingMatrix(bindingGroup.getMaster());
+                return ((Vertex)bindingGroup.getMaster()).move(v.inverse().times(m).times(v), ignoreProblems);
+            }
+
+            if (bindingGroup != null) {
+                Matrix m2 = null;
+                for(int i=0; i<20 && !m.equals(m2); i++) {
+                    m2 = m.times(bindingGroup.krank);
+                    //System.out.println(m.minus(m2));
+                }
+                if (!m.equals(m2)) return true;
+            }
+
             Point op = this.p;
             Point pt = m.times(this.p);
             for(Vertex v : (Iterable<Vertex>)getBoundPeers()) {
             Point op = this.p;
             Point pt = m.times(this.p);
             for(Vertex v : (Iterable<Vertex>)getBoundPeers()) {
@@ -312,13 +326,20 @@ public class Mesh implements Iterable<Mesh.T> {
                 (edu.berkeley.qfat.geom.BindingGroup<E>)newBindingGroup_;
             if (newBindingGroup==null) return;
             if (this==newBindingGroup.getMaster()) return;
                 (edu.berkeley.qfat.geom.BindingGroup<E>)newBindingGroup_;
             if (newBindingGroup==null) return;
             if (this==newBindingGroup.getMaster()) return;
-            for(E eother : (Iterable<E>)newBindingGroup) {
+            HashSet<E> nbg = new HashSet<E>();
+            for(E eother : (Iterable<E>)newBindingGroup) nbg.add(eother);
+            for(E eother : nbg) {
                 if (next==null || prev==null) continue;
                 if (eother.next==null || eother.prev==null) continue;
                 if (next.isBoundTo(eother.pair.prev.pair) && !prev.isBoundTo(eother.pair.next.pair))
                     prev.bindTo(next.getBindingMatrix(eother.pair.prev.pair), eother.pair.next.pair);
                 if (!next.isBoundTo(eother.pair.prev.pair) && prev.isBoundTo(eother.pair.next.pair))
                     next.bindTo(prev.getBindingMatrix(eother.pair.next.pair), eother.pair.prev.pair);
                 if (next==null || prev==null) continue;
                 if (eother.next==null || eother.prev==null) continue;
                 if (next.isBoundTo(eother.pair.prev.pair) && !prev.isBoundTo(eother.pair.next.pair))
                     prev.bindTo(next.getBindingMatrix(eother.pair.prev.pair), eother.pair.next.pair);
                 if (!next.isBoundTo(eother.pair.prev.pair) && prev.isBoundTo(eother.pair.next.pair))
                     next.bindTo(prev.getBindingMatrix(eother.pair.next.pair), eother.pair.prev.pair);
+
+                if (next.isBoundTo(eother.next) && !prev.isBoundTo(eother.prev))
+                    prev.bindTo(next.getBindingMatrix(eother.next), eother.prev);
+                if (!next.isBoundTo(eother.next) && prev.isBoundTo(eother.prev))
+                    next.bindTo(prev.getBindingMatrix(eother.prev), eother.next);
             }
 
         }
             }
 
         }
@@ -554,7 +575,22 @@ public class Mesh implements Iterable<Mesh.T> {
         if (v2 != null) return new E(v2.getFreeIncident(), p1).pair;
         return new E(p1, p2);
     }
         if (v2 != null) return new E(v2.getFreeIncident(), p1).pair;
         return new E(p1, p2);
     }
+    public boolean coalesce = false;
+    private static float round(float f) {
+        return Math.round(f*1000)/1000f;
+    }
     public T newT(Point p1, Point p2, Point p3, Vec norm, int colorclass) {
     public T newT(Point p1, Point p2, Point p3, Vec norm, int colorclass) {
+        if (coalesce) {
+
+            for(Vertex v : vertices) { if (p1.distance(v.p) < EPSILON) { p1 = v.p; break; } }
+            for(Vertex v : vertices) { if (p2.distance(v.p) < EPSILON) { p2 = v.p; break; } }
+            for(Vertex v : vertices) { if (p3.distance(v.p) < EPSILON) { p3 = v.p; break; } }
+            /*
+            p1 = new Point(round(p1.x), round(p1.y), round(p1.z));
+            p2 = new Point(round(p2.x), round(p2.y), round(p2.z));
+            p3 = new Point(round(p3.x), round(p3.y), round(p3.z));
+            */
+        }
         if (norm != null) {
             Vec norm2 = p3.minus(p1).cross(p2.minus(p1));
             float dot = norm.dot(norm2);
         if (norm != null) {
             Vec norm2 = p3.minus(p1).cross(p2.minus(p1));
             float dot = norm.dot(norm2);
@@ -625,11 +661,11 @@ public class Mesh implements Iterable<Mesh.T> {
         public void reinsert() { triangles.remove(this); triangles.add(this); }
 
         public boolean shouldBeDrawn() {
         public void reinsert() { triangles.remove(this); triangles.add(this); }
 
         public boolean shouldBeDrawn() {
-            /*
+
             if (e1().bindingGroupSize() <= 1) return false;
             if (e2().bindingGroupSize() <= 1) return false;
             if (e3().bindingGroupSize() <= 1) return false;
             if (e1().bindingGroupSize() <= 1) return false;
             if (e2().bindingGroupSize() <= 1) return false;
             if (e3().bindingGroupSize() <= 1) return false;
-            */
+
             return true;
         }
 
             return true;
         }
 
index e8f4586..9e98480 100644 (file)
@@ -22,6 +22,7 @@ public class MeshViewer implements GLEventListener, MouseListener, MouseMotionLi
     public boolean tilemeshon = false;
     public boolean goalon = false;
     public boolean anneal = false;
     public boolean tilemeshon = false;
     public boolean goalon = false;
     public boolean anneal = false;
+    public boolean neighbors = false;
 
     public int breaks = 0;
     boolean alt = false;
 
     public int breaks = 0;
     boolean alt = false;
@@ -41,6 +42,7 @@ public class MeshViewer implements GLEventListener, MouseListener, MouseMotionLi
             case KeyEvent.VK_SPACE: breaks++; break;
             case KeyEvent.VK_D: dump(); break;
             case KeyEvent.VK_A: anneal = !anneal; break;
             case KeyEvent.VK_SPACE: breaks++; break;
             case KeyEvent.VK_D: dump(); break;
             case KeyEvent.VK_A: anneal = !anneal; break;
+            case KeyEvent.VK_N: neighbors = !neighbors; break;
             case KeyEvent.VK_T: tileon = !tileon; break;
             case KeyEvent.VK_G: goalon = !goalon; break;
             case KeyEvent.VK_M: tilemeshon = !tilemeshon; break;
             case KeyEvent.VK_T: tileon = !tileon; break;
             case KeyEvent.VK_G: goalon = !goalon; break;
             case KeyEvent.VK_M: tilemeshon = !tilemeshon; break;
@@ -120,29 +122,29 @@ public class MeshViewer implements GLEventListener, MouseListener, MouseMotionLi
         float mat_specular[] = { 0.5f, 0.5f, 0.5f, 0.5f };
         float mat_shininess[] = { 50.0f };
         gl.glShadeModel(GL.GL_SMOOTH);
         float mat_specular[] = { 0.5f, 0.5f, 0.5f, 0.5f };
         float mat_shininess[] = { 50.0f };
         gl.glShadeModel(GL.GL_SMOOTH);
-        gl.glMaterialfv(GL.GL_FRONT, GL.GL_DIFFUSE, mat_specular, 0);  
+        //gl.glMaterialfv(GL.GL_FRONT, GL.GL_DIFFUSE, mat_specular, 0);
         //gl.glMaterialfv(GL.GL_FRONT, GL.GL_SPECULAR, mat_specular, 0);  
         //gl.glMaterialfv(GL.GL_FRONT, GL.GL_SPECULAR, mat_specular, 0);  
-        gl.glMaterialfv(GL.GL_FRONT, GL.GL_AMBIENT, new float[] { 0.3f, 0.3f, 0.3f, 0.3f }, 0);  
+        //gl.glMaterialfv(GL.GL_FRONT, GL.GL_AMBIENT, new float[] { 0.3f, 0.3f, 0.3f, 0.3f }, 0);  
         //gl.glMaterialfv(GL.GL_FRONT, GL.GL_SHININESS, mat_shininess, 0);
         //gl.glMaterialfv(GL.GL_FRONT, GL.GL_SHININESS, mat_shininess, 0);
-        gl.glLightfv(GL.GL_LIGHT0, GL.GL_POSITION, new float[] { 1.0f, 4.0f, -10.0f, 0.0f }, 0);
-        gl.glLightfv(GL.GL_LIGHT1, GL.GL_POSITION, new float[] { -10.0f, 10.0f, 10.0f, 0.0f }, 0);
-        gl.glLightfv(GL.GL_LIGHT2, GL.GL_POSITION, new float[] { 10.0f, -10.0f, 10.0f, 0.0f }, 0);
-        gl.glLightfv(GL.GL_LIGHT3, GL.GL_POSITION, new float[] { 10.0f, 10.0f,  -10.0f, 0.0f }, 0);
-        gl.glLightfv(GL.GL_LIGHT4, GL.GL_POSITION, new float[] { -10.0f, 10.0f, -10.0f, 0.0f }, 0);
-        gl.glLightfv(GL.GL_LIGHT5, GL.GL_POSITION, new float[] { 10.0f, -10.0f, -10.0f, 0.0f }, 0);
+        gl.glLightfv(GL.GL_LIGHT0, GL.GL_POSITION, new float[] { 1.0f,    4.0f,  -10.0f, 0.0f }, 0);
+        gl.glLightfv(GL.GL_LIGHT1, GL.GL_POSITION, new float[] { -10.0f, 10.0f,   10.0f, 0.0f }, 0);
+        gl.glLightfv(GL.GL_LIGHT2, GL.GL_POSITION, new float[] { 10.0f, -10.0f,   10.0f, 0.0f }, 0);
+        gl.glLightfv(GL.GL_LIGHT3, GL.GL_POSITION, new float[] { 10.0f,  10.0f,  -10.0f, 0.0f }, 0);
+        gl.glLightfv(GL.GL_LIGHT4, GL.GL_POSITION, new float[] { -10.0f, 10.0f,  -10.0f, 0.0f }, 0);
+        gl.glLightfv(GL.GL_LIGHT5, GL.GL_POSITION, new float[] { 10.0f, -10.0f,  -10.0f, 0.0f }, 0);
         gl.glEnable(GL.GL_LIGHTING);
         gl.glEnable(GL.GL_LIGHT0);
         gl.glEnable(GL.GL_LIGHTING);
         gl.glEnable(GL.GL_LIGHT0);
+        /*
         gl.glEnable(GL.GL_LIGHT1);
         gl.glEnable(GL.GL_LIGHT2);
         gl.glEnable(GL.GL_LIGHT3);
         gl.glEnable(GL.GL_LIGHT4);
         gl.glEnable(GL.GL_LIGHT5);
         gl.glEnable(GL.GL_LIGHT1);
         gl.glEnable(GL.GL_LIGHT2);
         gl.glEnable(GL.GL_LIGHT3);
         gl.glEnable(GL.GL_LIGHT4);
         gl.glEnable(GL.GL_LIGHT5);
-
+        */
         gl.glColorMaterial(GL.GL_FRONT_AND_BACK, GL.GL_AMBIENT_AND_DIFFUSE);
         gl.glEnable(GL.GL_COLOR_MATERIAL);
 
         display(gld);
         gl.glColorMaterial(GL.GL_FRONT_AND_BACK, GL.GL_AMBIENT_AND_DIFFUSE);
         gl.glEnable(GL.GL_COLOR_MATERIAL);
 
         display(gld);
-
     }
 
     public int temps;
     }
 
     public int temps;
@@ -172,9 +174,8 @@ public class MeshViewer implements GLEventListener, MouseListener, MouseMotionLi
         gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
         gl.glPointSize(5.0f);
         gl.glLoadIdentity();
         gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
         gl.glPointSize(5.0f);
         gl.glLoadIdentity();
-        glu.gluPerspective(50-tz, ((float)drawable.getWidth())/drawable.getHeight(), 0.5, 10);
-        glu.gluLookAt(0, 0, -1, 0, 0, 0, 0, 1, 0);
-        gl.glTranslatef(tx/(float)20, ty/(float)20, 0);
+        glu.gluPerspective(50, ((float)drawable.getWidth())/drawable.getHeight(), 0.5, 10);
+        glu.gluLookAt(0, 0, (tz/10)-1, 0, 0, 0, 0, 1, 0);
         gl.glRotatef(anglex/3, 0, 1, 0);
         gl.glRotatef(angley/3, 1, 0, 0);
 
         gl.glRotatef(anglex/3, 0, 1, 0);
         gl.glRotatef(angley/3, 1, 0, 0);
 
@@ -199,15 +200,15 @@ public class MeshViewer implements GLEventListener, MouseListener, MouseMotionLi
         gl.glColor4f(1,1,1,1);
         for(Matrix m : translations) {
             //if (v1.z==0 && v1.y==0) continue;
         gl.glColor4f(1,1,1,1);
         for(Matrix m : translations) {
             //if (v1.z==0 && v1.y==0) continue;
-            //if (i>0) continue;
             i++;
             i++;
+            //if (i>4) continue;
             /*
             Point p = new Point(0, 0, 0).times(m);
             Vec v = new Vec(p.x, p.y, p.z);
             v = v.times((float)1.04);
             gl.glTranslatef(v.x, v.y, v.z);
             */
             /*
             Point p = new Point(0, 0, 0).times(m);
             Vec v = new Vec(p.x, p.y, p.z);
             v = v.times((float)1.04);
             gl.glTranslatef(v.x, v.y, v.z);
             */
-            draw(gl, false, safeTriangles, m);
+            if (neighbors) draw(gl, false, safeTriangles, m);
             /*
             gl.glTranslatef(-v.x, -v.y, -v.z);
             */
             /*
             gl.glTranslatef(-v.x, -v.y, -v.z);
             */
index fbd1879..8c2d9a7 100644 (file)
@@ -4,6 +4,8 @@ import java.util.*;
 
 public class BindingGroup<T extends HasBindingGroup> implements Iterable<T> {
 
 
 public class BindingGroup<T extends HasBindingGroup> implements Iterable<T> {
 
+    public Matrix krank = Matrix.ONE;
+
     private T                  master   = null;
     private HashMap<T,Matrix>  matrices = new HashMap<T,Matrix>();
 
     private T                  master   = null;
     private HashMap<T,Matrix>  matrices = new HashMap<T,Matrix>();
 
index ad9ee31..d884672 100644 (file)
@@ -4,7 +4,7 @@ import java.util.*;
 
 public abstract class HasBindingGroup {
 
 
 public abstract class HasBindingGroup {
 
-    BindingGroup bindingGroup;
+    public BindingGroup bindingGroup;
 
     // know:      self   = bindingGroup[self] * master
     // know:      other  = other.bindingGroup[other] * other.bindingGroup.master
 
     // know:      self   = bindingGroup[self] * master
     // know:      other  = other.bindingGroup[other] * other.bindingGroup.master
@@ -24,13 +24,22 @@ public abstract class HasBindingGroup {
                             + "; expected "
                             + getBindingMatrix(other));
             */
                             + "; expected "
                             + getBindingMatrix(other));
             */
-            System.err.println("WARNING: discarding rebind attempt: "+this+" and "+other+" with "
-                               + bindingMatrix
-                               + "; expected "
-                               + getBindingMatrix(other));
+            Matrix vom = other.getBindingMatrix(bindingGroup.getMaster());
+            Matrix v2 = bindingMatrix;
+            Matrix v3 = getBindingMatrix(other);
+            Matrix m = vom.inverse().times(v2.inverse()).times(v3).times(vom);
+            bindingGroup.krank = bindingGroup.krank.times(m);
+            /*
+              System.err.println("WARNING: discarding rebind attempt: "+this+" and "+other+m);
+            */
+            //" with "
+            //+ bindingMatrix
+            //+ "; expected "
+            //+ getBindingMatrix(other));
             return;
         }
 
             return;
         }
 
+
         bindingMatrix =
             getBindingMatrix().inverse()
             .times(bindingMatrix)
         bindingMatrix =
             getBindingMatrix().inverse()
             .times(bindingMatrix)
index 1f79b06..419bb93 100644 (file)
@@ -14,7 +14,7 @@ public class Plane {
     public Point intersect(Plane p1, Plane p2) {
         Plane p3 = this;
         float z = p1.norm.dot(p2.norm.cross(p3.norm));
     public Point intersect(Plane p1, Plane p2) {
         Plane p3 = this;
         float z = p1.norm.dot(p2.norm.cross(p3.norm));
-        if (Math.abs(z) == 0) return null;  // planes do not intersect at a point
+        if (Math.abs(z) < 0.0001) return null;  // planes do not intersect at a point
         Vec v1 = p2.norm.cross(p3.norm).times(-1 * p1.dvalue);
         Vec v2 = p3.norm.cross(p1.norm).times(-1 * p2.dvalue);
         Vec v3 = p1.norm.cross(p2.norm).times(-1 * p3.dvalue);
         Vec v1 = p2.norm.cross(p3.norm).times(-1 * p1.dvalue);
         Vec v2 = p3.norm.cross(p1.norm).times(-1 * p2.dvalue);
         Vec v3 = p1.norm.cross(p2.norm).times(-1 * p3.dvalue);
index e2d3bc5..ff75939 100644 (file)
@@ -25,6 +25,10 @@ public final class Polygon {
         return new Polygon(plane, newHalfSpaces);
     }
 
         return new Polygon(plane, newHalfSpaces);
     }
 
+    private static final float EPSILON = 0.00001f;
+    private static float round(float f) {
+        return Math.round(f*1000)/1000f;
+    }
     public Triangle[] tesselate(Mesh mesh) {
         // FIXME: check for closedness
         // find a starting point
     public Triangle[] tesselate(Mesh mesh) {
         // FIXME: check for closedness
         // find a starting point
@@ -36,18 +40,21 @@ public final class Polygon {
                 if (i==j) continue;
                 Point p = plane.intersect(halfSpaces[i], halfSpaces[j]);
                 if (p==null) continue;
                 if (i==j) continue;
                 Point p = plane.intersect(halfSpaces[i], halfSpaces[j]);
                 if (p==null) continue;
+
+                //p = new Point(round(p.x), round(p.y), round(p.z));
+
                 for(int k=0; k<halfSpaces.length; k++) {
                     if (i==k || j==k) continue;
                 for(int k=0; k<halfSpaces.length; k++) {
                     if (i==k || j==k) continue;
-                    //if (!halfSpaces[k].contains(p)) { p = null; break; }
+                    if (!halfSpaces[k].contains(p)) { p = null; break; }
                 }
                 if (p!=null) {
                     if (p1==null) p1 = p;
                 }
                 if (p!=null) {
                     if (p1==null) p1 = p;
-                    else if (p2==null) { if (!p.equals(p1)) p2 = p; }
-                    else throw new Error();
+                    else if (p2==null) { if (p.distance(p1)>EPSILON) p2 = p; }
+                    else if (p.distance(p1)>EPSILON && p.distance(p2)>EPSILON) throw new Error("three points! " + p + " " + p1 + " " + p2);
                 }
             }
             if (p1!=null && p2!=null) {
                 }
             }
             if (p1!=null && p2!=null) {
-                System.out.println("new segment: " + p1 + " " + p2);
+                //System.out.println("new segment: " + p1 + " " + p2);
                 segments.add(new Segment(p1, p2));
             }
         }
                 segments.add(new Segment(p1, p2));
             }
         }
@@ -55,6 +62,8 @@ public final class Polygon {
         for(Segment s : segments)
             cen = cen.plus(s.p1.minus(Point.ORIGIN)).plus(s.p2.minus(Point.ORIGIN));
         Point centroid = Point.ORIGIN.plus(cen.times(1f/(2*segments.size())));
         for(Segment s : segments)
             cen = cen.plus(s.p1.minus(Point.ORIGIN)).plus(s.p2.minus(Point.ORIGIN));
         Point centroid = Point.ORIGIN.plus(cen.times(1f/(2*segments.size())));
+        //centroid = new Point(round(centroid.x), round(centroid.y), round(centroid.z));
+        if (segments.size() >= 3)
         for(Segment s : segments) {
             System.out.println("newt! " + s.p1 + " " + centroid + " " + s.p2 + " " + plane.norm.times(-1));
             mesh.newT(s.p1, centroid, s.p2, plane.norm.times(-1), 0);
         for(Segment s : segments) {
             System.out.println("newt! " + s.p1 + " " + centroid + " " + s.p2 + " " + plane.norm.times(-1));
             mesh.newT(s.p1, centroid, s.p2, plane.norm.times(-1), 0);
index 9d1d30b..c601b15 100644 (file)
@@ -9,6 +9,7 @@ public final class Vec {
     public Vec(Point p1, Point p2) { this(p2.x-p1.x, p2.y-p1.y, p2.z-p1.z); }
     public Vec cross(Vec v) { return new Vec(y*v.z-z*v.y, z*v.x-x*v.z, x*v.y-y*v.x); }
     public Vec plus(Vec v) { return new Vec(x+v.x, y+v.y, z+v.z); }
     public Vec(Point p1, Point p2) { this(p2.x-p1.x, p2.y-p1.y, p2.z-p1.z); }
     public Vec cross(Vec v) { return new Vec(y*v.z-z*v.y, z*v.x-x*v.z, x*v.y-y*v.x); }
     public Vec plus(Vec v) { return new Vec(x+v.x, y+v.y, z+v.z); }
+    public Vec minus(Vec v) { return new Vec(x-v.x, y-v.y, z-v.z); }
     public Vec norm() { return mag()==0 ? this : div(mag()); }
     public float mag() { return (float)Math.sqrt(x*x+y*y+z*z); }
     public float dot(Vec v) { return x*v.x + y*v.y + z*v.z; }
     public Vec norm() { return mag()==0 ? this : div(mag()); }
     public float mag() { return (float)Math.sqrt(x*x+y*y+z*z); }
     public float dot(Vec v) { return x*v.x + y*v.y + z*v.z; }