[Bprocessor-commit] gl/src/net/sourceforge/bprocessor/gl/tool AbstractPencil.java,1.22,1.23
Status: Pre-Alpha
Brought to you by:
henryml
From: Nordholt <nor...@us...> - 2006-04-13 13:35:15
|
Update of /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26793 Modified Files: AbstractPencil.java Log Message: Finds better workplanes. Can lock a direction using the shift key. Changed the color of the parrallel aligning constructor to orange for better visibility Index: AbstractPencil.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool/AbstractPencil.java,v retrieving revision 1.22 retrieving revision 1.23 diff -C2 -d -r1.22 -r1.23 *** AbstractPencil.java 5 Apr 2006 10:49:09 -0000 1.22 --- AbstractPencil.java 13 Apr 2006 13:34:56 -0000 1.23 *************** *** 30,33 **** --- 30,35 ---- import net.sourceforge.bprocessor.model.Surface; import net.sourceforge.bprocessor.model.Vertex; + import net.sourceforge.bprocessor.model.Camera; + import org.apache.log4j.Logger; *************** *** 60,63 **** --- 62,71 ---- protected Intersection incident; + /** Locked */ + protected Vertex locked; + + /** wherther or not the tool is locked */ + protected boolean lock; + /** Work plane */ protected Plane plane; *************** *** 78,81 **** --- 86,91 ---- timer = new Timer(500, new TargetAction()); timer.setRepeats(false); + lock = false; + plane = new Plane (0, 0, 1, 0); } *************** *** 98,108 **** */ protected Intersection findIntersection(MouseEvent e) { Collection unwanted = new HashSet(); unwanted.addAll(elements); unwanted.addAll(excluded); ! Intersection intersection = (Intersection) glv.getView().getObjectAtPoint(e.getX(), e.getY(), ! unwanted, true, new Plane(0, 0, 1, 0)); return intersection; } /** * Insert a vertex into model --- 108,150 ---- */ protected Intersection findIntersection(MouseEvent e) { + plane = bestAlignedPlane(); + if (start != null) { + Vertex planeNormal = plane.normal(); + plane = new Plane(planeNormal.getX(), + planeNormal.getY(), + planeNormal.getZ(), + -(planeNormal.getX() * start.vertex().getX() + + planeNormal.getY() * start.vertex().getY() + + planeNormal.getZ() * start.vertex().getZ())); + } Collection unwanted = new HashSet(); unwanted.addAll(elements); unwanted.addAll(excluded); ! Intersection intersection = ! (Intersection) glv.getView().getObjectAtPoint(e.getX(), e.getY(), ! unwanted, true, plane); ! if (lock) { ! intersection = lockedIntersection(intersection); ! } return intersection; } + + /** + * If the tool is locked correct the intersection + * @param intersection the original intersection + * @return the corrected intersection + */ + private Intersection lockedIntersection(Intersection intersection) { + if (start != null) { + Vertex lockedcopy = locked.copy(); + Vertex unlocked = intersection.vertex().minus(start.vertex()); + lockedcopy.scale(locked.dot(unlocked)); + lockedcopy = lockedcopy.add(start.vertex()); + return new Intersection(lockedcopy, Intersection.VERTEX, lockedcopy); + } else { + return intersection; + } + } + /** * Insert a vertex into model *************** *** 335,339 **** if (!isAxisAligned(parrallel)) { parrallel.setConstructor(true); ! glv.getView().changeColor(parrallel, new float[] {1, 1, 0}); constructors.add(parrallel); } --- 377,381 ---- if (!isAxisAligned(parrallel)) { parrallel.setConstructor(true); ! glv.getView().changeColor(parrallel, new float[] {255f / 255f, 153f / 255f, 0}); constructors.add(parrallel); } *************** *** 376,379 **** --- 418,456 ---- excluded.addAll(feed); } + + /** + * Get the plane out of the XY XZ and YZ planes that is best aligned + * with screen. + * @return the plane + */ + protected Plane bestAlignedPlane() { + 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]); + eyeVector.scale(1 / eyeVector.length()); + + Vertex normal; + Vertex xyNormal = new Vertex(0, 0, 1); + Vertex xzNormal = new Vertex(0, 1, 0); + Vertex yzNormal = new Vertex(1, 0, 0); + if (Math.abs(eyeVector.dot(xyNormal)) > + Math.abs(eyeVector.dot(xzNormal))) { + normal = xyNormal; + } else { + normal = xzNormal; + } + if (Math.abs(eyeVector.dot(yzNormal)) > + Math.abs(eyeVector.dot(normal))) { + normal = yzNormal; + } + return new Plane(normal.getX(), + normal.getY(), + normal.getZ(), 0); + } + /** *************** *** 451,455 **** case Intersection.SURFACE: target = intersection.object(); ! plane = ((Surface) target).plane(); break; case Intersection.EDGE_MIDPOINT: --- 528,532 ---- case Intersection.SURFACE: target = intersection.object(); ! //plane = ((Surface) target).plane(); break; case Intersection.EDGE_MIDPOINT: *************** *** 464,468 **** case Intersection.PLANE_INTERSECTION: target = null; ! plane = (Plane) intersection.object(); break; } --- 541,545 ---- case Intersection.PLANE_INTERSECTION: target = null; ! //plane = (Plane) intersection.object(); break; } *************** *** 535,538 **** --- 612,621 ---- } glv.repaint(); + } else if (e.getKeyCode() == KeyEvent.VK_SHIFT) { + if (start != null && current != null) { + locked = start.vertex().minus(current.vertex()); + locked.scale(1 / locked.length()); + } + lock = !lock; } else if (e.getKeyCode() == KeyEvent.VK_ESCAPE) { cleanUp(); *************** *** 590,594 **** v.scale((d / 1000) / v.length()); Vertex to = before.add(v); ! current = new Intersection(to, Intersection.VERTEX, null); onVertex(); number = ""; --- 673,677 ---- v.scale((d / 1000) / v.length()); Vertex to = before.add(v); ! current = new Intersection(to, Intersection.VERTEX, to); onVertex(); number = ""; *************** *** 614,618 **** */ public void cleanUp() { ! plane = null; start = null; current = null; --- 697,701 ---- */ public void cleanUp() { ! plane = new Plane(0, 0, 1, 0);; start = null; current = null; |