Hi,

I am trying to use bounding boxes for simple collision detection with a very
simple model. My model is composed of six boxes of various sizes. I have
imported each box from a .osg file as a node. Each node is then parented to
a MatrixTransform, which allows them to rotate along different axes. The
MatrixTransforms then are parented to each other (box1->box2->box3, etc.)

I was able to do this rough collision detection easily with bounding
spheres:

    osg::Node* box1 = osgDB::readNodeFile("box1.osg");
    osg::MatrixTransform* rotateBox1 = new osg::MatrixTransform;
    rotateBox1->addChild(box1);

    osg::Node* box2 = osgDB::readNodeFile("box2.osg");
    osg::MatrixTransform* rotateBox2 = new osg::MatrixTransform;
    rotateBox2->addChild(box2);

    const osg::BoundingSphere& bs = rotateBox1->getBound();
    const osg::BoundingSphere& bs2 = rotateBox2->getBound();
        if(bs.intersects(bs2))
        {
               //Collision
        }


My question: how can I do a similar test with bounding boxes?


I read through as many of the archived posts as I could find, but I have
been unable to find a solution. Bounding boxes would work perfectly for my
situation (since my nodes are actually boxes) but work only for Drawables. I
tried creating Box Shapes and parenting those to Geodes, which were then
parented to the MatrixTransforms.

    osg::Box* box1 = new osg::Box(osg::Vec3(7.0f,0.0f,0.0f),8.5f,2.5f,2.5f);
    osg::ShapeDrawable* box1Drawable = new osg::ShapeDrawable(box1);
    osg::Geode* box1Geode = new osg::Geode;
    box1Geode->addDrawable(box1Draw able);
    rotateBox1->addChild(box1Geode);

    osg::Box* box2 = new osg::Box(osg::Vec3(1.0f,0.0f,0.0f),2.5f,2.5f,2.5f);
    osg::ShapeDrawable* box2Drawable = new osg::ShapeDrawable(box2);
    osg::Geode* box2Geode = new osg::Geode;
    box2Geode->addDrawable(box2Drawable);
    rotateBox2->addChild(box2Geode);

    const osg::BoundingBox& bb1 = box2Geode->getBoundingBox();
    const osg::BoundingBox& bb2 = box2Geode->getBoundingBox();
        if(bb1.intersects(bb2))
        {
            //Collision
        }

This didn't work either. The bounding box did not seem to reflect what was
shown in the scene (it said the boxes were intersecting whereas the scene
showed them as not intersecting.) I don't need precise detection, or any
kind of localization. This, and the ease of using Bounding box make it seem
like a nice option. So how can I use bounding boxes in this situation?

Thank you very much for your help,

Jake
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to