[osg-users] Collision of Spheres

Vijay Patil vijay.patil at gmail.com
Thu Sep 4 04:16:46 PDT 2008

Hi J-S

Thanks for you reply.

On Wed, Sep 3, 2008 at 6:26 PM, Jean-Sébastien Guay
<jean-sebastien.guay at cm-labs.com> wrote:
> Hello Vijay,
>> I expect the bounding sphere to coincide with actual spherical object,
> I haven't looked at the code specifically, but I think this is the
> assumption which turns out to be false. The Drawables have bounding boxes,
> and then the Geodes containing them have bounding spheres which are built to
> encompass the Drawables' bounding boxes. Hence, the Geode's bounding sphere
> will be larger than the original sphere because it has to encompass the
> sphere's bounding box, which has to encompass the sphere itself.

You are right, my assumption was wrong. I briefly looked at the
relevant OSG source code. Since 'class MatrixTransform' is derived
from 'class Group', I studied Group::computeBound(). Indeed, we are
iterating over all children and calling 'getBound' on them. If a
Drawable object is a child then of course call to getBound will return
a BoundingBox object, which is expanded further (i.e enclosed in a

Following is relevant code:

Group.cpp, BoundingSphere Group::computeBound()

    for(itr=_children.begin();itr!=_children.end(); ++itr)
        const osg::Transform* transform = (*itr)->asTransform();
        if (!transform ||

So when I call getBound on MatrixTransform object, spherical shape
will be enclosed in a bounding box, which in turn will be enclosed in
final bounding sphere. This is what caused the problem.

Also after calling getBound, Drawable objects returning a BoundingBox
(instead of BoundingSphere) object is just a design decision, right?
Is there anything that prevents us in having a BoundingSphere for
Drawable objects?

> I hope this makes sense. If not, draw it on a piece of paper: draw a circle
> (which is your graphical object), then draw the smallest box that
> encompasses this circle, and then draw the smallest circle that encompasses
> that box. The second circle will inevitably be larger than the first one.
> It's also pretty easy to make a visitor that will add a graphical
> representation of all bounding volumes of a scene.

Yes I think so. IIRC there was a thread with lots of attachment about
this. Will look into it.

Thanks again.

Vijay Patil

More information about the osg-users mailing list