setPosition doesnot update bounding box ?

You discovered a bug in the engine, and you are sure that it is not a problem of your code? Just post it in here. Please read the bug posting guidelines first.
Post Reply
kevinlynx
Posts: 24
Joined: Mon Jun 18, 2007 3:45 pm

setPosition doesnot update bounding box ?

Post by kevinlynx »

Hi,
i found a strang problem . It's a problem about ISceneNode::setPosition and the scene node's bounding box . Maybe if you are familiar with Irrlicht, you already can guess what problem i 'm facing .

The problem is:
1.i add a scene node to the scene graph:

Code: Select all

mNode = smgr->addAnimatedMeshSceneNode( mesh );
2.and then :

Code: Select all

mNode->setPosition( vector3df( 1000, 0, 100 ) );
3.and now i checked the node 's bounding box :

Code: Select all

aabbox3df box = mNode->getTransformedBoundingBox();

The problem is, the box always around the origin point. But later:

Code: Select all

mNode->setPosition( somewhere );
The bounding box is correct ! But why ?

I searched in the forum , and i found updateAbsolutePosition(). So when i set a new position to a scene node, i should :

Code: Select all

mNode->updateAbsolutePosition();
to make the bounding box be correct at the first time . But can somebody explain the reason to me ? Why the bounding box is incorrect at the first time ( setPosition ) ?

Thanks in advance.
Klasker
Posts: 230
Joined: Thu May 20, 2004 8:53 am
Contact:

Post by Klasker »

It is because the transformed bounding box requires the absolute transformation matrix to be correct. The absolute transformation matrix depends on the position, rotation, and scale of the node and all its parents. But it takes some time to calculate, so it is only calculated when it is really needed. Therefore you should call updateAbsolutePosition() to indicate that you know it is obsolete and needs to be recalculated.

In case you wonder: Why not store a boolean flag, obsoleteAbsoluteMatrix, to keep in mind whether the matrix needs to recalculated? If it was only depending on the node itself, that would work, but since it also depend on the parents, it cannot be done properly.
kevinlynx
Posts: 24
Joined: Mon Jun 18, 2007 3:45 pm

Post by kevinlynx »

Klasker, thank you for your reply.
Alough the bounding box is incorrect at first time, after that, the box is correct . And i want to get this reason . Thank you.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

However, there are some improvements in the chain for Irrlicht's handling of relative and absolute trasnformations which might also fix this behavior (although it's usually ok to query these things only while rendering, i.e. when the values are correct). The thing is that some parts of the code might become faster if we implement an update-on-read you'd get correct values and don't loose performance in another calculation afterwards. But this might require some more time and work after the animation system changes.
Post Reply