checkpoint
[anneal.git] / src / edu / berkeley / qfat / MeshViewer.java
index 97a31f8..57d1543 100644 (file)
@@ -13,11 +13,15 @@ import edu.berkeley.qfat.geom.Point;
 
 public class MeshViewer extends JPanel implements GLEventListener, MouseListener, MouseMotionListener, KeyListener, MouseWheelListener {
 
+    Main main;
+
+
     private float tz = 0;
     private float anglex = 0;
     private float angley = 0;
 
     private Mesh.Vertex closest = null;
+    private Point       closestOriginallyAt = null;
     private int         mousex;
     private int         mousey;
     private Matrix      projection = null;
@@ -93,8 +97,14 @@ public class MeshViewer extends JPanel implements GLEventListener, MouseListener
 
         gl.glEnable(GL.GL_LIGHTING);
         gl.glShadeModel(GL.GL_SMOOTH);
-        for(Mesh mesh : meshes)
+        for(Mesh mesh : meshes) {
             mesh.render(gl, Matrix.ONE);
+            if (main != null && main.whichNeighbor>0 && main.transforms!=null && !mesh.option_wireframe) {
+                mesh.option_wireframe = true;
+                mesh.render(gl, main.transforms[main.whichNeighbor-1]);
+                mesh.option_wireframe = false;
+            }
+        }
 
         // highlight the point closest to the mouse; we do this here to avoid flicker
         if (closest != null) {
@@ -116,6 +126,7 @@ public class MeshViewer extends JPanel implements GLEventListener, MouseListener
             //Matrix projection = Matrix.getProjectionMatrix(gl);
             double dist = Double.MAX_VALUE;
             closest = null;
+            closestOriginallyAt = null;
             for(Mesh mesh : meshes)
                 if (mesh.option_selectable)
                     for(Mesh.Vertex v : mesh.vertices()) {
@@ -213,9 +224,9 @@ public class MeshViewer extends JPanel implements GLEventListener, MouseListener
         if ((e.getModifiersEx() & MouseEvent.SHIFT_DOWN_MASK) != 0) {
             if (closest != null && projection != null) {
                 synchronized(this) {
-                    Point clickClosest = closest == null ? null : closest.getPoint();
+                    if (closestOriginallyAt==null) closestOriginallyAt = closest.getPoint();
                     Vec d1 = projection.inverse().times(getMouse()).minus(projection.inverse().times(clickPoint));
-                    Vec delta = d1.plus(clickClosest).minus(closest.getPoint());
+                    Vec delta = d1.plus(closestOriginallyAt).minus(closest.getPoint());
                     closest.move(delta, false);
                 }
             }