checkpoint
authoradam <adam@megacz.com>
Mon, 30 Jun 2008 00:15:30 +0000 (17:15 -0700)
committeradam <adam@megacz.com>
Mon, 30 Jun 2008 00:15:30 +0000 (17:15 -0700)
darcs-hash:20080630001530-5007d-a41b7fcfd6cde90280122f130ec8c3025c33222b.gz

src/edu/berkeley/qfat/MeshViewer.java
src/edu/berkeley/qfat/Viewer.java

index eaafed6..aea2799 100644 (file)
@@ -101,34 +101,13 @@ public class MeshViewer extends Viewer {
 
 
         int i = 0;
-        //gl.glDisable(GL.GL_DEPTH_TEST);
         gl.glColor4f(1,1,1,1);
         for(Matrix m : transforms) {
-            /*
-              gl.glColor4f(0, 1, 1, 1);
-              gl.glBegin(GL.GL_LINES);
-              new Point(0,0,0).glVertex(gl);
-              new Point(0,0,0).plus(m.getTranslationalComponent()).glVertex(gl);
-              gl.glEnd();
-              gl.glEnable(GL.GL_LIGHTING);
-            */
-            //if (v1.z==0 && v1.y==0) continue;
             i++;
             if (neighborsWireOne && i!=whichNeighbor) continue;
-            //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);
-            */
             if (neighbors) draw(gl, true, safeTriangles, m);
             else if (neighborsWire || neighborsWireOne) draw(gl, false, safeTriangles, m);
-            /*
-            gl.glTranslatef(-v.x, -v.y, -v.z);
-            */
         }
-        //gl.glEnable(GL.GL_DEPTH_TEST);
 
         gl.glDisable(GL.GL_LIGHTING);
         gl.glShadeModel(GL.GL_FLAT);
@@ -137,13 +116,6 @@ public class MeshViewer extends Viewer {
             gl.glBegin(gl.GL_POINTS);
             closest.getPoint().glVertex(gl);
             gl.glEnd();
-            /*
-            Mesh.Vertex v2 = closest.hack(gl, getMouse());
-            gl.glBegin(GL.GL_LINES);        
-            closest.getPoint().glVertex(gl);                                                                                                  
-            if (v2 != null) v2.getPoint().glVertex(gl);
-            gl.glEnd();
-            */
         }
 
         gl.glFlush();
@@ -154,48 +126,6 @@ public class MeshViewer extends Viewer {
         gl.glDisable(GL.GL_LIGHTING);
         gl.glShadeModel(GL.GL_FLAT);
 
-        IntBuffer buf = ByteBuffer.allocateDirect(9*4*4).order(ByteOrder.nativeOrder()).asIntBuffer();
-        gl.glColor3f(0,0,0);
-        gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
-        double dist = Double.MAX_VALUE;
-        if (clickPoint==null) closest = null;
-        synchronized(this) {
-            for(Mesh.T t : safeTriangles)
-                t.glTriangle(gl, null);
-            for(Mesh.Vertex v : tile.vertices()) {
-                Point p = v.getPoint();
-                gl.glColor3f(1,1,1);
-                gl.glBegin(gl.GL_POINTS);
-                p.glVertex(gl);
-                gl.glEnd();
-                gl.glFlush();
-
-                Point projected = projection.times(p);
-                int x = (int)projected.x;
-                int y = (int)projected.y;
-                gl.glReadPixels(x-1, y-1, 3, 3, gl.GL_RGB, gl.GL_UNSIGNED_BYTE, buf);
-
-                boolean vis = false;
-                for(int j=0; j<9*4; j++) vis |= buf.get(j)!=0;
-                v.visible = vis;
-                if (vis) {
-                    gl.glColor3f(0,0,0);
-                    gl.glBegin(gl.GL_POINTS);
-                    p.glVertex(gl);
-                    gl.glEnd();
-                    y = glcanvas.getHeight()-y;
-                    if (clickPoint==null) {
-                        if (closest==null || (x-mousex)*(x-mousex)+(y-mousey)*(y-mousey) < dist) {
-                            dist = (x-mousex)*(x-mousex)+(y-mousey)*(y-mousey);
-                            closest = v;
-                        }
-                    }
-                }
-            }
-        }
-        gl.glShadeModel(GL.GL_SMOOTH);
-        gl.glEnable(GL.GL_LIGHTING);
-        gl.glDrawBuffer(GL.GL_FRONT);
     }
 
 
index b39f2a6..b879650 100644 (file)
@@ -73,12 +73,59 @@ public abstract class Viewer implements GLEventListener, MouseListener, MouseMot
     }
 
     public abstract void _display(GLAutoDrawable drawable, GL gl);
-    public void display(GLAutoDrawable drawable) {
+    public final void display(GLAutoDrawable drawable) {
         GL gl = drawable.getGL();
         _display(drawable, gl);
         this.projection = Matrix.getProjectionMatrix(gl);
+        updateVisibility(gl, tile);
     }
 
+    private void updateVisibility(GL gl, Mesh mesh) {
+        IntBuffer buf = ByteBuffer.allocateDirect(9*4*4).order(ByteOrder.nativeOrder()).asIntBuffer();
+        gl.glColor3f(0,0,0);
+        gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
+        double dist = Double.MAX_VALUE;
+        if (clickPoint==null) closest = null;
+        synchronized(this) {
+            for(Mesh.T t : mesh)
+                t.glTriangle(gl, null);
+            for(Mesh.Vertex v : mesh.vertices()) {
+                Point p = v.getPoint();
+                gl.glColor3f(1,1,1);
+                gl.glBegin(gl.GL_POINTS);
+                p.glVertex(gl);
+                gl.glEnd();
+                gl.glFlush();
+
+                Point projected = projection.times(p);
+                int x = (int)projected.x;
+                int y = (int)projected.y;
+                gl.glReadPixels(x-1, y-1, 3, 3, gl.GL_RGB, gl.GL_UNSIGNED_BYTE, buf);
+
+                boolean vis = false;
+                for(int j=0; j<9*4; j++) vis |= buf.get(j)!=0;
+                v.visible = vis;
+                if (vis) {
+                    gl.glColor3f(0,0,0);
+                    gl.glBegin(gl.GL_POINTS);
+                    p.glVertex(gl);
+                    gl.glEnd();
+                    y = glcanvas.getHeight()-y;
+                    if (clickPoint==null) {
+                        if (closest==null || (x-mousex)*(x-mousex)+(y-mousey)*(y-mousey) < dist) {
+                            dist = (x-mousex)*(x-mousex)+(y-mousey)*(y-mousey);
+                            closest = v;
+                        }
+                    }
+                }
+            }
+        }
+        gl.glShadeModel(GL.GL_SMOOTH);
+        gl.glEnable(GL.GL_LIGHTING);
+        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);