X-Git-Url: http://git.megacz.com/?p=anneal.git;a=blobdiff_plain;f=src%2Fedu%2Fberkeley%2Fqfat%2FViewer.java;h=89ba7b323c76b2b511875c655a216597c53b75e4;hp=b87965055bdca6b6869ae9853f244b2f914e80be;hb=2a2e64829786ee415fd0c0f16957c55e174b793b;hpb=381c4e0df15e58f3c2304d89b58e2df8142121f4 diff --git a/src/edu/berkeley/qfat/Viewer.java b/src/edu/berkeley/qfat/Viewer.java index b879650..89ba7b3 100644 --- a/src/edu/berkeley/qfat/Viewer.java +++ b/src/edu/berkeley/qfat/Viewer.java @@ -14,11 +14,12 @@ import edu.berkeley.qfat.geom.Point; public abstract class Viewer implements GLEventListener, MouseListener, MouseMotionListener, KeyListener, MouseWheelListener { Mesh.Vertex closest = null; - Matrix projection = null; public Mesh tile = new Mesh(false); public Mesh goal = new Mesh(false); + private Matrix projection = null; + JFrame f; GLCanvas glcanvas; Point clickPoint = null; @@ -76,48 +77,41 @@ public abstract class Viewer implements GLEventListener, MouseListener, MouseMot public final void display(GLAutoDrawable drawable) { GL gl = drawable.getGL(); _display(drawable, gl); - this.projection = Matrix.getProjectionMatrix(gl); - updateVisibility(gl, tile); + projection = Matrix.getProjectionMatrix(gl); } - private void updateVisibility(GL gl, Mesh mesh) { + protected synchronized void updateVisibility(GL gl, Mesh mesh) { + Matrix projection = Matrix.getProjectionMatrix(gl); IntBuffer buf = ByteBuffer.allocateDirect(9*4*4).order(ByteOrder.nativeOrder()).asIntBuffer(); + gl.glFlush(); + gl.glDrawBuffer(GL.GL_BACK); + gl.glReadBuffer( GL.GL_BACK ); + gl.glPixelStorei( GL.GL_PACK_ALIGNMENT, 1); + gl.glFlush(); + gl.glDisable(GL.GL_LIGHTING); + gl.glShadeModel(GL.GL_FLAT); 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); + 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); + gl.glReadPixels((int)projected.x-1, (int)projected.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(); - 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); @@ -182,7 +176,7 @@ public abstract class Viewer implements GLEventListener, MouseListener, MouseMot 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), true); + closest.move(Matrix.translate(delta), false); } } } else {