public class MeshViewer extends Viewer {
+ public int whichNeighbor = 1;
+ public double temp;
+ public boolean tileon = true;
+ public boolean tilemeshon = false;
+ public boolean goalon = true;
+ public boolean anneal = false;
+ public boolean hillclimb = false;
+ public boolean neighbors = false;
+ public boolean neighborsWire = false;
+ public boolean neighborsWireOne = false;
+ public boolean errorNormals = false;
+
+ public boolean force = false;
+ public Matrix[] transforms;
+ public Mesh.Vertex[] points;
+ public int breaks = 0;
+
+ public int temps;
+ public int accepts;
+ public int vertss;
+
public MeshViewer(JFrame f) { super(f); }
+ public void _display(GLAutoDrawable drawable, GL gl) {
+
+ if (transforms==null) return;
+ glcanvas.setSize(f.getWidth(), f.getHeight() - 100);
+
+ GLU glu = new GLU();
+ gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
+ 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);
+
+ // highlight the point closest to the mouse
+ gl.glDisable(GL.GL_LIGHTING);
+ gl.glShadeModel(GL.GL_FLAT);
+ if (closest != null) {
+ gl.glColor3f(1,1,1);
+ gl.glBegin(gl.GL_POINTS);
+ closest.getPoint().glVertex(gl);
+ 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 (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;
+ 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;
+ }
+ }
+ }
+
}
\ No newline at end of file