[Bprocessor-commit] gl/src/net/sourceforge/bprocessor/gl/tool PencilTool.java,1.52,1.53
Status: Pre-Alpha
Brought to you by:
henryml
From: Nordholt <nor...@us...> - 2005-12-26 15:10:40
|
Update of /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10121 Modified Files: PencilTool.java Log Message: added method for finding the plane currently being drawn in, if such a plane can be found there is now only two constructors both in that plane Index: PencilTool.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool/PencilTool.java,v retrieving revision 1.52 retrieving revision 1.53 diff -C2 -d -r1.52 -r1.53 *** PencilTool.java 21 Dec 2005 14:37:17 -0000 1.52 --- PencilTool.java 26 Dec 2005 15:10:28 -0000 1.53 *************** *** 51,54 **** --- 51,60 ---- /** The constructors from the snap vertex */ private Set snapConstructors; + + /** Whether to show the constructors */ + private boolean showConstructors; + + /** The plane currently drawn in */ + private Plane currentPlane; /** The active */ *************** *** 101,104 **** --- 107,111 ---- public PencilTool(GLView glv, Cursor cursor) { super(glv, cursor); + showConstructors = true; } *************** *** 194,204 **** snapVertex = vertex; glv.getView().setSnapVertex(vertex); ! clearConstructors(snapConstructors); ! snapConstructors = makeXYZConstructors(vertex); } } ! } ! ! --- 201,211 ---- snapVertex = vertex; glv.getView().setSnapVertex(vertex); ! if (showConstructors) { ! clearConstructors(snapConstructors); ! snapConstructors = makeXYZConstructors(vertex); ! } } } ! } *************** *** 234,240 **** constructors.add(y); constructors.add(z); ! glv.getView().addTempEdge(x); ! glv.getView().addTempEdge(y); ! glv.getView().addTempEdge(z); return constructors; } --- 241,247 ---- constructors.add(y); constructors.add(z); ! if (showConstructors) { ! displayConstructors(constructors); ! } return constructors; } *************** *** 305,316 **** constructors.add(second); constructors.add(third); ! glv.getView().addTempEdge(first); ! glv.getView().addTempEdge(second); ! glv.getView().addTempEdge(third); return constructors; } return null; } ! /** * Removes a set of constructors. --- 312,373 ---- constructors.add(second); constructors.add(third); ! if (showConstructors) { ! displayConstructors(constructors); ! } return constructors; } return null; } ! ! ! /** ! * makes a constructor on an edge and an other constructor ! * that is othogonal to the first and lies in a given plane. ! * The constructors are returned in a set. ! * If no such constructors can be created null is returned. ! * @param v the vertex where the to constructors should cross. ! * @param e the edge ! * @param p the plane ! * @return the set of constructors. ! */ ! public Set makeInPlaneConstructors(Vertex v, Edge e, Plane p) { ! if (v != null && e != null && p != null) { ! /** ! algorithm: the A, B, C part of the plane equation is ! a normal-vector for the plane. By first finding a ! vector with the direction of the edge and finding a ! cross with the normal vector we should find a vector in the plane ! orthogonal to the edge. ! */ ! double[] planeRep = p.getDoublev(); ! Vertex planeNormal = new Vertex(planeRep[0], planeRep[1], planeRep[2]); ! Vertex edgeDir = e.getTo().minus(e.getFrom()); ! Vertex orthoDir = edgeDir.cross(planeNormal); ! ! edgeDir.scale(50 / edgeDir.length()); ! Vertex fromEdge = edgeDir.copy().add(v); ! edgeDir.scale(-1); ! Vertex toEdge = edgeDir.copy().add(v); ! Edge edgeConstructor = new Edge(fromEdge, toEdge); ! edgeConstructor.setConstructor(true); ! ! orthoDir.scale(50 / orthoDir.length()); ! Vertex fromOrtho = orthoDir.copy().add(v); ! orthoDir.scale(-1); ! Vertex toOrtho = orthoDir.copy().add(v); ! Edge orthoConstructor = new Edge(fromOrtho, toOrtho); ! orthoConstructor.setConstructor(true); ! ! Set constructors = new HashSet(); ! constructors.add(orthoConstructor); ! constructors.add(edgeConstructor); ! if (showConstructors) { ! displayConstructors(constructors); ! } ! return constructors; ! } ! return null; ! } ! /** * Removes a set of constructors. *************** *** 326,329 **** --- 383,400 ---- } } + + /** + * Makes a set of constructors be displayed. + * @param constructors a set of constructors. + */ + private void displayConstructors(Set constructors) { + if (constructors != null) { + Iterator it = constructors.iterator(); + while (it.hasNext()) { + Edge constructor = (Edge)it.next(); + glv.getView().addTempEdge(constructor); + } + } + } /** *************** *** 364,367 **** --- 435,440 ---- if (active == null) { edges = new ArrayList(); + currentPlane = null; + findCurrentPlane(); intern(vertex); from = vertex; *************** *** 376,381 **** clearConstructors(currentConstructors); ! currentConstructors = makeAlignedConstructors(vertex, active); ! from = vertex; active = new Edge(from, to); --- 449,461 ---- clearConstructors(currentConstructors); ! findCurrentPlane(); ! if (currentPlane == null) { ! currentConstructors = makeAlignedConstructors(vertex, active); ! } else { ! currentConstructors = makeInPlaneConstructors(vertex, ! active, ! currentPlane); ! } ! from = vertex; active = new Edge(from, to); *************** *** 411,415 **** } } ! /** * Round to grid --- 491,528 ---- } } ! ! /** ! * Finds and sets the current plane if one can be found. ! */ ! private void findCurrentPlane() { ! if (edges != null && edges.size() > 1) { ! Iterator it = edges.iterator(); ! Edge edge1 = null; ! Edge edge2 = null; ! edge1 = (Edge)it.next(); ! edge2 = (Edge)it.next();; ! currentPlane = planeFromEdges(edge1, edge2); ! } else if (target instanceof Surface) { ! Surface currentSurface = (Surface)target; ! currentPlane = currentSurface.plane(); ! } ! } ! ! /** ! * Calculates the plane of two edges ! * @param e1 the first edge ! * @param e2 the second edge ! * @return the plane ! */ ! private Plane planeFromEdges(Edge e1, Edge e2) { ! Vertex dir1 = e1.getTo().minus(e1.getFrom()); ! Vertex dir2 = e2.getTo().minus(e2.getFrom()); ! Vertex normal = dir1.cross(dir2); ! return new Plane(normal.getX(), normal.getY(), normal.getZ(), ! (-normal.getX() * e1.getTo().getX() - ! normal.getY() * e1.getTo().getY() - ! normal.getZ() * e1.getTo().getZ())); ! } ! /** * Round to grid *************** *** 784,787 **** --- 897,910 ---- } changed = true; + } else if (e.getKeyCode() == KeyEvent.VK_SPACE) { + showConstructors = !showConstructors; + if (!showConstructors) { + clearConstructors(currentConstructors); + clearConstructors(snapConstructors); + glv.repaint(); + } else { + displayConstructors(currentConstructors); + glv.repaint(); + } } else { super.keyPressed(e); |