[Bprocessor-commit] gl/src/net/sourceforge/bprocessor/gl/tool OffsetTool.java, 1.1, 1.2
Status: Pre-Alpha
Brought to you by:
henryml
From: Nordholt <nor...@us...> - 2006-07-10 12:19:31
|
Update of /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv12424 Modified Files: OffsetTool.java Log Message: Changed the way the offset tool is used. Changed the constructor contour to a full surface. Lengthfield should also work in the new offset tool. Index: OffsetTool.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool/OffsetTool.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** OffsetTool.java 9 Jul 2006 16:19:55 -0000 1.1 --- OffsetTool.java 10 Jul 2006 12:19:28 -0000 1.2 *************** *** 19,23 **** import net.sourceforge.bprocessor.gl.GLView; - import net.sourceforge.bprocessor.gl.model.Intersection; import net.sourceforge.bprocessor.model.Edge; import net.sourceforge.bprocessor.model.Surface; --- 19,22 ---- *************** *** 35,40 **** private Map directionMap; ! /** The intersection before the current */ ! private Intersection lastIntersection; /** Dragging flag */ --- 34,47 ---- private Map directionMap; ! /** The last point the offset was moved to */ ! private Vertex lastOffsetPoint; ! ! /** Tells if a surface is found to do the offset from */ ! private boolean surfaceFound; ! ! /** A vector perpendicular to both the edge clicked to start the offset, ! and the normal of the surface that is being offset. ! This vector should point away from the surface */ ! private Vertex outNormal; /** Dragging flag */ *************** *** 50,54 **** --- 57,63 ---- contour = new LinkedList(); directionMap = new HashMap(); + surfaceFound = false; dragging = false; + outNormal = null; } *************** *** 58,75 **** */ public void updateFeedback() { ! if (start != null) { ! double lastRadius = start.vertex().minus(lastIntersection.vertex()).length(); ! double newRadius = start.vertex().minus(current.vertex()).length(); ! double delta = newRadius - lastRadius; ! Iterator it = collect(contour).iterator(); ! while (it.hasNext()) { ! Vertex v = (Vertex)it.next(); ! Vertex dir = ((Vertex)directionMap.get(v)).copy(); ! dir.scale(delta); ! v.move(dir.getX(), dir.getY(), dir.getZ()); } } makeTarget(current); } /** --- 67,117 ---- */ public void updateFeedback() { ! if (start != null && lastOffsetPoint != null) { ! if (!surfaceFound) { ! Edge startEdge = (Edge)start.object(); ! if (current != null && ! current.object() instanceof Surface && ! ((Surface)current.object()).contains(startEdge)) { ! surfaceFound = true; ! Surface surface = (Surface)current.object(); ! contour = copyContour(surface); ! directionMap = findDirections(contour, surface.normal()); ! feedback(contour); ! outNormal = startEdge.getDirection().cross(surface.normal()); ! if (current.vertex().minus(start.vertex()).dot(outNormal) > 0) { ! outNormal.scale(1 / outNormal.length()); ! } else { ! outNormal.scale(-1 / outNormal.length()); ! } ! } ! } else { ! Vertex projection = outNormal.copy(); ! projection.scale((lastOffsetPoint.minus(current.vertex())).dot(projection)); ! double length; ! if (projection.dot(outNormal) > 0) { ! length = projection.length(); ! } else { ! length = (-1 * projection.length()); ! } ! moveContour(length); ! lastOffsetPoint = current.vertex().copy(); } } makeTarget(current); } + + /** + * Moves the offset contour by the sepcified length + * @param length the length to move the offset + */ + private void moveContour(double length) { + Iterator it = collect(contour).iterator(); + while (it.hasNext()) { + Vertex v = (Vertex)it.next(); + Vertex dir = ((Vertex)directionMap.get(v)).copy(); + dir.scale(length); + v.move(dir.getX(), dir.getY(), dir.getZ()); + } + } /** *************** *** 78,83 **** */ protected void moved(MouseEvent e) { ! lastIntersection = current; ! current = findIntersection(e); if (current != null) { updateFeedback(); --- 120,124 ---- */ protected void moved(MouseEvent e) { ! current = findIntersection(e); if (current != null) { updateFeedback(); *************** *** 92,105 **** protected void pressed(MouseEvent e) { if (start == null) { ! if (current != null && current.object() instanceof Surface) { start = current; ! Surface surface = (Surface)current.object(); ! contour = copyContour(surface); ! directionMap = findDirections(contour, surface.normal()); ! feedback(contour); ! } } else { endOffset(); ! } } /** --- 133,143 ---- protected void pressed(MouseEvent e) { if (start == null) { ! if (current != null && current.object() instanceof Edge) { start = current; ! lastOffsetPoint = start.vertex().copy(); ! } } else { endOffset(); ! } } /** *************** *** 108,113 **** */ public void onVertex() { ! if (start != null) { ! updateFeedback(); endOffset(); } --- 146,160 ---- */ public void onVertex() { ! if (start != null && current != null && lastOffsetPoint != null) { ! Vertex lengthVector = start.vertex().minus(current.vertex()); ! Vertex projection = outNormal.copy(); ! projection.scale(start.vertex().minus(lastOffsetPoint).dot(projection)); ! double projectionLength = projection.length(); ! double length = lengthVector.length(); ! if (projection.dot(outNormal) < 0) { ! moveContour(projectionLength - length); ! } else { ! moveContour(length - projectionLength); ! } endOffset(); } *************** *** 118,130 **** */ private void endOffset() { ! Iterator it = contour.iterator(); ! while (it.hasNext()) { ! Edge edge = (Edge)it.next(); ! insertEdge(edge, false); ! } directionMap = new HashMap(); contour = new LinkedList(); - feedback(contour); start = null; } --- 165,176 ---- */ private void endOffset() { ! insertEdges(contour); directionMap = new HashMap(); contour = new LinkedList(); start = null; + lastOffsetPoint = null; + surfaceFound = false; + outNormal = null; + feedback(contour); } *************** *** 197,206 **** to = ((Vertex)it.next()).copy(); Edge offsetEdge = new Edge(from, to); - offsetEdge.setConstructor(true); edges.add(offsetEdge); from = to; } Edge offsetEdge = new Edge(from, first); - offsetEdge.setConstructor(true); edges.add(offsetEdge); return edges; --- 243,250 ---- *************** *** 228,230 **** --- 272,287 ---- } } + + /** + * Update the length field + */ + protected void updateLength() { + if (start != null && lastOffsetPoint != null && outNormal != null) { + Vertex projection = outNormal.copy(); + projection.scale((lastOffsetPoint.minus(start.vertex())).dot(projection)); + glv.setLength(projection.length()); + } else { + super.updateLength(); + } + } } |