checkpoint
[anneal.git] / src / edu / berkeley / qfat / MeshViewer.java
index aea2799..356fbad 100644 (file)
@@ -38,7 +38,6 @@ public class MeshViewer extends Viewer {
 
     public MeshViewer(JFrame f) { super(f); }
 
-
     public void _display(GLAutoDrawable drawable, GL gl) {
 
         if (transforms==null) return;
@@ -126,8 +125,24 @@ public class MeshViewer extends Viewer {
         gl.glDisable(GL.GL_LIGHTING);
         gl.glShadeModel(GL.GL_FLAT);
 
-    }
+        updateVisibility(gl, tile);
 
+        Matrix projection = Matrix.getProjectionMatrix(gl);
+        double dist = Double.MAX_VALUE;
+        if (clickPoint != 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;
+            if (closest==null || (x-mousex)*(x-mousex)+(y-mousey)*(y-mousey) < dist) {
+                dist = (x-mousex)*(x-mousex)+(y-mousey)*(y-mousey);
+                closest = v;
+            }
+        }
+    }
 
     private void draw(GL gl, boolean triangles, Iterable<Mesh.T> tris) { draw(gl, triangles, tris, Matrix.ONE); }
     private void draw(GL gl, boolean triangles, Iterable<Mesh.T> tris, Matrix m) {