# World Bound Confusion

Hello!
I’ve created a Geometry with the Mesh of the WorldBound of another Geometry.
So, as far as I understood (maybe wrong) the WorldBound sort of calculates the furthest point the Geometry reaches and the method [java]boxWireBox.fromBoundingBox((BoundingBox) boxGeometry.getWorldBound());[/java] creates a Box that contains even the furthest point.
So the WorldBound would change if a Geometry is being rotated, at least it looks right when you rotate a simple Box and watch its BoundingVolume grow and shrink.
But when rotating a Sphere an watching it’s WorldBound (in form of a Box) confuses me, because it should remain it’s size, shouldn’t it?
Because I think that I can’t explain very well, here is the test-case:
[java]package mygame;

import com.jme3.app.SimpleApplication;
import com.jme3.bounding.BoundingBox;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.scene.Geometry;
import com.jme3.scene.debug.WireBox;
import com.jme3.scene.shape.Box;
import com.jme3.scene.shape.Sphere;

/**

• test

• @author normenhansen
*/
public class Main extends SimpleApplication
{

private WireBox boxWireBox = new WireBox();
private Geometry boxBound = new Geometry(“A”, boxWireBox);
private WireBox sphereWireBox = new WireBox();
private Geometry sphereBound = new Geometry(“B”, sphereWireBox);
private Geometry boxGeometry;
private Geometry sphereGeometry;

public static void main(String[] args)
{
Main app = new Main();
app.start();
}

@Override
public void simpleInitApp()
{
flyCam.setMoveSpeed(40);
Box b = new Box(1, 1, 1);
boxGeometry = new Geometry(“Box”, b);
boxGeometry.move(12, 0, 0);
Sphere s = new Sphere(20, 20, 1);
sphereGeometry = new Geometry(“Sphere”, s);
Material mat = new Material(assetManager, “Common/MatDefs/Misc/Unshaded.j3md”);
mat.setColor(“Color”, ColorRGBA.Blue);
boxGeometry.setMaterial(mat);
mat.setColor(“Color”, ColorRGBA.Blue);
sphereGeometry.setMaterial(mat);
mat.setColor(“Color”, ColorRGBA.White);
boxBound.setMaterial(mat);
sphereBound.setMaterial(mat);
rootNode.attachChild(boxGeometry);
rootNode.attachChild(sphereGeometry);
rootNode.attachChild(boxBound);
rootNode.attachChild(sphereBound);
}

@Override
public void simpleUpdate(float tpf)
{
boxGeometry.rotate(.01f, .01f, .01f);
boxWireBox.fromBoundingBox((BoundingBox) boxGeometry.getWorldBound());
boxBound.setLocalTranslation(boxGeometry.getLocalTranslation());
sphereGeometry.rotate(.01f, .01f, .01f);
sphereWireBox.fromBoundingBox((BoundingBox) sphereGeometry.getWorldBound());
}
}
[/java]
Now, maybe the BoundingBox isn’t supposed to work for the a sphere, But when I try to use a BoundingSphere but then I get an Exception:

[java]java.lang.ClassCastException: com.jme3.bounding.BoundingBox cannot be cast to com.jme3.bounding.BoundingSphere[/java]
Even though the line would say:
[java]sphereWireSphere.fromBoundingSphere((BoundingSphere) sphereGeometry.getWorldBound());[/java]
So far my confusion…
Now am I using the BoundingSphere (and WireSphere) in a wrong way?
The Editor doesn’t show any errors or warning on startup, but when the scene is created.
Or how to explain the strangely behaving BoundingBox of a sphere Geometry?

The world bound of a Spatial is guaranteed to contain all the geometries under that Spatial, but it is not guaranteed to be the smallest possible bound for those geometries.

1 Like

Didn’t know that, thanks for clearing that up.

Don’t know how to mark the topic as solved… but it is, trying to find the “solved” button…

1 Like
@sgold said: The world bound of a Spatial is guaranteed to contain all the geometries under that Spatial, but it is not guaranteed to be the smallest possible bound for those geometries.
Does this include ParticleEmitters (since they are spatials)? Because it seems not to work there. Example: [java]public class Main extends SimpleApplication {
``````WireBox wBox = new WireBox();
Geometry box = new Geometry("WB", wBox);
ParticleEmitter emitter = new ParticleEmitter("emitter", ParticleMesh.Type.Triangle, 2000);

public static void main(String[] args)
{
Main app = new Main();
app.start();
}

@Override
public void simpleInitApp()
{
flyCam.setDragToRotate(true);
flyCam.setMoveSpeed(100);
Material particleMat = new Material(assetManager,
"Common/MatDefs/Misc/Particle.j3md");
emitter.setMaterial(particleMat);
emitter.setGravity(-.5f, 3f, 1f);
emitter.getParticleInfluencer().setInitialVelocity(new Vector3f(.1f, -.3f, .4f));
emitter.getParticleInfluencer().setVelocityVariation(.8f);
rootNode.attachChild(emitter);
rootNode.attachChild(box);
cam.setLocation(new Vector3f(10, 0, 10));
cam.lookAt(Vector3f.ZERO, Vector3f.UNIT_Y);
}

@Override
public void simpleUpdate(float tpf)
{
wBox.fromBoundingBox((BoundingBox) emitter.getWorldBound());
}
``````

}[/java]

I haven’t checked, but I would expect the precomputed box to include only the generating shape of the emitter, not all the particles.

There are ways to compute the minimal bounding box for any set of vertices, if that’s what you need.