How do I show the model bound(boundingbox || boundingsphere)

Hi,



I just received a task to highlight each model when the mouse clicks on them. So I was thinking that I could somehow use a bounding box or a bounding sphere's specs and then build another box according to their size, and then make that box somewhat transparent for the highlighting purpose.



However, even after I updateModelBound(), the size of the bounding volumes aren't really changed, everything (center location, radius, xyzExtents of the boundingbox, etc) is still 0 after the update:



BoundingSphere bs = new BoundingSphere();

translatedModel.setModelBound(bs);

translatedModel.updateModelBound();



Box box = new Box("test box", bs.getCenter(), bs.getRadius(), bs.getRadius(), bs.getRadius());

box.setModelBound(new BoundingSphere());

box.updateModelBound();



box.setSolidColor(ColorRGBA.red);

rootNode.attachChild(box);



But I never see the highlighting box show itself, and then after inserting whole bunch System.out.println()'s , I found that bs.getCenter() simply gives me the origin of the world, and bs.getRadius() gives me 0.0.



I tried a similar code for a bounding box, I simply got the origin of the world and 0x 0y 0z extents.



Does anyone know why is this like that? Or is there another way that I should be using for this type of highlighting box?

sorry , the color yellow is a bit hard to see, here is the black version:



BoundingSphere bs = new BoundingSphere();

translatedModel.setModelBound(bs);

translatedModel.updateModelBound();



Box box = new Box("test box", bs.getCenter(), bs.getRadius(), bs.getRadius(), bs.getRadius());

box.setModelBound(new BoundingSphere());

box.updateModelBound();



box.setSolidColor(ColorRGBA.red);

rootNode.attachChild(box);


Try adding translatedModel.updateWorldBound() after updating the local bound.

I added the update world bound method, but it still doesn't work. I tested the radius of the Bounding Sphere right after I updated both the local bound and the world bound, it gives me 0.0

It looks as if the BoundingSphere never gets a chance to set the model Radius

logic flow: updateModelBound()->computeFromPoints()->calcWelz()->recurseMini()



It goes into the calcWelz method, which calls the recurseMini method, which sets the radius and center to zero on it's first pass.  Then at the end of the recurse method:

if (tempA.distanceSquared(center) - (radius * radius) > radiusEpsilon - 1f) {
....
....
....
recurseMini(points, i, b + 1, ap + 1);
}



tempA == (0,0,0);
center == (0,0,0);
radius == 0;
radiusEpsilon == 1.00000001f;
Which results in:


tempA.distanceSquared(center) - (radius * radius) > radiusEpsilon - 1f
0 - (0*0) > 0.00000001f



which is false, therefore the recurseMini is never called again and the radius and center are never computed; which only happens during the second recursion.
Although tempA looks like it should be set to each point, which should be correct.  You can verify there is an issue by setting the bounding sphere radius directly, and indeed the box is created based on that radius.

At least this is what it looks like to me tracing through the BoundingSphere code in jME 1.0

So what should I do in this case? Is there another way to do a highlighting box??

well, if you know the radius of your sphere you can just call BoundingSphere().setRadius() …

but I was trying to use the bounding sphere to find the radius though… is there another way to determine the radius and the center of a model??