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; } }
/** * This method returns the bounding sphere of the given geometries. * * @param geometries * the list of geometries * @return bounding sphere of the given geometries */ /* package */static BoundingSphere getBoundingSphere(Geometry... geometries) { BoundingSphere result = null; for (Geometry geometry : geometries) { geometry.updateModelBound(); BoundingVolume bv = geometry.getModelBound(); if (bv instanceof BoundingBox) { BoundingBox bb = (BoundingBox) bv; float r = Math.max(bb.getXExtent(), bb.getYExtent()); r = Math.max(r, bb.getZExtent()); return new BoundingSphere(r, bb.getCenter()); } else if (bv instanceof BoundingSphere) { return (BoundingSphere) bv; } else { throw new IllegalStateException("Unknown bounding volume type: " + bv.getClass().getName()); } } return result; }
/** * 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); } }
protected void ensurePositiveVolumeBBox() { if (getModelBound() instanceof BoundingBox) { if (((BoundingBox)getModelBound()).getYExtent() < 0.001f) { // a correction so the box always has a volume ((BoundingBox)getModelBound()).setYExtent(0.001f); updateWorldBound(); } } }
/** * Create a geometry suitable for visualizing the specified bounding box. * * @param bbox the bounding box (not null) * @return a new Geometry instance in world space */ public static Geometry makeGeometry(BoundingBox bbox) { float xExtent = bbox.getXExtent(); float yExtent = bbox.getYExtent(); float zExtent = bbox.getZExtent(); WireBox mesh = new WireBox(xExtent, yExtent, zExtent); Geometry result = new Geometry("bounding box", mesh); Vector3f center = bbox.getCenter(); result.setLocalTranslation(center); return result; } }
/** * used by attachBoundChildren() */ private void attachBoundingBox(BoundingBox bb, Node parent) { WireBox wb = new WireBox(bb.getXExtent(), bb.getYExtent(), bb.getZExtent()); Geometry g = new Geometry(); g.setMesh(wb); g.setLocalTranslation(bb.getCenter()); parent.attachChild(g); }
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) {
box.getCenter().y - box.getYExtent(), box.getCenter().z - box.getZExtent()}; box.getCenter().y + box.getYExtent(), box.getCenter().z + box.getZExtent()};
casterBB.setYExtent(casterBB.getYExtent() + 2.0f); casterBB.setZExtent(casterBB.getZExtent() + 2.0f);
@Override public boolean intersectsBox(BoundingBox box, TempVars vars) { Vector3f axis1 = getScaledAxis(0, vars.vect1); Vector3f axis2 = getScaledAxis(1, vars.vect2); Vector3f axis3 = getScaledAxis(2, vars.vect3); Vector3f tn = vars.vect4; Plane p = vars.plane; Vector3f c = box.getCenter(); p.setNormal(0, 0, -1); p.setConstant(-(c.z + box.getZExtent())); if (!insidePlane(p, axis1, axis2, axis3, tn)) return false; p.setNormal(0, 0, 1); p.setConstant(c.z - box.getZExtent()); if (!insidePlane(p, axis1, axis2, axis3, tn)) return false; p.setNormal(0, -1, 0); p.setConstant(-(c.y + box.getYExtent())); if (!insidePlane(p, axis1, axis2, axis3, tn)) return false; p.setNormal(0, 1, 0); p.setConstant(c.y - box.getYExtent()); if (!insidePlane(p, axis1, axis2, axis3, tn)) return false; p.setNormal(-1, 0, 0); p.setConstant(-(c.x + box.getXExtent())); if (!insidePlane(p, axis1, axis2, axis3, tn)) return false; p.setNormal(1, 0, 0); p.setConstant(c.x - box.getXExtent()); if (!insidePlane(p, axis1, axis2, axis3, tn)) return false; return true; }
pos.addLocal(0, bbox.getYExtent(), 0); ray.setOrigin(pos);
radVect.set(box.getXExtent(), box.getYExtent(), box.getZExtent()); float otherRadiusSquared = radVect.lengthSquared(); float otherRadius = FastMath.sqrt(otherRadiusSquared);
Vector3f z = new Vector3f(0, 0, 1); Vector3f min = bb.getMin(null); float[] ext = new float[] { bb.getXExtent() * 2.0f, bb.getYExtent() * 2.0f, bb.getZExtent() * 2.0f };
public void updateBoindPoints(Vector3f[] points) { BoundingBox bb = (BoundingBox) batch.getWorldBound(); float xe = bb.getXExtent(); float ye = bb.getYExtent(); float ze = bb.getZExtent(); float x = bb.getCenter().x; float y = bb.getCenter().y; float z = bb.getCenter().z; points[0].set(new Vector3f(x - xe, y - ye, z - ze)); points[1].set(new Vector3f(x - xe, y + ye, z - ze)); points[2].set(new Vector3f(x + xe, y + ye, z - ze)); points[3].set(new Vector3f(x + xe, y - ye, z - ze)); points[4].set(new Vector3f(x + xe, y - ye, z + ze)); points[5].set(new Vector3f(x - xe, y - ye, z + ze)); points[6].set(new Vector3f(x - xe, y + ye, z + ze)); points[7].set(new Vector3f(x + xe, y + ye, z + ze)); } }
public void makeBoxWire(BoundingBox box) { Vector3f[] points = new Vector3f[8]; for (int i = 0; i < 8; i++) { points[i] = new Vector3f(); } points[0].set(-1, -1, 1); points[1].set(-1, 1, 1); points[2].set(1, 1, 1); points[3].set(1, -1, 1); points[4].set(-1, -1, -1); points[5].set(-1, 1, -1); points[6].set(1, 1, -1); points[7].set(1, -1, -1); WireFrustum frustumShape = new WireFrustum(points); aabbGeom = new Geometry("box", frustumShape); aabbGeom.setMaterial(new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md")); aabbGeom.getMaterial().getAdditionalRenderState().setWireframe(true); aabbGeom.setLocalTranslation(box.getCenter()); aabbGeom.setLocalScale(box.getXExtent(), box.getYExtent(), box.getZExtent()); rootNode.attachChild(aabbGeom); }
this.guiBounding.setYExtent(cam.guiBounding.getYExtent()); this.guiBounding.setZExtent(cam.guiBounding.getZExtent()); this.guiBounding.setCenter(cam.guiBounding.getCenter());
BoundingBox bb = (BoundingBox) sphere.getBound(); Vector3f min = bb.getMin(null); float[] ext = new float[]{bb.getXExtent() * 2, bb.getYExtent() * 2, bb.getZExtent() * 2};
model.setLocalScale(1.2f / (b.getYExtent() * 2));
float height = boundingBox.getYExtent() * 2; float depth = boundingBox.getZExtent() * 2;
wheel_fr.center(); box = (BoundingBox) wheel_fr.getModelBound(); wheelRadius = box.getYExtent(); float back_wheel_h = (wheelRadius * 1.7f) - 1f; float front_wheel_h = (wheelRadius * 1.9f) - 1f;