BoundingBox casterBB = new BoundingBox(); BoundingBox receiverBB = new BoundingBox(); BoundingVolume recvBox = bv.transform(viewProjMatrix, vars.bbox); if (splitBB.intersects(recvBox)) { receiverBB.mergeLocal(recvBox); receiverCount++; casterBB.setXExtent(casterBB.getXExtent() + 2.0f); casterBB.setYExtent(casterBB.getYExtent() + 2.0f); casterBB.setZExtent(casterBB.getZExtent() + 2.0f); Vector3f casterMin = casterBB.getMin(vars.vect1); Vector3f casterMax = casterBB.getMax(vars.vect2); Vector3f receiverMin = receiverBB.getMin(vars.vect3); Vector3f receiverMax = receiverBB.getMax(vars.vect4); Vector3f splitMin = splitBB.getMin(vars.vect5); Vector3f splitMax = splitBB.getMax(vars.vect6);
this.viewProjectionMatrix.set(cam.viewProjectionMatrix); this.guiBounding.setXExtent(cam.guiBounding.getXExtent()); this.guiBounding.setYExtent(cam.guiBounding.getYExtent()); this.guiBounding.setZExtent(cam.guiBounding.getZExtent()); this.guiBounding.setCenter(cam.guiBounding.getCenter()); this.guiBounding.setCheckPlane(cam.guiBounding.getCheckPlane());
/** * Use the bounding box of the supplied spatial to create a * BoxCollisionShape. * * @param spatial the spatial on which to base the shape (not null) * @param parent unused * @return a new shape with the dimensions of the spatial's bounding box * (not null) */ private static BoxCollisionShape createSingleBoxShape(Spatial spatial, Spatial parent) { //TODO: using world bound here instead of "local world" bound... BoxCollisionShape shape = new BoxCollisionShape( ((BoundingBox) spatial.getWorldBound()).getExtent(new Vector3f())); return shape; }
private static float calcScreenArea(BoundingBox bound, float distance, float screenWidth) { // Calc as if we are a BoundingSphere for now... float radiusSquare = bound.getXExtent() * bound.getXExtent() + bound.getYExtent() * bound.getYExtent() + bound.getZExtent() * bound.getZExtent(); return ((radiusSquare * screenWidth * screenWidth) / (distance * distance * 4)) * FastMath.PI; } }
private void setGuiBounding() { float sx = width * viewPortLeft; float ex = width * viewPortRight; float sy = height * viewPortBottom; float ey = height * viewPortTop; float xExtent = Math.max(0f, (ex - sx) / 2f); float yExtent = Math.max(0f, (ey - sy) / 2f); guiBounding.setCenter(sx + xExtent, sy + yExtent, 0); guiBounding.setXExtent(xExtent); guiBounding.setYExtent(yExtent); guiBounding.setZExtent(Float.MAX_VALUE); }
/** * Flat projection for 2D textures. * * @param mesh * mesh that is to be projected * @param bb * the bounding box for projecting * @return UV coordinates after the projection */ public static float[] flatProjection(float[] positions, BoundingBox bb) { Vector3f min = bb.getMin(null); float[] ext = new float[] { bb.getXExtent() * 2.0f, bb.getZExtent() * 2.0f }; float[] uvCoordinates = new float[positions.length / 3 * 2]; for (int i = 0, j = 0; i < positions.length; i += 3, j += 2) { uvCoordinates[j] = (positions[i] - min.x) / ext[0]; // skip the Y-coordinate uvCoordinates[j + 1] = (positions[i + 2] - min.z) / ext[1]; } return uvCoordinates; }
/** * This method converts the given point into 3D UV coordinates. * * @param boundingBox * the bounding box of the mesh * @param point * the point to be transformed * @param uvs * the result UV coordinates */ private void toTextureUV(BoundingBox boundingBox, Vector3f point, float[] uvs) { uvs[0] = (point.x - boundingBox.getCenter().x) / (boundingBox.getXExtent() == 0 ? 1 : boundingBox.getXExtent()); uvs[1] = (point.y - boundingBox.getCenter().y) / (boundingBox.getYExtent() == 0 ? 1 : boundingBox.getYExtent()); uvs[2] = (point.z - boundingBox.getCenter().z) / (boundingBox.getZExtent() == 0 ? 1 : boundingBox.getZExtent()); // UVS cannot go outside <0, 1> range, but since we are generating texture for triangle envelope it might happen that // some points of the envelope will exceet the bounding box of the mesh thus generating uvs outside the range for (int i = 0; i < 3; ++i) { uvs[i] = FastMath.clamp(uvs[i], 0, 1); } }
if (splitBB.intersects(recvBox)) { visRecvList.add(recvBox); boolean intersects = splitBB.intersects(occBox); if (!intersects && occBox instanceof BoundingBox) { BoundingBox occBB = (BoundingBox) occBox; occBB.setZExtent(occBB.getZExtent() + 50); occBB.setCenter(occBB.getCenter().addLocal(0, 0, 25)); if (splitBB.intersects(occBB)) { occBB.setZExtent(occBB.getZExtent() - 50); occBB.setCenter(occBB.getCenter().subtractLocal(0, 0, 25)); visOccList.add(occBox); if (splitOccluders != null) { casterBB.setXExtent(casterBB.getXExtent() + 2.0f); casterBB.setYExtent(casterBB.getYExtent() + 2.0f); casterBB.setZExtent(casterBB.getZExtent() + 2.0f); Vector3f casterMin = casterBB.getMin(null); Vector3f casterMax = casterBB.getMax(null); Vector3f receiverMin = receiverBB.getMin(null); Vector3f receiverMax = receiverBB.getMax(null); Vector3f splitMin = splitBB.getMin(null); Vector3f splitMax = splitBB.getMax(null);
Vector3f min = bb.getMin(null); float[] uvCoordsResults = new float[4];// used for coordinates swapping float[] ext = new float[] { bb.getXExtent() * 2, bb.getYExtent() * 2, bb.getZExtent() * 2 }; for (int i = 0; i < ext.length; ++i) { if (ext[i] == 0) {
geomsList.toArray(geoms); bbox = new BoundingBox(); for (Geometry geom : geoms){ BoundingVolume bv = geom.getWorldBound(); bbox.mergeLocal(bv); float extent = Math.max(bbox.getXExtent(), Math.max(bbox.getYExtent(), bbox.getZExtent())); bbox.setXExtent(extent); bbox.setYExtent(extent); bbox.setZExtent(extent);
BoundingVolume occBox = bv.transform(viewProjMatrix, vars.bbox); boolean intersects = splitBB.intersects(occBox); if (!intersects && occBox instanceof BoundingBox) { BoundingBox occBB = (BoundingBox) occBox; occBB.setZExtent(occBB.getZExtent() + 50); occBB.setCenter(occBB.getCenter().addLocal(0, 0, 25)); if (splitBB.intersects(occBB)) { occBB.setZExtent(occBB.getZExtent() - 50); occBB.setCenter(occBB.getCenter().subtractLocal(0, 0, 25)); casterBB.mergeLocal(occBox); casterCount++; casterBB.mergeLocal(occBox); casterCount++; if (splitOccluders != null) { BoundingVolume occBox = bv.transform(viewProjMatrix, vars.bbox); intersects = splitBB.intersects(occBox); if (!intersects && occBox instanceof BoundingBox) { BoundingBox occBB = (BoundingBox) occBox; occBB.setZExtent(occBB.getZExtent() + 50); occBB.setCenter(occBB.getCenter().addLocal(0, 0, 25)); intersects = splitBB.intersects(occBB);
Vector3f exteriorExt = nodeBbox.getExtent(null); Vector3f interiorExt = currentBox.getExtent(null); exteriorExt.subtractLocal(interiorExt); float split = currentBox.getCenter().get(axis); int pivot = sortTriangles(l, r, split, axis); if (pivot == l || pivot == r) { BoundingBox rbbox = new BoundingBox(currentBox); setMinMax(rbbox, true, axis, split); return createNode(l, r, rbbox, depth + 1); } else if (pivot > r) { BoundingBox lbbox = new BoundingBox(currentBox); setMinMax(lbbox, false, axis, split); return createNode(l, r, lbbox, depth + 1); BoundingBox lbbox = new BoundingBox(currentBox); setMinMax(lbbox, false, axis, split); BoundingBox rbbox = new BoundingBox(currentBox); setMinMax(rbbox, true, axis, split);
Vector3f topLeft = worldCoordinateToLocal(new Vector3f(bbox.getCenter().x-bbox.getXExtent(), 0, bbox.getCenter().z-bbox.getZExtent())); Vector3f topRight = worldCoordinateToLocal(new Vector3f(bbox.getCenter().x+bbox.getXExtent(), 0, bbox.getCenter().z-bbox.getZExtent())); Vector3f bottomLeft = worldCoordinateToLocal(new Vector3f(bbox.getCenter().x-bbox.getXExtent(), 0, bbox.getCenter().z+bbox.getZExtent())); Vector3f bottomRight = worldCoordinateToLocal(new Vector3f(bbox.getCenter().x+bbox.getXExtent(), 0, bbox.getCenter().z+bbox.getZExtent())); if (t != null && bbox.collideWith(t, results) > 0) return 1; t = getTriangle(topRight.x, topRight.z); if (t != null && bbox.collideWith(t, results) > 0) return 1; t = getTriangle(bottomLeft.x, bottomLeft.z); if (t != null && bbox.collideWith(t, results) > 0) return 1; t = getTriangle(bottomRight.x, bottomRight.z); if (t != null && bbox.collideWith(t, results) > 0) return 1; continue; t = getTriangle(x,z); if (t != null && bbox.collideWith(t, results) > 0) return 1;
/** * This will cause all normals for this terrain quad to be recalculated */ protected void setNeedToRecalculateNormals() { affectedAreaBBox = new BoundingBox(getWorldTranslation(), Float.MAX_VALUE, Float.MAX_VALUE, Float.MAX_VALUE); }
private static void findChildBound(BoundingBox bbox, int side){ float extent = bbox.getXExtent() * 0.5f; bbox.getCenter().set(bbox.getCenter().x + extent * Octnode.extentMult[side].x, bbox.getCenter().y + extent * Octnode.extentMult[side].y, bbox.getCenter().z + extent * Octnode.extentMult[side].z); bbox.setXExtent(extent); bbox.setYExtent(extent); bbox.setZExtent(extent); }
/** * Computes the bounds of multiple bounding volumes * * @param bv * @return */ public static BoundingBox computeUnionBound(List<BoundingVolume> bv) { BoundingBox bbox = new BoundingBox(); for (int i = 0; i < bv.size(); i++) { BoundingVolume vol = bv.get(i); bbox.mergeLocal(vol); } return bbox; }
vis.setLocalTranslation(1 + bb.getCenter().x - bb.getXExtent(), y - bb.getCenter().y - bb.getYExtent(), 0); y -= bb.getYExtent() * 2;