📄 trianglestriparrayretained.java
字号:
/* * $RCSfile: TriangleStripArrayRetained.java,v $ * * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved. * * Use is subject to license terms. * * $Revision: 1.7 $ * $Date: 2007/02/09 17:18:29 $ * $State: Exp $ */package javax.media.j3d;import javax.vecmath.*;import java.lang.Math;/** * The TriangleStripArray object draws an array of vertices as a set of * connected triangle strips. An array of per-strip vertex counts specifies * where the separate strips appear in the vertex array. * For every strip in the set, * each vertex, beginning with the third vertex in the array, * defines a triangle to be drawn using the current vertex and * the two previous vertices. */class TriangleStripArrayRetained extends GeometryStripArrayRetained { TriangleStripArrayRetained() { this.geoType = GEO_TYPE_TRI_STRIP_SET; } 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; 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 < stripVertexCounts.length) { j = stripStartVertexIndices[i]; end = j + stripVertexCounts[i++]; for(int k=0; k<2; k++) { vtxIndexArr[k] = j; getVertexData(j++, pnts[k]); } while (j < end) { 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]; 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; case PickShape.PICKSEGMENT: PickSegment pickSegment = (PickSegment) pickShape; while (i < stripVertexCounts.length) { j = stripStartVertexIndices[i]; end = j + stripVertexCounts[i++]; for(int k=0; k<2; k++) { vtxIndexArr[k] = j; getVertexData(j++, pnts[k]); } while (j < end) { vtxIndexArr[2] = j; getVertexData(j++, pnts[2]); if (intersectSegment(pnts, pickSegment.start, pickSegment.end, 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]); } } pnts[0].set(pnts[1]); vtxIndexArr[0] = vtxIndexArr[1]; pnts[1].set(pnts[2]); vtxIndexArr[1] = vtxIndexArr[2]; } } break; case PickShape.PICKBOUNDINGBOX: BoundingBox bbox = (BoundingBox) ((PickBounds) pickShape).bounds; while (i < stripVertexCounts.length) { j = stripStartVertexIndices[i]; end = j + stripVertexCounts[i++]; for(int k=0; k<2; k++) { vtxIndexArr[k] = j; getVertexData(j++, pnts[k]); } while (j < end) { vtxIndexArr[2] = j; getVertexData(j++, pnts[2]); 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]); } } pnts[0].set(pnts[1]); vtxIndexArr[0] = vtxIndexArr[1]; pnts[1].set(pnts[2]); vtxIndexArr[1] = vtxIndexArr[2]; } } break; case PickShape.PICKBOUNDINGSPHERE: BoundingSphere bsphere = (BoundingSphere) ((PickBounds) pickShape).bounds; while (i < stripVertexCounts.length) { j = stripStartVertexIndices[i]; end = j + stripVertexCounts[i++]; for(int k=0; k<2; k++) { vtxIndexArr[k] = j; getVertexData(j++, pnts[k]); } while (j < end) { vtxIndexArr[2] = j; getVertexData(j++, pnts[2]); 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]); } } pnts[0].set(pnts[1]); vtxIndexArr[0] = vtxIndexArr[1]; pnts[1].set(pnts[2]); vtxIndexArr[1] = vtxIndexArr[2]; } } break; case PickShape.PICKBOUNDINGPOLYTOPE: BoundingPolytope bpolytope = (BoundingPolytope) ((PickBounds) pickShape).bounds; while (i < stripVertexCounts.length) { j = stripStartVertexIndices[i]; end = j + stripVertexCounts[i++]; for(int k=0; k<2; k++) { vtxIndexArr[k] = j; getVertexData(j++, pnts[k]); } while (j < end) { vtxIndexArr[2] = j; getVertexData(j++, pnts[2]); 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]); } } pnts[0].set(pnts[1]); vtxIndexArr[0] = vtxIndexArr[1]; pnts[1].set(pnts[2]); vtxIndexArr[1] = vtxIndexArr[2]; } } break; case PickShape.PICKCYLINDER: PickCylinder pickCylinder= (PickCylinder) pickShape; while (i < stripVertexCounts.length) { j = stripStartVertexIndices[i]; end = j + stripVertexCounts[i++]; for(int k=0; k<2; k++) { vtxIndexArr[k] = j; getVertexData(j++, pnts[k]); } while (j < end) { vtxIndexArr[2] = j; getVertexData(j++, pnts[2]); 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]); } } pnts[0].set(pnts[1]); vtxIndexArr[0] = vtxIndexArr[1]; pnts[1].set(pnts[2]); vtxIndexArr[1] = vtxIndexArr[2]; } } break; case PickShape.PICKCONE: PickCone pickCone= (PickCone) pickShape; while (i < stripVertexCounts.length) { j = stripStartVertexIndices[i]; end = j + stripVertexCounts[i++]; for(int k=0; k<2; k++) { vtxIndexArr[k] = j; getVertexData(j++, pnts[k]); } while (j < end) { vtxIndexArr[2] = j; getVertexData(j++, pnts[2]); if (intersectCone(pnts, pickCone, sdist, iPnt)) { if (flags == 0) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -