public class Main extends InteractiveMeshViewer {
+
public static int verts = 1;
public static final Random random = new Random();
public Main(JFrame f) { super(f); }
- public void fixupTile() {
- synchronized(safeTriangles) {
+ public synchronized void fixupTile() {
for(Matrix m1 : transforms) {
for(Matrix m2 : transforms) {
if (m1==m2) continue;
tile.error_against = goal;
goal.error_against = tile;
fixupGoal();
- }
}
public void breakit() {
Vec v = new Vec(random.nextFloat(), random.nextFloat(), random.nextFloat());
v = v.norm().times((random.nextFloat() - 0.5f) * max);
Matrix m = Matrix.translate(v);
-
- boolean good = p.move(m, false);
+ boolean good = p.move(v, false);
if (!good) { return false; }
double new_tile_error = tile.error();
hits++;
p.goodp = p.p;
} else {
- p.move(Matrix.translate(v.times(-1)), true);
+ p.move(v.times(-1), true);
misses++;
}
p.reComputeErrorAround();
double acceptance = 1;
while(true) {
synchronized(this) {
- synchronized(safeTriangles) {
- safeTriangles.clear();
- for(Mesh.T t : tile)
- if (t.shouldBeDrawn())
- safeTriangles.add(t);
- }
- if (!anneal) { repaint(); Thread.sleep(10); continue; }
+ if (!anneal) { repaint(); Thread.sleep(10); continue; }
double ratio = (hits+misses==0) ? 1 : (hits / (hits+misses));
hits = 0;
}
public void actionPerformed(ActionEvent event) {
synchronized(Main.this) {
- synchronized(safeTriangles) {
hit();
- }
}
}
public void hit() {}
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)),
/*
setError(nerror);
}
- public boolean move(Matrix m, boolean ignoreProblems) {
+ public boolean move(Vec vv, boolean ignoreProblems) {
boolean good = true;
// 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);
+ Matrix m2 = getBindingMatrix(bindingGroup.getMaster());
+ Vec v2 = m2.times(vv.plus(getPoint())).minus(m2.times(getPoint()));
+ return ((Vertex)bindingGroup.getMaster()).move(v2, ignoreProblems);
}
+ Point op = this.p;
+ Point pp = vv.plus(getPoint());
if (bindingGroup != null) {
- Matrix m2 = null;
- for(int i=0; i<20 && !m.equals(m2); i++) {
- m2 = m.times(getConstraint());
+ /*
+ for(int i=0; i<20 ; i++) {
+ Point p2 = getConstraint().times(pp);
+ pp = pp.midpoint(p2);
//System.out.println(m.minus(m2));
}
- if (!m.equals(m2)) return true;
+ */
+ pp = getConstraint().times(pp);
}
+ pp = pp.minus(op).norm().times(vv.mag()).plus(op);
ok = false;
- Point op = this.p;
- Point pt = m.times(this.p);
+ Point pt = pp;
for(Vertex v : (Iterable<Vertex>)getBoundPeers()) {
Point pt2 = v.getBindingMatrix(this).times(pt);
/*
unApplyQuadricToNeighbor();
-
boolean illegalbefore = illegal;
illegal = false;
/*
public int temps;
public int accepts;
public int vertss;
- protected HashSet<Mesh.T> safeTriangles = new HashSet<Mesh.T>();
public MeshViewer(JFrame f) { super(f); }
gl.glPointSize(5.0f);
gl.glLoadIdentity();
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);
tile.render(gl, Matrix.ONE);
goal.render(gl, Matrix.ONE);
- int i = 0;
- gl.glColor4f(1,1,1,1);
- for(Matrix m : transforms) {
- i++;
- if (neighborsWireOne && i!=whichNeighbor) continue;
- if (neighbors) tile.render(gl, m);
- else if (neighborsWire || neighborsWireOne) tile.render(gl, m);
- }
-
+ // highlight the point closest to the mouse
gl.glDisable(GL.GL_LIGHTING);
gl.glShadeModel(GL.GL_FLAT);
if (closest != null) {
gl.glEnd();
}
+ // update vertex visibilities
+ // FIXME: only do this when we switch into vertex-finding mode
updateVisibility(gl, tile);
Matrix projection = Matrix.getProjectionMatrix(gl);
double dist = Double.MAX_VALUE;
- if (clickPoint != null) return;
+ if (getMouseClick() != null) return;
closest = null;
for(Mesh.Vertex v : tile.vertices()) {
if (!v.visible) continue;
Point p = projection.times(v.getPoint());
int x = (int)p.x;
int y = (int)p.y;
- y = glcanvas.getHeight()-y;
+ //y = glcanvas.getHeight()-y;
+ int mousex = (int)getMouse().x;
+ int mousey = (int)getMouse().y;
if (closest==null || (x-mousex)*(x-mousex)+(y-mousey)*(y-mousey) < dist) {
dist = (x-mousex)*(x-mousex)+(y-mousey)*(y-mousey);
closest = v;
public Mesh tile = new Mesh(false);
public Mesh goal = new Mesh(false);
+ private int mousex;
+ private int mousey;
private Matrix projection = null;
JFrame f;
GLCanvas glcanvas;
- Point clickPoint = null;
+
+ private Point clickPoint = null;
Point clickClosest = null;
- int mousex;
- int mousey;
- float tx = 0;
- float ty = 0;
float tz = 0;
float anglex = 0;
float angley = 0;
gl.glDrawBuffer(GL.GL_FRONT);
}
-
/** return the position of the mouse as a point in window-space */
public Point getMouse() {
return new Point(mousex, glcanvas.getHeight()-mousey, 0);
}
+ /** return the position where the mouse button was pressed, or null if it is not currently pressed */
+ public Point getMouseClick() {
+ return clickPoint;
+ }
+
public void mouseWheelMoved(MouseWheelEvent e) {
tz -= e.getWheelRotation();
}
public void mouseDragged(MouseEvent e) {
if (shift) {
- /*
- tx += (mousex - e.getX())/(float)20;
- ty += (mousey - e.getY())/(float)20;
- */
if (closest != null && projection != null && clickClosest != null) {
synchronized(this) {
Vec d1 = projection.inverse().times(getMouse()).minus(projection.inverse().times(clickPoint));
Vec delta = d1.plus(clickClosest).minus(closest.getPoint());
- //System.out.println(delta + " " + closest.getPoint());
- System.out.println(getMouse().minus(clickPoint));
- closest.move(Matrix.translate(delta), false);
+ closest.move(delta, false);
}
}
} else {
public Vec minus(Point p) { return new Vec(x-p.x, y-p.y, z-p.z); }
public Point plus(Vec v) { return new Point(x+v.x, y+v.y, z+v.z); }
+ public Point midpoint(Point p) { return new Point((x+p.x)/2, (y+p.y)/2, (z+p.z)/2); }
public void glVertex(GL gl) { gl.glVertex3f(x, y, z); }