aboutsummaryrefslogtreecommitdiffstats
path: root/src/classes/share
diff options
context:
space:
mode:
authorChien Yang <[email protected]>2007-04-03 23:14:20 +0000
committerChien Yang <[email protected]>2007-04-03 23:14:20 +0000
commit56c485453abdddc3282bab4b42d76c920f5e29af (patch)
tree9fc4e026ca5da88b5833e78c7ab6c332ee41c19e /src/classes/share
parent1a9b22fe879d999ac84c7926a77f256c777ca6a1 (diff)
1) Submitted by Nvaidya - Fixed to Issue 447 : Enhance Element Traversal To Improve Pick Hits
2) Renamed zip file for src target. 3) Removed zip clean targets. git-svn-id: https://svn.java.net/svn/j3d-core~svn/trunk@809 ba19aa83-45c5-6ac9-afd3-db810772062c
Diffstat (limited to 'src/classes/share')
-rw-r--r--src/classes/share/javax/media/j3d/IndexedLineArrayRetained.java686
-rw-r--r--src/classes/share/javax/media/j3d/IndexedQuadArrayRetained.java90
-rw-r--r--src/classes/share/javax/media/j3d/IndexedTriangleArrayRetained.java72
3 files changed, 439 insertions, 409 deletions
diff --git a/src/classes/share/javax/media/j3d/IndexedLineArrayRetained.java b/src/classes/share/javax/media/j3d/IndexedLineArrayRetained.java
index df54f80..be93378 100644
--- a/src/classes/share/javax/media/j3d/IndexedLineArrayRetained.java
+++ b/src/classes/share/javax/media/j3d/IndexedLineArrayRetained.java
@@ -27,373 +27,383 @@ class IndexedLineArrayRetained extends IndexedGeometryArrayRetained {
}
boolean intersect(PickShape pickShape, PickInfo pickInfo, int flags, Point3d iPnt,
- GeometryRetained geom, int geomIndex) {
+ 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 i = ((vertexFormat & GeometryArray.BY_REFERENCE) == 0 ?
- initialVertexIndex : initialCoordIndex);
- pnts[0] = new Point3d();
- pnts[1] = new Point3d();
+ double sdist[] = new double[1];
+ double minDist = Double.MAX_VALUE;
+ double x = 0, y = 0, z = 0;
+ //NVaidya
+ // Bug 447: While loops below now traverse over all
+ // elements in the valid index range from initialIndexIndex
+ // to initialIndexInex + validIndexCount - 1
+ int i = initialIndexIndex;
+ int loopStopIndex = initialIndexIndex + validIndexCount;
+ 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) {
- 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)) {
- if (flags == 0) {
- return true;
- }
- if (sdist[0] < minDist) {
- minDist = sdist[0];
- 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]);
+
+ switch (pickShape.getPickType()) {
+ case PickShape.PICKRAY:
+ PickRay pickRay= (PickRay) pickShape;
+
+ while (i < loopStopIndex) {
+ 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)) {
+ if (flags == 0) {
+ return true;
+ }
+ if (sdist[0] < minDist) {
+ minDist = sdist[0];
+ 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]);
}
- }
- if((flags & PickInfo.ALL_GEOM_INFO) != 0) {
- storeInterestData(pickInfo, flags, geom, geomIndex,
- vtxIndexArr, iPnt, sdist[0]);
}
- }
- }
- break;
- case PickShape.PICKSEGMENT:
- PickSegment pickSegment = (PickSegment) pickShape;
- Vector3d dir =
- new Vector3d(pickSegment.end.x - pickSegment.start.x,
- pickSegment.end.y - pickSegment.start.y,
- pickSegment.end.z - pickSegment.start.z);
-
- while (i < validVertexCount) {
- 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) &&
- (sdist[0] <= 1.0)) {
- if (flags == 0) {
- return true;
- }
- if (sdist[0] < minDist) {
- minDist = sdist[0];
- 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]);
+ break;
+ case PickShape.PICKSEGMENT:
+ PickSegment pickSegment = (PickSegment) pickShape;
+ Vector3d dir =
+ new Vector3d(pickSegment.end.x - pickSegment.start.x,
+ pickSegment.end.y - pickSegment.start.y,
+ pickSegment.end.z - pickSegment.start.z);
+
+ while (i < loopStopIndex) {
+ 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) &&
+ (sdist[0] <= 1.0)) {
+ if (flags == 0) {
+ return true;
+ }
+ if (sdist[0] < minDist) {
+ minDist = sdist[0];
+ 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]);
}
- }
- if((flags & PickInfo.ALL_GEOM_INFO) != 0) {
- storeInterestData(pickInfo, flags, geom, geomIndex,
- vtxIndexArr, iPnt, sdist[0]);
}
- }
- }
- break;
- case PickShape.PICKBOUNDINGBOX:
- BoundingBox bbox = (BoundingBox)
- ((PickBounds) pickShape).bounds;
-
- while (i < validVertexCount) {
- 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];
- 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]);
+ break;
+ case PickShape.PICKBOUNDINGBOX:
+ BoundingBox bbox = (BoundingBox)
+ ((PickBounds) pickShape).bounds;
+
+ while (i < loopStopIndex) {
+ 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];
+ 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]);
}
- }
- 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) {
- 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];
- 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]);
+ break;
+ case PickShape.PICKBOUNDINGSPHERE:
+ BoundingSphere bsphere = (BoundingSphere)
+ ((PickBounds) pickShape).bounds;
+
+ while (i < loopStopIndex) {
+ 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];
+ 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]);
}
- }
- if((flags & PickInfo.ALL_GEOM_INFO) != 0) {
- storeInterestData(pickInfo, flags, geom, geomIndex,
- vtxIndexArr, iPnt, sdist[0]);
}
- }
- }
- break;
- case PickShape.PICKBOUNDINGPOLYTOPE:
- BoundingPolytope bpolytope = (BoundingPolytope)
- ((PickBounds) pickShape).bounds;
-
- while (i < validVertexCount) {
- 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];
- 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]);
+ break;
+ case PickShape.PICKBOUNDINGPOLYTOPE:
+ BoundingPolytope bpolytope = (BoundingPolytope)
+ ((PickBounds) pickShape).bounds;
+
+ while (i < loopStopIndex) {
+ 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];
+ 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]);
}
- }
- 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) {
- 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];
- 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]);
+ break;
+ case PickShape.PICKCYLINDER:
+ PickCylinder pickCylinder= (PickCylinder) pickShape;
+
+ while (i < loopStopIndex) {
+ 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];
+ 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]);
}
- }
- if((flags & PickInfo.ALL_GEOM_INFO) != 0) {
- storeInterestData(pickInfo, flags, geom, geomIndex,
- vtxIndexArr, iPnt, sdist[0]);
}
- }
- }
- break;
- case PickShape.PICKCONE:
- PickCone pickCone= (PickCone) pickShape;
-
- while (i < validVertexCount) {
- 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];
- 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]);
+ break;
+ case PickShape.PICKCONE:
+ PickCone pickCone= (PickCone) pickShape;
+
+ while (i < loopStopIndex) {
+ 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];
+ 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]);
}
- }
- if((flags & PickInfo.ALL_GEOM_INFO) != 0) {
- storeInterestData(pickInfo, flags, geom, geomIndex,
- vtxIndexArr, iPnt, sdist[0]);
}
- }
- }
- break;
- case PickShape.PICKPOINT:
- // Should not happen since API already check for this
- throw new IllegalArgumentException(J3dI18N.getString("IndexedLineArrayRetained0"));
- default:
- throw new RuntimeException ("PickShape not supported for intersection");
- }
-
- if (minDist < Double.MAX_VALUE) {
- iPnt.x = x;
- iPnt.y = y;
- iPnt.z = z;
- return true;
- }
- return false;
-
- }
+ }
+ break;
+ case PickShape.PICKPOINT:
+ // Should not happen since API already check for this
+ throw new IllegalArgumentException(J3dI18N.getString("IndexedLineArrayRetained0"));
+ default:
+ throw new RuntimeException("PickShape not supported for intersection");
+ }
+
+ if (minDist < Double.MAX_VALUE) {
+ iPnt.x = x;
+ iPnt.y = y;
+ iPnt.z = z;
+ return true;
+ }
+ return false;
+
+ }
boolean intersect(Point3d[] pnts) {
- Point3d[] points = new Point3d[2];
- Vector3d dir;
- double dist[] = new double[1];
- int i = ((vertexFormat & GeometryArray.BY_REFERENCE) == 0 ?
- initialVertexIndex : initialCoordIndex);
- points[0] = new Point3d();
- points[1] = new Point3d();
-
- switch (pnts.length) {
- case 3: // Triangle/Quad , common case first
- case 4:
- while (i < validVertexCount) {
- getVertexData(indexCoord[i++], points[0]);
- getVertexData(indexCoord[i++], points[1]);
- if (intersectSegment(pnts, points[0], points[1], dist,
- null)) {
- return true;
- }
- }
- break;
- case 2: // Line
- dir = new Vector3d();
- while (i < validVertexCount) {
- getVertexData(indexCoord[i++], points[0]);
- getVertexData(indexCoord[i++], points[1]);
- dir.x = points[1].x - points[0].x;
- dir.y = points[1].y - points[0].y;
- dir.z = points[1].z - points[0].z;
- if (intersectLineAndRay(pnts[0], pnts[1], points[0],
- dir, dist, null) &&
- (dist[0] <= 1.0)) {
- return true;
- }
- }
- break;
- case 1: // Point
- dir = new Vector3d();
- while (i < validVertexCount) {
- getVertexData(indexCoord[i++], points[0]);
- getVertexData(indexCoord[i++], points[1]);
- dir.x = points[1].x - points[0].x;
- dir.y = points[1].y - points[0].y;
- dir.z = points[1].z - points[0].z;
- if (intersectPntAndRay(pnts[0], points[0], dir, dist) &&
- (dist[0] <= 1.0)) {
- return true;
- }
- }
- break;
- }
- return false;
+ Point3d[] points = new Point3d[2];
+ Vector3d dir;
+ double dist[] = new double[1];
+ //NVaidya
+ // Bug 447: correction for loop indices
+ int i = initialIndexIndex;
+ int loopStopIndex = initialIndexIndex + validIndexCount;
+ points[0] = new Point3d();
+ points[1] = new Point3d();
+
+ switch (pnts.length) {
+ case 3: // Triangle/Quad , common case first
+ case 4:
+ while (i < loopStopIndex) {
+ getVertexData(indexCoord[i++], points[0]);
+ getVertexData(indexCoord[i++], points[1]);
+ if (intersectSegment(pnts, points[0], points[1], dist,
+ null)) {
+ return true;
+ }
+ }
+ break;
+ case 2: // Line
+ dir = new Vector3d();
+ while (i < loopStopIndex) {
+ getVertexData(indexCoord[i++], points[0]);
+ getVertexData(indexCoord[i++], points[1]);
+ dir.x = points[1].x - points[0].x;
+ dir.y = points[1].y - points[0].y;
+ dir.z = points[1].z - points[0].z;
+ if (intersectLineAndRay(pnts[0], pnts[1], points[0],
+ dir, dist, null) &&
+ (dist[0] <= 1.0)) {
+ return true;
+ }
+ }
+ break;
+ case 1: // Point
+ dir = new Vector3d();
+ while (i < loopStopIndex) {
+ getVertexData(indexCoord[i++], points[0]);
+ getVertexData(indexCoord[i++], points[1]);
+ dir.x = points[1].x - points[0].x;
+ dir.y = points[1].y - points[0].y;
+ dir.z = points[1].z - points[0].z;
+ if (intersectPntAndRay(pnts[0], points[0], dir, dist) &&
+ (dist[0] <= 1.0)) {
+ return true;
+ }
+ }
+ break;
+ }
+ return false;
}
-
-
+
+
boolean intersect(Transform3D thisToOtherVworld,
- GeometryRetained geom) {
-
- Point3d[] pnts = new Point3d[2];
- int i = ((vertexFormat & GeometryArray.BY_REFERENCE) == 0 ?
- initialVertexIndex : initialCoordIndex);
- pnts[0] = new Point3d();
- pnts[1] = new Point3d();
-
- while (i < validVertexCount) {
- getVertexData(indexCoord[i++], pnts[0]);
- getVertexData(indexCoord[i++], pnts[1]);
- thisToOtherVworld.transform(pnts[0]);
- thisToOtherVworld.transform(pnts[1]);
- if (geom.intersect(pnts)) {
- return true;
- }
- }
- return false;
+ GeometryRetained geom) {
+
+ Point3d[] pnts = new Point3d[2];
+ //NVaidya
+ // Bug 447: correction for loop indices
+ int i = initialIndexIndex;
+ int loopStopIndex = initialIndexIndex + validIndexCount;
+ pnts[0] = new Point3d();
+ pnts[1] = new Point3d();
+
+ while (i < loopStopIndex) {
+ getVertexData(indexCoord[i++], pnts[0]);
+ getVertexData(indexCoord[i++], pnts[1]);
+ thisToOtherVworld.transform(pnts[0]);
+ thisToOtherVworld.transform(pnts[1]);
+ if (geom.intersect(pnts)) {
+ return true;
+ }
+ }
+ return false;
}
-
+
// the bounds argument is already transformed
boolean intersect(Bounds targetBound) {
- Point3d[] pnts = new Point3d[2];
- int i = ((vertexFormat & GeometryArray.BY_REFERENCE) == 0 ?
- initialVertexIndex : initialCoordIndex);
- pnts[0] = new Point3d();
- pnts[1] = new Point3d();
-
- switch(targetBound.getPickType()) {
- case PickShape.PICKBOUNDINGBOX:
- BoundingBox box = (BoundingBox) targetBound;
-
- while(i < validVertexCount) {
- getVertexData(indexCoord[i++], pnts[0]);
- getVertexData(indexCoord[i++], pnts[1]);
- if (intersectBoundingBox(pnts, box, null, null)) {
- return true;
- }
- }
- break;
- case PickShape.PICKBOUNDINGSPHERE:
- BoundingSphere bsphere = (BoundingSphere) targetBound;
-
- while(i < validVertexCount) {
- getVertexData(indexCoord[i++], pnts[0]);
- getVertexData(indexCoord[i++], pnts[1]);
- if (intersectBoundingSphere(pnts, bsphere, null, null)) {
- return true;
- }
- }
- break;
- case PickShape.PICKBOUNDINGPOLYTOPE:
- BoundingPolytope bpolytope = (BoundingPolytope) targetBound;
-
- while(i < validVertexCount) {
- getVertexData(indexCoord[i++], pnts[0]);
- getVertexData(indexCoord[i++], pnts[1]);
- if (intersectBoundingPolytope(pnts, bpolytope, null, null)) {
- return true;
- }
- }
- break;
- default:
- throw new RuntimeException("Bounds not supported for intersection "
- + targetBound);
- }
- return false;
+ Point3d[] pnts = new Point3d[2];
+ //NVaidya
+ // Bug 447: correction for loop indices
+ int i = initialIndexIndex;
+ int loopStopIndex = initialIndexIndex + validIndexCount;
+ pnts[0] = new Point3d();
+ pnts[1] = new Point3d();
+
+ switch(targetBound.getPickType()) {
+ case PickShape.PICKBOUNDINGBOX:
+ BoundingBox box = (BoundingBox) targetBound;
+
+ while(i < loopStopIndex) {
+ getVertexData(indexCoord[i++], pnts[0]);
+ getVertexData(indexCoord[i++], pnts[1]);
+ if (intersectBoundingBox(pnts, box, null, null)) {
+ return true;
+ }
+ }
+ break;
+ case PickShape.PICKBOUNDINGSPHERE:
+ BoundingSphere bsphere = (BoundingSphere) targetBound;
+
+ while(i < loopStopIndex) {
+ getVertexData(indexCoord[i++], pnts[0]);
+ getVertexData(indexCoord[i++], pnts[1]);
+ if (intersectBoundingSphere(pnts, bsphere, null, null)) {
+ return true;
+ }
+ }
+ break;
+ case PickShape.PICKBOUNDINGPOLYTOPE:
+ BoundingPolytope bpolytope = (BoundingPolytope) targetBound;
+
+ while(i < loopStopIndex) {
+ getVertexData(indexCoord[i++], pnts[0]);
+ getVertexData(indexCoord[i++], pnts[1]);
+ if (intersectBoundingPolytope(pnts, bpolytope, null, null)) {
+ return true;
+ }
+ }
+ break;
+ default:
+ throw new RuntimeException("Bounds not supported for intersection "
+ + targetBound);
+ }
+ return false;
}
int getClassType() {
diff --git a/src/classes/share/javax/media/j3d/IndexedQuadArrayRetained.java b/src/classes/share/javax/media/j3d/IndexedQuadArrayRetained.java
index 86234ee..6b58410 100644
--- a/src/classes/share/javax/media/j3d/IndexedQuadArrayRetained.java
+++ b/src/classes/share/javax/media/j3d/IndexedQuadArrayRetained.java
@@ -34,19 +34,23 @@ class IndexedQuadArrayRetained extends IndexedGeometryArrayRetained {
double minDist = Double.MAX_VALUE;
double x = 0, y = 0, z = 0;
int[] vtxIndexArr = new int[4];
-
- int i = ((vertexFormat & GeometryArray.BY_REFERENCE) == 0 ?
- initialVertexIndex : initialCoordIndex);
- pnts[0] = new Point3d();
- pnts[1] = new Point3d();
- pnts[2] = new Point3d();
+
+ //NVaidya
+ // Bug 447: While loops below now traverse over all
+ // elements in the valid index range from initialIndexIndex
+ // to initialIndexInex + validIndexCount - 1
+ int i = initialIndexIndex;
+ int loopStopIndex = initialIndexIndex + validIndexCount;
+ pnts[0] = new Point3d();
+ pnts[1] = new Point3d();
+ pnts[2] = new Point3d();
pnts[3] = new Point3d();
switch (pickShape.getPickType()) {
case PickShape.PICKRAY:
PickRay pickRay= (PickRay) pickShape;
- while (i < validVertexCount) {
+ while (i < loopStopIndex) {
for(int j=0; j<4; j++) {
vtxIndexArr[j] = indexCoord[i];
getVertexData(indexCoord[i++], pnts[j]);
@@ -75,7 +79,7 @@ class IndexedQuadArrayRetained extends IndexedGeometryArrayRetained {
case PickShape.PICKSEGMENT:
PickSegment pickSegment = (PickSegment) pickShape;
- while (i < validVertexCount) {
+ while (i < loopStopIndex) {
for(int j=0; j<4; j++) {
vtxIndexArr[j] = indexCoord[i];
getVertexData(indexCoord[i++], pnts[j]);
@@ -105,7 +109,7 @@ class IndexedQuadArrayRetained extends IndexedGeometryArrayRetained {
case PickShape.PICKBOUNDINGBOX:
BoundingBox bbox = (BoundingBox)
((PickBounds) pickShape).bounds;
- while (i < validVertexCount) {
+ while (i < loopStopIndex) {
for(int j=0; j<4; j++) {
vtxIndexArr[j] = indexCoord[i];
getVertexData(indexCoord[i++], pnts[j]);
@@ -134,7 +138,7 @@ class IndexedQuadArrayRetained extends IndexedGeometryArrayRetained {
case PickShape.PICKBOUNDINGSPHERE:
BoundingSphere bsphere = (BoundingSphere)
((PickBounds) pickShape).bounds;
- while (i < validVertexCount) {
+ while (i < loopStopIndex) {
for(int j=0; j<4; j++) {
vtxIndexArr[j] = indexCoord[i];
getVertexData(indexCoord[i++], pnts[j]);
@@ -163,7 +167,7 @@ class IndexedQuadArrayRetained extends IndexedGeometryArrayRetained {
case PickShape.PICKBOUNDINGPOLYTOPE:
BoundingPolytope bpolytope = (BoundingPolytope)
((PickBounds) pickShape).bounds;
- while (i < validVertexCount) {
+ while (i < loopStopIndex) {
for(int j=0; j<4; j++) {
vtxIndexArr[j] = indexCoord[i];
getVertexData(indexCoord[i++], pnts[j]);
@@ -191,7 +195,7 @@ class IndexedQuadArrayRetained extends IndexedGeometryArrayRetained {
break;
case PickShape.PICKCYLINDER:
PickCylinder pickCylinder= (PickCylinder) pickShape;
- while (i < validVertexCount) {
+ while (i < loopStopIndex) {
for(int j=0; j<4; j++) {
vtxIndexArr[j] = indexCoord[i];
getVertexData(indexCoord[i++], pnts[j]);
@@ -219,7 +223,7 @@ class IndexedQuadArrayRetained extends IndexedGeometryArrayRetained {
break;
case PickShape.PICKCONE:
PickCone pickCone= (PickCone) pickShape;
- while (i < validVertexCount) {
+ while (i < loopStopIndex) {
for(int j=0; j<4; j++) {
vtxIndexArr[j] = indexCoord[i];
getVertexData(indexCoord[i++], pnts[j]);
@@ -265,18 +269,20 @@ class IndexedQuadArrayRetained extends IndexedGeometryArrayRetained {
// intersect pnts[] with every quad in this object
boolean intersect(Point3d[] pnts) {
Point3d[] points = new Point3d[4];
- double dist[] = new double[1];
- int i = ((vertexFormat & GeometryArray.BY_REFERENCE) == 0 ?
- initialVertexIndex : initialCoordIndex);
-
- points[0] = new Point3d();
- points[1] = new Point3d();
+ double dist[] = new double[1];
+ //NVaidya
+ // Bug 447: correction for loop indices
+ int i = initialIndexIndex;
+ int loopStopIndex = initialIndexIndex + validIndexCount;
+
+ points[0] = new Point3d();
+ points[1] = new Point3d();
points[2] = new Point3d();
points[3] = new Point3d();
switch (pnts.length) {
case 3: // Triangle
- while (i < validVertexCount) {
+ while (i < loopStopIndex) {
getVertexData(indexCoord[i++], points[0]);
getVertexData(indexCoord[i++], points[1]);
getVertexData(indexCoord[i++], points[2]);
@@ -290,7 +296,7 @@ class IndexedQuadArrayRetained extends IndexedGeometryArrayRetained {
}
break;
case 4: // Quad
- while (i < validVertexCount) {
+ while (i < loopStopIndex) {
getVertexData(indexCoord[i++], points[0]);
getVertexData(indexCoord[i++], points[1]);
getVertexData(indexCoord[i++], points[2]);
@@ -308,7 +314,7 @@ class IndexedQuadArrayRetained extends IndexedGeometryArrayRetained {
}
break;
case 2: // Line
- while (i < validVertexCount) {
+ while (i < loopStopIndex) {
getVertexData(indexCoord[i++], points[0]);
getVertexData(indexCoord[i++], points[1]);
getVertexData(indexCoord[i++], points[2]);
@@ -320,7 +326,7 @@ class IndexedQuadArrayRetained extends IndexedGeometryArrayRetained {
}
break;
case 1: // Point
- while (i < validVertexCount) {
+ while (i < loopStopIndex) {
getVertexData(indexCoord[i++], points[0]);
getVertexData(indexCoord[i++], points[1]);
getVertexData(indexCoord[i++], points[2]);
@@ -341,16 +347,18 @@ class IndexedQuadArrayRetained extends IndexedGeometryArrayRetained {
boolean intersect(Transform3D thisToOtherVworld,
GeometryRetained geom) {
- Point3d[] points = new Point3d[4];
- int i = ((vertexFormat & GeometryArray.BY_REFERENCE) == 0 ?
- initialVertexIndex : initialCoordIndex);
-
- points[0] = new Point3d();
+ Point3d[] points = new Point3d[4];
+ //NVaidya
+ // Bug 447: correction for loop indices
+ int i = initialIndexIndex;
+ int loopStopIndex = initialIndexIndex + validIndexCount;
+
+ points[0] = new Point3d();
points[1] = new Point3d();
points[2] = new Point3d();
points[3] = new Point3d();
- while (i < validVertexCount) {
+ while (i < loopStopIndex) {
getVertexData(indexCoord[i++], points[0]);
getVertexData(indexCoord[i++], points[1]);
getVertexData(indexCoord[i++], points[2]);
@@ -368,20 +376,22 @@ class IndexedQuadArrayRetained extends IndexedGeometryArrayRetained {
// the bounds argument is already transformed
boolean intersect(Bounds targetBound) {
- Point3d[] points = new Point3d[4];
- int i = ((vertexFormat & GeometryArray.BY_REFERENCE) == 0 ?
- initialVertexIndex : initialCoordIndex);
-
- points[0] = new Point3d();
- points[1] = new Point3d();
- points[2] = new Point3d();
- points[3] = new Point3d();
+ Point3d[] points = new Point3d[4];
+ //NVaidya
+ // Bug 447: correction for loop indices
+ int i = initialIndexIndex;
+ int loopStopIndex = initialIndexIndex + validIndexCount;
+
+ points[0] = new Point3d();
+ points[1] = new Point3d();
+ points[2] = new Point3d();
+ points[3] = new Point3d();
switch(targetBound.getPickType()) {
case PickShape.PICKBOUNDINGBOX:
BoundingBox box = (BoundingBox) targetBound;
- while (i < validVertexCount) {
+ while (i < loopStopIndex) {
getVertexData(indexCoord[i++], points[0]);
getVertexData(indexCoord[i++], points[1]);
getVertexData(indexCoord[i++], points[2]);
@@ -394,7 +404,7 @@ class IndexedQuadArrayRetained extends IndexedGeometryArrayRetained {
case PickShape.PICKBOUNDINGSPHERE:
BoundingSphere bsphere = (BoundingSphere) targetBound;
- while (i < validVertexCount) {
+ while (i < loopStopIndex) {
getVertexData(indexCoord[i++], points[0]);
getVertexData(indexCoord[i++], points[1]);
getVertexData(indexCoord[i++], points[2]);
@@ -407,7 +417,7 @@ class IndexedQuadArrayRetained extends IndexedGeometryArrayRetained {
break;
case PickShape.PICKBOUNDINGPOLYTOPE:
BoundingPolytope bpolytope = (BoundingPolytope) targetBound;
- while (i < validVertexCount) {
+ while (i < loopStopIndex) {
getVertexData(indexCoord[i++], points[0]);
getVertexData(indexCoord[i++], points[1]);
getVertexData(indexCoord[i++], points[2]);
diff --git a/src/classes/share/javax/media/j3d/IndexedTriangleArrayRetained.java b/src/classes/share/javax/media/j3d/IndexedTriangleArrayRetained.java
index 0f12d22..ecdc8fb 100644
--- a/src/classes/share/javax/media/j3d/IndexedTriangleArrayRetained.java
+++ b/src/classes/share/javax/media/j3d/IndexedTriangleArrayRetained.java
@@ -29,14 +29,18 @@ class IndexedTriangleArrayRetained extends IndexedGeometryArrayRetained {
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;
+ 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);
+ //NVaidya
+ // Bug 447: While loops below now traverse over all
+ // elements in the valid index range from initialIndexIndex
+ // to initialIndexInex + validIndexCount - 1
+ int i = initialIndexIndex;
+ int loopStopIndex = initialIndexIndex + validIndexCount;
pnts[0] = new Point3d();
pnts[1] = new Point3d();
pnts[2] = new Point3d();
@@ -45,7 +49,7 @@ class IndexedTriangleArrayRetained extends IndexedGeometryArrayRetained {
case PickShape.PICKRAY:
PickRay pickRay= (PickRay) pickShape;
- while (i < validVertexCount) {
+ while (i < loopStopIndex) {
for(int j=0; j<3; j++) {
vtxIndexArr[j] = indexCoord[i];
getVertexData(indexCoord[i++], pnts[j]);
@@ -73,7 +77,7 @@ class IndexedTriangleArrayRetained extends IndexedGeometryArrayRetained {
break;
case PickShape.PICKSEGMENT:
PickSegment pickSegment = (PickSegment) pickShape;
- while (i < validVertexCount) {
+ while (i < loopStopIndex) {
for(int j=0; j<3; j++) {
vtxIndexArr[j] = indexCoord[i];
getVertexData(indexCoord[i++], pnts[j]);
@@ -104,7 +108,7 @@ class IndexedTriangleArrayRetained extends IndexedGeometryArrayRetained {
BoundingBox bbox = (BoundingBox)
((PickBounds) pickShape).bounds;
- while (i < validVertexCount) {
+ while (i < loopStopIndex) {
for(int j=0; j<3; j++) {
vtxIndexArr[j] = indexCoord[i];
getVertexData(indexCoord[i++], pnts[j]);
@@ -134,7 +138,7 @@ class IndexedTriangleArrayRetained extends IndexedGeometryArrayRetained {
BoundingSphere bsphere = (BoundingSphere)
((PickBounds) pickShape).bounds;
- while (i < validVertexCount) {
+ while (i < loopStopIndex) {
for(int j=0; j<3; j++) {
vtxIndexArr[j] = indexCoord[i];
getVertexData(indexCoord[i++], pnts[j]);
@@ -164,7 +168,7 @@ class IndexedTriangleArrayRetained extends IndexedGeometryArrayRetained {
BoundingPolytope bpolytope = (BoundingPolytope)
((PickBounds) pickShape).bounds;
- while (i < validVertexCount) {
+ while (i < loopStopIndex) {
for(int j=0; j<3; j++) {
vtxIndexArr[j] = indexCoord[i];
getVertexData(indexCoord[i++], pnts[j]);
@@ -193,7 +197,7 @@ class IndexedTriangleArrayRetained extends IndexedGeometryArrayRetained {
break;
case PickShape.PICKCYLINDER:
PickCylinder pickCylinder= (PickCylinder) pickShape;
- while (i < validVertexCount) {
+ while (i < loopStopIndex) {
for(int j=0; j<3; j++) {
vtxIndexArr[j] = indexCoord[i];
getVertexData(indexCoord[i++], pnts[j]);
@@ -223,7 +227,7 @@ class IndexedTriangleArrayRetained extends IndexedGeometryArrayRetained {
case PickShape.PICKCONE:
PickCone pickCone= (PickCone) pickShape;
- while (i < validVertexCount) {
+ while (i < loopStopIndex) {
for(int j=0; j<3; j++) {
vtxIndexArr[j] = indexCoord[i];
getVertexData(indexCoord[i++], pnts[j]);
@@ -268,9 +272,11 @@ class IndexedTriangleArrayRetained extends IndexedGeometryArrayRetained {
// intersect pnts[] with every triangle in this object
boolean intersect(Point3d[] pnts) {
Point3d[] points = new Point3d[3];
- double dist[] = new double[1];
- int i = ((vertexFormat & GeometryArray.BY_REFERENCE) == 0 ?
- initialVertexIndex : initialCoordIndex);
+ double dist[] = new double[1];
+ //NVaidya
+ // Bug 447: correction for loop indices
+ int i = initialIndexIndex;
+ int loopStopIndex = initialIndexIndex + validIndexCount;
points[0] = new Point3d();
points[1] = new Point3d();
@@ -278,7 +284,7 @@ class IndexedTriangleArrayRetained extends IndexedGeometryArrayRetained {
switch (pnts.length) {
case 3: // Triangle
- while (i<validVertexCount) {
+ while (i<loopStopIndex) {
getVertexData(indexCoord[i++], points[0]);
getVertexData(indexCoord[i++], points[1]);
getVertexData(indexCoord[i++], points[2]);
@@ -289,7 +295,7 @@ class IndexedTriangleArrayRetained extends IndexedGeometryArrayRetained {
}
break;
case 4: // Quad
- while (i<validVertexCount) {
+ while (i<loopStopIndex) {
getVertexData(indexCoord[i++], points[0]);
getVertexData(indexCoord[i++], points[1]);
getVertexData(indexCoord[i++], points[2]);
@@ -302,7 +308,7 @@ class IndexedTriangleArrayRetained extends IndexedGeometryArrayRetained {
}
break;
case 2: // Line
- while (i<validVertexCount) {
+ while (i<loopStopIndex) {
getVertexData(indexCoord[i++], points[0]);
getVertexData(indexCoord[i++], points[1]);
getVertexData(indexCoord[i++], points[2]);
@@ -313,7 +319,7 @@ class IndexedTriangleArrayRetained extends IndexedGeometryArrayRetained {
}
break;
case 1: // Point
- while (i<validVertexCount) {
+ while (i<loopStopIndex) {
getVertexData(indexCoord[i++], points[0]);
getVertexData(indexCoord[i++], points[1]);
getVertexData(indexCoord[i++], points[2]);
@@ -329,14 +335,16 @@ class IndexedTriangleArrayRetained extends IndexedGeometryArrayRetained {
boolean intersect(Transform3D thisToOtherVworld, GeometryRetained geom) {
- Point3d[] pnts = new Point3d[3];
- int i = ((vertexFormat & GeometryArray.BY_REFERENCE) == 0 ?
- initialVertexIndex : initialCoordIndex);
+ Point3d[] pnts = new Point3d[3];
+ //NVaidya
+ // Bug 447: correction for loop indices
+ int i = initialIndexIndex;
+ int loopStopIndex = initialIndexIndex + validIndexCount;
pnts[0] = new Point3d();
pnts[1] = new Point3d();
pnts[2] = new Point3d();
- while (i < validVertexCount) {
+ while (i < loopStopIndex) {
getVertexData(indexCoord[i++], pnts[0]);
getVertexData(indexCoord[i++], pnts[1]);
getVertexData(indexCoord[i++], pnts[2]);
@@ -352,10 +360,12 @@ class IndexedTriangleArrayRetained extends IndexedGeometryArrayRetained {
// the bounds argument is already transformed
boolean intersect(Bounds targetBound) {
- Point3d[] pnts = new Point3d[3];
- int i = ((vertexFormat & GeometryArray.BY_REFERENCE) == 0 ?
- initialVertexIndex : initialCoordIndex);
- pnts[0] = new Point3d();
+ Point3d[] pnts = new Point3d[3];
+ //NVaidya
+ // Bug 447: correction for loop indices
+ int i = initialIndexIndex;
+ int loopStopIndex = initialIndexIndex + validIndexCount;
+ pnts[0] = new Point3d();
pnts[1] = new Point3d();
pnts[2] = new Point3d();
@@ -363,7 +373,7 @@ class IndexedTriangleArrayRetained extends IndexedGeometryArrayRetained {
case PickShape.PICKBOUNDINGBOX:
BoundingBox box = (BoundingBox) targetBound;
- while (i < validVertexCount) {
+ while (i < loopStopIndex) {
getVertexData(indexCoord[i++], pnts[0]);
getVertexData(indexCoord[i++], pnts[1]);
getVertexData(indexCoord[i++], pnts[2]);
@@ -375,7 +385,7 @@ class IndexedTriangleArrayRetained extends IndexedGeometryArrayRetained {
case PickShape.PICKBOUNDINGSPHERE:
BoundingSphere bsphere = (BoundingSphere) targetBound;
- while (i < validVertexCount) {
+ while (i < loopStopIndex) {
getVertexData(indexCoord[i++], pnts[0]);
getVertexData(indexCoord[i++], pnts[1]);
getVertexData(indexCoord[i++], pnts[1]);
@@ -388,7 +398,7 @@ class IndexedTriangleArrayRetained extends IndexedGeometryArrayRetained {
case PickShape.PICKBOUNDINGPOLYTOPE:
BoundingPolytope bpolytope = (BoundingPolytope) targetBound;
- while (i < validVertexCount) {
+ while (i < loopStopIndex) {
getVertexData(indexCoord[i++], pnts[0]);
getVertexData(indexCoord[i++], pnts[1]);
getVertexData(indexCoord[i++], pnts[2]);