BoundingVolume question

I am trying to scale an object in my application so that it fits into a “box”, let says defined by “X, Y, Z” that is aligned with the axis. To do that I figure out I would need to calculate the “size” of the object and calculate the scale factor to scale the object to fit into that certain box. I saw that a Geometry has a getWorldBound() and getModelBound() methods, that returns a BoundingVolume, which could be a sphere or a box. Here I think I actually need a result as a BoundingBox. But I am not sure if I will always get a box. The question is when will the result be a box and when will it be a sphere? Can I force the result to be a BoundingBox?



Generally, if you have a better approach to scale an arbitrary object so that it fits into a box, please let me know. Thanks in advance.

A mesh’s default bound is a BoundingBox.

But you can check with an instanceof to determine if it is a BoundingBox or a BoundingSphere, and use their values accordingly.

Thanks, Splored for a very fast reply. Supposed some day I actually get a BoundingSphere (or just not BoundingBox). Could I force the result to be a BoundingBox? Let’s say by setModelBound( new BoundingBox() ) and then call getWorldBound()? The code will then be somewhat like:



[java]

BoundingVolume worldBound = mesh.getWorldBound();

if ( ! (worldBound instanceof BoundingBox) ) {

mesh.setModelBound(new BoundingBox());

worldBound = mesh.getWorldBound();

}

[/java]



I do not want to do just type check because there is already a sign in code that some days other type of bounds will be added. And having to change my code whenever a new BoundVolume is added seems to be a bad idea.

Jme probably won’t change bounding volume types. Probably the only time it would change is if you force the meshes in your code to use a different kind of bounding volume. But you can make sure that it is a bbox by just setting the bounding volume, via setModelBound(), when you add a mesh to the scene.

@Sploreg said:
Jme probably won't change bounding volume types. Probably the only time it would change is if you force the meshes in your code to use a different kind of bounding volume. But you can make sure that it is a bbox by just setting the bounding volume, via setModelBound(), when you add a mesh to the scene.


Thanks a lot, again, for your help :). This information is exactly what I am looking for.