diff options
Diffstat (limited to 'src')
22 files changed, 1389 insertions, 790 deletions
diff --git a/src/classes/share/javax/media/j3d/CompressedGeometryRetained.java b/src/classes/share/javax/media/j3d/CompressedGeometryRetained.java index 737fa4d..62a471a 100644 --- a/src/classes/share/javax/media/j3d/CompressedGeometryRetained.java +++ b/src/classes/share/javax/media/j3d/CompressedGeometryRetained.java @@ -316,15 +316,16 @@ class CompressedGeometryRetained extends GeometryRetained { gdr.getBoundingBox(geoBounds) ; return pickGeometry ; } - + // // The following intersect() methods are used to implement geometry-based // picking and collision. // - boolean intersect(PickShape pickShape, PickInfo.IntersectionInfo iInfo, int flags, Point3d iPnt) { - GeometryRetained geom = getPickGeometry() ; - return (geom != null ? - geom.intersect(pickShape, iInfo, flags, iPnt) : false); + boolean intersect(PickShape pickShape, PickInfo pickInfo, int flags, Point3d iPnt, + GeometryRetained geom, int geomIndex) { + GeometryRetained geomR = getPickGeometry() ; + return (geomR != null ? + geomR.intersect(pickShape, pickInfo, flags, iPnt, geom, geomIndex) : false); } boolean intersect(Bounds targetBound) { diff --git a/src/classes/share/javax/media/j3d/GeometryRetained.java b/src/classes/share/javax/media/j3d/GeometryRetained.java index 1f02d17..c322d17 100644 --- a/src/classes/share/javax/media/j3d/GeometryRetained.java +++ b/src/classes/share/javax/media/j3d/GeometryRetained.java @@ -229,11 +229,49 @@ abstract class GeometryRetained extends NodeComponentRetained { return 0 ; } - abstract boolean intersect(PickShape pickShape, PickInfo.IntersectionInfo iInfo, int flags, Point3d iPnt); + // Issue 199 -- Chien + abstract boolean intersect(PickShape pickShape, PickInfo pickInfo, int flags, Point3d iPnt, + GeometryRetained geom, int geomIndex); + + // Old stuff -- Chien + //abstract boolean intersect(PickShape pickShape, PickInfo.IntersectionInfo iInfo, int flags, Point3d iPnt); + abstract boolean intersect(Bounds targetBound); abstract boolean intersect(Point3d[] pnts); abstract boolean intersect(Transform3D thisToOtherVworld, GeometryRetained geom); + void storeInterestData(PickInfo pickInfo, int flags, GeometryRetained geom, int geomIndex, + int[] vtxIndexArr, Point3d iPnt, double dist) { + + PickInfo.IntersectionInfo iInfo = null; + + if((flags & PickInfo.CLOSEST_GEOM_INFO) != 0) { + PickInfo.IntersectionInfo iInfoArr[] = pickInfo.getIntersectionInfos(); + if((iInfoArr == null) || (iInfoArr.length == 0)) { + iInfo = pickInfo.createIntersectionInfo(); + pickInfo.insertIntersectionInfo(iInfo); + } + else { + assert(iInfoArr.length == 1); + iInfo = iInfoArr[0]; + } + } + else if((flags & PickInfo.ALL_GEOM_INFO) != 0) { + iInfo = pickInfo.createIntersectionInfo(); + pickInfo.insertIntersectionInfo(iInfo); + } + else { + assert(false); + } + // This only set the reference to geometry.source. + iInfo.setGeometry((Geometry) geom.source); + // The rest are by copy. + iInfo.setGeometryIndex(geomIndex); + iInfo.setDistance(dist); + iInfo.setIntersectionPoint(iPnt); + iInfo.setVertexIndices(vtxIndexArr); + } + boolean intersect(Transform3D thisLocalToVworld, Transform3D otherLocalToVworld, GeometryRetained geom) { Transform3D tg = VirtualUniverse.mc.getTransform3D(null); diff --git a/src/classes/share/javax/media/j3d/IndexedLineArrayRetained.java b/src/classes/share/javax/media/j3d/IndexedLineArrayRetained.java index bb9731f..c62c6c7 100644 --- a/src/classes/share/javax/media/j3d/IndexedLineArrayRetained.java +++ b/src/classes/share/javax/media/j3d/IndexedLineArrayRetained.java @@ -26,26 +26,27 @@ class IndexedLineArrayRetained extends IndexedGeometryArrayRetained { this.geoType = GEO_TYPE_INDEXED_LINE_SET; } - boolean intersect(PickShape pickShape, PickInfo.IntersectionInfo iInfo, int flags, Point3d iPnt) { + boolean intersect(PickShape pickShape, PickInfo pickInfo, int flags, Point3d iPnt, + GeometryRetained geom, int geomIndex) { Point3d pnts[] = new Point3d[2]; double sdist[] = new double[1]; double minDist = Double.MAX_VALUE; double x = 0, y = 0, z = 0; - int count = 0; - int minICount = 0; int i = ((vertexFormat & GeometryArray.BY_REFERENCE) == 0 ? initialVertexIndex : initialCoordIndex); pnts[0] = new Point3d(); pnts[1] = new Point3d(); + int[] vtxIndexArr = new int[2]; switch (pickShape.getPickType()) { case PickShape.PICKRAY: PickRay pickRay= (PickRay) pickShape; while (i < validVertexCount) { - getVertexData(indexCoord[i++], pnts[0]); - getVertexData(indexCoord[i++], pnts[1]); - count += 2; + for(int k=0; k<2; k++) { + vtxIndexArr[k] = indexCoord[i]; + getVertexData(indexCoord[i++], pnts[k]); + } if (intersectLineAndRay(pnts[0], pnts[1], pickRay.origin, pickRay.direction, sdist, iPnt)) { @@ -54,11 +55,18 @@ class IndexedLineArrayRetained extends IndexedGeometryArrayRetained { } if (sdist[0] < minDist) { minDist = sdist[0]; - minICount = count; x = iPnt.x; y = iPnt.y; z = iPnt.z; + if((flags & PickInfo.CLOSEST_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } } + if((flags & PickInfo.ALL_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } } } break; @@ -70,9 +78,10 @@ class IndexedLineArrayRetained extends IndexedGeometryArrayRetained { pickSegment.end.z - pickSegment.start.z); while (i < validVertexCount) { - getVertexData(indexCoord[i++], pnts[0]); - getVertexData(indexCoord[i++], pnts[1]); - count += 2; + for(int k=0; k<2; k++) { + vtxIndexArr[k] = indexCoord[i]; + getVertexData(indexCoord[i++], pnts[k]); + } if (intersectLineAndRay(pnts[0], pnts[1], pickSegment.start, dir, sdist, iPnt) && @@ -82,11 +91,18 @@ class IndexedLineArrayRetained extends IndexedGeometryArrayRetained { } if (sdist[0] < minDist) { minDist = sdist[0]; - minICount = count; x = iPnt.x; y = iPnt.y; z = iPnt.z; + if((flags & PickInfo.CLOSEST_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } } + if((flags & PickInfo.ALL_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } } } break; @@ -95,43 +111,58 @@ class IndexedLineArrayRetained extends IndexedGeometryArrayRetained { ((PickBounds) pickShape).bounds; while (i < validVertexCount) { - getVertexData(indexCoord[i++], pnts[0]); - getVertexData(indexCoord[i++], pnts[1]); - count += 2; + for(int k=0; k<2; k++) { + vtxIndexArr[k] = indexCoord[i]; + getVertexData(indexCoord[i++], pnts[k]); + } if (intersectBoundingBox(pnts, bbox, sdist, iPnt)) { if (flags == 0) { return true; } if (sdist[0] < minDist) { minDist = sdist[0]; - minICount = count; x = iPnt.x; y = iPnt.y; z = iPnt.z; + if((flags & PickInfo.CLOSEST_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } } + if((flags & PickInfo.ALL_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } } } - break; case PickShape.PICKBOUNDINGSPHERE: BoundingSphere bsphere = (BoundingSphere) ((PickBounds) pickShape).bounds; while (i < validVertexCount) { - getVertexData(indexCoord[i++], pnts[0]); - getVertexData(indexCoord[i++], pnts[1]); - count += 2; + for(int k=0; k<2; k++) { + vtxIndexArr[k] = indexCoord[i]; + getVertexData(indexCoord[i++], pnts[k]); + } if (intersectBoundingSphere(pnts, bsphere, sdist, iPnt)) { if (flags == 0) { return true; } if (sdist[0] < minDist) { minDist = sdist[0]; - minICount = count; x = iPnt.x; y = iPnt.y; z = iPnt.z; + if((flags & PickInfo.CLOSEST_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } } + if((flags & PickInfo.ALL_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } } } break; @@ -140,20 +171,28 @@ class IndexedLineArrayRetained extends IndexedGeometryArrayRetained { ((PickBounds) pickShape).bounds; while (i < validVertexCount) { - getVertexData(indexCoord[i++], pnts[0]); - getVertexData(indexCoord[i++], pnts[1]); - count += 2; + for(int k=0; k<2; k++) { + vtxIndexArr[k] = indexCoord[i]; + getVertexData(indexCoord[i++], pnts[k]); + } if (intersectBoundingPolytope(pnts, bpolytope, sdist, iPnt)) { if (flags == 0) { return true; } if (sdist[0] < minDist) { minDist = sdist[0]; - minICount = count; x = iPnt.x; y = iPnt.y; z = iPnt.z; + if((flags & PickInfo.CLOSEST_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } } + if((flags & PickInfo.ALL_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } } } break; @@ -161,20 +200,28 @@ class IndexedLineArrayRetained extends IndexedGeometryArrayRetained { PickCylinder pickCylinder= (PickCylinder) pickShape; while (i < validVertexCount) { - getVertexData(indexCoord[i++], pnts[0]); - getVertexData(indexCoord[i++], pnts[1]); - count += 2; + for(int k=0; k<2; k++) { + vtxIndexArr[k] = indexCoord[i]; + getVertexData(indexCoord[i++], pnts[k]); + } if (intersectCylinder(pnts, pickCylinder, sdist, iPnt)) { if (flags == 0) { return true; } if (sdist[0] < minDist) { minDist = sdist[0]; - minICount = count; x = iPnt.x; y = iPnt.y; z = iPnt.z; + if((flags & PickInfo.CLOSEST_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } } + if((flags & PickInfo.ALL_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } } } break; @@ -182,20 +229,28 @@ class IndexedLineArrayRetained extends IndexedGeometryArrayRetained { PickCone pickCone= (PickCone) pickShape; while (i < validVertexCount) { - getVertexData(indexCoord[i++], pnts[0]); - getVertexData(indexCoord[i++], pnts[1]); - count += 2; + for(int k=0; k<2; k++) { + vtxIndexArr[k] = indexCoord[i]; + getVertexData(indexCoord[i++], pnts[k]); + } if (intersectCone(pnts, pickCone, sdist, iPnt)) { if (flags == 0) { return true; } if (sdist[0] < minDist) { minDist = sdist[0]; - minICount = count; x = iPnt.x; y = iPnt.y; z = iPnt.z; + if((flags & PickInfo.CLOSEST_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } } + if((flags & PickInfo.ALL_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } } } break; @@ -207,14 +262,6 @@ class IndexedLineArrayRetained extends IndexedGeometryArrayRetained { } if (minDist < Double.MAX_VALUE) { - assert(minICount >=2); - int[] vertexIndices = iInfo.getVertexIndices(); - if (vertexIndices == null) { - vertexIndices = new int[2]; - iInfo.setVertexIndices(vertexIndices); - } - vertexIndices[0] = minICount - 2; - vertexIndices[1] = minICount - 1; iPnt.x = x; iPnt.y = y; iPnt.z = z; diff --git a/src/classes/share/javax/media/j3d/IndexedLineStripArrayRetained.java b/src/classes/share/javax/media/j3d/IndexedLineStripArrayRetained.java index 8791b9f..b518093 100644 --- a/src/classes/share/javax/media/j3d/IndexedLineStripArrayRetained.java +++ b/src/classes/share/javax/media/j3d/IndexedLineStripArrayRetained.java @@ -29,15 +29,16 @@ class IndexedLineStripArrayRetained extends IndexedGeometryStripArrayRetained { geoType = GEO_TYPE_INDEXED_LINE_STRIP_SET; } - boolean intersect(PickShape pickShape, PickInfo.IntersectionInfo iInfo, int flags, Point3d iPnt) { + boolean intersect(PickShape pickShape, PickInfo pickInfo, int flags, Point3d iPnt, + GeometryRetained geom, int geomIndex) { Point3d pnts[] = new Point3d[2]; double sdist[] = new double[1]; double minDist = Double.MAX_VALUE; double x = 0, y = 0, z = 0; int scount, j, i = 0; int count = 0; - int minICount = 0; - + int[] vtxIndexArr = new int[2]; + pnts[0] = new Point3d(); pnts[1] = new Point3d(); @@ -45,11 +46,12 @@ class IndexedLineStripArrayRetained extends IndexedGeometryStripArrayRetained { case PickShape.PICKRAY: PickRay pickRay= (PickRay) pickShape; - while (i < stripIndexCounts.length) { + while (i < stripIndexCounts.length) { + vtxIndexArr[0] = indexCoord[count]; getVertexData(indexCoord[count++], pnts[0]); scount = stripIndexCounts[i++]; - - for (j=1; j < scount; j++) { + for (j=1; j < scount; j++) { + vtxIndexArr[1] = indexCoord[count]; getVertexData(indexCoord[count++], pnts[1]); if (intersectLineAndRay(pnts[0], pnts[1], pickRay.origin, pickRay.direction, sdist, @@ -59,13 +61,21 @@ class IndexedLineStripArrayRetained extends IndexedGeometryStripArrayRetained { } if (sdist[0] < minDist) { minDist = sdist[0]; - minICount = count; x = iPnt.x; y = iPnt.y; z = iPnt.z; - } - } + if((flags & PickInfo.CLOSEST_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } + } + if((flags & PickInfo.ALL_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } + } pnts[0].set(pnts[1]); + vtxIndexArr[0] = vtxIndexArr[1]; } } break; @@ -77,10 +87,11 @@ class IndexedLineStripArrayRetained extends IndexedGeometryStripArrayRetained { pickSegment.end.z - pickSegment.start.z); while (i < stripIndexCounts.length) { + vtxIndexArr[0] = indexCoord[count]; getVertexData(indexCoord[count++], pnts[0]); scount = stripIndexCounts[i++]; - for (j=1; j < scount; j++) { + vtxIndexArr[1] = indexCoord[count]; getVertexData(indexCoord[count++], pnts[1]); if (intersectLineAndRay(pnts[0], pnts[1], pickSegment.start, @@ -91,13 +102,21 @@ class IndexedLineStripArrayRetained extends IndexedGeometryStripArrayRetained { } if (sdist[0] < minDist) { minDist = sdist[0]; - minICount = count; x = iPnt.x; y = iPnt.y; z = iPnt.z; - } - } - pnts[0].set(pnts[1]); + if((flags & PickInfo.CLOSEST_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } + } + if((flags & PickInfo.ALL_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } + } + pnts[0].set(pnts[1]); + vtxIndexArr[0] = vtxIndexArr[1]; } } break; @@ -106,53 +125,68 @@ class IndexedLineStripArrayRetained extends IndexedGeometryStripArrayRetained { ((PickBounds) pickShape).bounds; while (i < stripIndexCounts.length) { + vtxIndexArr[0] = indexCoord[count]; getVertexData(indexCoord[count++], pnts[0]); scount = stripIndexCounts[i++]; - for (j=1; j < scount; j++) { + vtxIndexArr[1] = indexCoord[count]; getVertexData(indexCoord[count++], pnts[1]); - if (intersectBoundingBox(pnts, bbox, sdist, iPnt)) { if (flags == 0) { return true; } if (sdist[0] < minDist) { minDist = sdist[0]; - minICount = count; x = iPnt.x; y = iPnt.y; z = iPnt.z; - } - } - pnts[0].set(pnts[1]); + if((flags & PickInfo.CLOSEST_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } + } + if((flags & PickInfo.ALL_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } + } + pnts[0].set(pnts[1]); + vtxIndexArr[0] = vtxIndexArr[1]; } } - break; case PickShape.PICKBOUNDINGSPHERE: BoundingSphere bsphere = (BoundingSphere) ((PickBounds) pickShape).bounds; while (i < stripIndexCounts.length) { + vtxIndexArr[0] = indexCoord[count]; getVertexData(indexCoord[count++], pnts[0]); scount = stripIndexCounts[i++]; - - for (j=1; j < scount; j++) { + for (j=1; j < scount; j++) { + vtxIndexArr[1] = indexCoord[count]; getVertexData(indexCoord[count++], pnts[1]); - if (intersectBoundingSphere(pnts, bsphere, sdist, iPnt)) { if (flags == 0) { return true; } if (sdist[0] < minDist) { minDist = sdist[0]; - minICount = count; x = iPnt.x; y = iPnt.y; z = iPnt.z; - } - } + if((flags & PickInfo.CLOSEST_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } + } + if((flags & PickInfo.ALL_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } + } pnts[0].set(pnts[1]); + vtxIndexArr[0] = vtxIndexArr[1]; } } break; @@ -161,25 +195,33 @@ class IndexedLineStripArrayRetained extends IndexedGeometryStripArrayRetained { ((PickBounds) pickShape).bounds; while (i < stripIndexCounts.length) { + vtxIndexArr[0] = indexCoord[count]; getVertexData(indexCoord[count++], pnts[0]); scount = stripIndexCounts[i++]; - - for (j=1; j < scount; j++) { + for (j=1; j < scount; j++) { + vtxIndexArr[1] = indexCoord[count]; getVertexData(indexCoord[count++], pnts[1]); - if (intersectBoundingPolytope(pnts, bpolytope, sdist, iPnt)) { if (flags == 0) { return true; } if (sdist[0] < minDist) { minDist = sdist[0]; - minICount = count; x = iPnt.x; y = iPnt.y; z = iPnt.z; - } - } + if((flags & PickInfo.CLOSEST_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } + } + if((flags & PickInfo.ALL_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } + } pnts[0].set(pnts[1]); + vtxIndexArr[0] = vtxIndexArr[1]; } } break; @@ -187,25 +229,33 @@ class IndexedLineStripArrayRetained extends IndexedGeometryStripArrayRetained { PickCylinder pickCylinder= (PickCylinder) pickShape; while (i < stripIndexCounts.length) { + vtxIndexArr[0] = indexCoord[count]; getVertexData(indexCoord[count++], pnts[0]); scount = stripIndexCounts[i++]; - - for (j=1; j < scount; j++) { + for (j=1; j < scount; j++) { + vtxIndexArr[1] = indexCoord[count]; getVertexData(indexCoord[count++], pnts[1]); - if (intersectCylinder(pnts, pickCylinder, sdist, iPnt)) { if (flags == 0) { return true; } if (sdist[0] < minDist) { minDist = sdist[0]; - minICount = count; x = iPnt.x; y = iPnt.y; z = iPnt.z; - } - } + if((flags & PickInfo.CLOSEST_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } + } + if((flags & PickInfo.ALL_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } + } pnts[0].set(pnts[1]); + vtxIndexArr[0] = vtxIndexArr[1]; } } break; @@ -213,25 +263,33 @@ class IndexedLineStripArrayRetained extends IndexedGeometryStripArrayRetained { PickCone pickCone= (PickCone) pickShape; while (i < stripIndexCounts.length) { + vtxIndexArr[0] = indexCoord[count]; getVertexData(indexCoord[count++], pnts[0]); scount = stripIndexCounts[i++]; - - for (j=1; j < scount; j++) { + for (j=1; j < scount; j++) { + vtxIndexArr[1] = indexCoord[count]; getVertexData(indexCoord[count++], pnts[1]); - if (intersectCone(pnts, pickCone, sdist, iPnt)) { if (flags == 0) { return true; } if (sdist[0] < minDist) { minDist = sdist[0]; - minICount = count; x = iPnt.x; y = iPnt.y; z = iPnt.z; - } - } + if((flags & PickInfo.CLOSEST_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } + } + if((flags & PickInfo.ALL_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } + } pnts[0].set(pnts[1]); + vtxIndexArr[0] = vtxIndexArr[1]; } } break; @@ -243,14 +301,6 @@ class IndexedLineStripArrayRetained extends IndexedGeometryStripArrayRetained { } if (minDist < Double.MAX_VALUE) { - assert(minICount >=2); - int[] vertexIndices = iInfo.getVertexIndices(); - if (vertexIndices == null) { - vertexIndices = new int[2]; - iInfo.setVertexIndices(vertexIndices); - } - vertexIndices[0] = minICount - 2; - vertexIndices[1] = minICount - 1; iPnt.x = x; iPnt.y = y; iPnt.z = z; diff --git a/src/classes/share/javax/media/j3d/IndexedPointArrayRetained.java b/src/classes/share/javax/media/j3d/IndexedPointArrayRetained.java index f7289c5..508676c 100644 --- a/src/classes/share/javax/media/j3d/IndexedPointArrayRetained.java +++ b/src/classes/share/javax/media/j3d/IndexedPointArrayRetained.java @@ -25,14 +25,15 @@ class IndexedPointArrayRetained extends IndexedGeometryArrayRetained { this.geoType = GEO_TYPE_INDEXED_POINT_SET; } - boolean intersect(PickShape pickShape, PickInfo.IntersectionInfo iInfo, int flags, Point3d iPnt) { - double sdist[] = new double[1]; + boolean intersect(PickShape pickShape, PickInfo pickInfo, int flags, Point3d iPnt, + GeometryRetained geom, int geomIndex) { + double sdist[] = new double[1]; double minDist = Double.MAX_VALUE; double x = 0, y = 0, z = 0; - int count = 0; - int minICount = 0; Point3d pnt = new Point3d(); - int i = ((vertexFormat & GeometryArray.BY_REFERENCE) == 0 ? + int[] vtxIndexArr = new int[1]; + + int i = ((vertexFormat & GeometryArray.BY_REFERENCE) == 0 ? initialVertexIndex : initialCoordIndex); switch (pickShape.getPickType()) { @@ -40,8 +41,8 @@ class IndexedPointArrayRetained extends IndexedGeometryArrayRetained { PickRay pickRay= (PickRay) pickShape; while (i < validVertexCount) { + vtxIndexArr[0] = indexCoord[i]; getVertexData(indexCoord[i++], pnt); - count++; if (intersectPntAndRay(pnt, pickRay.origin, pickRay.direction, sdist)) { if (flags == 0) { @@ -49,11 +50,18 @@ class IndexedPointArrayRetained extends IndexedGeometryArrayRetained { } if (sdist[0] < minDist) { minDist = sdist[0]; - minICount = count; x = pnt.x; y = pnt.y; z = pnt.z; + if((flags & PickInfo.CLOSEST_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } } + if((flags & PickInfo.ALL_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } } } break; @@ -65,8 +73,8 @@ class IndexedPointArrayRetained extends IndexedGeometryArrayRetained { pickSegment.end.z - pickSegment.start.z); while (i < validVertexCount) { + vtxIndexArr[0] = indexCoord[i]; getVertexData(indexCoord[i++], pnt); - count++; if (intersectPntAndRay(pnt, pickSegment.start, dir, sdist) && (sdist[0] <= 1.0)) { @@ -75,11 +83,18 @@ class IndexedPointArrayRetained extends IndexedGeometryArrayRetained { } if (sdist[0] < minDist) { minDist = sdist[0]; - minICount = count; x = pnt.x; y = pnt.y; z = pnt.z; + if((flags & PickInfo.CLOSEST_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } } + if((flags & PickInfo.ALL_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } } } break; @@ -89,8 +104,8 @@ class IndexedPointArrayRetained extends IndexedGeometryArrayRetained { Bounds bounds = ((PickBounds) pickShape).bounds; while (i < validVertexCount) { + vtxIndexArr[0] = indexCoord[i]; getVertexData(indexCoord[i++], pnt); - count++; if (bounds.intersect(pnt)) { if (flags == 0) { return true; @@ -98,11 +113,18 @@ class IndexedPointArrayRetained extends IndexedGeometryArrayRetained { sdist[0] = pickShape.distance(pnt); if (sdist[0] < minDist) { minDist = sdist[0]; - minICount = count; x = pnt.x; y = pnt.y; z = pnt.z; + if((flags & PickInfo.CLOSEST_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } } + if((flags & PickInfo.ALL_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } } } break; @@ -110,19 +132,26 @@ class IndexedPointArrayRetained extends IndexedGeometryArrayRetained { PickCylinder pickCylinder= (PickCylinder) pickShape; while (i < validVertexCount) { + vtxIndexArr[0] = indexCoord[i]; getVertexData(indexCoord[i++], pnt); - count++; if (intersectCylinder(pnt, pickCylinder, sdist)) { if (flags == 0) { return true; } if (sdist[0] < minDist) { minDist = sdist[0]; - minICount = count; x = pnt.x; y = pnt.y; z = pnt.z; + if((flags & PickInfo.CLOSEST_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } } + if((flags & PickInfo.ALL_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } } } break; @@ -130,19 +159,26 @@ class IndexedPointArrayRetained extends IndexedGeometryArrayRetained { PickCone pickCone= (PickCone) pickShape; while (i < validVertexCount) { + vtxIndexArr[0] = indexCoord[i]; getVertexData(indexCoord[i++], pnt); - count++; if (intersectCone(pnt, pickCone, sdist)) { if (flags == 0) { return true; } if (sdist[0] < minDist) { minDist = sdist[0]; - minICount = count; x = pnt.x; y = pnt.y; z = pnt.z; + if((flags & PickInfo.CLOSEST_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } } + if((flags & PickInfo.ALL_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } } } break; @@ -154,13 +190,6 @@ class IndexedPointArrayRetained extends IndexedGeometryArrayRetained { } if (minDist < Double.MAX_VALUE) { - assert(minICount >=1); - int[] vertexIndices = iInfo.getVertexIndices(); - if (vertexIndices == null) { - vertexIndices = new int[1]; - iInfo.setVertexIndices(vertexIndices); - } - vertexIndices[0] = minICount - 1; iPnt.x = x; iPnt.y = y; iPnt.z = z; diff --git a/src/classes/share/javax/media/j3d/IndexedQuadArrayRetained.java b/src/classes/share/javax/media/j3d/IndexedQuadArrayRetained.java index 355f471..ff0fae9 100644 --- a/src/classes/share/javax/media/j3d/IndexedQuadArrayRetained.java +++ b/src/classes/share/javax/media/j3d/IndexedQuadArrayRetained.java @@ -27,14 +27,15 @@ class IndexedQuadArrayRetained extends IndexedGeometryArrayRetained { this.geoType = GEO_TYPE_INDEXED_QUAD_SET; } - boolean intersect(PickShape pickShape, PickInfo.IntersectionInfo iInfo, int flags, Point3d iPnt) { + boolean intersect(PickShape pickShape, PickInfo pickInfo, int flags, Point3d iPnt, + GeometryRetained geom, int geomIndex) { Point3d pnts[] = new Point3d[4]; double sdist[] = new double[1]; double minDist = Double.MAX_VALUE; double x = 0, y = 0, z = 0; - int count = 0; - int minICount = 0; - int i = ((vertexFormat & GeometryArray.BY_REFERENCE) == 0 ? + int[] vtxIndexArr = new int[4]; + + int i = ((vertexFormat & GeometryArray.BY_REFERENCE) == 0 ? initialVertexIndex : initialCoordIndex); pnts[0] = new Point3d(); pnts[1] = new Point3d(); @@ -46,22 +47,28 @@ class IndexedQuadArrayRetained extends IndexedGeometryArrayRetained { PickRay pickRay= (PickRay) pickShape; while (i < validVertexCount) { - getVertexData(indexCoord[i++], pnts[0]); - getVertexData(indexCoord[i++], pnts[1]); - getVertexData(indexCoord[i++], pnts[2]); - getVertexData(indexCoord[i++], pnts[3]); - count += 4; + for(int j=0; j<4; j++) { + vtxIndexArr[j] = indexCoord[i]; + getVertexData(indexCoord[i++], pnts[j]); + } if (intersectRay(pnts, pickRay, sdist, iPnt)) { if (flags == 0) { return true; } if (sdist[0] < minDist) { minDist = sdist[0]; - minICount = count; x = iPnt.x; y = iPnt.y; z = iPnt.z; + if((flags & PickInfo.CLOSEST_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } } + if((flags & PickInfo.ALL_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } } } break; @@ -69,11 +76,10 @@ class IndexedQuadArrayRetained extends IndexedGeometryArrayRetained { PickSegment pickSegment = (PickSegment) pickShape; while (i < validVertexCount) { - getVertexData(indexCoord[i++], pnts[0]); - getVertexData(indexCoord[i++], pnts[1]); - getVertexData(indexCoord[i++], pnts[2]); - getVertexData(indexCoord[i++], pnts[3]); - count += 4; + for(int j=0; j<4; j++) { + vtxIndexArr[j] = indexCoord[i]; + getVertexData(indexCoord[i++], pnts[j]); + } if (intersectSegment(pnts, pickSegment.start, pickSegment.end, sdist, iPnt)) { if (flags == 0) { @@ -81,10 +87,17 @@ class IndexedQuadArrayRetained extends IndexedGeometryArrayRetained { } if (sdist[0] < minDist) { minDist = sdist[0]; - minICount = count; x = iPnt.x; y = iPnt.y; z = iPnt.z; + if((flags & PickInfo.CLOSEST_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } + } + if((flags & PickInfo.ALL_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); } } } @@ -93,21 +106,27 @@ class IndexedQuadArrayRetained extends IndexedGeometryArrayRetained { BoundingBox bbox = (BoundingBox) ((PickBounds) pickShape).bounds; while (i < validVertexCount) { - getVertexData(indexCoord[i++], pnts[0]); - getVertexData(indexCoord[i++], pnts[1]); - getVertexData(indexCoord[i++], pnts[2]); - getVertexData(indexCoord[i++], pnts[3]); - count += 4; + for(int j=0; j<4; j++) { + vtxIndexArr[j] = indexCoord[i]; + getVertexData(indexCoord[i++], pnts[j]); + } if (intersectBoundingBox(pnts, bbox, sdist, iPnt)) { if (flags == 0) { return true; } if (sdist[0] < minDist) { minDist = sdist[0]; - minICount = count; x = iPnt.x; y = iPnt.y; z = iPnt.z; + if((flags & PickInfo.CLOSEST_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } + } + if((flags & PickInfo.ALL_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); } } } @@ -116,21 +135,27 @@ class IndexedQuadArrayRetained extends IndexedGeometryArrayRetained { BoundingSphere bsphere = (BoundingSphere) ((PickBounds) pickShape).bounds; while (i < validVertexCount) { - getVertexData(indexCoord[i++], pnts[0]); - getVertexData(indexCoord[i++], pnts[1]); - getVertexData(indexCoord[i++], pnts[2]); - getVertexData(indexCoord[i++], pnts[3]); - count += 4; + for(int j=0; j<4; j++) { + vtxIndexArr[j] = indexCoord[i]; + getVertexData(indexCoord[i++], pnts[j]); + } if (intersectBoundingSphere(pnts, bsphere, sdist, iPnt)) { if (flags == 0) { return true; } if (sdist[0] < minDist) { minDist = sdist[0]; - minICount = count; x = iPnt.x; y = iPnt.y; z = iPnt.z; + if((flags & PickInfo.CLOSEST_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } + } + if((flags & PickInfo.ALL_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); } } } @@ -139,21 +164,27 @@ class IndexedQuadArrayRetained extends IndexedGeometryArrayRetained { BoundingPolytope bpolytope = (BoundingPolytope) ((PickBounds) pickShape).bounds; while (i < validVertexCount) { - getVertexData(indexCoord[i++], pnts[0]); - getVertexData(indexCoord[i++], pnts[1]); - getVertexData(indexCoord[i++], pnts[2]); - getVertexData(indexCoord[i++], pnts[3]); - count += 4; + for(int j=0; j<4; j++) { + vtxIndexArr[j] = indexCoord[i]; + getVertexData(indexCoord[i++], pnts[j]); + } if (intersectBoundingPolytope(pnts, bpolytope, sdist, iPnt)) { if (flags == 0) { return true; } if (sdist[0] < minDist) { minDist = sdist[0]; - minICount = count; x = iPnt.x; y = iPnt.y; z = iPnt.z; + if((flags & PickInfo.CLOSEST_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } + } + if((flags & PickInfo.ALL_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); } } } @@ -161,21 +192,27 @@ class IndexedQuadArrayRetained extends IndexedGeometryArrayRetained { case PickShape.PICKCYLINDER: PickCylinder pickCylinder= (PickCylinder) pickShape; while (i < validVertexCount) { - getVertexData(indexCoord[i++], pnts[0]); - getVertexData(indexCoord[i++], pnts[1]); - getVertexData(indexCoord[i++], pnts[2]); - getVertexData(indexCoord[i++], pnts[3]); - count += 4; + for(int j=0; j<4; j++) { + vtxIndexArr[j] = indexCoord[i]; + getVertexData(indexCoord[i++], pnts[j]); + } if (intersectCylinder(pnts, pickCylinder, sdist, iPnt)) { if (flags == 0) { return true; } if (sdist[0] < minDist) { minDist = sdist[0]; - minICount = count; x = iPnt.x; y = iPnt.y; z = iPnt.z; + if((flags & PickInfo.CLOSEST_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } + } + if((flags & PickInfo.ALL_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); } } } @@ -183,21 +220,27 @@ class IndexedQuadArrayRetained extends IndexedGeometryArrayRetained { case PickShape.PICKCONE: PickCone pickCone= (PickCone) pickShape; while (i < validVertexCount) { - getVertexData(indexCoord[i++], pnts[0]); - getVertexData(indexCoord[i++], pnts[1]); - getVertexData(indexCoord[i++], pnts[2]); - getVertexData(indexCoord[i++], pnts[3]); - count += 4; + for(int j=0; j<4; j++) { + vtxIndexArr[j] = indexCoord[i]; + getVertexData(indexCoord[i++], pnts[j]); + } if (intersectCone(pnts, pickCone, sdist, iPnt)) { if (flags == 0) { return true; } if (sdist[0] < minDist) { minDist = sdist[0]; - minICount = count; x = iPnt.x; y = iPnt.y; z = iPnt.z; + if((flags & PickInfo.CLOSEST_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } + } + if((flags & PickInfo.ALL_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); } } } @@ -210,16 +253,6 @@ class IndexedQuadArrayRetained extends IndexedGeometryArrayRetained { } if (minDist < Double.MAX_VALUE) { - assert(minICount >= 4); - int[] vertexIndices = iInfo.getVertexIndices(); - if (vertexIndices == null) { - vertexIndices = new int[4]; - iInfo.setVertexIndices(vertexIndices); - } - vertexIndices[0] = minICount - 4; - vertexIndices[1] = minICount - 3; - vertexIndices[2] = minICount - 2; - vertexIndices[3] = minICount - 1; iPnt.x = x; iPnt.y = y; iPnt.z = z; diff --git a/src/classes/share/javax/media/j3d/IndexedTriangleArrayRetained.java b/src/classes/share/javax/media/j3d/IndexedTriangleArrayRetained.java index d977894..29c54bf 100644 --- a/src/classes/share/javax/media/j3d/IndexedTriangleArrayRetained.java +++ b/src/classes/share/javax/media/j3d/IndexedTriangleArrayRetained.java @@ -27,13 +27,14 @@ class IndexedTriangleArrayRetained extends IndexedGeometryArrayRetained { this.geoType = GEO_TYPE_INDEXED_TRI_SET; } - boolean intersect(PickShape pickShape, PickInfo.IntersectionInfo iInfo, int flags, Point3d iPnt) { + boolean intersect(PickShape pickShape, PickInfo pickInfo, int flags, Point3d iPnt, + GeometryRetained geom, int geomIndex) { Point3d pnts[] = new Point3d[3]; double sdist[] = new double[1]; double minDist = Double.MAX_VALUE; double x = 0, y = 0, z = 0; - int count = 0; - int minICount = 0; + int[] vtxIndexArr = new int[3]; + int i = ((vertexFormat & GeometryArray.BY_REFERENCE) == 0 ? initialVertexIndex : initialCoordIndex); pnts[0] = new Point3d(); @@ -45,31 +46,38 @@ class IndexedTriangleArrayRetained extends IndexedGeometryArrayRetained { PickRay pickRay= (PickRay) pickShape; while (i < validVertexCount) { - getVertexData(indexCoord[i++], pnts[0]); - getVertexData(indexCoord[i++], pnts[1]); - getVertexData(indexCoord[i++], pnts[2]); - count += 3; + for(int j=0; j<4; j++) { + vtxIndexArr[j] = indexCoord[i]; + getVertexData(indexCoord[i++], pnts[j]); + } if (intersectRay(pnts, pickRay, sdist, iPnt)) { if (flags == 0) { return true; } if (sdist[0] < minDist) { minDist = sdist[0]; - minICount = count; x = iPnt.x; y = iPnt.y; z = iPnt.z; + if((flags & PickInfo.CLOSEST_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } } + if((flags & PickInfo.ALL_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } } } break; case PickShape.PICKSEGMENT: PickSegment pickSegment = (PickSegment) pickShape; while (i < validVertexCount) { - getVertexData(indexCoord[i++], pnts[0]); - getVertexData(indexCoord[i++], pnts[1]); - getVertexData(indexCoord[i++], pnts[2]); - count += 3; + for(int j=0; j<4; j++) { + vtxIndexArr[j] = indexCoord[i]; + getVertexData(indexCoord[i++], pnts[j]); + } if (intersectSegment(pnts, pickSegment.start, pickSegment.end, sdist, iPnt)) { if (flags == 0) { @@ -77,10 +85,17 @@ class IndexedTriangleArrayRetained extends IndexedGeometryArrayRetained { } if (sdist[0] < minDist) { minDist = sdist[0]; - minICount = count; x = iPnt.x; y = iPnt.y; z = iPnt.z; + if((flags & PickInfo.CLOSEST_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } + } + if((flags & PickInfo.ALL_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); } } } @@ -90,21 +105,28 @@ class IndexedTriangleArrayRetained extends IndexedGeometryArrayRetained { ((PickBounds) pickShape).bounds; while (i < validVertexCount) { - getVertexData(indexCoord[i++], pnts[0]); - getVertexData(indexCoord[i++], pnts[1]); - getVertexData(indexCoord[i++], pnts[2]); - count += 3; + for(int j=0; j<4; j++) { + vtxIndexArr[j] = indexCoord[i]; + getVertexData(indexCoord[i++], pnts[j]); + } if (intersectBoundingBox(pnts, bbox, sdist, iPnt)) { if (flags == 0) { return true; } if (sdist[0] < minDist) { minDist = sdist[0]; - minICount = count; x = iPnt.x; y = iPnt.y; z = iPnt.z; + if((flags & PickInfo.CLOSEST_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } } + if((flags & PickInfo.ALL_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } } } break; @@ -113,21 +135,28 @@ class IndexedTriangleArrayRetained extends IndexedGeometryArrayRetained { ((PickBounds) pickShape).bounds; while (i < validVertexCount) { - getVertexData(indexCoord[i++], pnts[0]); - getVertexData(indexCoord[i++], pnts[1]); - getVertexData(indexCoord[i++], pnts[2]); - count += 3; + for(int j=0; j<4; j++) { + vtxIndexArr[j] = indexCoord[i]; + getVertexData(indexCoord[i++], pnts[j]); + } if (intersectBoundingSphere(pnts, bsphere, sdist, iPnt)) { if (flags == 0) { return true; } if (sdist[0] < minDist) { minDist = sdist[0]; - minICount = count; x = iPnt.x; y = iPnt.y; z = iPnt.z; + if((flags & PickInfo.CLOSEST_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } } + if((flags & PickInfo.ALL_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } } } break; @@ -136,10 +165,10 @@ class IndexedTriangleArrayRetained extends IndexedGeometryArrayRetained { ((PickBounds) pickShape).bounds; while (i < validVertexCount) { - getVertexData(indexCoord[i++], pnts[0]); - getVertexData(indexCoord[i++], pnts[1]); - getVertexData(indexCoord[i++], pnts[2]); - count += 3; + for(int j=0; j<4; j++) { + vtxIndexArr[j] = indexCoord[i]; + getVertexData(indexCoord[i++], pnts[j]); + } if (intersectBoundingPolytope(pnts, bpolytope, sdist,iPnt)) { if (flags == 0) { @@ -147,21 +176,28 @@ class IndexedTriangleArrayRetained extends IndexedGeometryArrayRetained { } if (sdist[0] < minDist) { minDist = sdist[0]; - minICount = count; x = iPnt.x; y = iPnt.y; z = iPnt.z; + if((flags & PickInfo.CLOSEST_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } } + if((flags & PickInfo.ALL_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } } } break; case PickShape.PICKCYLINDER: PickCylinder pickCylinder= (PickCylinder) pickShape; while (i < validVertexCount) { - getVertexData(indexCoord[i++], pnts[0]); - getVertexData(indexCoord[i++], pnts[1]); - getVertexData(indexCoord[i++], pnts[2]); - count += 3; + for(int j=0; j<4; j++) { + vtxIndexArr[j] = indexCoord[i]; + getVertexData(indexCoord[i++], pnts[j]); + } if (intersectCylinder(pnts, pickCylinder, sdist, iPnt)) { if (flags == 0) { @@ -169,11 +205,18 @@ class IndexedTriangleArrayRetained extends IndexedGeometryArrayRetained { } if (sdist[0] < minDist) { minDist = sdist[0]; - minICount = count; x = iPnt.x; y = iPnt.y; z = iPnt.z; + if((flags & PickInfo.CLOSEST_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } } + if((flags & PickInfo.ALL_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } } } break; @@ -181,21 +224,28 @@ class IndexedTriangleArrayRetained extends IndexedGeometryArrayRetained { PickCone pickCone= (PickCone) pickShape; while (i < validVertexCount) { - getVertexData(indexCoord[i++], pnts[0]); - getVertexData(indexCoord[i++], pnts[1]); - getVertexData(indexCoord[i++], pnts[2]); - count += 3; + for(int j=0; j<4; j++) { + vtxIndexArr[j] = indexCoord[i]; + getVertexData(indexCoord[i++], pnts[j]); + } if (intersectCone(pnts, pickCone, sdist, iPnt)) { if (flags == 0) { return true; } if (sdist[0] < minDist) { minDist = sdist[0]; - minICount = count; x = iPnt.x; y = iPnt.y; z = iPnt.z; + if((flags & PickInfo.CLOSEST_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } } + if((flags & PickInfo.ALL_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } } } break; @@ -205,18 +255,8 @@ class IndexedTriangleArrayRetained extends IndexedGeometryArrayRetained { default: throw new RuntimeException ("PickShape not supported for intersection"); } - - + if (minDist < Double.MAX_VALUE) { - assert(minICount >= 3); - int[] vertexIndices = iInfo.getVertexIndices(); - if (vertexIndices == null) { - vertexIndices = new int[3]; - iInfo.setVertexIndices(vertexIndices); - } - vertexIndices[0] = minICount - 3; - vertexIndices[1] = minICount - 2; - vertexIndices[2] = minICount - 1; iPnt.x = x; iPnt.y = y; iPnt.z = z; diff --git a/src/classes/share/javax/media/j3d/IndexedTriangleFanArrayRetained.java b/src/classes/share/javax/media/j3d/IndexedTriangleFanArrayRetained.java index c6e37f7..c83e9d5 100644 --- a/src/classes/share/javax/media/j3d/IndexedTriangleFanArrayRetained.java +++ b/src/classes/share/javax/media/j3d/IndexedTriangleFanArrayRetained.java @@ -32,45 +32,53 @@ class IndexedTriangleFanArrayRetained extends IndexedGeometryStripArrayRetained geoType = GEO_TYPE_INDEXED_TRI_FAN_SET; } - boolean intersect(PickShape pickShape, PickInfo.IntersectionInfo iInfo, int flags, Point3d iPnt) { + boolean intersect(PickShape pickShape, PickInfo pickInfo, int flags, Point3d iPnt, + GeometryRetained geom, int geomIndex) { Point3d pnts[] = new Point3d[3]; double sdist[] = new double[1]; double minDist = Double.MAX_VALUE; double x = 0, y = 0, z = 0; int i = 0; - int j, scount, count = 0, fSCount; - int minICount = 0; - int minFSCount = 0; + int j, scount, count = 0; pnts[0] = new Point3d(); pnts[1] = new Point3d(); pnts[2] = new Point3d(); + int[] vtxIndexArr = new int[3]; switch (pickShape.getPickType()) { case PickShape.PICKRAY: PickRay pickRay= (PickRay) pickShape; - while (i < stripIndexCounts.length) { - fSCount = count; - getVertexData(indexCoord[count++], pnts[0]); - getVertexData(indexCoord[count++], pnts[1]); + while (i < stripIndexCounts.length) { + for(int k=0; k<2; k++) { + vtxIndexArr[k] = indexCoord[count]; + getVertexData(indexCoord[count++], pnts[k]); + } scount = stripIndexCounts[i++]; - for (j=2; j < scount; j++) { - getVertexData(indexCoord[count++], pnts[2]); + vtxIndexArr[2] = indexCoord[count]; + getVertexData(indexCoord[count++], pnts[2]); if (intersectRay(pnts, pickRay, sdist, iPnt)) { if (flags == 0) { return true; } if (sdist[0] < minDist) { minDist = sdist[0]; - minFSCount = fSCount; - minICount = count; x = iPnt.x; y = iPnt.y; z = iPnt.z; - } - } + if((flags & PickInfo.CLOSEST_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } + } + if((flags & PickInfo.ALL_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } + } pnts[1].set(pnts[2]); + vtxIndexArr[1] = vtxIndexArr[2]; } } break; @@ -78,11 +86,13 @@ class IndexedTriangleFanArrayRetained extends IndexedGeometryStripArrayRetained PickSegment pickSegment = (PickSegment) pickShape; while (i < stripIndexCounts.length) { - fSCount = count; - getVertexData(indexCoord[count++], pnts[0]); - getVertexData(indexCoord[count++], pnts[1]); + for(int k=0; k<2; k++) { + vtxIndexArr[k] = indexCoord[count]; + getVertexData(indexCoord[count++], pnts[k]); + } scount = stripIndexCounts[i++]; for (j=2; j < scount; j++) { + vtxIndexArr[2] = indexCoord[count]; getVertexData(indexCoord[count++], pnts[2]); if (intersectSegment(pnts, pickSegment.start, pickSegment.end, sdist, iPnt)) { @@ -91,14 +101,21 @@ class IndexedTriangleFanArrayRetained extends IndexedGeometryStripArrayRetained } if (sdist[0] < minDist) { minDist = sdist[0]; - minFSCount = fSCount; - minICount = count; x = iPnt.x; y = iPnt.y; z = iPnt.z; - } - } + if((flags & PickInfo.CLOSEST_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } + } + if((flags & PickInfo.ALL_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } + } pnts[1].set(pnts[2]); + vtxIndexArr[1] = vtxIndexArr[2]; } } break; @@ -107,11 +124,13 @@ class IndexedTriangleFanArrayRetained extends IndexedGeometryStripArrayRetained ((PickBounds) pickShape).bounds; while (i < stripIndexCounts.length) { - fSCount = count; - getVertexData(indexCoord[count++], pnts[0]); - getVertexData(indexCoord[count++], pnts[1]); + for(int k=0; k<2; k++) { + vtxIndexArr[k] = indexCoord[count]; + getVertexData(indexCoord[count++], pnts[k]); + } scount = stripIndexCounts[i++]; for (j=2; j < scount; j++) { + vtxIndexArr[2] = indexCoord[count]; getVertexData(indexCoord[count++], pnts[2]); if (intersectBoundingBox(pnts, bbox, sdist, iPnt)) { if (flags == 0) { @@ -119,14 +138,21 @@ class IndexedTriangleFanArrayRetained extends IndexedGeometryStripArrayRetained } if (sdist[0] < minDist) { minDist = sdist[0]; - minFSCount = fSCount; - minICount = count; x = iPnt.x; y = iPnt.y; z = iPnt.z; - } - } + if((flags & PickInfo.CLOSEST_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } + } + if((flags & PickInfo.ALL_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } + } pnts[1].set(pnts[2]); + vtxIndexArr[1] = vtxIndexArr[2]; } } break; @@ -135,12 +161,13 @@ class IndexedTriangleFanArrayRetained extends IndexedGeometryStripArrayRetained ((PickBounds) pickShape).bounds; while (i < stripIndexCounts.length) { - fSCount = count; - getVertexData(indexCoord[count++], pnts[0]); - getVertexData(indexCoord[count++], pnts[1]); + for(int k=0; k<2; k++) { + vtxIndexArr[k] = indexCoord[count]; + getVertexData(indexCoord[count++], pnts[k]); + } scount = stripIndexCounts[i++]; - for (j=2; j < scount; j++) { + vtxIndexArr[2] = indexCoord[count]; getVertexData(indexCoord[count++], pnts[2]); if (intersectBoundingSphere(pnts, bsphere, sdist, iPnt)) { @@ -149,14 +176,21 @@ class IndexedTriangleFanArrayRetained extends IndexedGeometryStripArrayRetained } if (sdist[0] < minDist) { minDist = sdist[0]; - minFSCount = fSCount; - minICount = count; x = iPnt.x; y = iPnt.y; z = iPnt.z; - } - } + if((flags & PickInfo.CLOSEST_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } + } + if((flags & PickInfo.ALL_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } + } pnts[1].set(pnts[2]); + vtxIndexArr[1] = vtxIndexArr[2]; } } break; @@ -165,12 +199,13 @@ class IndexedTriangleFanArrayRetained extends IndexedGeometryStripArrayRetained ((PickBounds) pickShape).bounds; while (i < stripIndexCounts.length) { - fSCount = count; - getVertexData(indexCoord[count++], pnts[0]); - getVertexData(indexCoord[count++], pnts[1]); + for(int k=0; k<2; k++) { + vtxIndexArr[k] = indexCoord[count]; + getVertexData(indexCoord[count++], pnts[k]); + } scount = stripIndexCounts[i++]; - for (j=2; j < scount; j++) { + vtxIndexArr[2] = indexCoord[count]; getVertexData(indexCoord[count++], pnts[2]); if (intersectBoundingPolytope(pnts, bpolytope, sdist, iPnt)) { @@ -179,14 +214,21 @@ class IndexedTriangleFanArrayRetained extends IndexedGeometryStripArrayRetained } if (sdist[0] < minDist) { minDist = sdist[0]; - minFSCount = fSCount; - minICount = count; x = iPnt.x; y = iPnt.y; z = iPnt.z; - } - } + if((flags & PickInfo.CLOSEST_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } + } + if((flags & PickInfo.ALL_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } + } pnts[1].set(pnts[2]); + vtxIndexArr[1] = vtxIndexArr[2]; } } break; @@ -194,12 +236,13 @@ class IndexedTriangleFanArrayRetained extends IndexedGeometryStripArrayRetained PickCylinder pickCylinder= (PickCylinder) pickShape; while (i < stripIndexCounts.length) { - fSCount = count; - getVertexData(indexCoord[count++], pnts[0]); - getVertexData(indexCoord[count++], pnts[1]); + for(int k=0; k<2; k++) { + vtxIndexArr[k] = indexCoord[count]; + getVertexData(indexCoord[count++], pnts[k]); + } scount = stripIndexCounts[i++]; - for (j=2; j < scount; j++) { + vtxIndexArr[2] = indexCoord[count]; getVertexData(indexCoord[count++], pnts[2]); if (intersectCylinder(pnts, pickCylinder, sdist, iPnt)) { if (flags == 0) { @@ -207,14 +250,21 @@ class IndexedTriangleFanArrayRetained extends IndexedGeometryStripArrayRetained } if (sdist[0] < minDist) { minDist = sdist[0]; - minFSCount = fSCount; - minICount = count; x = iPnt.x; y = iPnt.y; z = iPnt.z; - } - } + if((flags & PickInfo.CLOSEST_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } + } + if((flags & PickInfo.ALL_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } + } pnts[1].set(pnts[2]); + vtxIndexArr[1] = vtxIndexArr[2]; } } break; @@ -222,12 +272,13 @@ class IndexedTriangleFanArrayRetained extends IndexedGeometryStripArrayRetained PickCone pickCone= (PickCone) pickShape; while (i < stripIndexCounts.length) { - fSCount = count; - getVertexData(indexCoord[count++], pnts[0]); - getVertexData(indexCoord[count++], pnts[1]); + for(int k=0; k<2; k++) { + vtxIndexArr[k] = indexCoord[count]; + getVertexData(indexCoord[count++], pnts[k]); + } scount = stripIndexCounts[i++]; - for (j=2; j < scount; j++) { + vtxIndexArr[2] = indexCoord[count]; getVertexData(indexCoord[count++], pnts[2]); if (intersectCone(pnts, pickCone, sdist, iPnt)) { if (flags == 0) { @@ -235,14 +286,21 @@ class IndexedTriangleFanArrayRetained extends IndexedGeometryStripArrayRetained } if (sdist[0] < minDist) { minDist = sdist[0]; - minFSCount = fSCount; - minICount = count; x = iPnt.x; y = iPnt.y; z = iPnt.z; - } - } + if((flags & PickInfo.CLOSEST_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } + } + if((flags & PickInfo.ALL_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } + } pnts[1].set(pnts[2]); + vtxIndexArr[1] = vtxIndexArr[2]; } } break; @@ -254,15 +312,6 @@ class IndexedTriangleFanArrayRetained extends IndexedGeometryStripArrayRetained } if (minDist < Double.MAX_VALUE) { - assert(minICount >= 3); - int[] vertexIndices = iInfo.getVertexIndices(); - if (vertexIndices == null) { - vertexIndices = new int[3]; - iInfo.setVertexIndices(vertexIndices); - } - vertexIndices[0] = minFSCount; - vertexIndices[1] = minICount - 2; - vertexIndices[2] = minICount - 1; iPnt.x = x; iPnt.y = y; iPnt.z = z; diff --git a/src/classes/share/javax/media/j3d/IndexedTriangleStripArrayRetained.java b/src/classes/share/javax/media/j3d/IndexedTriangleStripArrayRetained.java index 888b0de..4907cc0 100644 --- a/src/classes/share/javax/media/j3d/IndexedTriangleStripArrayRetained.java +++ b/src/classes/share/javax/media/j3d/IndexedTriangleStripArrayRetained.java @@ -31,29 +31,31 @@ class IndexedTriangleStripArrayRetained extends IndexedGeometryStripArrayRetaine geoType = GEO_TYPE_INDEXED_TRI_STRIP_SET; } - boolean intersect(PickShape pickShape, PickInfo.IntersectionInfo iInfo, int flags, Point3d iPnt) { + boolean intersect(PickShape pickShape, PickInfo pickInfo, int flags, Point3d iPnt, + GeometryRetained geom, int geomIndex) { Point3d pnts[] = new Point3d[3]; double sdist[] = new double[1]; double minDist = Double.MAX_VALUE; double x = 0, y = 0, z = 0; int i = 0; int j, scount, count = 0; - int minICount = 0; - pnts[0] = new Point3d(); pnts[1] = new Point3d(); pnts[2] = new Point3d(); + int[] vtxIndexArr = new int[3]; switch (pickShape.getPickType()) { case PickShape.PICKRAY: PickRay pickRay= (PickRay) pickShape; while (i < stripIndexCounts.length) { - getVertexData(indexCoord[count++], pnts[0]); - getVertexData(indexCoord[count++], pnts[1]); + for(int k=0; k<2; k++) { + vtxIndexArr[k] = indexCoord[count]; + getVertexData(indexCoord[count++], pnts[k]); + } scount = stripIndexCounts[i++]; - for (j=2; j < scount; j++) { + vtxIndexArr[2] = indexCoord[count]; getVertexData(indexCoord[count++], pnts[2]); if (intersectRay(pnts, pickRay, sdist, iPnt)) { if (flags == 0) { @@ -61,14 +63,23 @@ class IndexedTriangleStripArrayRetained extends IndexedGeometryStripArrayRetaine } if (sdist[0] < minDist) { minDist = sdist[0]; - minICount = count; x = iPnt.x; y = iPnt.y; z = iPnt.z; + if((flags & PickInfo.CLOSEST_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } } - } + if((flags & PickInfo.ALL_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } + } pnts[0].set(pnts[1]); + vtxIndexArr[0] = vtxIndexArr[1]; pnts[1].set(pnts[2]); + vtxIndexArr[1] = vtxIndexArr[2]; } } break; @@ -76,10 +87,13 @@ class IndexedTriangleStripArrayRetained extends IndexedGeometryStripArrayRetaine PickSegment pickSegment = (PickSegment) pickShape; while (i < stripIndexCounts.length) { - getVertexData(indexCoord[count++], pnts[0]); - getVertexData(indexCoord[count++], pnts[1]); + for(int k=0; k<2; k++) { + vtxIndexArr[k] = indexCoord[count]; + getVertexData(indexCoord[count++], pnts[k]); + } scount = stripIndexCounts[i++]; for (j=2; j < scount; j++) { + vtxIndexArr[2] = indexCoord[count]; getVertexData(indexCoord[count++], pnts[2]); if (intersectSegment(pnts, pickSegment.start, pickSegment.end, sdist, iPnt)) { @@ -88,14 +102,23 @@ class IndexedTriangleStripArrayRetained extends IndexedGeometryStripArrayRetaine } if (sdist[0] < minDist) { minDist = sdist[0]; - minICount = count; x = iPnt.x; y = iPnt.y; z = iPnt.z; - } - } + if((flags & PickInfo.CLOSEST_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } + } + if((flags & PickInfo.ALL_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } + } pnts[0].set(pnts[1]); + vtxIndexArr[0] = vtxIndexArr[1]; pnts[1].set(pnts[2]); + vtxIndexArr[1] = vtxIndexArr[2]; } } break; @@ -104,10 +127,13 @@ class IndexedTriangleStripArrayRetained extends IndexedGeometryStripArrayRetaine ((PickBounds) pickShape).bounds; while (i < stripIndexCounts.length) { - getVertexData(indexCoord[count++], pnts[0]); - getVertexData(indexCoord[count++], pnts[1]); + for(int k=0; k<2; k++) { + vtxIndexArr[k] = indexCoord[count]; + getVertexData(indexCoord[count++], pnts[k]); + } scount = stripIndexCounts[i++]; for (j=2; j < scount; j++) { + vtxIndexArr[2] = indexCoord[count]; getVertexData(indexCoord[count++], pnts[2]); if (intersectBoundingBox(pnts, bbox, sdist, iPnt)) { if (flags == 0) { @@ -115,14 +141,23 @@ class IndexedTriangleStripArrayRetained extends IndexedGeometryStripArrayRetaine } if (sdist[0] < minDist) { minDist = sdist[0]; - minICount = count; x = iPnt.x; y = iPnt.y; z = iPnt.z; - } - } + if((flags & PickInfo.CLOSEST_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } + } + if((flags & PickInfo.ALL_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } + } pnts[0].set(pnts[1]); + vtxIndexArr[0] = vtxIndexArr[1]; pnts[1].set(pnts[2]); + vtxIndexArr[1] = vtxIndexArr[2]; } } break; @@ -131,11 +166,13 @@ class IndexedTriangleStripArrayRetained extends IndexedGeometryStripArrayRetaine ((PickBounds) pickShape).bounds; while (i < stripIndexCounts.length) { - getVertexData(indexCoord[count++], pnts[0]); - getVertexData(indexCoord[count++], pnts[1]); + for(int k=0; k<2; k++) { + vtxIndexArr[k] = indexCoord[count]; + getVertexData(indexCoord[count++], pnts[k]); + } scount = stripIndexCounts[i++]; - for (j=2; j < scount; j++) { + vtxIndexArr[2] = indexCoord[count]; getVertexData(indexCoord[count++], pnts[2]); if (intersectBoundingSphere(pnts, bsphere, sdist, iPnt)) { @@ -144,14 +181,23 @@ class IndexedTriangleStripArrayRetained extends IndexedGeometryStripArrayRetaine } if (sdist[0] < minDist) { minDist = sdist[0]; - minICount = count; x = iPnt.x; y = iPnt.y; z = iPnt.z; - } - } + if((flags & PickInfo.CLOSEST_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } + } + if((flags & PickInfo.ALL_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } + } pnts[0].set(pnts[1]); + vtxIndexArr[0] = vtxIndexArr[1]; pnts[1].set(pnts[2]); + vtxIndexArr[1] = vtxIndexArr[2]; } } break; @@ -160,11 +206,13 @@ class IndexedTriangleStripArrayRetained extends IndexedGeometryStripArrayRetaine ((PickBounds) pickShape).bounds; while (i < stripIndexCounts.length) { - getVertexData(indexCoord[count++], pnts[0]); - getVertexData(indexCoord[count++], pnts[1]); + for(int k=0; k<2; k++) { + vtxIndexArr[k] = indexCoord[count]; + getVertexData(indexCoord[count++], pnts[k]); + } scount = stripIndexCounts[i++]; - for (j=2; j < scount; j++) { + vtxIndexArr[2] = indexCoord[count]; getVertexData(indexCoord[count++], pnts[2]); if (intersectBoundingPolytope(pnts, bpolytope, sdist, iPnt)) { @@ -173,14 +221,23 @@ class IndexedTriangleStripArrayRetained extends IndexedGeometryStripArrayRetaine } if (sdist[0] < minDist) { minDist = sdist[0]; - minICount = count; x = iPnt.x; y = iPnt.y; z = iPnt.z; - } - } + if((flags & PickInfo.CLOSEST_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } + } + if((flags & PickInfo.ALL_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } + } pnts[0].set(pnts[1]); + vtxIndexArr[0] = vtxIndexArr[1]; pnts[1].set(pnts[2]); + vtxIndexArr[1] = vtxIndexArr[2]; } } break; @@ -188,11 +245,13 @@ class IndexedTriangleStripArrayRetained extends IndexedGeometryStripArrayRetaine PickCylinder pickCylinder= (PickCylinder) pickShape; while (i < stripIndexCounts.length) { - getVertexData(indexCoord[count++], pnts[0]); - getVertexData(indexCoord[count++], pnts[1]); + for(int k=0; k<2; k++) { + vtxIndexArr[k] = indexCoord[count]; + getVertexData(indexCoord[count++], pnts[k]); + } scount = stripIndexCounts[i++]; - for (j=2; j < scount; j++) { + vtxIndexArr[2] = indexCoord[count]; getVertexData(indexCoord[count++], pnts[2]); if (intersectCylinder(pnts, pickCylinder, sdist, iPnt)) { if (flags == 0) { @@ -200,14 +259,23 @@ class IndexedTriangleStripArrayRetained extends IndexedGeometryStripArrayRetaine } if (sdist[0] < minDist) { minDist = sdist[0]; - minICount = count; x = iPnt.x; y = iPnt.y; z = iPnt.z; - } - } + if((flags & PickInfo.CLOSEST_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } + } + if((flags & PickInfo.ALL_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } + } pnts[0].set(pnts[1]); + vtxIndexArr[0] = vtxIndexArr[1]; pnts[1].set(pnts[2]); + vtxIndexArr[1] = vtxIndexArr[2]; } } break; @@ -215,11 +283,13 @@ class IndexedTriangleStripArrayRetained extends IndexedGeometryStripArrayRetaine PickCone pickCone= (PickCone) pickShape; while (i < stripIndexCounts.length) { - getVertexData(indexCoord[count++], pnts[0]); - getVertexData(indexCoord[count++], pnts[1]); + for(int k=0; k<2; k++) { + vtxIndexArr[k] = indexCoord[count]; + getVertexData(indexCoord[count++], pnts[k]); + } scount = stripIndexCounts[i++]; - for (j=2; j < scount; j++) { + vtxIndexArr[2] = indexCoord[count]; getVertexData(indexCoord[count++], pnts[2]); if (intersectCone(pnts, pickCone, sdist, iPnt)) { if (flags == 0) { @@ -227,14 +297,23 @@ class IndexedTriangleStripArrayRetained extends IndexedGeometryStripArrayRetaine } if (sdist[0] < minDist) { minDist = sdist[0]; - minICount = count; x = iPnt.x; y = iPnt.y; z = iPnt.z; - } - } + if((flags & PickInfo.CLOSEST_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } + } + if((flags & PickInfo.ALL_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } + } pnts[0].set(pnts[1]); + vtxIndexArr[0] = vtxIndexArr[1]; pnts[1].set(pnts[2]); + vtxIndexArr[1] = vtxIndexArr[2]; } } break; @@ -246,15 +325,6 @@ class IndexedTriangleStripArrayRetained extends IndexedGeometryStripArrayRetaine } if (minDist < Double.MAX_VALUE) { - assert(minICount >=3); - int[] vertexIndices = iInfo.getVertexIndices(); - if (vertexIndices == null) { - vertexIndices = new int[3]; - iInfo.setVertexIndices(vertexIndices); - } - vertexIndices[0] = minICount - 3; - vertexIndices[1] = minICount - 2; - vertexIndices[2] = minICount - 1; iPnt.x = x; iPnt.y = y; iPnt.z = z; diff --git a/src/classes/share/javax/media/j3d/LineArrayRetained.java b/src/classes/share/javax/media/j3d/LineArrayRetained.java index 2b07b54..14ce9cb 100644 --- a/src/classes/share/javax/media/j3d/LineArrayRetained.java +++ b/src/classes/share/javax/media/j3d/LineArrayRetained.java @@ -21,18 +21,19 @@ import java.lang.Math; */ class LineArrayRetained extends GeometryArrayRetained implements Cloneable { - + LineArrayRetained() { this.geoType = GEO_TYPE_LINE_SET; } - boolean intersect(PickShape pickShape, PickInfo.IntersectionInfo iInfo, int flags, Point3d iPnt) { + boolean intersect(PickShape pickShape, PickInfo pickInfo, int flags, Point3d iPnt, + GeometryRetained geom, int geomIndex) { Point3d pnts[] = new Point3d[2]; double sdist[] = new double[1]; double minDist = Double.MAX_VALUE; double x = 0, y = 0, z = 0; - int count = 0; - int minICount = 0; + int[] vtxIndexArr = new int[2]; + int i = ((vertexFormat & GeometryArray.BY_REFERENCE) == 0 ? initialVertexIndex : initialCoordIndex); pnts[0] = new Point3d(); @@ -43,9 +44,10 @@ class LineArrayRetained extends GeometryArrayRetained implements Cloneable { PickRay pickRay= (PickRay) pickShape; while (i < validVertexCount) { - getVertexData(i++, pnts[0]); - getVertexData(i++, pnts[1]); - count += 2; + for(int j=0; j<2; j++) { + vtxIndexArr[j] = i; + getVertexData(i++, pnts[j]); + } if (intersectLineAndRay(pnts[0], pnts[1], pickRay.origin, pickRay.direction, sdist, iPnt)) { @@ -54,10 +56,17 @@ class LineArrayRetained extends GeometryArrayRetained implements Cloneable { } if (sdist[0] < minDist) { minDist = sdist[0]; - minICount = count; x = iPnt.x; y = iPnt.y; z = iPnt.z; + if((flags & PickInfo.CLOSEST_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } + } + if((flags & PickInfo.ALL_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); } } } @@ -70,9 +79,10 @@ class LineArrayRetained extends GeometryArrayRetained implements Cloneable { pickSegment.end.z - pickSegment.start.z); while (i < validVertexCount) { - getVertexData(i++, pnts[0]); - getVertexData(i++, pnts[1]); - count += 2; + for(int j=0; j<2; j++) { + vtxIndexArr[j] = i; + getVertexData(i++, pnts[j]); + } if (intersectLineAndRay(pnts[0], pnts[1], pickSegment.start, dir, sdist, iPnt) && @@ -82,11 +92,18 @@ class LineArrayRetained extends GeometryArrayRetained implements Cloneable { } if (sdist[0] < minDist) { minDist = sdist[0]; - minICount = count; x = iPnt.x; y = iPnt.y; z = iPnt.z; + if((flags & PickInfo.CLOSEST_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } } + if((flags & PickInfo.ALL_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } } } break; @@ -94,20 +111,28 @@ class LineArrayRetained extends GeometryArrayRetained implements Cloneable { BoundingBox bbox = (BoundingBox) ((PickBounds) pickShape).bounds; while (i < validVertexCount) { - getVertexData(i++, pnts[0]); - getVertexData(i++, pnts[1]); - count += 2; + for(int j=0; j<2; j++) { + vtxIndexArr[j] = i; + getVertexData(i++, pnts[j]); + } if (intersectBoundingBox(pnts, bbox, sdist, iPnt)) { if (flags == 0) { return true; } if (sdist[0] < minDist) { minDist = sdist[0]; - minICount = count; x = iPnt.x; y = iPnt.y; z = iPnt.z; + if((flags & PickInfo.CLOSEST_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } } + if((flags & PickInfo.ALL_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } } } @@ -117,20 +142,28 @@ class LineArrayRetained extends GeometryArrayRetained implements Cloneable { ((PickBounds) pickShape).bounds; while (i < validVertexCount) { - getVertexData(i++, pnts[0]); - getVertexData(i++, pnts[1]); - count += 2; + for(int j=0; j<2; j++) { + vtxIndexArr[j] = i; + getVertexData(i++, pnts[j]); + } if (intersectBoundingSphere(pnts, bsphere, sdist, iPnt)) { if (flags == 0) { return true; } if (sdist[0] < minDist) { minDist = sdist[0]; - minICount = count; x = iPnt.x; y = iPnt.y; z = iPnt.z; + if((flags & PickInfo.CLOSEST_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } } + if((flags & PickInfo.ALL_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } } } break; @@ -139,20 +172,28 @@ class LineArrayRetained extends GeometryArrayRetained implements Cloneable { ((PickBounds) pickShape).bounds; while (i < validVertexCount) { - getVertexData(i++, pnts[0]); - getVertexData(i++, pnts[1]); - count += 2; + for(int j=0; j<2; j++) { + vtxIndexArr[j] = i; + getVertexData(i++, pnts[j]); + } if (intersectBoundingPolytope(pnts, bpolytope, sdist, iPnt)) { if (flags == 0) { return true; } if (sdist[0] < minDist) { minDist = sdist[0]; - minICount = count; x = iPnt.x; y = iPnt.y; z = iPnt.z; + if((flags & PickInfo.CLOSEST_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } } + if((flags & PickInfo.ALL_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } } } break; @@ -160,20 +201,28 @@ class LineArrayRetained extends GeometryArrayRetained implements Cloneable { PickCylinder pickCylinder= (PickCylinder) pickShape; while (i < validVertexCount) { - getVertexData(i++, pnts[0]); - getVertexData(i++, pnts[1]); - count += 2; + for(int j=0; j<2; j++) { + vtxIndexArr[j] = i; + getVertexData(i++, pnts[j]); + } if (intersectCylinder(pnts, pickCylinder, sdist, iPnt)) { if (flags == 0) { return true; } if (sdist[0] < minDist) { minDist = sdist[0]; - minICount = count; x = iPnt.x; y = iPnt.y; z = iPnt.z; + if((flags & PickInfo.CLOSEST_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } } + if((flags & PickInfo.ALL_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } } } break; @@ -181,20 +230,28 @@ class LineArrayRetained extends GeometryArrayRetained implements Cloneable { PickCone pickCone= (PickCone) pickShape; while (i < validVertexCount) { - getVertexData(i++, pnts[0]); - getVertexData(i++, pnts[1]); - count += 2; + for(int j=0; j<2; j++) { + vtxIndexArr[j] = i; + getVertexData(i++, pnts[j]); + } if (intersectCone(pnts, pickCone, sdist, iPnt)) { if (flags == 0) { return true; } if (sdist[0] < minDist) { minDist = sdist[0]; - minICount = count; x = iPnt.x; y = iPnt.y; z = iPnt.z; + if((flags & PickInfo.CLOSEST_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } } + if((flags & PickInfo.ALL_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } } } break; @@ -206,14 +263,6 @@ class LineArrayRetained extends GeometryArrayRetained implements Cloneable { } if (minDist < Double.MAX_VALUE) { - assert(minICount >=2); - int[] vertexIndices = iInfo.getVertexIndices(); - if (vertexIndices == null) { - vertexIndices = new int[2]; - iInfo.setVertexIndices(vertexIndices); - } - vertexIndices[0] = minICount - 2; - vertexIndices[1] = minICount - 1; iPnt.x = x; iPnt.y = y; iPnt.z = z; diff --git a/src/classes/share/javax/media/j3d/LineStripArrayRetained.java b/src/classes/share/javax/media/j3d/LineStripArrayRetained.java index 69fa80b..f2285ed 100644 --- a/src/classes/share/javax/media/j3d/LineStripArrayRetained.java +++ b/src/classes/share/javax/media/j3d/LineStripArrayRetained.java @@ -30,17 +30,17 @@ class LineStripArrayRetained extends GeometryStripArrayRetained { this.geoType = GEO_TYPE_LINE_STRIP_SET; } - boolean intersect(PickShape pickShape, PickInfo.IntersectionInfo iInfo, int flags, Point3d iPnt) { + boolean intersect(PickShape pickShape, PickInfo pickInfo, int flags, Point3d iPnt, + GeometryRetained geom, int geomIndex) { Point3d pnts[] = new Point3d[2]; double sdist[] = new double[1]; double minDist = Double.MAX_VALUE; double x = 0, y = 0, z = 0; int j, end; int i = 0; - int count = 0; - int minICount = 0; pnts[0] = new Point3d(); pnts[1] = new Point3d(); + int[] vtxIndexArr = new int[2]; switch (pickShape.getPickType()) { case PickShape.PICKRAY: @@ -49,11 +49,11 @@ class LineStripArrayRetained extends GeometryStripArrayRetained { while(i < stripVertexCounts.length) { j = stripStartVertexIndices[i]; end = j + stripVertexCounts[i++]; + vtxIndexArr[0] = j; getVertexData(j++, pnts[0]); - count++; while (j < end) { - getVertexData(j++, pnts[1]); - count++; + vtxIndexArr[1] = j; + getVertexData(j++, pnts[1]); if (intersectLineAndRay(pnts[0], pnts[1], pickRay.origin, pickRay.direction, sdist, iPnt)) { @@ -62,14 +62,22 @@ class LineStripArrayRetained extends GeometryStripArrayRetained { } if (sdist[0] < minDist) { minDist = sdist[0]; - minICount = count; x = iPnt.x; y = iPnt.y; z = iPnt.z; - } - } + if((flags & PickInfo.CLOSEST_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } + } + if((flags & PickInfo.ALL_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } + } pnts[0].set(pnts[1]); - } + vtxIndexArr[0] = vtxIndexArr[1]; + } } break; case PickShape.PICKSEGMENT: @@ -82,11 +90,11 @@ class LineStripArrayRetained extends GeometryStripArrayRetained { while (i < stripVertexCounts.length) { j = stripStartVertexIndices[i]; end = j + stripVertexCounts[i++]; + vtxIndexArr[0] = j; getVertexData(j++, pnts[0]); - count++; while (j < end) { + vtxIndexArr[1] = j; getVertexData(j++, pnts[1]); - count++; if (intersectLineAndRay(pnts[0], pnts[1], pickSegment.start, dir, sdist, iPnt) && @@ -96,13 +104,21 @@ class LineStripArrayRetained extends GeometryStripArrayRetained { } if (sdist[0] < minDist) { minDist = sdist[0]; - minICount = count; x = iPnt.x; y = iPnt.y; z = iPnt.z; - } + if((flags & PickInfo.CLOSEST_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } + } + if((flags & PickInfo.ALL_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } } pnts[0].set(pnts[1]); + vtxIndexArr[0] = vtxIndexArr[1]; } } break; @@ -113,24 +129,32 @@ class LineStripArrayRetained extends GeometryStripArrayRetained { while (i < stripVertexCounts.length) { j = stripStartVertexIndices[i]; end = j + stripVertexCounts[i++]; + vtxIndexArr[0] = j; getVertexData(j++, pnts[0]); - count++; while (j < end) { + vtxIndexArr[1] = j; getVertexData(j++, pnts[1]); - count++; if (intersectBoundingBox(pnts, bbox, sdist, iPnt)) { if (flags == 0) { return true; } if (sdist[0] < minDist) { minDist = sdist[0]; - minICount = count; x = iPnt.x; y = iPnt.y; z = iPnt.z; - } + if((flags & PickInfo.CLOSEST_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } + } + if((flags & PickInfo.ALL_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } } pnts[0].set(pnts[1]); + vtxIndexArr[0] = vtxIndexArr[1]; } } @@ -142,24 +166,32 @@ class LineStripArrayRetained extends GeometryStripArrayRetained { while (i < stripVertexCounts.length) { j = stripStartVertexIndices[i]; end = j + stripVertexCounts[i++]; + vtxIndexArr[0] = j; getVertexData(j++, pnts[0]); - count++; while (j < end) { + vtxIndexArr[1] = j; getVertexData(j++, pnts[1]); - count++; if (intersectBoundingSphere(pnts, bsphere, sdist, iPnt)) { if (flags == 0) { return true; } if (sdist[0] < minDist) { minDist = sdist[0]; - minICount = count; x = iPnt.x; y = iPnt.y; z = iPnt.z; - } + if((flags & PickInfo.CLOSEST_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } + } + if((flags & PickInfo.ALL_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } } - pnts[0].set(pnts[1]); + pnts[0].set(pnts[1]); + vtxIndexArr[0] = vtxIndexArr[1]; } } break; @@ -170,24 +202,32 @@ class LineStripArrayRetained extends GeometryStripArrayRetained { while (i < stripVertexCounts.length) { j = stripStartVertexIndices[i]; end = j + stripVertexCounts[i++]; + vtxIndexArr[0] = j; getVertexData(j++, pnts[0]); - count++; while (j < end) { + vtxIndexArr[1] = j; getVertexData(j++, pnts[1]); - count++; if (intersectBoundingPolytope(pnts, bpolytope, sdist, iPnt)) { if (flags == 0) { return true; } if (sdist[0] < minDist) { minDist = sdist[0]; - minICount = count; x = iPnt.x; y = iPnt.y; z = iPnt.z; - } + if((flags & PickInfo.CLOSEST_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } + } + if((flags & PickInfo.ALL_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } } - pnts[0].set(pnts[1]); + pnts[0].set(pnts[1]); + vtxIndexArr[0] = vtxIndexArr[1]; } } break; @@ -197,24 +237,32 @@ class LineStripArrayRetained extends GeometryStripArrayRetained { while (i < stripVertexCounts.length) { j = stripStartVertexIndices[i]; end = j + stripVertexCounts[i++]; + vtxIndexArr[0] = j; getVertexData(j++, pnts[0]); - count++; while (j < end) { - getVertexData(j++, pnts[1]); - count++; + vtxIndexArr[1] = j; + getVertexData(j++, pnts[1]); if (intersectCylinder(pnts, pickCylinder, sdist, iPnt)) { if (flags == 0) { return true; } if (sdist[0] < minDist) { minDist = sdist[0]; - minICount = count; x = iPnt.x; y = iPnt.y; z = iPnt.z; - } + if((flags & PickInfo.CLOSEST_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } + } + if((flags & PickInfo.ALL_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } } - pnts[0].set(pnts[1]); + pnts[0].set(pnts[1]); + vtxIndexArr[0] = vtxIndexArr[1]; } } break; @@ -224,24 +272,32 @@ class LineStripArrayRetained extends GeometryStripArrayRetained { while (i < stripVertexCounts.length) { j = stripStartVertexIndices[i]; end = j + stripVertexCounts[i++]; + vtxIndexArr[0] = j; getVertexData(j++, pnts[0]); - count++; while (j < end) { + vtxIndexArr[1] = j; getVertexData(j++, pnts[1]); - count++; if (intersectCone(pnts, pickCone, sdist, iPnt)) { if (flags == 0) { return true; } if (sdist[0] < minDist) { minDist = sdist[0]; - minICount = count; x = iPnt.x; y = iPnt.y; z = iPnt.z; - } + if((flags & PickInfo.CLOSEST_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } + } + if((flags & PickInfo.ALL_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } } - pnts[0].set(pnts[1]); + pnts[0].set(pnts[1]); + vtxIndexArr[0] = vtxIndexArr[1]; } } break; @@ -253,14 +309,6 @@ class LineStripArrayRetained extends GeometryStripArrayRetained { } if (minDist < Double.MAX_VALUE) { - assert(minICount >= 2); - int[] vertexIndices = iInfo.getVertexIndices(); - if (vertexIndices == null) { - vertexIndices = new int[2]; - iInfo.setVertexIndices(vertexIndices); - } - vertexIndices[0] = minICount - 2; - vertexIndices[1] = minICount - 1; iPnt.x = x; iPnt.y = y; iPnt.z = z; diff --git a/src/classes/share/javax/media/j3d/MorphRetained.java b/src/classes/share/javax/media/j3d/MorphRetained.java index 351122f..5c98b3c 100644 --- a/src/classes/share/javax/media/j3d/MorphRetained.java +++ b/src/classes/share/javax/media/j3d/MorphRetained.java @@ -478,31 +478,23 @@ class MorphRetained extends LeafRetained implements GeometryUpdater { ((flags & PickInfo.CLOSEST_DISTANCE) == 0) && ((flags & PickInfo.CLOSEST_GEOM_INFO) == 0) && ((flags & PickInfo.ALL_GEOM_INFO) == 0)) { - return geo.intersect(newPS, null, 0, null); + return geo.intersect(newPS, null, 0, null, null, 0); } else { Point3d closestIPnt = new Point3d(); Point3d iPnt = new Point3d(); Point3d iPntVW = new Point3d(); - PickInfo.IntersectionInfo intersectionInfo - = pickInfo.createIntersectionInfo(); - if (geo.intersect(newPS, intersectionInfo, flags, iPnt)) { + if (geo.intersect(newPS, pickInfo, flags, iPnt, geo, 0)) { iPntVW.set(iPnt); localToVworld.transform(iPntVW); double distance = pickShape.distance(iPntVW); + if ((flags & PickInfo.CLOSEST_DISTANCE) != 0) { pickInfo.setClosestDistance(distance); } if((flags & PickInfo.CLOSEST_INTERSECTION_POINT) != 0) { pickInfo.setClosestIntersectionPoint(iPnt); - } else if ((flags & PickInfo.CLOSEST_GEOM_INFO) != 0) { - intersectionInfo.setGeometry((Geometry) geo.source); - intersectionInfo.setGeometryIndex(0); - intersectionInfo.setIntersectionPoint(iPnt); - intersectionInfo.setDistance(distance); - // VertexIndices has been computed in intersect method. - pickInfo.insertIntersectionInfo(intersectionInfo); } return true; } diff --git a/src/classes/share/javax/media/j3d/PickInfo.java b/src/classes/share/javax/media/j3d/PickInfo.java index 343c9f6..d036e7d 100644 --- a/src/classes/share/javax/media/j3d/PickInfo.java +++ b/src/classes/share/javax/media/j3d/PickInfo.java @@ -1008,7 +1008,8 @@ public class PickInfo extends Object { } void setIntersectionPoint(Point3d intersectionPoint) { - this.intersectionPoint = intersectionPoint; + assert(intersectionPoint != null); + this.intersectionPoint = new Point3d(intersectionPoint); } void setDistance(double distance) { @@ -1016,7 +1017,11 @@ public class PickInfo extends Object { } void setVertexIndices(int[] vertexIndices) { - this.vertexIndices = vertexIndices; + assert(vertexIndices != null); + this.vertexIndices = new int[vertexIndices.length]; + for(int i=0; i<vertexIndices.length; i++) { + this.vertexIndices[i] = vertexIndices[i]; + } } diff --git a/src/classes/share/javax/media/j3d/PointArrayRetained.java b/src/classes/share/javax/media/j3d/PointArrayRetained.java index 319a643..84e5642 100644 --- a/src/classes/share/javax/media/j3d/PointArrayRetained.java +++ b/src/classes/share/javax/media/j3d/PointArrayRetained.java @@ -25,23 +25,23 @@ class PointArrayRetained extends GeometryArrayRetained { this.geoType = GEO_TYPE_POINT_SET; } - boolean intersect(PickShape pickShape, PickInfo.IntersectionInfo iInfo, int flags, Point3d iPnt) { + boolean intersect(PickShape pickShape, PickInfo pickInfo, int flags, Point3d iPnt, + GeometryRetained geom, int geomIndex) { double sdist[] = new double[1]; double minDist = Double.MAX_VALUE; double x = 0, y = 0, z = 0; - int count = 0; - int minICount = 0; int i = ((vertexFormat & GeometryArray.BY_REFERENCE) == 0 ? initialVertexIndex : initialCoordIndex); Point3d pnt = new Point3d(); - + int[] vtxIndexArr = new int[1]; + switch (pickShape.getPickType()) { case PickShape.PICKRAY: PickRay pickRay= (PickRay) pickShape; while (i < validVertexCount) { + vtxIndexArr[0] = i; getVertexData(i++, pnt); - count++; if (intersectPntAndRay(pnt, pickRay.origin, pickRay.direction, sdist)) { if (flags == 0) { @@ -49,11 +49,18 @@ class PointArrayRetained extends GeometryArrayRetained { } if (sdist[0] < minDist) { minDist = sdist[0]; - minICount = count; x = pnt.x; y = pnt.y; z = pnt.z; + if((flags & PickInfo.CLOSEST_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } } + if((flags & PickInfo.ALL_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } } } break; @@ -64,8 +71,8 @@ class PointArrayRetained extends GeometryArrayRetained { pickSegment.end.y - pickSegment.start.y, pickSegment.end.z - pickSegment.start.z); while (i < validVertexCount) { + vtxIndexArr[0] = i; getVertexData(i++, pnt); - count++; if (intersectPntAndRay(pnt, pickSegment.start, dir, sdist) && (sdist[0] <= 1.0)) { @@ -74,12 +81,18 @@ class PointArrayRetained extends GeometryArrayRetained { } if (sdist[0] < minDist) { minDist = sdist[0]; - minICount = count; x = pnt.x; y = pnt.y; z = pnt.z; + if((flags & PickInfo.CLOSEST_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } } - + if((flags & PickInfo.ALL_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } } } break; @@ -89,8 +102,8 @@ class PointArrayRetained extends GeometryArrayRetained { Bounds bounds = ((PickBounds) pickShape).bounds; while (i < validVertexCount) { + vtxIndexArr[0] = i; getVertexData(i++, pnt); - count++; if (bounds.intersect(pnt)) { if (flags == 0) { return true; @@ -98,11 +111,18 @@ class PointArrayRetained extends GeometryArrayRetained { sdist[0] = pickShape.distance(pnt); if (sdist[0] < minDist) { minDist = sdist[0]; - minICount = count; x = pnt.x; y = pnt.y; z = pnt.z; + if((flags & PickInfo.CLOSEST_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } } + if((flags & PickInfo.ALL_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } } } @@ -111,19 +131,26 @@ class PointArrayRetained extends GeometryArrayRetained { PickCylinder pickCylinder= (PickCylinder) pickShape; while (i < validVertexCount) { + vtxIndexArr[0] = i; getVertexData(i++, pnt); - count++; if (intersectCylinder(pnt, pickCylinder, sdist)) { if (flags == 0) { return true; } if (sdist[0] < minDist) { minDist = sdist[0]; - minICount = count; x = pnt.x; y = pnt.y; z = pnt.z; + if((flags & PickInfo.CLOSEST_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } } + if((flags & PickInfo.ALL_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } } } break; @@ -131,19 +158,26 @@ class PointArrayRetained extends GeometryArrayRetained { PickCone pickCone= (PickCone) pickShape; while (i < validVertexCount) { + vtxIndexArr[0] = i; getVertexData(i++, pnt); - count++; if (intersectCone(pnt, pickCone, sdist)) { if (flags == 0) { return true; } if (sdist[0] < minDist) { minDist = sdist[0]; - minICount = count; x = pnt.x; y = pnt.y; z = pnt.z; + if((flags & PickInfo.CLOSEST_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } } + if((flags & PickInfo.ALL_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } } } break; @@ -155,13 +189,6 @@ class PointArrayRetained extends GeometryArrayRetained { } if (minDist < Double.MAX_VALUE) { - assert(minICount >=1); - int[] vertexIndices = iInfo.getVertexIndices(); - if (vertexIndices == null) { - vertexIndices = new int[1]; - iInfo.setVertexIndices(vertexIndices); - } - vertexIndices[0] = minICount - 1; iPnt.x = x; iPnt.y = y; iPnt.z = z; diff --git a/src/classes/share/javax/media/j3d/QuadArrayRetained.java b/src/classes/share/javax/media/j3d/QuadArrayRetained.java index 5e95b76..efdd2b9 100644 --- a/src/classes/share/javax/media/j3d/QuadArrayRetained.java +++ b/src/classes/share/javax/media/j3d/QuadArrayRetained.java @@ -26,14 +26,16 @@ class QuadArrayRetained extends GeometryArrayRetained { QuadArrayRetained() { this.geoType = GEO_TYPE_QUAD_SET; } - - boolean intersect(PickShape pickShape, PickInfo.IntersectionInfo iInfo, int flags, Point3d iPnt) { + + boolean intersect(PickShape pickShape, PickInfo pickInfo, int flags, Point3d iPnt, + GeometryRetained geom, int geomIndex) { + Point3d pnts[] = new Point3d[4]; double sdist[] = new double[1]; double minDist = Double.MAX_VALUE; double x = 0, y = 0, z = 0; - int count = 0; - int minICount = 0; + int[] vtxIndexArr = new int[4]; + int i = ((vertexFormat & GeometryArray.BY_REFERENCE) == 0 ? initialVertexIndex : initialCoordIndex); pnts[0] = new Point3d(); @@ -46,22 +48,28 @@ class QuadArrayRetained extends GeometryArrayRetained { PickRay pickRay= (PickRay) pickShape; while (i < validVertexCount) { - getVertexData(i++, pnts[0]); - getVertexData(i++, pnts[1]); - getVertexData(i++, pnts[2]); - getVertexData(i++, pnts[3]); - count += 4; + for(int j=0; j<4; j++) { + vtxIndexArr[j] = i; + getVertexData(i++, pnts[j]); + } if (intersectRay(pnts, pickRay, sdist, iPnt)) { if (flags == 0) { return true; } if (sdist[0] < minDist) { minDist = sdist[0]; - minICount = count; x = iPnt.x; y = iPnt.y; z = iPnt.z; + if((flags & PickInfo.CLOSEST_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } } + if((flags & PickInfo.ALL_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } } } break; @@ -69,11 +77,10 @@ class QuadArrayRetained extends GeometryArrayRetained { PickSegment pickSegment = (PickSegment) pickShape; while (i < validVertexCount) { - getVertexData(i++, pnts[0]); - getVertexData(i++, pnts[1]); - getVertexData(i++, pnts[2]); - getVertexData(i++, pnts[3]); - count += 4; + for(int j=0; j<4; j++) { + vtxIndexArr[j] = i; + getVertexData(i++, pnts[j]); + } if (intersectSegment(pnts, pickSegment.start, pickSegment.end, sdist, iPnt)) { if (flags == 0) { @@ -81,11 +88,18 @@ class QuadArrayRetained extends GeometryArrayRetained { } if (sdist[0] < minDist) { minDist = sdist[0]; - minICount = count; x = iPnt.x; y = iPnt.y; z = iPnt.z; + if((flags & PickInfo.CLOSEST_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } } + if((flags & PickInfo.ALL_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } } } break; @@ -93,22 +107,28 @@ class QuadArrayRetained extends GeometryArrayRetained { BoundingBox bbox = (BoundingBox) ((PickBounds) pickShape).bounds; while (i < validVertexCount) { - getVertexData(i++, pnts[0]); - getVertexData(i++, pnts[1]); - getVertexData(i++, pnts[2]); - getVertexData(i++, pnts[3]); - count += 4; + for(int j=0; j<4; j++) { + vtxIndexArr[j] = i; + getVertexData(i++, pnts[j]); + } if (intersectBoundingBox(pnts, bbox, sdist, iPnt)) { if (flags == 0) { return true; } if (sdist[0] < minDist) { minDist = sdist[0]; - minICount = count; x = iPnt.x; y = iPnt.y; z = iPnt.z; + if((flags & PickInfo.CLOSEST_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } } + if((flags & PickInfo.ALL_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } } } break; @@ -117,22 +137,28 @@ class QuadArrayRetained extends GeometryArrayRetained { ((PickBounds) pickShape).bounds; while (i < validVertexCount) { - getVertexData(i++, pnts[0]); - getVertexData(i++, pnts[1]); - getVertexData(i++, pnts[2]); - getVertexData(i++, pnts[3]); - count += 4; + for(int j=0; j<4; j++) { + vtxIndexArr[j] = i; + getVertexData(i++, pnts[j]); + } if (intersectBoundingSphere(pnts, bsphere, sdist, iPnt)) { if (flags == 0) { return true; } if (sdist[0] < minDist) { minDist = sdist[0]; - minICount = count; x = iPnt.x; y = iPnt.y; z = iPnt.z; + if((flags & PickInfo.CLOSEST_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } } + if((flags & PickInfo.ALL_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } } } break; @@ -142,22 +168,28 @@ class QuadArrayRetained extends GeometryArrayRetained { ((PickBounds) pickShape).bounds; while (i < validVertexCount) { - getVertexData(i++, pnts[0]); - getVertexData(i++, pnts[1]); - getVertexData(i++, pnts[2]); - getVertexData(i++, pnts[3]); - count += 4; + for(int j=0; j<4; j++) { + vtxIndexArr[j] = i; + getVertexData(i++, pnts[j]); + } if (intersectBoundingPolytope(pnts, bpolytope, sdist, iPnt)) { if (flags == 0) { return true; } if (sdist[0] < minDist) { minDist = sdist[0]; - minICount = count; x = iPnt.x; y = iPnt.y; z = iPnt.z; + if((flags & PickInfo.CLOSEST_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } } + if((flags & PickInfo.ALL_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } } } break; @@ -165,22 +197,28 @@ class QuadArrayRetained extends GeometryArrayRetained { PickCylinder pickCylinder= (PickCylinder) pickShape; while (i < validVertexCount) { - getVertexData(i++, pnts[0]); - getVertexData(i++, pnts[1]); - getVertexData(i++, pnts[2]); - getVertexData(i++, pnts[3]); - count += 4; + for(int j=0; j<4; j++) { + vtxIndexArr[j] = i; + getVertexData(i++, pnts[j]); + } if (intersectCylinder(pnts, pickCylinder, sdist, iPnt)) { if (flags == 0) { return true; } if (sdist[0] < minDist) { minDist = sdist[0]; - minICount = count; x = iPnt.x; y = iPnt.y; z = iPnt.z; + if((flags & PickInfo.CLOSEST_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } } + if((flags & PickInfo.ALL_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } } } break; @@ -188,22 +226,28 @@ class QuadArrayRetained extends GeometryArrayRetained { PickCone pickCone= (PickCone) pickShape; while (i < validVertexCount) { - getVertexData(i++, pnts[0]); - getVertexData(i++, pnts[1]); - getVertexData(i++, pnts[2]); - getVertexData(i++, pnts[3]); - count += 4; + for(int j=0; j<4; j++) { + vtxIndexArr[j] = i; + getVertexData(i++, pnts[j]); + } if (intersectCone(pnts, pickCone, sdist, iPnt)) { if (flags == 0) { return true; } if (sdist[0] < minDist) { minDist = sdist[0]; - minICount = count; x = iPnt.x; y = iPnt.y; z = iPnt.z; + if((flags & PickInfo.CLOSEST_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } } + if((flags & PickInfo.ALL_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } } } break; @@ -215,16 +259,6 @@ class QuadArrayRetained extends GeometryArrayRetained { } if (minDist < Double.MAX_VALUE) { - assert(minICount >= 4); - int[] vertexIndices = iInfo.getVertexIndices(); - if (vertexIndices == null) { - vertexIndices = new int[4]; - iInfo.setVertexIndices(vertexIndices); - } - vertexIndices[0] = minICount - 4; - vertexIndices[1] = minICount - 3; - vertexIndices[2] = minICount - 2; - vertexIndices[3] = minICount - 1; iPnt.x = x; iPnt.y = y; iPnt.z = z; diff --git a/src/classes/share/javax/media/j3d/RasterRetained.java b/src/classes/share/javax/media/j3d/RasterRetained.java index bd591b9..c9f64ff 100644 --- a/src/classes/share/javax/media/j3d/RasterRetained.java +++ b/src/classes/share/javax/media/j3d/RasterRetained.java @@ -687,9 +687,10 @@ class RasterRetained extends GeometryRetained { ImageComponentUpdateInfo value) { } - boolean intersect(PickShape pickShape, PickInfo.IntersectionInfo iInfo, int flags, Point3d iPnt) { - return false; - } + boolean intersect(PickShape pickShape, PickInfo pickInfo, int flags, Point3d iPnt, + GeometryRetained geom, int geomIndex) { + return false; + } boolean intersect(Bounds targetBound) { return false; diff --git a/src/classes/share/javax/media/j3d/Shape3DCompileRetained.java b/src/classes/share/javax/media/j3d/Shape3DCompileRetained.java index a3e604d..c01ef83 100644 --- a/src/classes/share/javax/media/j3d/Shape3DCompileRetained.java +++ b/src/classes/share/javax/media/j3d/Shape3DCompileRetained.java @@ -482,7 +482,7 @@ class Shape3DCompileRetained extends Shape3DRetained { } // Need to modify this method // if (geometry.intersect(newPS, null, null)) { - if (geometry.intersect(newPS, null, 0, null)) { + if (geometry.intersect(newPS, null, 0, null, null, 0)) { return true; } } @@ -494,13 +494,6 @@ class Shape3DCompileRetained extends Shape3DRetained { Point3d closestIPnt = new Point3d(); Point3d iPnt = new Point3d(); Point3d iPntVW = new Point3d(); - PickInfo.IntersectionInfo closestInfo = null; - PickInfo.IntersectionInfo intersectionInfo - = pickInfo.createIntersectionInfo(); - - if ((flags & PickInfo.CLOSEST_GEOM_INFO) != 0) { - closestInfo = pickInfo.createIntersectionInfo(); - } for (int i=0; i < geomListSize; i++) { geometry = (GeometryRetained) geometryList.get(i); @@ -508,7 +501,7 @@ class Shape3DCompileRetained extends Shape3DRetained { if (geometry.mirrorGeometry != null) { geometry = geometry.mirrorGeometry; } - if (geometry.intersect(newPS, intersectionInfo, flags, iPnt)) { + if (geometry.intersect(newPS, pickInfo, flags, iPnt, geometry, i)) { iPntVW.set(iPnt); localToVworld.transform(iPntVW); @@ -517,27 +510,8 @@ class Shape3DCompileRetained extends Shape3DRetained { if (minDist > distance) { minDist = distance; closestIPnt.set(iPnt); - - if ((flags & PickInfo.CLOSEST_GEOM_INFO) != 0) { - closestInfo.setGeometry((Geometry) geometry.source); - closestInfo.setGeometryIndex(i); - closestInfo.setIntersectionPoint(closestIPnt); - closestInfo.setDistance(distance); - closestInfo.setVertexIndices(intersectionInfo.getVertexIndices()); - } - } - - if ((flags & PickInfo.ALL_GEOM_INFO) != 0) { - - intersectionInfo.setGeometry((Geometry) geometry.source); - intersectionInfo.setGeometryIndex(i); - intersectionInfo.setIntersectionPoint(iPnt); - intersectionInfo.setDistance(distance); - // VertexIndices has been computed in intersect method. - pickInfo.insertIntersectionInfo(intersectionInfo); - intersectionInfo = pickInfo.createIntersectionInfo(); - } - } + } + } } } @@ -548,9 +522,6 @@ class Shape3DCompileRetained extends Shape3DRetained { if((flags & PickInfo.CLOSEST_INTERSECTION_POINT) != 0) { pickInfo.setClosestIntersectionPoint(closestIPnt); } - if ((flags & PickInfo.CLOSEST_GEOM_INFO) != 0) { - pickInfo.insertIntersectionInfo(closestInfo); - } return true; } } diff --git a/src/classes/share/javax/media/j3d/Shape3DRetained.java b/src/classes/share/javax/media/j3d/Shape3DRetained.java index 8d3002c..7124804 100644 --- a/src/classes/share/javax/media/j3d/Shape3DRetained.java +++ b/src/classes/share/javax/media/j3d/Shape3DRetained.java @@ -647,7 +647,7 @@ class Shape3DRetained extends LeafRetained { if (geometry.mirrorGeometry != null) { geometry = geometry.mirrorGeometry; } - if (geometry.intersect(newPS, null, 0, null)) { + if (geometry.intersect(newPS, null, 0, null, null, 0)) { return true; } } @@ -657,14 +657,7 @@ class Shape3DRetained extends LeafRetained { double minDist = Double.POSITIVE_INFINITY; Point3d closestIPnt = new Point3d(); Point3d iPnt = new Point3d(); - Point3d iPntVW = new Point3d(); - PickInfo.IntersectionInfo closestInfo = null; - PickInfo.IntersectionInfo intersectionInfo - = pickInfo.createIntersectionInfo(); - - if ((flags & PickInfo.CLOSEST_GEOM_INFO) != 0) { - closestInfo = pickInfo.createIntersectionInfo(); - } + Point3d iPntVW = new Point3d(); for (int i=0; i < geomListSize; i++) { geometry = (GeometryRetained) geometryList.get(i); @@ -672,7 +665,8 @@ class Shape3DRetained extends LeafRetained { if (geometry.mirrorGeometry != null) { geometry = geometry.mirrorGeometry; } - if (geometry.intersect(newPS, intersectionInfo, flags, iPnt)) { + //if (geometry.intersect(newPS, intersectionInfo, flags, iPnt)) { + if(geometry.intersect(newPS, pickInfo, flags, iPnt, geometry, i)) { iPntVW.set(iPnt); localToVworld.transform(iPntVW); @@ -681,25 +675,6 @@ class Shape3DRetained extends LeafRetained { if (minDist > distance) { minDist = distance; closestIPnt.set(iPnt); - - if ((flags & PickInfo.CLOSEST_GEOM_INFO) != 0) { - closestInfo.setGeometry((Geometry) geometry.source); - closestInfo.setGeometryIndex(i); - closestInfo.setIntersectionPoint(closestIPnt); - closestInfo.setDistance(distance); - closestInfo.setVertexIndices(intersectionInfo.getVertexIndices()); - } - } - - if ((flags & PickInfo.ALL_GEOM_INFO) != 0) { - - intersectionInfo.setGeometry((Geometry) geometry.source); - intersectionInfo.setGeometryIndex(i); - intersectionInfo.setIntersectionPoint(iPnt); - intersectionInfo.setDistance(distance); - // VertexIndices has been computed in intersect method. - pickInfo.insertIntersectionInfo(intersectionInfo); - intersectionInfo = pickInfo.createIntersectionInfo(); } } } @@ -712,9 +687,6 @@ class Shape3DRetained extends LeafRetained { if((flags & PickInfo.CLOSEST_INTERSECTION_POINT) != 0) { pickInfo.setClosestIntersectionPoint(closestIPnt); } - if ((flags & PickInfo.CLOSEST_GEOM_INFO) != 0) { - pickInfo.insertIntersectionInfo(closestInfo); - } return true; } } diff --git a/src/classes/share/javax/media/j3d/Text3DRetained.java b/src/classes/share/javax/media/j3d/Text3DRetained.java index 23c2ae6..d437c51 100644 --- a/src/classes/share/javax/media/j3d/Text3DRetained.java +++ b/src/classes/share/javax/media/j3d/Text3DRetained.java @@ -838,7 +838,9 @@ class Text3DRetained extends GeometryRetained { super.markAsLive(); } - boolean intersect(PickShape pickShape, PickInfo.IntersectionInfo iInfo, int flags, Point3d iPnt) { + // TODO -- Need to rethink. Might have to consider charTransform[] in returns pickInfo. + boolean intersect(PickShape pickShape, PickInfo pickInfo, int flags, Point3d iPnt, + GeometryRetained geom, int geomIndex) { Transform3D tempT3D = new Transform3D(); GeometryArrayRetained geo = null; int sIndex = -1; @@ -852,7 +854,7 @@ class Text3DRetained extends GeometryRetained { if (geo != null) { tempT3D.invert(charTransforms[i]); newPS = pickShape.transform(tempT3D); - if (geo.intersect(newPS, iInfo, flags, iPnt)) { + if (geo.intersect(newPS, pickInfo, flags, iPnt, geom, geomIndex)) { if (flags == 0) { return true; } diff --git a/src/classes/share/javax/media/j3d/TriangleArrayRetained.java b/src/classes/share/javax/media/j3d/TriangleArrayRetained.java index 577495f..9c039b0 100644 --- a/src/classes/share/javax/media/j3d/TriangleArrayRetained.java +++ b/src/classes/share/javax/media/j3d/TriangleArrayRetained.java @@ -27,15 +27,16 @@ class TriangleArrayRetained extends GeometryArrayRetained { this.geoType = GEO_TYPE_TRI_SET; } - boolean intersect(PickShape pickShape, PickInfo.IntersectionInfo iInfo, int flags, Point3d iPnt) { - Point3d pnts[] = new Point3d[3]; + boolean intersect(PickShape pickShape, PickInfo pickInfo, int flags, Point3d iPnt, + GeometryRetained geom, int geomIndex) { + Point3d pnts[] = new Point3d[3]; double sdist[] = new double[1]; double minDist = Double.MAX_VALUE; double x = 0, y = 0, z = 0; + int[] vtxIndexArr = new int[3]; + int i = ((vertexFormat & GeometryArray.BY_REFERENCE) == 0 ? initialVertexIndex : initialCoordIndex); - int count = 0; - int minICount = 0; pnts[0] = new Point3d(); pnts[1] = new Point3d(); pnts[2] = new Point3d(); @@ -45,20 +46,27 @@ class TriangleArrayRetained extends GeometryArrayRetained { PickRay pickRay= (PickRay) pickShape; while (i < validVertexCount) { - getVertexData(i++, pnts[0]); - getVertexData(i++, pnts[1]); - getVertexData(i++, pnts[2]); - count += 3; + for(int j=0; j<3; j++) { + vtxIndexArr[j] = i; + getVertexData(i++, pnts[j]); + } if (intersectRay(pnts, pickRay, sdist, iPnt)) { if (flags == 0) { return true; } if (sdist[0] < minDist) { minDist = sdist[0]; - minICount = count; x = iPnt.x; y = iPnt.y; z = iPnt.z; + if((flags & PickInfo.CLOSEST_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } + } + if((flags & PickInfo.ALL_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); } } } @@ -67,10 +75,10 @@ class TriangleArrayRetained extends GeometryArrayRetained { PickSegment pickSegment = (PickSegment) pickShape; while (i < validVertexCount) { - getVertexData(i++, pnts[0]); - getVertexData(i++, pnts[1]); - getVertexData(i++, pnts[2]); - count += 3; + for(int j=0; j<3; j++) { + vtxIndexArr[j] = i; + getVertexData(i++, pnts[j]); + } if (intersectSegment(pnts, pickSegment.start, pickSegment.end, sdist, iPnt)) { if (flags == 0) { @@ -78,10 +86,17 @@ class TriangleArrayRetained extends GeometryArrayRetained { } if (sdist[0] < minDist) { minDist = sdist[0]; - minICount = count; x = iPnt.x; y = iPnt.y; z = iPnt.z; + if((flags & PickInfo.CLOSEST_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } + } + if((flags & PickInfo.ALL_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); } } } @@ -91,21 +106,28 @@ class TriangleArrayRetained extends GeometryArrayRetained { ((PickBounds) pickShape).bounds; while (i < validVertexCount) { - getVertexData(i++, pnts[0]); - getVertexData(i++, pnts[1]); - getVertexData(i++, pnts[2]); - count += 3; + for(int j=0; j<3; j++) { + vtxIndexArr[j] = i; + getVertexData(i++, pnts[j]); + } if (intersectBoundingBox(pnts, bbox, sdist, iPnt)) { if (flags == 0) { return true; } if (sdist[0] < minDist) { minDist = sdist[0]; - minICount = count; x = iPnt.x; y = iPnt.y; z = iPnt.z; + if((flags & PickInfo.CLOSEST_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } } + if((flags & PickInfo.ALL_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } } } break; @@ -114,21 +136,28 @@ class TriangleArrayRetained extends GeometryArrayRetained { ((PickBounds) pickShape).bounds; while (i < validVertexCount) { - getVertexData(i++, pnts[0]); - getVertexData(i++, pnts[1]); - getVertexData(i++, pnts[2]); - count += 3; + for(int j=0; j<3; j++) { + vtxIndexArr[j] = i; + getVertexData(i++, pnts[j]); + } if (intersectBoundingSphere(pnts, bsphere, sdist, iPnt)) { if (flags == 0) { return true; } if (sdist[0] < minDist) { minDist = sdist[0]; - minICount = count; x = iPnt.x; y = iPnt.y; z = iPnt.z; + if((flags & PickInfo.CLOSEST_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } } + if((flags & PickInfo.ALL_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } } } break; @@ -137,10 +166,10 @@ class TriangleArrayRetained extends GeometryArrayRetained { ((PickBounds) pickShape).bounds; while (i < validVertexCount) { - getVertexData(i++, pnts[0]); - getVertexData(i++, pnts[1]); - getVertexData(i++, pnts[2]); - count += 3; + for(int j=0; j<3; j++) { + vtxIndexArr[j] = i; + getVertexData(i++, pnts[j]); + } if (intersectBoundingPolytope(pnts, bpolytope, sdist,iPnt)) { if (flags == 0) { @@ -148,21 +177,28 @@ class TriangleArrayRetained extends GeometryArrayRetained { } if (sdist[0] < minDist) { minDist = sdist[0]; - minICount = count; x = iPnt.x; y = iPnt.y; z = iPnt.z; + if((flags & PickInfo.CLOSEST_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } } + if((flags & PickInfo.ALL_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } } } break; case PickShape.PICKCYLINDER: PickCylinder pickCylinder= (PickCylinder) pickShape; while (i < validVertexCount) { - getVertexData(i++, pnts[0]); - getVertexData(i++, pnts[1]); - getVertexData(i++, pnts[2]); - count += 3; + for(int j=0; j<3; j++) { + vtxIndexArr[j] = i; + getVertexData(i++, pnts[j]); + } if (intersectCylinder(pnts, pickCylinder, sdist, iPnt)) { if (flags == 0) { @@ -170,11 +206,18 @@ class TriangleArrayRetained extends GeometryArrayRetained { } if (sdist[0] < minDist) { minDist = sdist[0]; - minICount = count; x = iPnt.x; y = iPnt.y; z = iPnt.z; + if((flags & PickInfo.CLOSEST_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } } + if((flags & PickInfo.ALL_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } } } break; @@ -182,21 +225,28 @@ class TriangleArrayRetained extends GeometryArrayRetained { PickCone pickCone= (PickCone) pickShape; while (i < validVertexCount) { - getVertexData(i++, pnts[0]); - getVertexData(i++, pnts[1]); - getVertexData(i++, pnts[2]); - count += 3; + for(int j=0; j<3; j++) { + vtxIndexArr[j] = i; + getVertexData(i++, pnts[j]); + } if (intersectCone(pnts, pickCone, sdist, iPnt)) { if (flags == 0) { return true; } if (sdist[0] < minDist) { minDist = sdist[0]; - minICount = count; x = iPnt.x; y = iPnt.y; z = iPnt.z; + if((flags & PickInfo.CLOSEST_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } } + if((flags & PickInfo.ALL_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } } } break; @@ -209,15 +259,6 @@ class TriangleArrayRetained extends GeometryArrayRetained { if (minDist < Double.MAX_VALUE) { - assert(minICount >=3); - int[] vertexIndices = iInfo.getVertexIndices(); - if (vertexIndices == null) { - vertexIndices = new int[3]; - iInfo.setVertexIndices(vertexIndices); - } - vertexIndices[0] = minICount - 3; - vertexIndices[1] = minICount - 2; - vertexIndices[2] = minICount - 1; iPnt.x = x; iPnt.y = y; iPnt.z = z; diff --git a/src/classes/share/javax/media/j3d/TriangleFanArrayRetained.java b/src/classes/share/javax/media/j3d/TriangleFanArrayRetained.java index 1c77d6c..63aa88a 100644 --- a/src/classes/share/javax/media/j3d/TriangleFanArrayRetained.java +++ b/src/classes/share/javax/media/j3d/TriangleFanArrayRetained.java @@ -32,19 +32,18 @@ class TriangleFanArrayRetained extends GeometryStripArrayRetained { this.geoType = GEO_TYPE_TRI_FAN_SET; } - boolean intersect(PickShape pickShape, PickInfo.IntersectionInfo iInfo, int flags, Point3d iPnt) { + boolean intersect(PickShape pickShape, PickInfo pickInfo, int flags, Point3d iPnt, + GeometryRetained geom, int geomIndex) { Point3d pnts[] = new Point3d[3]; double sdist[] = new double[1]; double minDist = Double.MAX_VALUE; double x = 0, y = 0, z = 0; int i = 0; int j, end; - int count = 0, fSCount; - int minICount = 0; - int minFSCount = 0; pnts[0] = new Point3d(); pnts[1] = new Point3d(); pnts[2] = new Point3d(); + int[] vtxIndexArr = new int[3]; switch (pickShape.getPickType()) { case PickShape.PICKRAY: @@ -53,28 +52,35 @@ class TriangleFanArrayRetained extends GeometryStripArrayRetained { while (i < stripVertexCounts.length) { j = stripStartVertexIndices[i]; end = j + stripVertexCounts[i++]; - fSCount = count; - getVertexData(j++, pnts[0]); - getVertexData(j++, pnts[1]); - count += 2; + for(int k=0; k<2; k++) { + vtxIndexArr[k] = j; + getVertexData(j++, pnts[k]); + } while (j < end) { + vtxIndexArr[2] = j; getVertexData(j++, pnts[2]); - count++; if (intersectRay(pnts, pickRay, sdist, iPnt)) { if (flags == 0) { return true; } - if (sdist[0] < minDist) { - minDist = sdist[0]; - minFSCount = count; - minICount = count; + if (sdist[0] < minDist) { + minDist = sdist[0]; x = iPnt.x; y = iPnt.y; z = iPnt.z; - } - } - pnts[1].set(pnts[2]); - } + if((flags & PickInfo.CLOSEST_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } + } + if((flags & PickInfo.ALL_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } + } + pnts[1].set(pnts[2]); + vtxIndexArr[1] = vtxIndexArr[2]; + } } break; case PickShape.PICKSEGMENT: @@ -83,13 +89,13 @@ class TriangleFanArrayRetained extends GeometryStripArrayRetained { while (i < stripVertexCounts.length) { j = stripStartVertexIndices[i]; end = j + stripVertexCounts[i++]; - fSCount = count; - getVertexData(j++, pnts[0]); - getVertexData(j++, pnts[1]); - count += 2; + for(int k=0; k<2; k++) { + vtxIndexArr[k] = j; + getVertexData(j++, pnts[k]); + } while (j < end) { + vtxIndexArr[2] = j; getVertexData(j++, pnts[2]); - count++; if (intersectSegment(pnts, pickSegment.start, pickSegment.end, sdist, iPnt)) { if (flags == 0) { @@ -97,14 +103,21 @@ class TriangleFanArrayRetained extends GeometryStripArrayRetained { } if (sdist[0] < minDist) { minDist = sdist[0]; - minFSCount = fSCount; - minICount = count; x = iPnt.x; y = iPnt.y; z = iPnt.z; - } - } - pnts[1].set(pnts[2]); + if((flags & PickInfo.CLOSEST_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } + } + if((flags & PickInfo.ALL_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } + } + pnts[1].set(pnts[2]); + vtxIndexArr[1] = vtxIndexArr[2]; } } break; @@ -115,27 +128,34 @@ class TriangleFanArrayRetained extends GeometryStripArrayRetained { while (i < stripVertexCounts.length) { j = stripStartVertexIndices[i]; end = j + stripVertexCounts[i++]; - fSCount = count; - getVertexData(j++, pnts[0]); - getVertexData(j++, pnts[1]); - count += 2; + for(int k=0; k<2; k++) { + vtxIndexArr[k] = j; + getVertexData(j++, pnts[k]); + } while (j < end) { + vtxIndexArr[2] = j; getVertexData(j++, pnts[2]); - count++; if (intersectBoundingBox(pnts, bbox, sdist, iPnt)) { if (flags == 0) { return true; } if (sdist[0] < minDist) { minDist = sdist[0]; - minFSCount = fSCount; - minICount = count; x = iPnt.x; y = iPnt.y; z = iPnt.z; - } - } - pnts[1].set(pnts[2]); + if((flags & PickInfo.CLOSEST_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } + } + if((flags & PickInfo.ALL_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } + } + pnts[1].set(pnts[2]); + vtxIndexArr[1] = vtxIndexArr[2]; } } break; @@ -146,13 +166,13 @@ class TriangleFanArrayRetained extends GeometryStripArrayRetained { while (i < stripVertexCounts.length) { j = stripStartVertexIndices[i]; end = j + stripVertexCounts[i++]; - fSCount = count; - getVertexData(j++, pnts[0]); - getVertexData(j++, pnts[1]); - count += 2; - while (j < end) { + for(int k=0; k<2; k++) { + vtxIndexArr[k] = j; + getVertexData(j++, pnts[k]); + } + while (j < end) { + vtxIndexArr[2] = j; getVertexData(j++, pnts[2]); - count++; if (intersectBoundingSphere(pnts, bsphere, sdist, iPnt)) { if (flags == 0) { @@ -160,14 +180,21 @@ class TriangleFanArrayRetained extends GeometryStripArrayRetained { } if (sdist[0] < minDist) { minDist = sdist[0]; - minFSCount = fSCount; - minICount = count; x = iPnt.x; y = iPnt.y; z = iPnt.z; - } - } - pnts[1].set(pnts[2]); + if((flags & PickInfo.CLOSEST_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } + } + if((flags & PickInfo.ALL_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } + } + pnts[1].set(pnts[2]); + vtxIndexArr[1] = vtxIndexArr[2]; } } break; @@ -178,13 +205,13 @@ class TriangleFanArrayRetained extends GeometryStripArrayRetained { while (i < stripVertexCounts.length) { j = stripStartVertexIndices[i]; end = j + stripVertexCounts[i++]; - fSCount = count; - getVertexData(j++, pnts[0]); - getVertexData(j++, pnts[1]); - count += 2; + for(int k=0; k<2; k++) { + vtxIndexArr[k] = j; + getVertexData(j++, pnts[k]); + } while (j < end) { + vtxIndexArr[2] = j; getVertexData(j++, pnts[2]); - count++; if (intersectBoundingPolytope(pnts, bpolytope, sdist, iPnt)) { if (flags == 0) { @@ -192,14 +219,21 @@ class TriangleFanArrayRetained extends GeometryStripArrayRetained { } if (sdist[0] < minDist) { minDist = sdist[0]; - minFSCount = fSCount; - minICount = count; x = iPnt.x; y = iPnt.y; z = iPnt.z; - } - } - pnts[1].set(pnts[2]); + if((flags & PickInfo.CLOSEST_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } + } + if((flags & PickInfo.ALL_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } + } + pnts[1].set(pnts[2]); + vtxIndexArr[1] = vtxIndexArr[2]; } } break; @@ -209,27 +243,34 @@ class TriangleFanArrayRetained extends GeometryStripArrayRetained { while (i < stripVertexCounts.length) { j = stripStartVertexIndices[i]; end = j + stripVertexCounts[i++]; - getVertexData(j++, pnts[0]); - getVertexData(j++, pnts[1]); - fSCount = count; - count += 2; + for(int k=0; k<2; k++) { + vtxIndexArr[k] = j; + getVertexData(j++, pnts[k]); + } while (j < end) { + vtxIndexArr[2] = j; getVertexData(j++, pnts[2]); - count++; if (intersectCylinder(pnts, pickCylinder, sdist, iPnt)) { if (flags == 0) { return true; } if (sdist[0] < minDist) { minDist = sdist[0]; - minFSCount = fSCount; - minICount = count; x = iPnt.x; y = iPnt.y; z = iPnt.z; - } - } - pnts[1].set(pnts[2]); + if((flags & PickInfo.CLOSEST_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } + } + if((flags & PickInfo.ALL_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } + } + pnts[1].set(pnts[2]); + vtxIndexArr[1] = vtxIndexArr[2]; } } break; @@ -239,27 +280,34 @@ class TriangleFanArrayRetained extends GeometryStripArrayRetained { while (i < stripVertexCounts.length) { j = stripStartVertexIndices[i]; end = j + stripVertexCounts[i++]; - fSCount = count; - getVertexData(j++, pnts[0]); - getVertexData(j++, pnts[1]); - count += 2; + for(int k=0; k<2; k++) { + vtxIndexArr[k] = j; + getVertexData(j++, pnts[k]); + } while (j < end) { + vtxIndexArr[2] = j; getVertexData(j++, pnts[2]); - count++; if (intersectCone(pnts, pickCone, sdist, iPnt)) { if (flags == 0) { return true; } if (sdist[0] < minDist) { minDist = sdist[0]; - minFSCount = fSCount; - minICount = count; x = iPnt.x; y = iPnt.y; z = iPnt.z; - } - } - pnts[1].set(pnts[2]); + if((flags & PickInfo.CLOSEST_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } + } + if((flags & PickInfo.ALL_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } + } + pnts[1].set(pnts[2]); + vtxIndexArr[1] = vtxIndexArr[2]; } } break; @@ -271,15 +319,6 @@ class TriangleFanArrayRetained extends GeometryStripArrayRetained { } if (minDist < Double.MAX_VALUE) { - assert(minICount >= 3); - int[] vertexIndices = iInfo.getVertexIndices(); - if (vertexIndices == null) { - vertexIndices = new int[3]; - iInfo.setVertexIndices(vertexIndices); - } - vertexIndices[0] = minFSCount; - vertexIndices[1] = minICount - 2; - vertexIndices[2] = minICount - 1; iPnt.x = x; iPnt.y = y; iPnt.z = z; diff --git a/src/classes/share/javax/media/j3d/TriangleStripArrayRetained.java b/src/classes/share/javax/media/j3d/TriangleStripArrayRetained.java index 14c177a..e298f42 100644 --- a/src/classes/share/javax/media/j3d/TriangleStripArrayRetained.java +++ b/src/classes/share/javax/media/j3d/TriangleStripArrayRetained.java @@ -31,18 +31,18 @@ class TriangleStripArrayRetained extends GeometryStripArrayRetained { this.geoType = GEO_TYPE_TRI_STRIP_SET; } - boolean intersect(PickShape pickShape, PickInfo.IntersectionInfo iInfo, int flags, Point3d iPnt) { + boolean intersect(PickShape pickShape, PickInfo pickInfo, int flags, Point3d iPnt, + GeometryRetained geom, int geomIndex) { Point3d pnts[] = new Point3d[3]; double sdist[] = new double[1]; double minDist = Double.MAX_VALUE; double x = 0, y = 0, z = 0; - int count = 0; - int minICount = 0; int i = 0; int j, end; pnts[0] = new Point3d(); pnts[1] = new Point3d(); pnts[2] = new Point3d(); + int[] vtxIndexArr = new int[3]; switch (pickShape.getPickType()) { case PickShape.PICKRAY: @@ -51,26 +51,36 @@ class TriangleStripArrayRetained extends GeometryStripArrayRetained { while (i < stripVertexCounts.length) { j = stripStartVertexIndices[i]; end = j + stripVertexCounts[i++]; - getVertexData(j++, pnts[0]); - getVertexData(j++, pnts[1]); - count += 2; + for(int k=0; k<2; k++) { + vtxIndexArr[k] = j; + getVertexData(j++, pnts[k]); + } while (j < end) { - getVertexData(j++, pnts[2]); - count++; + vtxIndexArr[2] = j; + getVertexData(j++, pnts[2]); if (intersectRay(pnts, pickRay, sdist, iPnt)) { if (flags == 0) { return true; } if (sdist[0] < minDist) { minDist = sdist[0]; - minICount = count; x = iPnt.x; y = iPnt.y; z = iPnt.z; + if((flags & PickInfo.CLOSEST_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } } - } + if((flags & PickInfo.ALL_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } + } pnts[0].set(pnts[1]); + vtxIndexArr[0] = vtxIndexArr[1]; pnts[1].set(pnts[2]); + vtxIndexArr[1] = vtxIndexArr[2]; } } break; @@ -80,12 +90,13 @@ class TriangleStripArrayRetained extends GeometryStripArrayRetained { while (i < stripVertexCounts.length) { j = stripStartVertexIndices[i]; end = j + stripVertexCounts[i++]; - getVertexData(j++, pnts[0]); - getVertexData(j++, pnts[1]); - count += 2; + for(int k=0; k<2; k++) { + vtxIndexArr[k] = j; + getVertexData(j++, pnts[k]); + } while (j < end) { + vtxIndexArr[2] = j; getVertexData(j++, pnts[2]); - count++; if (intersectSegment(pnts, pickSegment.start, pickSegment.end, sdist, iPnt)) { if (flags == 0) { @@ -93,14 +104,23 @@ class TriangleStripArrayRetained extends GeometryStripArrayRetained { } if (sdist[0] < minDist) { minDist = sdist[0]; - minICount = count; x = iPnt.x; y = iPnt.y; z = iPnt.z; - } - } + if((flags & PickInfo.CLOSEST_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } + } + if((flags & PickInfo.ALL_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } + } pnts[0].set(pnts[1]); + vtxIndexArr[0] = vtxIndexArr[1]; pnts[1].set(pnts[2]); + vtxIndexArr[1] = vtxIndexArr[2]; } } break; @@ -111,26 +131,36 @@ class TriangleStripArrayRetained extends GeometryStripArrayRetained { while (i < stripVertexCounts.length) { j = stripStartVertexIndices[i]; end = j + stripVertexCounts[i++]; - getVertexData(j++, pnts[0]); - getVertexData(j++, pnts[1]); - count += 2; + for(int k=0; k<2; k++) { + vtxIndexArr[k] = j; + getVertexData(j++, pnts[k]); + } while (j < end) { + vtxIndexArr[2] = j; getVertexData(j++, pnts[2]); - count++; if (intersectBoundingBox(pnts, bbox, sdist, iPnt)) { if (flags == 0) { return true; } if (sdist[0] < minDist) { minDist = sdist[0]; - minICount = count; x = iPnt.x; y = iPnt.y; z = iPnt.z; - } - } + if((flags & PickInfo.CLOSEST_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } + } + if((flags & PickInfo.ALL_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } + } pnts[0].set(pnts[1]); + vtxIndexArr[0] = vtxIndexArr[1]; pnts[1].set(pnts[2]); + vtxIndexArr[1] = vtxIndexArr[2]; } } break; @@ -141,12 +171,13 @@ class TriangleStripArrayRetained extends GeometryStripArrayRetained { while (i < stripVertexCounts.length) { j = stripStartVertexIndices[i]; end = j + stripVertexCounts[i++]; - getVertexData(j++, pnts[0]); - getVertexData(j++, pnts[1]); - count += 2; + for(int k=0; k<2; k++) { + vtxIndexArr[k] = j; + getVertexData(j++, pnts[k]); + } while (j < end) { + vtxIndexArr[2] = j; getVertexData(j++, pnts[2]); - count++; if (intersectBoundingSphere(pnts, bsphere, sdist, iPnt)) { if (flags == 0) { @@ -154,14 +185,23 @@ class TriangleStripArrayRetained extends GeometryStripArrayRetained { } if (sdist[0] < minDist) { minDist = sdist[0]; - minICount = count; x = iPnt.x; y = iPnt.y; z = iPnt.z; - } - } + if((flags & PickInfo.CLOSEST_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } + } + if((flags & PickInfo.ALL_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } + } pnts[0].set(pnts[1]); + vtxIndexArr[0] = vtxIndexArr[1]; pnts[1].set(pnts[2]); + vtxIndexArr[1] = vtxIndexArr[2]; } } break; @@ -172,12 +212,13 @@ class TriangleStripArrayRetained extends GeometryStripArrayRetained { while (i < stripVertexCounts.length) { j = stripStartVertexIndices[i]; end = j + stripVertexCounts[i++]; - getVertexData(j++, pnts[0]); - getVertexData(j++, pnts[1]); - count += 2; + for(int k=0; k<2; k++) { + vtxIndexArr[k] = j; + getVertexData(j++, pnts[k]); + } while (j < end) { + vtxIndexArr[2] = j; getVertexData(j++, pnts[2]); - count++; if (intersectBoundingPolytope(pnts, bpolytope, sdist, iPnt)) { if (flags == 0) { @@ -185,14 +226,23 @@ class TriangleStripArrayRetained extends GeometryStripArrayRetained { } if (sdist[0] < minDist) { minDist = sdist[0]; - minICount = count; x = iPnt.x; y = iPnt.y; z = iPnt.z; - } - } + if((flags & PickInfo.CLOSEST_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } + } + if((flags & PickInfo.ALL_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } + } pnts[0].set(pnts[1]); + vtxIndexArr[0] = vtxIndexArr[1]; pnts[1].set(pnts[2]); + vtxIndexArr[1] = vtxIndexArr[2]; } } break; @@ -202,26 +252,36 @@ class TriangleStripArrayRetained extends GeometryStripArrayRetained { while (i < stripVertexCounts.length) { j = stripStartVertexIndices[i]; end = j + stripVertexCounts[i++]; - getVertexData(j++, pnts[0]); - getVertexData(j++, pnts[1]); - count += 2; + for(int k=0; k<2; k++) { + vtxIndexArr[k] = j; + getVertexData(j++, pnts[k]); + } while (j < end) { + vtxIndexArr[2] = j; getVertexData(j++, pnts[2]); - count++; if (intersectCylinder(pnts, pickCylinder, sdist, iPnt)) { if (flags == 0) { return true; } if (sdist[0] < minDist) { minDist = sdist[0]; - minICount = count; x = iPnt.x; y = iPnt.y; z = iPnt.z; - } - } + if((flags & PickInfo.CLOSEST_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } + } + if((flags & PickInfo.ALL_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } + } pnts[0].set(pnts[1]); + vtxIndexArr[0] = vtxIndexArr[1]; pnts[1].set(pnts[2]); + vtxIndexArr[1] = vtxIndexArr[2]; } } break; @@ -231,26 +291,36 @@ class TriangleStripArrayRetained extends GeometryStripArrayRetained { while (i < stripVertexCounts.length) { j = stripStartVertexIndices[i]; end = j + stripVertexCounts[i++]; - getVertexData(j++, pnts[0]); - getVertexData(j++, pnts[1]); - count += 2; + for(int k=0; k<2; k++) { + vtxIndexArr[k] = j; + getVertexData(j++, pnts[k]); + } while (j < end) { + vtxIndexArr[2] = j; getVertexData(j++, pnts[2]); - count++; if (intersectCone(pnts, pickCone, sdist, iPnt)) { if (flags == 0) { return true; } if (sdist[0] < minDist) { minDist = sdist[0]; - minICount = count; x = iPnt.x; y = iPnt.y; z = iPnt.z; - } - } + if((flags & PickInfo.CLOSEST_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } + } + if((flags & PickInfo.ALL_GEOM_INFO) != 0) { + storeInterestData(pickInfo, flags, geom, geomIndex, + vtxIndexArr, iPnt, sdist[0]); + } + } pnts[0].set(pnts[1]); + vtxIndexArr[0] = vtxIndexArr[1]; pnts[1].set(pnts[2]); + vtxIndexArr[1] = vtxIndexArr[2]; } } break; @@ -262,15 +332,6 @@ class TriangleStripArrayRetained extends GeometryStripArrayRetained { } if (minDist < Double.MAX_VALUE) { - assert(minICount >=3); - int[] vertexIndices = iInfo.getVertexIndices(); - if (vertexIndices == null) { - vertexIndices = new int[3]; - iInfo.setVertexIndices(vertexIndices); - } - vertexIndices[0] = minICount - 3; - vertexIndices[1] = minICount - 2; - vertexIndices[2] = minICount - 1; iPnt.x = x; iPnt.y = y; iPnt.z = z; |