1 package edu.berkeley.qfat;
5 import java.awt.event.*;
7 import javax.media.opengl.*;
8 import javax.media.opengl.glu.*;
9 import com.sun.opengl.util.*;
11 import edu.berkeley.qfat.geom.*;
12 import edu.berkeley.qfat.geom.Point;
14 public class MeshViewer extends Viewer {
16 public int whichNeighbor = 1;
18 public boolean tileon = true;
19 public boolean tilemeshon = false;
20 public boolean goalon = true;
21 public boolean anneal = false;
22 public boolean hillclimb = false;
23 public boolean neighbors = false;
24 public boolean neighborsWire = false;
25 public boolean neighborsWireOne = false;
26 public boolean errorNormals = false;
28 public boolean force = false;
29 public Matrix[] transforms;
30 public Mesh.Vertex[] points;
31 public int breaks = 0;
37 public MeshViewer(JFrame f) { super(f); }
39 public void _display(GLAutoDrawable drawable, GL gl) {
41 if (transforms==null) return;
42 glcanvas.setSize(f.getWidth(), f.getHeight() - 100);
45 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
48 glu.gluPerspective(50, ((float)drawable.getWidth())/drawable.getHeight(), 0.5, 10);
50 glu.gluLookAt(0, 0, -((tz/10)-1), 0, 0, 0, 0, 1, 0);
51 gl.glRotatef(anglex/3, 0, 1, 0);
52 gl.glRotatef(-(angley/3), 1, 0, 0);
54 tile.render(gl, Matrix.ONE);
55 goal.render(gl, Matrix.ONE);
57 // highlight the point closest to the mouse
58 gl.glDisable(GL.GL_LIGHTING);
59 gl.glShadeModel(GL.GL_FLAT);
60 if (closest != null) {
62 gl.glBegin(gl.GL_POINTS);
63 closest.getPoint().glVertex(gl);
67 // update vertex visibilities
68 // FIXME: only do this when we switch into vertex-finding mode
69 updateVisibility(gl, tile);
71 Matrix projection = Matrix.getProjectionMatrix(gl);
72 double dist = Double.MAX_VALUE;
73 if (getMouseClick() != null) return;
75 for(Mesh.Vertex v : tile.vertices()) {
76 if (!v.visible) continue;
77 Point p = projection.times(v.getPoint());
80 //y = glcanvas.getHeight()-y;
81 int mousex = (int)getMouse().x;
82 int mousey = (int)getMouse().y;
83 if (closest==null || (x-mousex)*(x-mousex)+(y-mousey)*(y-mousey) < dist) {
84 dist = (x-mousex)*(x-mousex)+(y-mousey)*(y-mousey);