Thread: [Bprocessor-commit] gl/src/net/sourceforge/bprocessor/gl/view AbstractView.java,1.71,1.72 View3D.jav
Status: Pre-Alpha
Brought to you by:
henryml
|
From: Michael L. <he...@us...> - 2005-12-11 13:06:52
|
Update of /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/view In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19771/src/net/sourceforge/bprocessor/gl/view Modified Files: AbstractView.java View3D.java Log Message: Different Hit-Detection Index: AbstractView.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/view/AbstractView.java,v retrieving revision 1.71 retrieving revision 1.72 diff -C2 -d -r1.71 -r1.72 *** AbstractView.java 6 Dec 2005 16:53:54 -0000 1.71 --- AbstractView.java 11 Dec 2005 13:06:41 -0000 1.72 *************** *** 930,934 **** Surface s = (Surface)it.next(); pushName(gl, s); ! drawSurface(s, false); popName(gl); } --- 930,934 ---- Surface s = (Surface)it.next(); pushName(gl, s); ! drawSurface(s); popName(gl); } *************** *** 937,941 **** Surface s = (Surface)tempSurfaceIt.next(); pushName(gl, s); ! drawSurface(s, false); popName(gl); } --- 937,941 ---- Surface s = (Surface)tempSurfaceIt.next(); pushName(gl, s); ! drawSurface(s); popName(gl); } *************** *** 1050,1054 **** gl.glPolygonStipple(highlight); Surface s = (Surface) o; ! drawSurface(s, false); gl.glDisable(GL.GL_POLYGON_STIPPLE); } --- 1050,1054 ---- gl.glPolygonStipple(highlight); Surface s = (Surface) o; ! drawSurface(s); gl.glDisable(GL.GL_POLYGON_STIPPLE); } *************** *** 1058,1064 **** * Draw a surface * @param s The surface to draw - * @param flip Flip the surface */ ! private void drawSurface(Surface s, boolean flip) { GLUtesselator tess = glu.gluNewTess(); GLUtesselatorCallback cb = new Callback(); --- 1058,1063 ---- * Draw a surface * @param s The surface to draw */ ! private void drawSurface(Surface s) { GLUtesselator tess = glu.gluNewTess(); GLUtesselatorCallback cb = new Callback(); *************** *** 1079,1095 **** if (norm != null) { norm.scale(1 / norm.length()); ! if (flip) { ! gl.glNormal3d(-norm.getX(), -norm.getY(), -norm.getZ()); ! } else { ! gl.glNormal3d(norm.getX(), norm.getY(), norm.getZ()); ! } } } //drawing the outer contour ! if (flip) { ! drawContourReverse(s, tess); ! } else { ! drawContour(s, tess); ! } //drawing the inner conturs Set innerSurfaces = s.getInnerSurfaces(); --- 1078,1086 ---- if (norm != null) { norm.scale(1 / norm.length()); ! gl.glNormal3d(norm.getX(), norm.getY(), norm.getZ()); } } //drawing the outer contour ! drawContour(s, tess); //drawing the inner conturs Set innerSurfaces = s.getInnerSurfaces(); *************** *** 1196,1200 **** */ private void drawVertexHit(Vertex v) { ! gl.glPointSize(7.0f); gl.glBegin(GL.GL_POINTS); gl.glVertex3d(v.getX(), v.getY(), v.getZ()); --- 1187,1191 ---- */ private void drawVertexHit(Vertex v) { ! gl.glPointSize(10.0f); gl.glBegin(GL.GL_POINTS); gl.glVertex3d(v.getX(), v.getY(), v.getZ()); *************** *** 1275,1300 **** if (isVisible(s)) { if (side == FRONT) { - // TODO check if a surface has a color assigned to - // the front and use that. - - // Where are drawing the front of the surface, so - // we should use the color of the Space associated with the - // back. - Domain back = s.getBackDomain(); gl.glColor3fv(getSpaceColor(back)); } if (side == BACK) { - // TODO check if a surface has a color assigned to - // the back and use that. - - // Where are drawing the back of the surface, so - // we should use the color of the Space associated with the - // front. - Domain front = s.getFrontDomain(); gl.glColor3fv(getSpaceColor(front)); } ! drawSurface(s, false); } } --- 1266,1277 ---- if (isVisible(s)) { if (side == FRONT) { Domain back = s.getBackDomain(); gl.glColor3fv(getSpaceColor(back)); } if (side == BACK) { Domain front = s.getFrontDomain(); gl.glColor3fv(getSpaceColor(front)); } ! drawSurface(s); } } *************** *** 1364,1372 **** } }; - // Iterator iter = surfaces.iterator(); - // while (iter.hasNext()) { - // Surface current = (Surface) iter.next(); - // drawSurface(current); - // } } } --- 1341,1344 ---- *************** *** 1490,1528 **** } - - /** - * Processes the select buffer - * @return the ID of the closest hit and -1 if no hit. - */ - private int processSelectSimple() { - //Processing hits - int bufferOffset = 0; - int names = 0; - long zMax = 0xFFFFFFFFL; - double nearest = 1.0; - int id = -1; - for (int i = 0; i < hits; i++) { - names = selectBuffer.get(bufferOffset); - if (names > 0) { - bufferOffset++; - long z1 = 0xFFFFFFFFL & selectBuffer.get(bufferOffset); - long z2 = 0xFFFFFFFFL & selectBuffer.get(bufferOffset + 1); - double near = (double) z1 / (double) zMax; - double far = (double) z2 / (double) zMax; - - bufferOffset += 2; - if (near < nearest) { - nearest = near; - id = selectBuffer.get(bufferOffset); - } - bufferOffset += names; - } else { - bufferOffset += 3; - } - } - - return id; - } - /** * Processes the select buffer --- 1462,1465 ---- *************** *** 1535,1545 **** --- 1472,1487 ---- long zMax = 0xFFFFFFFFL; double nearest = 1.0; + double nearestConstructor = 1.0; int id = -1; + Edge closestConstructor = null; Object closest = null; Object current = null; + Object candidate = null; Set vertices = new HashSet(); Set edges = new HashSet(); + Set constructors = new HashSet(); + for (int i = 0; i < hits; i++) { names = selectBuffer.get(bufferOffset); *************** *** 1554,1565 **** id = selectBuffer.get(bufferOffset); current = getName(id); if (current instanceof Vertex) { vertices.add(current); } else if (current instanceof Edge) { ! edges.add(current); } ! if (near < nearest) { ! nearest = near; ! closest = current; } bufferOffset += names; --- 1496,1521 ---- id = selectBuffer.get(bufferOffset); current = getName(id); + boolean isConstructor = false; if (current instanceof Vertex) { vertices.add(current); } else if (current instanceof Edge) { ! Edge e = (Edge) current; ! if (e.getConstructor()) { ! isConstructor = true; ! constructors.add(e); ! } else { ! edges.add(current); ! } } ! if (isConstructor) { ! if (near < nearestConstructor) { ! nearestConstructor = near; ! closestConstructor = (Edge) current; ! } ! } else { ! if (near < nearest) { ! nearest = near; ! closest = current; ! } } bufferOffset += names; *************** *** 1568,1603 **** } } if (closest instanceof Surface) { Surface surface = (Surface) closest; CoordinateSystem system = surface.coordinateSystem(); ! // Look for a Vertex { Iterator iter = vertices.iterator(); ! while (iter.hasNext()) { ! // TODO Find the clost point measured as XY distance in ! // the closest surface Vertex v = (Vertex) iter.next(); - // Test if v is in the same plane as the closest surface Vertex vLocal = system.translate(v); if (Math.abs(vLocal.getZ()) < 0.0000000001) { ! selection.add(v); ! return selection; } } } - // Look for an Edge { Iterator iter = edges.iterator(); ! while (iter.hasNext()) { ! // TODO Find the two closest edges measured as XY distance in ! // the closest surface Edge e = (Edge) iter.next(); Vertex from = e.getFrom(); Vertex to = e.getTo(); - // Test if from and to are in the same plane as the closest surface Vertex fromLocal = system.translate(from); Vertex toLocal = system.translate(to); --- 1524,1557 ---- } } + + if (closest instanceof ClippingPlane) { + selection.add(closest); + return selection; + } + if (closest instanceof Surface) { Surface surface = (Surface) closest; CoordinateSystem system = surface.coordinateSystem(); ! { Iterator iter = vertices.iterator(); ! while (iter.hasNext() && (candidate == null)) { Vertex v = (Vertex) iter.next(); Vertex vLocal = system.translate(v); if (Math.abs(vLocal.getZ()) < 0.0000000001) { ! candidate = v; } } } { Iterator iter = edges.iterator(); ! while (iter.hasNext() && (candidate == null)) { Edge e = (Edge) iter.next(); Vertex from = e.getFrom(); Vertex to = e.getTo(); Vertex fromLocal = system.translate(from); Vertex toLocal = system.translate(to); *************** *** 1606,1651 **** if (fromIn && vertices.contains(from)) { ! selection.add(from); ! return selection; } if (toIn && vertices.contains(to)) { ! selection.add(to); ! return selection; } if (fromIn && toIn) { ! selection.add(e); } } } - if (!selection.isEmpty()) { - return selection; - } } if (closest instanceof Edge) { Edge edge = (Edge) closest; if (vertices.contains(edge.getFrom())) { ! selection.add(edge.getFrom()); ! return selection; } if (vertices.contains(edge.getTo())) { ! selection.add(edge.getTo()); ! return selection; } ! selection.add(edge); ! Iterator iter = edges.iterator(); while (iter.hasNext()) { ! Object o = iter.next(); ! if (o != edge) { ! selection.add(o); } } return selection; } - if (closest instanceof ClippingPlane) { - ClippingPlane cp = (ClippingPlane) closest; - } - selection.add(closest); - return selection; } --- 1560,1654 ---- if (fromIn && vertices.contains(from)) { ! candidate = from; ! break; } if (toIn && vertices.contains(to)) { ! candidate = to; ! break; } if (fromIn && toIn) { ! candidate = e; ! break; } } } } if (closest instanceof Edge) { Edge edge = (Edge) closest; if (vertices.contains(edge.getFrom())) { ! candidate = edge.getFrom(); } if (vertices.contains(edge.getTo())) { ! candidate = edge.getTo(); } ! } ! if (candidate != null) { ! closest = candidate; ! } ! ! if (closest == null) { ! selection.add(closestConstructor); ! Iterator iter = constructors.iterator(); while (iter.hasNext()) { ! Edge c = (Edge) iter.next(); ! if (c != closestConstructor) { ! selection.add(c); } } return selection; + } else { + if (closest instanceof Edge) { + selection.add(closest); + if (closestConstructor != null) { + selection.add(closestConstructor); + Iterator iter = constructors.iterator(); + while (iter.hasNext()) { + Edge c = (Edge) iter.next(); + if (c != closestConstructor) { + selection.add(c); + } + } + } + return selection; + } + if (closest instanceof Surface) { + if (nearestConstructor < nearest) { + if (closestConstructor != null) { + selection.add(closestConstructor); + Iterator iter = constructors.iterator(); + while (iter.hasNext()) { + Edge c = (Edge) iter.next(); + if (c != closestConstructor) { + selection.add(c); + } + } + return selection; + } + } else { + Surface surface = (Surface) closest; + CoordinateSystem system = surface.coordinateSystem(); + Iterator iter = constructors.iterator(); + while (iter.hasNext()) { + Edge e = (Edge) iter.next(); + Vertex from = e.getFrom(); + Vertex to = e.getTo(); + Vertex fromLocal = system.translate(from); + Vertex toLocal = system.translate(to); + boolean fromIn = (Math.abs(fromLocal.getZ()) < 0.0000000001); + boolean toIn = (Math.abs(toLocal.getZ()) < 0.0000000001); + + if (fromIn && toIn) { + selection.add(e); + } + } + if (!selection.isEmpty()) { + return selection; + } + } + } + selection.add(closest); + return selection; } } *************** *** 1661,1668 **** this.y = y; - // indicating that I am trying to pick picking = 10; selectMode = ALL; - //repainting to get selection buffer glv.repaint(true); --- 1664,1669 ---- Index: View3D.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/view/View3D.java,v retrieving revision 1.24 retrieving revision 1.25 diff -C2 -d -r1.24 -r1.25 *** View3D.java 1 Dec 2005 10:10:02 -0000 1.24 --- View3D.java 11 Dec 2005 13:06:41 -0000 1.25 *************** *** 85,89 **** if (picking > 0) { int[] viewport = new int[] {0, 0, (int)width, (int)height}; ! glu.gluPickMatrix(x, viewport[3] - y, 5, 5, viewport); } --- 85,89 ---- if (picking > 0) { int[] viewport = new int[] {0, 0, (int)width, (int)height}; ! glu.gluPickMatrix(x, viewport[3] - y, 10, 10, viewport); } |