📄 indexedlinearrayretained.java
字号:
/* * $RCSfile: IndexedLineArrayRetained.java,v $ * * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved. * * Use is subject to license terms. * * $Revision: 1.7 $ * $Date: 2007/04/03 23:14:19 $ * $State: Exp $ */package javax.media.j3d;import javax.vecmath.*;import java.lang.Math;/** * The IndexedLineArray object draws the array of vertices as individual * line segments. Each pair of vertices defines a line to be drawn. */class IndexedLineArrayRetained extends IndexedGeometryArrayRetained { IndexedLineArrayRetained() { this.geoType = GEO_TYPE_INDEXED_LINE_SET; } 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; //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 < 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]); } } } 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]); } } } 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]); } } } 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]); } } } 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]); } } } break; case PickShape.PICKCYLINDER: PickCylinder pickCylinder= (PickCylinder) pickShape; while (i < loopStopIndex) { for(int k=0; k<2; k++) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -