[Bprocessor-commit] gl/src/net/sourceforge/bprocessor/gl/tool VectorMoveStrategy.java,1.2,1.3 Contro
Status: Pre-Alpha
Brought to you by:
henryml
From: Nordholt <nor...@us...> - 2006-04-05 10:25:13
|
Update of /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13148 Modified Files: VectorMoveStrategy.java ControlledMoveStrategy.java MoveTool.java Log Message: large changes due to cvs outage Index: MoveTool.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool/MoveTool.java,v retrieving revision 1.51 retrieving revision 1.52 diff -C2 -d -r1.51 -r1.52 *** MoveTool.java 30 Mar 2006 08:03:40 -0000 1.51 --- MoveTool.java 5 Apr 2006 10:24:56 -0000 1.52 *************** *** 13,24 **** import net.sourceforge.bprocessor.model.Edge; import net.sourceforge.bprocessor.model.Entity; - import net.sourceforge.bprocessor.model.Plane; import net.sourceforge.bprocessor.model.Project; import net.sourceforge.bprocessor.model.Vertex; import net.sourceforge.bprocessor.model.Surface; - import net.sourceforge.bprocessor.gl.view.Transformation; - import net.sourceforge.bprocessor.gl.view.View; - import java.awt.Cursor; import java.awt.event.MouseEvent; --- 13,20 ---- *************** *** 30,37 **** import java.util.HashSet; import java.util.LinkedList; - //import java.util.Timer; - import java.util.TimerTask; - - import org.apache.log4j.Logger; --- 26,29 ---- *************** *** 44,50 **** private static Logger log = Logger.getLogger(MoveTool.class); - /** The initial movepoint */ - protected Vertex initial; - /** The location to move from */ protected Vertex from; --- 36,39 ---- *************** *** 56,62 **** protected Vertex lastMoveDirection; - /** Number typed when using the length field */ - protected String number; - /** The Collection of entities being moved*/ protected Collection moveEntities; --- 45,48 ---- *************** *** 65,81 **** private MoveTool strategy; ! /** The move vector */ ! protected Edge moveVector; ! ! /** The aligning edge */ ! protected Edge alignEdge; ! ! /** Number of clicks when in 3 click mode */ ! protected int numberOfClicks; - /** The plane that the movevector ends - in if nothing else is hit */ - protected Plane currentPlane; - /** * The Constructor --- 51,57 ---- private MoveTool strategy; ! /** Move constructor */ ! protected Edge moveConstructor; /** * The Constructor *************** *** 87,94 **** strategy = null; lastMoveDirection = null; - alignEdge = null; - numberOfClicks = 1; - currentPlane = null; start = null; } --- 63,68 ---- strategy = null; lastMoveDirection = null; start = null; + moveConstructor = null; } *************** *** 132,214 **** excluded(getAffected(moveEntities)); if (!moveEntities.isEmpty()) { ! start = current; } } else { start = null; moveEntities = null; excluded(new HashSet()); } } - /* - findTarget(e); - if (numberOfClicks == 1) { - moveEntities = new HashSet(); - if (target != null) { - Vertex moveStart = findInitial(target, e); - moveVector = new Edge(moveStart, moveStart); - moveVector.setConstructor(true); - glv.getView().addTempEdgeOnTop(moveVector); - initial = moveStart.copy(); - from = moveStart.copy(); - numberOfClicks = 2; - number = ""; - } - if (selection.isEmpty() && target != null) { - moveEntities.add(target); - } else if (!selection.isEmpty()) { - moveEntities.addAll(selection); - } - } else if (numberOfClicks == 2) { - glv.getView().removeEntityOnTop(moveVector); - moveVector = null; - if (alignEdge != null) { - glv.getView().removeTempEdge(alignEdge); - alignEdge = null; - } - update(); - numberOfClicks = 1; - } - }*/ - } - - /** - * Finds the point clicked. - * @param entity the entity clicked - * @param e the mouse event associated with the click. - * @return the point. - */ - protected Vertex findInitial(Object entity, MouseEvent e) { - double x = e.getX(); - double y = View.getHeight() - e.getY(); - View v = glv.getView(); - Transformation transformation = v.transformation(); - Vertex near = new Vertex(x, y, 0.0); - Vertex far = new Vertex(x, y, 1.0); - Edge ray = new Edge(near, far); - ray = transformation.unProject(ray); - if (entity instanceof Vertex) { - return ((Vertex)entity).copy(); - } else if (entity instanceof Surface) { - Plane plane = ((Surface)entity).plane(); - return plane.intersection(ray); - } else if (entity instanceof Edge) { - Edge edge = (Edge) entity; - Edge intersection = edge.intersection(ray); - if (intersection != null) { - return intersection.getFrom(); - } else { - return null; - } - } else if (entity instanceof ClippingPlane) { - Plane plane = ((ClippingPlane) entity).getPlane(); - return plane.intersection(ray); - } else if (entity instanceof Plane) { - Plane plane = (Plane)entity; - return plane.intersection(ray); - } else if (entity instanceof Intersection) { - return ((Intersection)entity).vertex(); - } - log.warn("The object is not an Entity"); - return null; } --- 106,127 ---- excluded(getAffected(moveEntities)); if (!moveEntities.isEmpty()) { ! vertices = collect(moveEntities); ! start = new Intersection(current.vertex().copy(), ! current.type(), ! current.object()); ! from = start.vertex().copy(); ! vertices.add(from); ! incident = null; ! } else { ! moveEntities = null; } } else { start = null; moveEntities = null; + incident = null; + vertices = null; excluded(new HashSet()); } } } *************** *** 238,304 **** current = findIntersection(e); if (current != null && ! oldCurrent != null && moveEntities != null) { ! move(moveEntities, current.vertex().minus(oldCurrent.vertex())); } updateConstructors(); } - /* - if (numberOfClicks == 2) { - boolean showAlign = false; - Set moveConstructors = makeXYZConerConstructors(new Vertex(0, 0, 0)); - displayConstructors(moveConstructors); - glv.getView().removeEntityOnTop(moveVector); - if (alignEdge != null) { - glv.getView().addTempEdge(alignEdge); - } - findTarget(e, (Set)moveEntities); - glv.getView().makeTarget(target); - if (target != null) { - if (target instanceof Edge) { - Edge targetEdge = (Edge)target; - if (!targetEdge.equals(alignEdge)) { - Timer alignTimer = new Timer(); - TimerTask alignTask = new AlignTask(targetEdge); - alignTimer.schedule(alignTask, 300); - } - if (alignEdge != null) { - Vertex alignDir = alignEdge.getDirection(); - Vertex targetDir = targetEdge.getDirection(); - Vertex dirCross = alignDir.cross(targetDir); - showAlign = dirCross.length() < 0.000001; - } - } - } - Intersection endPoint = - (Intersection)glv.getView().getObjectAtPoint(e.getX(), e.getY(), - (Set)moveEntities, true, - currentPlane); - Vertex to = endPoint.vertex(); - if (to != null) { - moveVector.setTo(to); - lastMoveDirection = to.minus(initial).copy(); - glv.setLength(lastMoveDirection.length()); - //Do we really want this to move also? - Vertex movement = to.minus(from); - if (vertices != null) { - move(vertices, movement); - } - from = to; - } - - if (moveVector != null) { - glv.getView().addTempEdgeOnTop(moveVector); - } - if (!showAlign) { - glv.getView().removeTempEdge(alignEdge); - } - clearConstructors(moveConstructors); - } else { - findTarget(e); - glv.getView().makeTarget(target); - } - } - */ } --- 151,160 ---- current = findIntersection(e); if (current != null && ! from != null && moveEntities != null) { ! move(vertices, current.vertex().minus(from)); } updateConstructors(); } } *************** *** 311,338 **** if (strategy != null) { strategy.dragged(e); - } - } - - /** - * Corrects a movement vector to make the - * movement snap to the initial position of - * the moved object(s). - * @param delta the movement vector. - * @return the corrected movement vector. - */ - protected Vertex snapToInitial(Vertex delta) { - Vertex parentPos = from.add(delta); - Vertex v = initial.minus(parentPos); - Vertex appr = initial.minus(from); - if (Math.abs(v.getX()) < .25) { - delta.setX(appr.getX()); - } - if (Math.abs(v.getY()) < .25) { - delta.setY(appr.getY()); } - if (Math.abs(v.getZ()) < .25) { - delta.setZ(appr.getZ()); - } - return delta; } --- 167,171 ---- *************** *** 342,346 **** * @param delta The movement */ ! protected void move(Collection sel, Vertex delta) { Iterator it = sel.iterator(); while (it.hasNext()) { --- 175,179 ---- * @param delta The movement */ ! protected void move(Set sel, Vertex delta) { Iterator it = sel.iterator(); while (it.hasNext()) { *************** *** 366,369 **** --- 199,203 ---- */ public void keyPressed(KeyEvent e) { + /* if (strategy != null) { strategy.keyPressed(e); *************** *** 400,404 **** double length = glv.getLength(); Vertex delta = initial.minus(from); ! if (delta.length() > 0) { delta.scale((delta.length() - length) / delta.length()); } else { --- 234,238 ---- double length = glv.getLength(); Vertex delta = initial.minus(from); ! if (delta.length( 0) { delta.scale((delta.length() - length) / delta.length()); } else { *************** *** 431,434 **** --- 265,269 ---- glv.repaint(true); } + */ } *************** *** 448,455 **** if (start != null && current != null) { super.updateConstructors(); ! Edge edge = new Edge(start.vertex(), current.vertex()); ! edge.setConstructor(true); ! constructors.add(edge); ! excluded.add(edge); Set constcopy = new HashSet(); constcopy.addAll(constructors); --- 283,290 ---- if (start != null && current != null) { super.updateConstructors(); ! moveConstructor = new Edge(start.vertex(), current.vertex()); ! moveConstructor.setConstructor(true); ! constructors.add(moveConstructor); ! excluded.add(moveConstructor); Set constcopy = new HashSet(); constcopy.addAll(constructors); *************** *** 458,462 **** excopy.addAll(excluded); excluded(excopy); ! glv.setLength(edge.getLength()); } else { constructors(new LinkedList()); --- 293,297 ---- excopy.addAll(excluded); excluded(excopy); ! glv.setLength(moveConstructor.getLength()); } else { constructors(new LinkedList()); *************** *** 472,476 **** * @return the affected elements */ ! private Collection getAffected(Collection moveElements) { HashSet affected = new HashSet(); HashSet affectedEdges = new HashSet(); --- 307,311 ---- * @return the affected elements */ ! protected Set getAffected(Collection moveElements) { HashSet affected = new HashSet(); HashSet affectedEdges = new HashSet(); *************** *** 479,484 **** Iterator it = affected.iterator(); while (it.hasNext()) { ! affectedEdges.addAll(((Vertex)it.next()).getEdges()); ! affectedSurfaces.addAll(((Vertex)it.next()).getSurfaces()); } affected.addAll(affectedEdges); --- 314,320 ---- Iterator it = affected.iterator(); while (it.hasNext()) { ! Vertex v = (Vertex)it.next(); ! affectedEdges.addAll(v.getEdges()); ! affectedSurfaces.addAll(v.getSurfaces()); } affected.addAll(affectedEdges); *************** *** 486,528 **** return affected; } - - - /** - * Class for handeling the task of assigning an alignedge. - */ - protected class AlignTask extends TimerTask { - /** The edge candidate to become the alignedge */ - private Edge candidateEdge; - - /** - * Constructor - * @param candidate the candidate to become alignedge - */ - public AlignTask(Edge candidate) { - super(); - candidateEdge = candidate; - } - - /** - * checks if the target is still the same edge, - * thus making it the alignedge - */ - public void run() { - - if (target instanceof Edge) { - candidateEdge.equals((Edge)target); - - Vertex direction = candidateEdge.getDirection(); - Vertex alignTo = direction.copy(); - Vertex alignFrom = direction.copy(); - alignFrom.scale(-1000); - alignTo.scale(1000); - glv.getView().removeTempEdge(alignEdge); - alignEdge = new Edge(alignFrom.add(initial), alignTo.add(initial)); - alignEdge.setConstructor(true); - glv.getView().addTempEdge(alignEdge); - glv.repaint(true); - } - } - } } --- 322,324 ---- Index: VectorMoveStrategy.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool/VectorMoveStrategy.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** VectorMoveStrategy.java 29 Mar 2006 18:39:25 -0000 1.2 --- VectorMoveStrategy.java 5 Apr 2006 10:24:56 -0000 1.3 *************** *** 9,15 **** import net.sourceforge.bprocessor.gl.GLView; ! import net.sourceforge.bprocessor.model.Plane; ! import java.util.HashSet; import java.awt.event.MouseEvent; --- 9,15 ---- import net.sourceforge.bprocessor.gl.GLView; ! //import net.sourceforge.bprocessor.model.Plane; ! //import java.util.HashSet; import java.awt.event.MouseEvent; *************** *** 35,39 **** public VectorMoveStrategy(GLView glv, Cursor cursor) { super(glv, cursor); - currentPlane = new Plane(0, 0, 1, 0); } --- 35,38 ---- *************** *** 44,51 **** protected void pressed(MouseEvent e) { super.pressed(e); - if (numberOfClicks == 2) { - vertices = new HashSet(); - collect(moveEntities, vertices); - } } --- 43,46 ---- Index: ControlledMoveStrategy.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool/ControlledMoveStrategy.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** ControlledMoveStrategy.java 29 Mar 2006 18:39:25 -0000 1.2 --- ControlledMoveStrategy.java 5 Apr 2006 10:24:56 -0000 1.3 *************** *** 12,21 **** import net.sourceforge.bprocessor.model.Surface; import net.sourceforge.bprocessor.model.Vertex; - import net.sourceforge.bprocessor.model.Entity; import net.sourceforge.bprocessor.model.Plane; ! import net.sourceforge.bprocessor.model.Project; ! import net.sourceforge.bprocessor.model.Camera; import java.util.HashSet; import java.util.HashMap; import java.util.List; --- 12,21 ---- import net.sourceforge.bprocessor.model.Surface; import net.sourceforge.bprocessor.model.Vertex; import net.sourceforge.bprocessor.model.Plane; ! import net.sourceforge.bprocessor.model.Geometric; import java.util.HashSet; + import java.util.Set; + import java.util.Map; import java.util.HashMap; import java.util.List; *************** *** 27,31 **** import java.awt.event.KeyEvent; - import org.apache.log4j.Logger; --- 27,30 ---- *************** *** 40,51 **** private HashMap slideMap; ! /** The entity to be moved controlled */ ! private Entity controlled; /** The plane to drag according to */ private Plane dragPlane; ! /** Vector to restrict movement in one direction */ ! private Vertex restrictionVector; /** --- 39,50 ---- private HashMap slideMap; ! /** The geometric to be moved controlled */ ! private Geometric controlled; /** The plane to drag according to */ private Plane dragPlane; ! /** Direction of the controlled movement */ ! private Vertex direction; /** *************** *** 56,61 **** public ControlledMoveStrategy(GLView glv, Cursor cursor) { super(glv, cursor); ! slideMap = new HashMap(); ! restrictionVector = null; } --- 55,60 ---- public ControlledMoveStrategy(GLView glv, Cursor cursor) { super(glv, cursor); ! slideMap = null; ! direction = null; } *************** *** 66,83 **** protected void pressed(MouseEvent e) { super.pressed(e); ! if (numberOfClicks == 2) { ! slideMap = new HashMap(); ! vertices = new HashSet(); ! ! if (!moveEntities.isEmpty()) { ! Iterator it = moveEntities.iterator(); ! controlled = (Entity)it.next(); ! } ! moveEntities.clear(); ! moveEntities.add(controlled); ! collect(moveEntities, vertices); ! } else if (numberOfClicks == 1) { slideMap = null; - controlled = null; } } --- 65,70 ---- protected void pressed(MouseEvent e) { super.pressed(e); ! if (start == null) { slideMap = null; } } *************** *** 88,96 **** */ protected void moved(MouseEvent e) { ! if (dragPlane == null) { ! findRestrictions(e); ! } ! if (dragPlane != null) { ! super.moved(e); } } --- 75,94 ---- */ protected void moved(MouseEvent e) { ! super.moved(e); ! if (slideMap == null && moveEntities != null) { ! if (createSlideMap(e)) { ! Iterator it = moveEntities.iterator(); ! boolean found = false; ! while (it.hasNext() && !found) { ! direction = direction((Geometric)it.next()); ! found = direction != null; ! } ! if (!found) { ! slideMap = null; ! } else { ! slideMap.put(from, direction); ! super.moved(e); ! } ! } } } *************** *** 105,235 **** /** ! * Set up the restriction to make the movement controlled ! * @param e a mouse event. */ ! private void findRestrictions(MouseEvent e) { ! if (controlled != null) { ! if (slideMap.isEmpty()) { ! findTarget(e); ! if (controlled instanceof Edge) { ! Edge controlledEdge = (Edge)controlled; ! if (target instanceof Surface) { ! Surface targetSurface = (Surface)target; ! if (controlledEdge.getSurfaces().contains(targetSurface)) { ! glv.getView().makeTarget(target); ! dragPlane = targetSurface.plane(); ! currentPlane = dragPlane; ! Vertex controlledDir = controlledEdge.getDirection(); ! Vertex surfaceNormal = targetSurface.normal(); ! restrictionVector = controlledDir.cross(surfaceNormal); ! restrictionVector.scale(1 / restrictionVector.length()); ! ! List edges = targetSurface.getEdges(); ! int index = edges.indexOf(controlledEdge); ! Edge leftEdge; ! Edge rightEdge; ! if (index == 0) { ! leftEdge = (Edge)edges.get(edges.size() - 1); ! rightEdge = (Edge)edges.get(index + 1); ! } else if (index == (edges.size() - 1)) { ! leftEdge = (Edge)edges.get(index - 1); ! rightEdge = (Edge)edges.get(0); ! } else { ! leftEdge = (Edge)edges.get(index - 1); ! rightEdge = (Edge)edges.get(index + 1); ! } ! Edge toSlideEdge = null; ! Edge fromSlideEdge = null; ! if (controlledDir.cross(leftEdge.getDirection()).length() > 0.00001 && ! controlledDir.cross(rightEdge.getDirection()).length() > 0.00001) { ! Vertex to = controlledEdge.getTo(); ! Vertex from = controlledEdge.getFrom(); ! if (to.getEdges().contains(leftEdge) && ! from.getEdges().contains(rightEdge)) { ! toSlideEdge = leftEdge; ! fromSlideEdge = rightEdge; ! } else if (from.getEdges().contains(leftEdge) && ! to.getEdges().contains(rightEdge)) { ! fromSlideEdge = leftEdge; ! toSlideEdge = rightEdge; ! } ! slideMap = new HashMap(); ! slideMap.put(controlledEdge.getTo(), toSlideEdge.getDirection()); ! slideMap.put(controlledEdge.getFrom(), fromSlideEdge.getDirection()); ! } else { ! dragPlane = null; ! restrictionVector = null; ! log.warn("This edge is bound"); ! } ! } ! } ! } else if (controlled instanceof Vertex) { ! Vertex controlledVertex = (Vertex)controlled; ! if (target instanceof Edge && ! controlledVertex.getEdges().contains((Edge)target)) { ! Edge targetEdge = (Edge)target; ! slideMap = new HashMap(); ! slideMap.put(controlledVertex, targetEdge.getDirection()); ! restrictionVector = targetEdge.getDirection(); ! findRestrictionPlane(); ! } ! } else if (controlled instanceof Surface) { ! Surface controlledSurface = (Surface)controlled; ! restrictionVector = controlledSurface.normal(); ! findRestrictionPlane(); ! slideMap = new HashMap(); ! Collection vertices = controlledSurface.getVertices(); ! Iterator it = vertices.iterator(); ! boolean bound = false; ! while (it.hasNext() && !bound) { ! Vertex vertex = (Vertex)it.next(); ! slideMap.put(vertex, restrictionVector); ! Collection edges = vertex.getEdges(); ! Iterator edgeIt = edges.iterator(); ! int otherEdges = 0; ! while (edgeIt.hasNext() && !bound) { ! Edge edge = (Edge)edgeIt.next(); ! if (!controlledSurface.getEdges().contains(edge)) { ! otherEdges++; ! slideMap.put(vertex, edge.getDirection()); ! } ! bound = otherEdges > 1; ! } ! } ! if (bound) { ! slideMap = new HashMap(); ! restrictionVector = null; ! dragPlane = null; ! log.warn("this surface is bound!"); ! } } } } } /** ! * Sets an appropriate dragPlane that aligned with the ! * restrictionvector and containing a specified point to ! * make reasonable movements. */ ! protected void findRestrictionPlane() { ! Camera camera = Project.getInstance().getCurrentCamera(); ! 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 cross = restrictionVector.cross(eyeVector); ! Vertex planeNormal; ! if (cross.isZero()) { ! double[] rollVector = camera.getRoll(); ! planeNormal = new Vertex(rollVector[0], rollVector[1], rollVector[2]); ! } else { ! planeNormal = (restrictionVector.cross(eyeVector)).cross(restrictionVector); } ! dragPlane = new Plane(planeNormal.getX(), planeNormal.getY(), planeNormal.getZ(), ! -planeNormal.dot(initial)); ! currentPlane = dragPlane; } --- 103,267 ---- /** ! * Finds the direction of the controlled movement. ! * @param geo a geometric object. ! * @return the direction. */ ! private Vertex direction(Geometric geo) { ! if (geo instanceof Surface) { ! Surface surface = (Surface)geo; ! return surface.normal(); ! } else if (geo instanceof Edge) { ! Edge edge = (Edge)geo; ! if (current.object() instanceof Surface) { ! Surface surface = (Surface)current.object(); ! if (edge.getSurfaces().contains(surface)) { ! Vertex edgeDir = edge.getDirection(); ! Vertex normal = surface.normal(); ! Vertex dir = edgeDir.cross(normal); ! dir.scale(1 / dir.length()); ! return dir; } } + } else if (geo instanceof Vertex) { + return (Vertex)slideMap.get(geo); } + return null; } + /** ! * Trys to create the slideMap, returns true if it is succesfull, ! * false otherwise. ! * @param e the mouse event ! * @return werther the creation of the map is succesfull. */ ! private boolean createSlideMap(MouseEvent e) { ! Set ex = new HashSet(moveEntities); ! ex.add(moveConstructor); ! excluded(ex); ! current = findIntersection(e); ! ex = getAffected(moveEntities); ! ex.add(moveConstructor); ! excluded(ex); ! ! slideMap = new HashMap(); ! if (moveEntities != null) { ! Iterator it = moveEntities.iterator(); ! while (it.hasNext()) { ! Geometric geo = (Geometric)it.next(); ! Map map = null; ! if (geo instanceof Edge) { ! map = createSlideMap((Edge)geo); ! } else if (geo instanceof Surface) { ! map = createSlideMap((Surface)geo); ! } else if (geo instanceof Vertex) { ! map = createSlideMap((Vertex)geo); ! } ! if (map != null) { ! slideMap.putAll(map); ! } else { ! slideMap = null; ! return false; ! } ! } ! return true; } ! slideMap = null; ! return false; ! } ! ! /** ! * Finds the slidemap for an edge. ! * @param edge the edge ! * @return a map for edge, null if none can be found ! */ ! private Map createSlideMap(Edge edge) { ! if (current.object() instanceof Surface) { ! Surface surface = (Surface)current.object(); ! if (edge.getSurfaces().contains(surface)) { ! dragPlane = surface.plane(); ! ! List edges = surface.getEdges(); ! int index = edges.indexOf(edge); ! Edge leftEdge; ! Edge rightEdge; ! if (index == 0) { ! leftEdge = (Edge)edges.get(edges.size() - 1); ! rightEdge = (Edge)edges.get(index + 1); ! } else if (index == (edges.size() - 1)) { ! leftEdge = (Edge)edges.get(index - 1); ! rightEdge = (Edge)edges.get(0); ! } else { ! leftEdge = (Edge)edges.get(index - 1); ! rightEdge = (Edge)edges.get(index + 1); ! } ! Edge toSlideEdge = null; ! Edge fromSlideEdge = null; ! Vertex to = edge.getTo(); ! Vertex from = edge.getFrom(); ! if (to.getEdges().contains(leftEdge) && ! from.getEdges().contains(rightEdge)) { ! toSlideEdge = leftEdge; ! fromSlideEdge = rightEdge; ! } else if (from.getEdges().contains(leftEdge) && ! to.getEdges().contains(rightEdge)) { ! fromSlideEdge = leftEdge; ! toSlideEdge = rightEdge; ! } ! Map map = new HashMap(); ! map.put(edge.getTo(), toSlideEdge.getDirection()); ! map.put(edge.getFrom(), fromSlideEdge.getDirection()); ! return map; ! } ! } ! return null; ! } ! ! /** ! * Finds the slide map for a vertex. ! * @param vertex the vertex ! * @return a map for the vertex, or null if none could be found. ! */ ! private Map createSlideMap(Vertex vertex) { ! if (current.object() instanceof Edge) { ! Edge edge = (Edge)current.object(); ! if (vertex.getEdges().contains(edge)) { ! Map map = new HashMap(); ! map.put(vertex, edge.getDirection()); ! return map; ! } ! } ! return null; ! } ! ! /** ! * Finds the slide map for a surface. ! * @param surface the surface ! * @return the map, or null if none could be found. ! */ ! private Map createSlideMap(Surface surface) { ! Collection verts = surface.getVertices(); ! Iterator it = vertices.iterator(); ! boolean bound = false; ! Map map = new HashMap(); ! while (it.hasNext() && !bound) { ! Vertex vertex = (Vertex)it.next(); ! map.put(vertex, surface.normal()); ! Collection edges = vertex.getEdges(); ! Iterator edgeIt = edges.iterator(); ! int otherEdges = 0; ! while (edgeIt.hasNext() && !bound) { ! Edge edge = (Edge)edgeIt.next(); ! if (!surface.getEdges().contains(edge)) { ! otherEdges++; ! map.put(vertex, edge.getDirection()); ! } ! bound = otherEdges > 1; ! } ! } ! if (!bound) { ! return map; ! } ! return null; } *************** *** 240,274 **** * @param delta the movement. */ ! protected void move(Collection vertices, Vertex delta) { ! Vertex restrictCopy = restrictionVector.copy(); ! restrictCopy.scale(1 / restrictCopy.length()); ! restrictCopy.scale(delta.dot(restrictCopy)); ! delta = restrictCopy; ! Vertex deltaUnit = delta.copy(); ! deltaUnit.scale(1 / delta.length()); ! Iterator it = vertices.iterator(); ! while (it.hasNext()) { ! Vertex vertex = (Vertex)it.next(); ! Vertex slideDir = ((Vertex)slideMap.get(vertex)).copy(); ! slideDir.scale(1 / slideDir.length()); ! double slideScale; ! if (delta == null) { ! log.info("delta null"); ! } ! if (slideDir == null) { ! log.info("slideDir null"); ! } ! if (deltaUnit == null) { ! log.info("deltaUnit null"); ! } ! if (delta.getX() != 0) { ! slideScale = delta.getX() / (slideDir.dot(deltaUnit) * deltaUnit.getX()); ! } else if (delta.getY() != 0) { ! slideScale = delta.getY() / (slideDir.dot(deltaUnit) * deltaUnit.getY()); ! } else { ! slideScale = delta.getZ() / (slideDir.dot(deltaUnit) * deltaUnit.getZ()); } - slideDir.scale(slideScale); - vertex.move(slideDir.getX(), slideDir.getY(), slideDir.getZ()); } } --- 272,310 ---- * @param delta the movement. */ ! protected void move(Set vertices, Vertex delta) { ! if (slideMap != null && slideMap.keySet().containsAll(vertices)) { ! Vertex directionCopy = direction.copy(); ! directionCopy.scale(1 / directionCopy.length()); ! directionCopy.scale(delta.dot(directionCopy)); ! delta = directionCopy; ! if (delta.length() != 0) { ! Vertex deltaUnit = delta.copy(); ! deltaUnit.scale(1 / delta.length()); ! Iterator it = vertices.iterator(); ! while (it.hasNext()) { ! Vertex vertex = (Vertex)it.next(); ! Vertex slideDir = ((Vertex)slideMap.get(vertex)).copy(); ! slideDir.scale(1 / slideDir.length()); ! double slideScale; ! if (delta == null) { ! log.info("delta null"); ! } ! if (slideDir == null) { ! log.info("slideDir null"); ! } ! if (deltaUnit == null) { ! log.info("deltaUnit null"); ! } ! if (delta.getX() != 0) { ! slideScale = delta.getX() / (slideDir.dot(deltaUnit) * deltaUnit.getX()); ! } else if (delta.getY() != 0) { ! slideScale = delta.getY() / (slideDir.dot(deltaUnit) * deltaUnit.getY()); ! } else { ! slideScale = delta.getZ() / (slideDir.dot(deltaUnit) * deltaUnit.getZ()); ! } ! slideDir.scale(slideScale); ! vertex.move(slideDir.getX(), slideDir.getY(), slideDir.getZ()); ! } } } } |