[osg-users] Collision of Spheres

Paul Martz pmartz at skew-matrix.com
Wed Sep 3 10:54:17 PDT 2008

> 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.

J-S is right here. But, there is a ShapeVisitor class and a
ConstShapeVisitor class that you can use to create a more accurate bounding
sphere, as in the code below... (Coding this off the top of my head, so
forgive typos, thanks.)

class SphereBoundVisitor : public osg::ConstShapeVisitor
    SphereBoundVisitor() {}
    virtual ~SphereBoundVisitor() {}

    virtual void apply( const osg::Shape& s )
        osg::notify( osg::WARN ) << "Unknown shape." << std::endl;
    virtual void apply( const osg::Sphere& s )
        osg::notify( osg::INFO ) << "Found Sphere." << std::endl;

        osg::Vec3 c = s.getCenter();
        float radius = s.getRadius();
        _bs = osg::BoundingSphere( c, r );

    osg::BoundingSphere _bs;

More information about the osg-users mailing list