[Bprocessor-commit] gl/src/net/sourceforge/bprocessor/gl/tool MoveTool.java,1.21,1.22
Status: Pre-Alpha
Brought to you by:
henryml
From: Nordholt <nor...@us...> - 2006-01-10 14:04:55
|
Update of /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18260 Modified Files: MoveTool.java Log Message: changed the way movetool works to restrict movement to a single constructor. Move can be done by length field now Index: MoveTool.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool/MoveTool.java,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** MoveTool.java 20 Dec 2005 13:55:51 -0000 1.21 --- MoveTool.java 10 Jan 2006 14:04:42 -0000 1.22 *************** *** 9,14 **** import net.sourceforge.bprocessor.gl.GLView; import net.sourceforge.bprocessor.gl.model.ClippingPlane; ! import net.sourceforge.bprocessor.gl.view.View; ! import net.sourceforge.bprocessor.gl.view.Transformation; import net.sourceforge.bprocessor.model.Edge; --- 9,13 ---- import net.sourceforge.bprocessor.gl.GLView; import net.sourceforge.bprocessor.gl.model.ClippingPlane; ! import net.sourceforge.bprocessor.model.Edge; *************** *** 16,19 **** --- 15,19 ---- import net.sourceforge.bprocessor.model.Vertex; import net.sourceforge.bprocessor.model.Surface; + import net.sourceforge.bprocessor.model.Camera; import java.awt.Cursor; *************** *** 25,28 **** --- 25,29 ---- import java.util.Iterator; import java.util.Set; + import java.util.List; import org.apache.log4j.Logger; *************** *** 62,68 **** private Plane dragPlane; ! /** The set of vertices to move **/ private Set vertices; ! /** * The Constructor --- 63,81 ---- private Plane dragPlane; ! /** The set of vertices to move */ private Set vertices; ! ! /** constructors for aligning the movement */ ! private Set moveConstructors; ! ! /** Vector to restrict movement in one direction */ ! private Vertex restrictionVector; ! ! /** The last restriction vector used */ ! private Vertex lastRestriction; ! ! /** Number typed when using the length field */ ! private String number; ! /** * The Constructor *************** *** 72,75 **** --- 85,90 ---- public MoveTool(GLView glv, Cursor cursor) { super(glv, cursor); + moveConstructors = null; + restrictionVector = null; } *************** *** 124,128 **** previousX = e.getX(); previousY = e.getY(); ! if (target != null) { dragPlane = findMovePlane(target); --- 139,144 ---- previousX = e.getX(); previousY = e.getY(); ! ! clearConstructors(moveConstructors); if (target != null) { dragPlane = findMovePlane(target); *************** *** 130,133 **** --- 146,157 ---- parentPos = new Vertex(initial.getX(), initial.getY(), initial.getZ()); from = new Vertex(initial.getX(), initial.getY(), initial.getZ()); + + moveConstructors = new HashSet(); + if (target instanceof Vertex) { + moveConstructors.addAll(makeEdgeConstructors((Vertex)target)); + } else { + moveConstructors.addAll(makeXYZConstructors(initial)); + } + displayConstructors(moveConstructors); vertices = new HashSet(); *************** *** 151,156 **** protected Plane findMovePlane(Object o) { Plane temp = null; - //indicating wherther or not we are moving an inner surface - boolean inner = false; if (o instanceof Vertex) { temp = new Plane(0, 0, 1, -((Vertex)o).getZ()); --- 175,178 ---- *************** *** 159,181 **** } else if (o instanceof Surface) { Surface sel = (Surface)o; - inner = sel.isInner(); temp = sel.plane(); } else if (o instanceof ClippingPlane) { ClippingPlane clippingplane = (ClippingPlane) o; temp = clippingplane.getPlane(); ! } ! // make a orthogonal plane to the current one ! if (moveMode == XZ && !inner) { ! Transformation trans = glv.getView().transformation(); ! double x = previousX; ! double y = View.getHeight() - previousY; ! Vertex near = new Vertex(x, y, 0.0); ! Vertex far = new Vertex(x, y, 1.0); ! Edge ray = new Edge(near, far); ! ray = trans.unProject(ray); ! return temp.orthogonalPlane(ray); ! } return temp; } /** --- 181,207 ---- } else if (o instanceof Surface) { Surface sel = (Surface)o; temp = sel.plane(); } else if (o instanceof ClippingPlane) { ClippingPlane clippingplane = (ClippingPlane) o; temp = clippingplane.getPlane(); ! } return temp; } + + /** + * Finds an appropriate dragPlane that contains the + * restrictionvector. + */ + protected void findRestrictionPlane() { + Camera camera = glv.getView().getCamera(); + double[] centerPoint = camera.getCenter(); + double[] cameraPoint = camera.getCamera(); + Vertex eyeVector = new Vertex(cameraPoint[0] - centerPoint[0], + cameraPoint[1] - centerPoint[1], + cameraPoint[2] - centerPoint[2]); + Vertex planeNormal = (restrictionVector.cross(eyeVector)).cross(restrictionVector); + dragPlane = new Plane(planeNormal.getX(), planeNormal.getY(), planeNormal.getZ(), + -planeNormal.dot(initial)); + } /** *************** *** 185,194 **** protected void released(MouseEvent e) { super.released(e); ! ! from = null; ! initial = null; dragPlane = null; ! parentPos = null; ! vertices = null; } --- 211,219 ---- protected void released(MouseEvent e) { super.released(e); ! clearConstructors(moveConstructors); ! moveConstructors = null; ! restrictionVector = null; dragPlane = null; ! number = ""; } *************** *** 204,208 **** return; } ! if (dragPlane != null) { int x = e.getX(); int y = e.getY(); --- 229,240 ---- return; } ! ! if (restrictionVector == null) { ! boolean found = findRestriction(e); ! if (found) { ! findRestrictionPlane(); ! } ! } ! if (dragPlane != null && restrictionVector != null) { int x = e.getX(); int y = e.getY(); *************** *** 210,213 **** --- 242,253 ---- parentPos = glv.getView().toPlaneCoords(new double[] {x, y}, dragPlane); Vertex delta = parentPos.minus(from); + + //Restricting movement align with restriction vector + Vertex restrictCopy = restrictionVector.copy(); + restrictCopy.scale(1 / restrictCopy.length()); + restrictCopy.scale(delta.dot(restrictCopy)); + delta = restrictCopy; + parentPos = from.add(delta); + if (log.isDebugEnabled()) { log.debug("from " + from.getX() + ", " + from.getY() + ", " + from.getZ()); *************** *** 215,218 **** --- 255,259 ---- } + //snapping to initial position Vertex v = initial.minus(parentPos); Vertex appr = initial.minus(from); *************** *** 225,230 **** if (Math.abs(v.getZ()) < .25) { delta.setZ(appr.getZ()); ! } ! move(vertices, delta); from.move(delta.getX(), delta.getY(), delta.getZ()); --- 266,271 ---- if (Math.abs(v.getZ()) < .25) { delta.setZ(appr.getZ()); ! } ! move(vertices, delta); from.move(delta.getX(), delta.getY(), delta.getZ()); *************** *** 236,240 **** --- 277,320 ---- previousY = e.getY(); } + + + /** + * Finds the current restriction vector. + * There must be some number of moveconstructors find a + * restriction vector. + * @param e the mouse event + * @return wherther or not a vector was found. + */ + private boolean findRestriction(MouseEvent e) { + if (moveConstructors != null) { + List hitEdges = glv.getView().getEdgeAtPoint(e.getX(), e.getY()); + Iterator it = moveConstructors.iterator(); + int numberOfAxis = 0; + Edge axis = null; + while (it.hasNext()) { + Edge tempAxis = (Edge)it.next(); + if (hitEdges.contains(tempAxis)) { + numberOfAxis++; + axis = tempAxis; + } + } + //Only assign a restriction vector when exactly one + //moveconstructor is selected. + if (numberOfAxis == 1) { + restrictionVector = axis.getFrom().minus(axis.getTo()); + lastRestriction = restrictionVector.copy(); + //when a moveconstructor is selected it is the + //only one shown. + clearConstructors(moveConstructors); + moveConstructors = new HashSet(); + moveConstructors.add(axis); + displayConstructors(moveConstructors); + return true; + } + } + return false; + } + /** * Move the entire selection *************** *** 257,279 **** /** ! * Invoked when a key has been pressed. Lets user control the speed ! * and mode of movement. * @param e The KeyEvent */ public void keyPressed(KeyEvent e) { ! if (e.getKeyCode() == KeyEvent.VK_A) { ! moveMode = XY; ! if (target != null) { ! dragPlane = findMovePlane(target); ! } ! } else if (e.getKeyCode() == KeyEvent.VK_S) { ! moveMode = XZ; ! if (target != null) { ! dragPlane = findMovePlane(target); ! } ! } else if (e.getKeyCode() == KeyEvent.VK_ESCAPE) { if (dragPlane != null) { dragPlane = null; ! move(selection, initial.minus(parentPos)); } } else { --- 337,402 ---- /** ! * Invoked when a key has been pressed. Lets user control the mode of movement. ! * ESCAPE - cancel movement * @param e The KeyEvent */ public void keyPressed(KeyEvent e) { ! if (e.getKeyCode() == KeyEvent.VK_ESCAPE) { if (dragPlane != null) { dragPlane = null; ! move(vertices, initial.minus(from)); ! } ! } else if (lastRestriction != null && ! initial != null && ! from != null && ! vertices != null) { ! if (e.getKeyCode() == KeyEvent.VK_1) { ! number += "1"; ! } else if (e.getKeyCode() == KeyEvent.VK_2) { ! number += "2"; ! } else if (e.getKeyCode() == KeyEvent.VK_3) { ! number += "3"; ! } else if (e.getKeyCode() == KeyEvent.VK_4) { ! number += "4"; ! } else if (e.getKeyCode() == KeyEvent.VK_5) { ! number += "5"; ! } else if (e.getKeyCode() == KeyEvent.VK_6) { ! number += "6"; ! } else if (e.getKeyCode() == KeyEvent.VK_7) { ! number += "7"; ! } else if (e.getKeyCode() == KeyEvent.VK_8) { ! number += "8"; ! } else if (e.getKeyCode() == KeyEvent.VK_9) { ! number += "9"; ! } else if (e.getKeyCode() == KeyEvent.VK_0) { ! number += "0"; ! } else if (e.getKeyCode() == KeyEvent.VK_ENTER) { ! if (!number.equals("")) { ! double length = glv.getLength(); ! Vertex delta = initial.minus(from); ! if (delta.length() > 0) { ! delta.scale((delta.length() - length) / delta.length()); ! } else { ! delta = lastRestriction.copy(); ! delta.scale(length / delta.length()); ! } ! move(vertices, delta); ! glv.repaint(); ! } ! } else if (e.getKeyCode() == KeyEvent.VK_BACK_SPACE) { ! int length = number.length(); ! if (length > 0) { ! number = number.substring(0, length - 1); ! } ! } ! if (number.equals("") || number.equals("-")) { ! glv.setLength(0); ! } else { ! try { ! double d = Double.parseDouble(number); ! glv.setLength(d / 1000); ! } catch (NumberFormatException exp) { ! System.out.println(exp); ! } } } else { |