private static float calcScreenArea(BoundingSphere bound, float distance, float screenWidth) { // Where is the center point and a radius point that lies in a plan parallel to the view plane? // // Calc radius based on these two points and plug into circle area formula. // Vector2f centerSP = null; // Vector2f outerSP = null; // float radiusSq = centerSP.subtract(outerSP).lengthSquared(); float radius = (bound.getRadius() * screenWidth) / (distance * 2); return radius * radius * FastMath.PI; }
/** * Create a WireSphere from a BoundingSphere * * @param bsph * BoundingSphere used to create the WireSphere * */ public void fromBoundingSphere(BoundingSphere bsph) { updatePositions(bsph.getRadius()); } }
private int collideWithBoundingVolume(BoundingVolume boundingVolume, CollisionResults results) { if (boundingVolume instanceof BoundingBox) return collideWithBoundingBox((BoundingBox)boundingVolume, results); else if(boundingVolume instanceof BoundingSphere) { BoundingSphere sphere = (BoundingSphere) boundingVolume; BoundingBox bbox = new BoundingBox(boundingVolume.getCenter().clone(), sphere.getRadius(), sphere.getRadius(), sphere.getRadius()); return collideWithBoundingBox(bbox, results); } return 0; }
/** * 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; }
private int collideWithBoundingVolume(BoundingVolume bv, Matrix4f worldMatrix, CollisionResults results) { BoundingBox bbox; if (bv instanceof BoundingSphere) { BoundingSphere sphere = (BoundingSphere) bv; bbox = new BoundingBox(bv.getCenter().clone(), sphere.getRadius(), sphere.getRadius(), sphere.getRadius()); } else if (bv instanceof BoundingBox) { bbox = new BoundingBox((BoundingBox) bv); } else { throw new UnsupportedCollisionException("BoundingVolume:" + bv); } bbox.transform(worldMatrix.invert(), bbox); return root.intersectWhere(bv, bbox, worldMatrix, this, results); }
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()); }
private int collideWithRay(Ray ray) { TempVars vars = TempVars.get(); Vector3f diff = vars.vect1.set(ray.getOrigin()).subtractLocal( center); float a = diff.dot(diff) - (getRadius() * getRadius()); float a1, discr; if (a <= 0.0) { // inside sphere vars.release(); return 1; } a1 = ray.direction.dot(diff); vars.release(); if (a1 >= 0.0) { return 0; } discr = a1 * a1 - a; if (discr < 0.0) { return 0; } else if (discr >= FastMath.ZERO_TOLERANCE) { return 2; } return 1; }
public static boolean intersect(BoundingSphere sphere, Vector3f center, float radius) { assert Vector3f.isValidVector(center) && Vector3f.isValidVector(sphere.center); TempVars vars = TempVars.get(); try { Vector3f diff = center.subtract(sphere.center, vars.vect1); float rsum = sphere.getRadius() + radius; return (diff.dot(diff) <= rsum * rsum); } finally { vars.release(); } }
public boolean intersects(Ray ray) { assert Vector3f.isValidVector(center); TempVars vars = TempVars.get(); Vector3f diff = vars.vect1.set(ray.getOrigin()).subtractLocal(center); float radiusSquared = getRadius() * getRadius(); float a = diff.dot(diff) - radiusSquared; if (a <= 0.0) { vars.release(); // in sphere return true; } // outside sphere float b = ray.getDirection().dot(diff); vars.release(); if (b >= 0.0) { return false; } return b * b >= a; }
float temp_radius = sphere.getRadius(); Vector3f temp_center = sphere.center; return merge(temp_radius, temp_center, this);
float temp_radius = sphere.getRadius(); Vector3f temp_center = sphere.center; BoundingSphere rVal = new BoundingSphere();
@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]; } } }
if (!Float.isInfinite( ((BoundingSphere)bv).getRadius() )) { if (!light.intersectsSphere((BoundingSphere)bv, vars)) { continue;
scale[2] *= ((BoundingBox) boundingVolume).getZExtent() * 2.0f; } else if (boundingVolume instanceof BoundingSphere) { float radius = ((BoundingSphere) boundingVolume).getRadius(); scale[0] *= radius * 2.0f; scale[1] *= radius * 2.0f;
private static float calcScreenArea(BoundingSphere bound, float distance, float screenWidth) { // Where is the center point and a radius point that lies in a plan parallel to the view plane? // // Calc radius based on these two points and plug into circle area formula. // Vector2f centerSP = null; // Vector2f outerSP = null; // float radiusSq = centerSP.subtract(outerSP).lengthSquared(); float radius = (bound.getRadius() * screenWidth) / (distance * 2); return radius * radius * FastMath.PI; }
/** * Create a WireSphere from a BoundingSphere * * @param bsph * BoundingSphere used to create the WireSphere * */ public void fromBoundingSphere(BoundingSphere bsph) { updatePositions(bsph.getRadius()); } }