Why is my bounding box null? How do I force an update?

Anything and everything that's related to OGRE or the wider graphics field that doesn't fit into the other forums.
Post Reply
srfnaked99
Gnoblar
Posts: 4
Joined: Tue Apr 19, 2005 11:41 pm

Why is my bounding box null? How do I force an update?

Post by srfnaked99 » Thu Apr 21, 2005 4:17 am

Looks like the problems I've been running into with collision detection aren't my fault. I have some code that goes as such:

Entity *ent = mSceneMgr->createEntity(...);
SceneNode *node = mSceneMgr->...->createChildSceneNode(entName);
node->attachObject(ent);

do {
node->setPosition(...);
} while (collides(ent));

bool collides(SceneNode *ent) {
list<Entity*>::iterator itr;
AxisAlignedBox myBox = ent->getWorldBoundingBox(), theirBox;

for (itr = mEntList.begin(); itr != mEntList.end(); itr++) {
if ((*itr) == ent)
continue;

theirBox = (*itr)->getWorldBoundingBox();

if (myBox.intersects(theirBox))
return true;
}

return false;
}


The problem is that although the node's position is being updated, the bounding box of the entity isn't. I looked into it more and found that the bounding boxes for all my entities have mNull=true, even though they have been initialized to their default locations and sizes. This causes the myBox.intersects(...) test to be false regardless of whether the boxes are actually intersecting due to the following lines in OgreAxisAlignedBox.h:

// Early-fail for nulls
if (this->isNull() || b2.isNull())
return false;

I came across SceneNode::needUpdate() but that doesn't seem to fix the problem either. Is there a manual way to force the scene manager to update all the scene nodes and their respective entities/bounding boxes?

What causes a bounding box to be null and how to I change it?
0 x

srfnaked99
Gnoblar
Posts: 4
Joined: Tue Apr 19, 2005 11:41 pm

Post by srfnaked99 » Thu Apr 21, 2005 4:23 am

Never seems to fail. As soon as you make the post you find the solution. Calling node->_update() after setting the position made it work.
0 x

Post Reply