public class MeshViewer extends JPanel implements GLEventListener, MouseListener, MouseMotionListener, KeyListener, MouseWheelListener {
+ Main main;
+
+
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;
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);
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()) {
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);
}
}