@Override public boolean intersectsSphere(BoundingSphere sphere, TempVars vars) { Vector3f closestPoint = getClosestPoint(vars, sphere.getCenter()); // check if the point intersects with the sphere bound if (sphere.intersects(closestPoint)) { return true; } return false; }
/** * This method returns the bounding box of the given geometries. * * @param geometries * the list of geometries * @return bounding box of the given geometries */ public static BoundingBox getBoundingBox(Geometry... geometries) { BoundingBox result = null; for (Geometry geometry : geometries) { geometry.updateModelBound(); BoundingVolume bv = geometry.getModelBound(); if (bv instanceof BoundingBox) { return (BoundingBox) bv; } else if (bv instanceof BoundingSphere) { BoundingSphere bs = (BoundingSphere) bv; float r = bs.getRadius(); return new BoundingBox(bs.getCenter(), r, r, r); } else { throw new IllegalStateException("Unknown bounding volume type: " + bv.getClass().getName()); } } return result; }
public void makeSphereWire(BoundingSphere sphere) { sphereGeom = new Geometry("box", new Sphere(16, 16, 10)); sphereGeom.setMaterial(new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md")); sphereGeom.getMaterial().getAdditionalRenderState().setWireframe(true); sphereGeom.setLocalTranslation(sphere.getCenter()); rootNode.attachChild(sphereGeom); }
@Override public void read(JmeImporter im) throws IOException { super.read(im); InputCapsule ic = im.getCapsule(this); prefilteredEnvMap = (TextureCubeMap) ic.readSavable("prefilteredEnvMap", null); position = (Vector3f) ic.readSavable("position", null); area = (ProbeArea)ic.readSavable("area", null); if(area == null) { // retro compat BoundingSphere bounds = (BoundingSphere) ic.readSavable("bounds", new BoundingSphere(1.0f, Vector3f.ZERO)); area = new SphereProbeArea(bounds.getCenter(), bounds.getRadius()); } area.setCenter(position); nbMipMaps = ic.readInt("nbMipMaps", 0); ready = ic.readBoolean("ready", false); Savable[] coeffs = ic.readSavableArray("shCoeffs", null); if (coeffs == null) { ready = false; logger.log(Level.WARNING, "LightProbe is missing parameters, it should be recomputed. Please use lightProbeFactory.updateProbe()"); } else { shCoeffs = new Vector3f[coeffs.length]; for (int i = 0; i < coeffs.length; i++) { shCoeffs[i] = (Vector3f) coeffs[i]; } } }
protected float getMinZ( BoundingVolume bv ) { if( bv instanceof BoundingBox ) { BoundingBox bb = (BoundingBox)bv; return bb.getCenter().z - bb.getZExtent(); } else if( bv instanceof BoundingSphere ) { BoundingSphere bs = (BoundingSphere)bv; return bs.getCenter().z - bs.getRadius(); } Vector3f offset = bv.getCenter().add(0, 0, -1000); return offset.z + bv.distanceTo(offset); // untested }
protected float getMaxZ( BoundingVolume bv ) { if( bv instanceof BoundingBox ) { BoundingBox bb = (BoundingBox)bv; return bb.getCenter().z + bb.getZExtent(); } else if( bv instanceof BoundingSphere ) { BoundingSphere bs = (BoundingSphere)bv; return bs.getCenter().z + bs.getRadius(); } else if( bv == null ) { // Apparently this can happen for empty nodes... return 0; } Vector3f offset = bv.getCenter().add(0, 0, 1000); return offset.z - bv.distanceTo(offset); }