Horde3D
http://www.horde3d.org/forums/

Grabbing the bounding box of a group node
http://www.horde3d.org/forums/viewtopic.php?f=6&t=1089
Page 1 of 1

Author:  AcidFaucet [ 31.01.2010, 22:23 ]
Post subject:  Grabbing the bounding box of a group node

May be useful to others, GroupNodes don't update their bounds (which is sensible) so I made a quick change to have them determine their bounds when it's asked for through the API.

In egMain.cpp
Code:
DLLEXP void h3dGetNodeAABB( NodeHandle node, float *minX, float *minY, float *minZ,
                            float *maxX, float *maxY, float *maxZ )
{
   SceneNode *sn = Modules::sceneMan().resolveNodeHandle( node );
   VALIDATE_NODE( sn, "h3dGetNodeAABB", EMPTY );

    Modules::sceneMan().updateNodes();
    if (sn->getType() == SceneNodeTypes::Group)
        ((GroupNode*)sn)->calculateBBox();
    if( minX != 0x0 ) *minX = sn->getBBox().min.x;
    if( minY != 0x0 ) *minY = sn->getBBox().min.y;
    if( minZ != 0x0 ) *minZ = sn->getBBox().min.z;
    if( maxX != 0x0 ) *maxX = sn->getBBox().max.x;
    if( maxY != 0x0 ) *maxY = sn->getBBox().max.y;
    if( maxZ != 0x0 ) *maxZ = sn->getBBox().max.z;
   
    if (sn->getType() == SceneNodeTypes::Group) //a little gross, but it's grosser if we don't clear it
        ((GroupNode*)sn)->clearBBox();
}


In egScene.h - GroupNode class declaration
Code:
void calculateBBox();


In egScene.cpp
Code:
void GroupNode::calculateBBox()
{
    for (std::vector<SceneNode*>::iterator it = _children.begin(); it != _children.end(); ++it) {
        if (*it) {
            if ((*it)->getType() == SceneNodeTypes::Group)
                ((GroupNode*)*it)->calculateBBox();
            _bBox.makeUnion((*it)->getBBox());
            if ((*it)->getType() == SceneNodeTypes::Group) //gross
                ((GroupNode*)*it)->clearBBox();
        }
    }
}

Author:  marciano [ 02.02.2010, 23:17 ]
Post subject:  Re: Grabbing the bounding box of a group node

Thanks. We used to have an AABB tree for culling but updating it has a considerable performance overhead (a lot of cache misses), that's why it was removed. Some different spatial structure will be used instead in the future.

Page 1 of 1 All times are UTC + 1 hour
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/