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?