From b6875b8bd79c804e15eb75bc64044ca2c770b07d Mon Sep 17 00:00:00 2001 From: adam Date: Tue, 4 Dec 2007 22:33:35 -0800 Subject: [PATCH] checkpoint darcs-hash:20071205063335-5007d-b5fee023de2b08d2dd98ba4483d870cecea0e5fb.gz --- src/edu/berkeley/qfat/Main.java | 8 ++--- src/edu/berkeley/qfat/Mesh.java | 60 ++++++++++++++++---------------- src/edu/berkeley/qfat/geom/Matrix.java | 3 ++ 3 files changed, 35 insertions(+), 36 deletions(-) diff --git a/src/edu/berkeley/qfat/Main.java b/src/edu/berkeley/qfat/Main.java index 6c663d0..b774066 100644 --- a/src/edu/berkeley/qfat/Main.java +++ b/src/edu/berkeley/qfat/Main.java @@ -209,11 +209,6 @@ public class Main implements GLEventListener, MouseListener, MouseMotionListener } } - for(Mesh.Vert vert : goal.vertices()) { - System.out.println("error: " + vert.quadric().preAndPostMultiply(vert.p)); - } - - //xMesh.Vert mid = lbf.getE(mbn).shatter(); // rescale to match volume @@ -269,7 +264,8 @@ public class Main implements GLEventListener, MouseListener, MouseMotionListener r1 = r1 - (float)Math.floor(r1); r1 = r1 * (float)0.01; r1 = r1 - (float)0.005; - Vec v = p.watchback().minus(p.p).norm().times(r1); + + Vec v = p.nearest_vert_in_other_mesh().minus(p.p).norm().times(r1); //v = p.norm().times(v.dot(p.norm())); diff --git a/src/edu/berkeley/qfat/Mesh.java b/src/edu/berkeley/qfat/Mesh.java index 08d89e7..f635754 100644 --- a/src/edu/berkeley/qfat/Mesh.java +++ b/src/edu/berkeley/qfat/Mesh.java @@ -126,11 +126,11 @@ public class Mesh implements Iterable { E e; // some edge *leaving* this point Vert bound_to = this; - int watch_count; - float watch_x; - float watch_y; - float watch_z; - Vert watch; + int nearest_vert_in_other_mesh_count; + float nearest_vert_in_other_mesh_x; + float nearest_vert_in_other_mesh_y; + float nearest_vert_in_other_mesh_z; + Vert nearest_vert_in_other_mesh; Matrix binding = new Matrix(); float oldscore = 0; boolean inserted = false; @@ -154,47 +154,47 @@ public class Mesh implements Iterable { } public float score() { return oldscore; } public void unscore() { - if (watch == null) return; - watch.watch_x -= p.x; - watch.watch_y -= p.y; - watch.watch_z -= p.z; - watch.watch_count--; - if (watch.watch_count==0) { - watch.watch_x = 0; - watch.watch_y = 0; - watch.watch_z = 0; + if (nearest_vert_in_other_mesh == null) return; + nearest_vert_in_other_mesh.nearest_vert_in_other_mesh_x -= p.x; + nearest_vert_in_other_mesh.nearest_vert_in_other_mesh_y -= p.y; + nearest_vert_in_other_mesh.nearest_vert_in_other_mesh_z -= p.z; + nearest_vert_in_other_mesh.nearest_vert_in_other_mesh_count--; + if (nearest_vert_in_other_mesh.nearest_vert_in_other_mesh_count==0) { + nearest_vert_in_other_mesh.nearest_vert_in_other_mesh_x = 0; + nearest_vert_in_other_mesh.nearest_vert_in_other_mesh_y = 0; + nearest_vert_in_other_mesh.nearest_vert_in_other_mesh_z = 0; } - watch = null; + nearest_vert_in_other_mesh = null; } - public Vert partner() { return watch==null ? this : watch; } - public Point watchback() { return watch_count==0 ? partner().p : - new Point(watch_x/watch_count, watch_y/watch_count, watch_z/watch_count); } + public Vert partner() { return nearest_vert_in_other_mesh==null ? this : nearest_vert_in_other_mesh; } + public Point nearest_vert_in_other_mesh() { return nearest_vert_in_other_mesh_count==0 ? partner().p : + new Point(nearest_vert_in_other_mesh_x/nearest_vert_in_other_mesh_count, nearest_vert_in_other_mesh_y/nearest_vert_in_other_mesh_count, nearest_vert_in_other_mesh_z/nearest_vert_in_other_mesh_count); } public void rescore() { if (score_against == null) return; score -= oldscore; oldscore = 0; - if (watch != null) unscore(); + if (nearest_vert_in_other_mesh != null) unscore(); Vert po = this; - if (watch == null) { - watch = score_against.nearest(po.p); + if (nearest_vert_in_other_mesh == null) { + nearest_vert_in_other_mesh = score_against.nearest(po.p); // don't attract to vertices that face the other way - if (watch.e == null || watch.norm().dot(norm()) < 0) { - watch = null; + if (nearest_vert_in_other_mesh.e == null || nearest_vert_in_other_mesh.norm().dot(norm()) < 0) { + nearest_vert_in_other_mesh = null; } else { - watch.watch_x += po.p.x; - watch.watch_y += po.p.y; - watch.watch_z += po.p.z; - watch.watch_count++; + nearest_vert_in_other_mesh.nearest_vert_in_other_mesh_x += po.p.x; + nearest_vert_in_other_mesh.nearest_vert_in_other_mesh_y += po.p.y; + nearest_vert_in_other_mesh.nearest_vert_in_other_mesh_z += po.p.z; + nearest_vert_in_other_mesh.nearest_vert_in_other_mesh_count++; } } double s1, s2; - if (watch_count==0) s1 = 0; - else s1 = p.distance(watch_x/watch_count, watch_y/watch_count, watch_z/watch_count); - s2 = watch==null ? 0 : po.p.distance(watch.p); + if (nearest_vert_in_other_mesh_count==0) s1 = 0; + else s1 = p.distance(nearest_vert_in_other_mesh_x/nearest_vert_in_other_mesh_count, nearest_vert_in_other_mesh_y/nearest_vert_in_other_mesh_count, nearest_vert_in_other_mesh_z/nearest_vert_in_other_mesh_count); + s2 = nearest_vert_in_other_mesh==null ? 0 : po.p.distance(nearest_vert_in_other_mesh.p); oldscore = (float)(s1 + s2); score += oldscore; } diff --git a/src/edu/berkeley/qfat/geom/Matrix.java b/src/edu/berkeley/qfat/geom/Matrix.java index 1f25ddc..7d14a71 100644 --- a/src/edu/berkeley/qfat/geom/Matrix.java +++ b/src/edu/berkeley/qfat/geom/Matrix.java @@ -39,6 +39,9 @@ public class Matrix { public Matrix plus(Matrix x) { return new Matrix(a+x.a, b+x.b, c+x.c, d+x.d, e+x.e, f+x.f, g+x.g, h+x.h, i+x.i, j+x.j, k+x.k, l+x.l, m+x.m, n+x.n, o+x.o, p+x.p); } + public Matrix minus(Matrix x) { + return new Matrix(a-x.a, b-x.b, c-x.c, d-x.d, e-x.e, f-x.f, g-x.g, h-x.h, i-x.i, j-x.j, k-x.k, l-x.l, m-x.m, n-x.n, o-x.o, p-x.p); + } public Matrix times(float x) { return new Matrix(a*x, b*x, c*x, d*x, e*x, f*x, g*x, h*x, i*x, j*x, k*x, l*x, m*x, n*x, o*x, p*x); } -- 1.7.10.4