import edu.berkeley.qfat.geom.*;
import edu.berkeley.qfat.geom.Point;
-public class MeshViewer implements GLEventListener, MouseListener, MouseMotionListener, KeyListener, MouseWheelListener {
+public class MeshViewer extends JPanel implements GLEventListener, MouseListener, MouseMotionListener, KeyListener, MouseWheelListener {
- Mesh.Vertex closest = null;
+ Main main;
- private int mousex;
- private int mousey;
- private Matrix projection = null;
- private Point clickPoint = null;
- private GLCanvas glcanvas;
- private boolean updateVisibilities = false;
+
+ private float tz = 0;
+ private float anglex = 0;
+ private float angley = 0;
+
+ private Mesh.Vertex closest = null;
+ private Point closestOriginallyAt = null;
+ private int mousex;
+ private int mousey;
+ private Matrix projection = null;
+ private Point clickPoint = null;
+ private GLCanvas glcanvas;
+ private boolean updateVisibilities = false;
+ private boolean mouseInside = false;
private HashSet<Mesh> meshes = new HashSet<Mesh>();
public synchronized void addMesh(Mesh m) { meshes.add(m); }
public synchronized void removeMesh(Mesh m) { meshes.remove(m); }
- float tz = 0;
- float anglex = 0;
- float angley = 0;
-
public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { }
public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) { }
+ public void addKeyListener(KeyListener kl) { glcanvas.addKeyListener(kl); }
+
public synchronized void init(GLAutoDrawable gld) {
GL gl = glcanvas.getGL();//gld.getGL();
gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
}
public synchronized final void display(GLAutoDrawable drawable) {
- glcanvas.setSize(glcanvas.getParent().getWidth(), glcanvas.getParent().getHeight() - 100);
+ glcanvas.setSize(glcanvas.getParent().getWidth(), glcanvas.getParent().getHeight());
GL gl = glcanvas.getGL();//drawable.getGL();
GLU glu = new GLU();
+
+ if (!mouseInside) gl.glClearColor(0.1f, 0.1f, 0.1f, 1.0f);
+ else gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
+
gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
gl.glPointSize(5.0f);
gl.glLoadIdentity();
gl.glEnable(GL.GL_LIGHTING);
gl.glShadeModel(GL.GL_SMOOTH);
- for(Mesh mesh : meshes)
+ for(Mesh mesh : meshes) {
mesh.render(gl, Matrix.ONE);
+ if (main != null && main.whichNeighbor>0 && main.transforms!=null && !mesh.option_wireframe) {
+ mesh.option_wireframe = true;
+ mesh.render(gl, main.transforms[main.whichNeighbor-1]);
+ mesh.option_wireframe = false;
+ }
+ }
// highlight the point closest to the mouse; we do this here to avoid flicker
if (closest != null) {
//Matrix projection = Matrix.getProjectionMatrix(gl);
double dist = Double.MAX_VALUE;
closest = null;
+ closestOriginallyAt = null;
for(Mesh mesh : meshes)
if (mesh.option_selectable)
for(Mesh.Vertex v : mesh.vertices()) {
public void keyReleased(KeyEvent e) { }
public void mouseClicked(MouseEvent e) { }
- public void mouseEntered(MouseEvent e) { }
- public void mouseExited(MouseEvent e) { }
+ public void mouseEntered(MouseEvent e) { mouseInside = true; }
+ public void mouseExited(MouseEvent e) { mouseInside = false; }
public void mousePressed(MouseEvent e) {
clickPoint = getMouse();
}
if ((e.getModifiersEx() & MouseEvent.SHIFT_DOWN_MASK) != 0) {
if (closest != null && projection != null) {
synchronized(this) {
- Point clickClosest = closest == null ? null : closest.getPoint();
+ if (closestOriginallyAt==null) closestOriginallyAt = closest.getPoint();
Vec d1 = projection.inverse().times(getMouse()).minus(projection.inverse().times(clickPoint));
- Vec delta = d1.plus(clickClosest).minus(closest.getPoint());
+ Vec delta = d1.plus(closestOriginallyAt).minus(closest.getPoint());
closest.move(delta, false);
}
}
mousey = e.getY();
}
- public MeshViewer(JFrame f) {
+ public MeshViewer() {
glcanvas = new GLCanvas();
glcanvas.addGLEventListener(this);
- f.add(glcanvas, BorderLayout.CENTER);
+ setLayout(new BorderLayout());
+ this.add(glcanvas, BorderLayout.CENTER);
glcanvas.addMouseListener(this);
glcanvas.addMouseMotionListener(this);
glcanvas.addMouseWheelListener(this);
}
public void repaint() {
- glcanvas.repaint();
+ if (glcanvas != null) glcanvas.repaint();
}
}
\ No newline at end of file