Java Code Examples for com.jme3.bounding.BoundingSphere#getRadius()
The following examples show how to use
com.jme3.bounding.BoundingSphere#getRadius() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PickEventSession.java From Lemur with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Returns the min and max world z values for the specified * spatial. */ protected float[] getZBounds( Spatial s ) { BoundingVolume bv = s.getWorldBound(); if( bv == null ) { // JME returns null for empty nodes return new float[] {0, 1}; } Vector3f center = bv.getCenter(); if( bv instanceof BoundingBox ) { BoundingBox bb = (BoundingBox)bv; return new float[] { center.z - bb.getZExtent(), center.z + bb.getZExtent() }; } else if( bv instanceof BoundingSphere ) { BoundingSphere bs = (BoundingSphere)bv; return new float[] { center.z - bs.getRadius(), center.z + bs.getRadius() }; } else { throw new UnsupportedOperationException("Bounding volume type not supported for:" + bv); } }
Example 2
Source File: TerrainPatch.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
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; }
Example 3
Source File: SpotLight.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public boolean intersectsSphere(BoundingSphere sphere, TempVars vars) { if (this.spotRange > 0f) { // Check spot range first. // Sphere v. sphere collision if (!Intersection.intersect(sphere, position, spotRange)) { return false; } } float otherRadiusSquared = FastMath.sqr(sphere.getRadius()); float otherRadius = sphere.getRadius(); // Check if sphere is within spot angle. // Cone v. sphere collision. Vector3f E = direction.mult(otherRadius * outerAngleSinRcp, vars.vect1); Vector3f U = position.subtract(E, vars.vect2); Vector3f D = sphere.getCenter().subtract(U, vars.vect3); float dsqr = D.dot(D); float e = direction.dot(D); if (e > 0f && e * e >= dsqr * outerAngleCosSqr) { D = sphere.getCenter().subtract(position, vars.vect3); dsqr = D.dot(D); e = -direction.dot(D); if (e > 0f && e * e >= dsqr * outerAngleSinSqr) { return dsqr <= otherRadiusSquared; } else { return true; } } return false; }
Example 4
Source File: AreaUtils.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
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; }
Example 5
Source File: LodGenerator.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
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()); }
Example 6
Source File: TerrainPatch.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
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; }
Example 7
Source File: UVCoordinatesGenerator.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
/** * This method returns the bounding box of the given mesh. * * @param mesh * the mesh * @return bounding box of the given mesh */ /* package */static BoundingBox getBoundingBox(Mesh mesh) { mesh.updateBound(); BoundingVolume bv = mesh.getBound(); 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()); } }
Example 8
Source File: AreaUtils.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
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; }