/** * returns the bounding volume of this LightProbe * @return a bounding volume. * @deprecated use {@link LightProbe#getArea()} */ @Deprecated public BoundingVolume getBounds() { return new BoundingSphere(((SphereProbeArea)area).getRadius(), ((SphereProbeArea)area).getCenter()); }
/** * 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; }
private void build() { BoundingSphere bs = new BoundingSphere(); bs.computeFromPoints(mesh.getFloatBuffer(VertexBuffer.Type.Position)); meshBoundingSphereRadius = bs.getRadius(); List<Vertex> vertexLookup = new ArrayList<Vertex>(); initialize(); gatherVertexData(mesh, vertexLookup); gatherIndexData(mesh, vertexLookup); computeCosts(); // assert (assertValidMesh()); }
float temp_radius = sphere.getRadius(); Vector3f temp_center = sphere.center; BoundingSphere rVal = new BoundingSphere(); return merge(temp_radius, temp_center, rVal); box.zExtent); Vector3f temp_center = box.center; BoundingSphere rVal = new BoundingSphere(); return merge(radVect.length(), temp_center, rVal);
/** * <code>clone</code> creates a new BoundingSphere object containing the * same data as this one. * * @param store * where to store the cloned information. if null or wrong class, * a new store is created. * @return the new BoundingSphere */ public BoundingVolume clone(BoundingVolume store) { if (store != null && store.getType() == Type.Sphere) { BoundingSphere rVal = (BoundingSphere) store; if (null == rVal.center) { rVal.center = new Vector3f(); } rVal.center.set(center); rVal.radius = radius; rVal.checkPlane = checkPlane; return rVal; } return new BoundingSphere(radius, center.clone()); }
public BoundingVolume transform(Matrix4f trans, BoundingVolume store) { BoundingSphere sphere; if (store == null || store.getType() != BoundingVolume.Type.Sphere) { sphere = new BoundingSphere(1, new Vector3f(0, 0, 0)); } else { sphere = (BoundingSphere) store; } trans.mult(center, sphere.center); Vector3f axes = new Vector3f(1, 1, 1); trans.mult(axes, axes); float ax = getMaxAxis(axes); sphere.radius = FastMath.abs(ax * radius) + RADIUS_EPSILON - 1f; return sphere; }
@Test public void testSphereSphereCollision() { BoundingSphere sphere1 = new BoundingSphere(1, Vector3f.ZERO); BoundingSphere sphere2 = new BoundingSphere(1, Vector3f.ZERO); checkCollision(sphere1, sphere2, 1); // Put it at the very edge - should still intersect. sphere2.setCenter(new Vector3f(2f, 0f, 0f)); checkCollision(sphere1, sphere2, 1); // Put it a wee bit farther - no intersection expected sphere2.setCenter(new Vector3f(2f + FastMath.ZERO_TOLERANCE, 0, 0)); checkCollision(sphere1, sphere2, 0); }
@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]; } } }
@Test public void testDirectionalFiltering() { geom.addLight(new DirectionalLight(Vector3f.UNIT_Y)); checkFilteredLights(1); // Directional lights must never be filtered // Test for bounding Sphere geom.setModelBound(new BoundingSphere(0.5f, Vector3f.ZERO)); checkFilteredLights(1); // Directional lights must never be filtered }
@Test public void testAmbientFiltering() { geom.addLight(new AmbientLight()); checkFilteredLights(1); // Ambient lights must never be filtered // Test for bounding Sphere geom.setModelBound(new BoundingSphere(0.5f, Vector3f.ZERO)); checkFilteredLights(1); // Ambient lights must never be filtered }
/** * <code>transform</code> modifies the center of the sphere to reflect the * change made via a rotation, translation and scale. * * @param trans * the transform to apply * @param store * sphere to store result in * @return BoundingVolume * @return ref */ public BoundingVolume transform(Transform trans, BoundingVolume store) { BoundingSphere sphere; if (store == null || store.getType() != BoundingVolume.Type.Sphere) { sphere = new BoundingSphere(1, new Vector3f(0, 0, 0)); } else { sphere = (BoundingSphere) store; } center.mult(trans.getScale(), sphere.center); trans.getRotation().mult(sphere.center, sphere.center); sphere.center.addLocal(trans.getTranslation()); sphere.radius = FastMath.abs(getMaxAxis(trans.getScale()) * radius) + RADIUS_EPSILON - 1f; return sphere; }
q.setBound(new BoundingSphere()); q.updateBound();
sky.setQueueBucket(Bucket.Sky); sky.setCullHint(Spatial.CullHint.Never); sky.setModelBound(new BoundingSphere(Float.POSITIVE_INFINITY, Vector3f.ZERO));
@Test public void testBoxSphereCollision() { BoundingBox box1 = new BoundingBox(Vector3f.ZERO, 1, 1, 1); BoundingSphere sphere2 = new BoundingSphere(1, Vector3f.ZERO); checkCollision(box1, sphere2, 1); // Put it at the very edge - for sphere vs. box, it will not intersect sphere2.setCenter(new Vector3f(2f, 0f, 0f)); checkCollision(box1, sphere2, 0); // Put it a wee bit closer - should intersect. sphere2.setCenter(new Vector3f(2f - FastMath.ZERO_TOLERANCE, 0, 0)); checkCollision(box1, sphere2, 1); // Test if the algorithm converts the sphere // to a box before testing the collision (incorrect) float sqrt3 = FastMath.sqrt(3); sphere2.setCenter(Vector3f.UNIT_XYZ.mult(2)); sphere2.setRadius(sqrt3); checkCollision(box1, sphere2, 0); // Make it a wee bit larger. sphere2.setRadius(sqrt3 + FastMath.ZERO_TOLERANCE); checkCollision(box1, sphere2, 1); }
@Test public void testSphereTriangleCollision() { BoundingSphere sphere = new BoundingSphere(1, Vector3f.ZERO); Geometry geom = new Geometry("geom", new Quad(1, 1)); checkCollision(sphere, geom, 2); // The box touches the edges of the triangles. sphere.setCenter(new Vector3f(-1f + FastMath.ZERO_TOLERANCE, 0, 0)); checkCollision(sphere, geom, 2); // Move it slightly farther.. sphere.setCenter(new Vector3f(-1f - FastMath.ZERO_TOLERANCE, 0, 0)); checkCollision(sphere, geom, 0); // Parallel triangle / box side, touching sphere.setCenter(new Vector3f(0, 0, -1f)); checkCollision(sphere, geom, 2); // Not touching sphere.setCenter(new Vector3f(0, 0, -1f - FastMath.ZERO_TOLERANCE)); checkCollision(sphere, geom, 0); // Test collisions only against one of the triangles sphere.setCenter(new Vector3f(-0.9f, 1.2f, 0f)); checkCollision(sphere, geom, 1); sphere.setCenter(new Vector3f(1.2f, -0.9f, 0f)); checkCollision(sphere, geom, 1); } }
sl.setDirection(Vector3f.UNIT_Z); geom.setLocalTranslation(Vector3f.ZERO); geom.setModelBound(new BoundingSphere(1f, Vector3f.ZERO)); geom.setModelBound(new BoundingSphere(5f, Vector3f.ZERO)); checkFilteredLights(1);
geom.setModelBound(new BoundingSphere(1f, Vector3f.ZERO)); geom.setLocalTranslation(0, 0, 2); pl.setPosition(new Vector3f(0, 0, 2f));
private void build() { BoundingSphere bs = new BoundingSphere(); bs.computeFromPoints(mesh.getFloatBuffer(VertexBuffer.Type.Position)); meshBoundingSphereRadius = bs.getRadius(); List<Vertex> vertexLookup = new ArrayList<Vertex>(); initialize(); gatherVertexData(mesh, vertexLookup); gatherIndexData(mesh, vertexLookup); computeCosts(); // assert (assertValidMesh()); }
@Override public void write(JmeExporter ex) throws IOException { super.write(ex); OutputCapsule oc = ex.getCapsule(this); oc.write(shCoeffs, "shCoeffs", null); oc.write(prefilteredEnvMap, "prefilteredEnvMap", null); oc.write(position, "position", null); oc.write(bounds, "bounds", new BoundingSphere(1.0f, Vector3f.ZERO)); oc.write(ready, "ready", false); oc.write(nbMipMaps, "nbMipMaps", 0); }
public BoundingVolume transform(Matrix4f trans, BoundingVolume store) { BoundingSphere sphere; if (store == null || store.getType() != BoundingVolume.Type.Sphere) { sphere = new BoundingSphere(1, new Vector3f(0, 0, 0)); } else { sphere = (BoundingSphere) store; } trans.mult(center, sphere.center); Vector3f axes = new Vector3f(1, 1, 1); trans.mult(axes, axes); float ax = getMaxAxis(axes); sphere.radius = FastMath.abs(ax * radius) + RADIUS_EPSILON - 1f; return sphere; }