[Bprocessor-commit] gl/src/net/sourceforge/bprocessor/gl/view View.java,1.69,1.70
Status: Pre-Alpha
Brought to you by:
henryml
|
From: Michael L. <he...@us...> - 2006-03-07 22:31:14
|
Update of /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/view In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18504/src/net/sourceforge/bprocessor/gl/view Modified Files: View.java Log Message: Implemented general mechanism for finding point in model (vertex, point on edge, point on surface, edge intersection, surface/edge intersection, edge midpoint) Index: View.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/view/View.java,v retrieving revision 1.69 retrieving revision 1.70 diff -C2 -d -r1.69 -r1.70 *** View.java 6 Mar 2006 06:51:52 -0000 1.69 --- View.java 7 Mar 2006 22:31:05 -0000 1.70 *************** *** 10,13 **** --- 10,14 ---- import net.sourceforge.bprocessor.gl.tool.SpaceTool; import net.sourceforge.bprocessor.gl.model.ClippingPlane; + import net.sourceforge.bprocessor.gl.model.Intersection; import net.sourceforge.bprocessor.gui.Defaults; import net.sourceforge.bprocessor.gui.Toolbar; *************** *** 1744,1748 **** * @return Selection */ ! private List processSelect(Collection unWantedEntities, boolean intersections) { int bufferOffset = 0; int names = 0; --- 1745,1749 ---- * @return Selection */ ! private Object processSelect(Collection unWantedEntities, boolean intersections) { int bufferOffset = 0; int names = 0; *************** *** 1762,1767 **** Collection edges = new HashSet(); - List result = new LinkedList(); - for (int i = 0; i < hits; i++) { names = selectBuffer.get(bufferOffset); --- 1763,1766 ---- *************** *** 1852,1911 **** } ! ! if (object != null) { ! result.add(object); ! } else { if (vertex != null) { ! result.add(vertex); } else { if (edge != null) { - if (intersections) { - Vertex intersection = null; - Transformation transformation = this.transformation(); - - Edge e1 = edge; - Vertex v1 = e1.getTo().minus(e1.getFrom()); - edges.remove(edge); - Iterator iter = edges.iterator(); ! while (iter.hasNext()) { ! Edge e2 = (Edge) iter.next(); ! Vertex v2 = e2.getTo().minus(e2.getFrom()); ! Vertex cross = v1.cross(v2); ! if (!cross.isZero()) { ! Edge intersect = e1.intersection(e2); ! if (intersect != null) { ! if (intersect.getLength() < 0.0000001) { ! intersection = intersect.getFrom(); } } } } ! if (intersection != null) { ! Vertex projected = transformation.project(intersection); ! double dx = x - projected.getX(); ! double dy = (height - y) - projected.getY(); ! double distance = Math.sqrt(dx * dx + dy * dy); ! if (distance < 6) { ! result.add(intersection); ! } else { ! result.add(edge); ! } ! } else { ! result.add(edge); } - } else { - result.add(edge); - edges.remove(edge); - result.addAll(edges); } } else { if (surface != null) { ! result.add(surface); } } } } ! return result; } --- 1851,1939 ---- } ! if (intersections) { ! Transformation transformation = this.transformation(); ! Vertex near = new Vertex(x, height - y, 0.0); ! Vertex far = new Vertex(x, height - y, 1.0); ! Edge ray = new Edge(near, far); ! ray = transformation.unProject(ray); if (vertex != null) { ! return new Intersection(vertex, Intersection.VERTEX, null); } else { if (edge != null) { ! Edge e1 = edge; ! Vertex v1 = e1.getTo().minus(e1.getFrom()); ! edges.remove(edge); ! Iterator iter = edges.iterator(); ! ! while (iter.hasNext()) { ! Edge e2 = (Edge) iter.next(); ! Vertex v2 = e2.getTo().minus(e2.getFrom()); ! Vertex cross = v1.cross(v2); ! if (!cross.isZero()) { ! Edge intersect = e1.intersection(e2); ! if (intersect != null) { ! if (intersect.getLength() < 0.0000001) { ! Vertex i = intersect.getFrom(); ! Vertex projected = transformation.project(i); ! double dx = x - projected.getX(); ! double dy = (height - y) - projected.getY(); ! double distance = Math.sqrt(dx * dx + dy * dy); ! if (distance < 6) { ! return new Intersection(i, Intersection.EDGE_INTERSECTION, edge); } } } } ! } ! ! { ! Vertex m = edge.getFrom().add(edge.getTo()); ! m.scale(0.5); ! Vertex projected = transformation.project(m); ! double dx = x - projected.getX(); ! double dy = (height - y) - projected.getY(); ! double distance = Math.sqrt(dx * dx + dy * dy); ! if (distance < 6) { ! return new Intersection(m, Intersection.EDGE_MIDPOINT, edge); } } + + { + Edge intersect = edge.intersection(ray); + Vertex intersection = intersect.getFrom(); + return new Intersection(intersection, Intersection.EDGE, edge); + } + } else { if (surface != null) { ! Plane plane = surface.plane(); ! Vertex intersection = plane.intersection(ray); ! return new Intersection(intersection, Intersection.SURFACE, surface); ! } else { ! Plane xy = new Plane(0, 0, 1, 0); ! Vertex intersection = xy.intersection(ray); ! if (intersection != null) { ! // FIXME The plane intersection should take care ! // of the following round off ! intersection.setZ(0.0); ! return new Intersection(intersection, Intersection.PLANE_INTERSECTION, null); ! } } } } + } else { + if (object != null) { + return object; + } else if (vertex != null) { + return vertex; + } else if (edge != null) { + return edge; + } else if (surface != null) { + return surface; + } } ! ! return null; } *************** *** 1922,1926 **** * @return entity under the point. */ ! public List getObjectAtPoint(double x, double y, Collection unWantedEntities, boolean intersections) { this.x = x; --- 1950,1954 ---- * @return entity under the point. */ ! public Object getObjectAtPoint(double x, double y, Collection unWantedEntities, boolean intersections) { this.x = x; *************** *** 1931,1937 **** glv.repaint(true); ! List selection = processSelect(unWantedEntities, intersections); clearNames(); ! return selection; } --- 1959,1965 ---- glv.repaint(true); ! Object object = processSelect(unWantedEntities, intersections); clearNames(); ! return object; } *************** *** 1942,1946 **** * @return The object under the point, null if no object is there */ ! public List getObjectAtPoint(double x, double y) { return getObjectAtPoint(x, y, new HashSet(), false); } --- 1970,1974 ---- * @return The object under the point, null if no object is there */ ! public Object getObjectAtPoint(double x, double y) { return getObjectAtPoint(x, y, new HashSet(), false); } *************** *** 2014,2018 **** glv.repaint(true); ! List selection = processSelect(new HashSet(), false); clearNames(); return selection; --- 2042,2050 ---- glv.repaint(true); ! List selection = new LinkedList(); ! Object object = processSelect(new HashSet(), false); ! if (object != null) { ! selection.add(object); ! } clearNames(); return selection; *************** *** 2033,2037 **** glv.repaint(true); ! List selection = processSelect(new HashSet(), false); clearNames(); return selection; --- 2065,2073 ---- glv.repaint(true); ! List selection = new LinkedList(); ! Object object = processSelect(new HashSet(), false); ! if (object != null) { ! selection.add(object); ! } clearNames(); return selection; |