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;
36 protected HashSet<Mesh.T> safeTriangles = new HashSet<Mesh.T>();
38 public MeshViewer(JFrame f) { super(f); }
40 public void _display(GLAutoDrawable drawable, GL gl) {
42 if (transforms==null) return;
43 glcanvas.setSize(f.getWidth(), f.getHeight() - 100);
46 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
49 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);
58 gl.glColor4f(1,1,1,1);
59 for(Matrix m : transforms) {
61 if (neighborsWireOne && i!=whichNeighbor) continue;
62 if (neighbors) tile.render(gl, m);
63 else if (neighborsWire || neighborsWireOne) tile.render(gl, m);
66 gl.glDisable(GL.GL_LIGHTING);
67 gl.glShadeModel(GL.GL_FLAT);
68 if (closest != null) {
70 gl.glBegin(gl.GL_POINTS);
71 closest.getPoint().glVertex(gl);
75 updateVisibility(gl, tile);
77 Matrix projection = Matrix.getProjectionMatrix(gl);
78 double dist = Double.MAX_VALUE;
79 if (clickPoint != null) return;
81 for(Mesh.Vertex v : tile.vertices()) {
82 if (!v.visible) continue;
83 Point p = projection.times(v.getPoint());
86 y = glcanvas.getHeight()-y;
87 if (closest==null || (x-mousex)*(x-mousex)+(y-mousey)*(y-mousey) < dist) {
88 dist = (x-mousex)*(x-mousex)+(y-mousey)*(y-mousey);