Page 1 of 2

Bounding boxes dont follow nodes?

Posted: Sat May 01, 2004 4:51 pm
by Mauc
Hi to all, my first post here. :)
I´ve been playing around with Irrlicht for couple of weeks now, and there is something that seems odd. When I draw a bounding box for a node

Code: Select all

driver->draw3DBox(node->getBoundingBox(), SColor(255, 255, 255, 255));
the bounding box always appears to be at (0,0,0), no matter where the node is. So I always get true for all collision detection using bounding boxes, because all the bounding boxes are at same location :P What am I missing here ?

Posted: Sat May 01, 2004 5:24 pm
by jox
Hi. The box you get with node->getBoundingBox() probably contains only local coordinates. Maybe a way would be to set the driver transformation before drawing the box:

Code: Select all

core::matrix4() m;
m.setTranslation(node->getPosition());
driver->setTransform(video::ETS_WORLD, m);

driver->draw3DBox(node->getBoundingBox(), SColor(255, 255, 255, 255)); 
a good idea also would be to set the material for the driver beforehand:

Code: Select all

video::SMaterial m; 
m.Lighting = false; 
driver->setMaterial(m);

core::matrix4() m;
m.setTranslation(node->getPosition());
driver->setTransform(video::ETS_WORLD, m);

driver->draw3DBox(node->getBoundingBox(), SColor(255, 255, 255, 255)); 
Maybe there is a better way.
Hope this helps...

Posted: Sat May 01, 2004 5:30 pm
by jox
Oh and don't forget the rotation... :)

Code: Select all

video::SMaterial m; 
m.Lighting = false; 
driver->setMaterial(m); 

core::matrix4() m; 
m.setTranslation(node->getPosition()); 
m.setRotationDegrees(node->getRotation()); // <----
driver->setTransform(video::ETS_WORLD, m); 

driver->draw3DBox(node->getBoundingBox(), SColor(255, 255, 255, 255)); 

Posted: Sat May 01, 2004 5:33 pm
by jox
Oops sorry, I accidentaly named the matrix and the material both "m". This is of course stupid. Name them differently... ;)

Posted: Sat May 01, 2004 5:42 pm
by mAUC
Thanks ! :)

Posted: Thu May 20, 2004 6:46 am
by luvcraft
I have a related problem. I have 2 mesh nodes in my scene, and when I call draw3DBox() passing either of their bounding boxes, the bounding box appears around the most-recently-created node that's also visible. So, if node 2 is behind the camera, it will draw the box around node 1, but if they're both in the scene, it will draw the box around node 2. The dimensions of the box are determined by which node I pass it, but the position of the box goes to whichever node was created last.

Any ideas on how to fix this, or is it a bug in Irrlicht?

Oh, I should also mention that I've tried this both with node->getBoundingBox() and mesh->getBoundingBox() with the same result.

Posted: Thu May 20, 2004 9:13 am
by jox
luvcraft, I don't know if I understand correctly, but it seems you just have to set the world transformation before drawing the/each box. Like I explained before... Same thing...

Code: Select all

core::matrix4() m; 
m.setTranslation(node->getPosition()); 
m.setRotationDegrees(node->getRotation());
m.setScale(node->getScale());
driver->setTransform(video::ETS_WORLD, m); 
driver->draw3DBox(node->getBoundingBox(), SColor(255, 255, 255, 255));

Posted: Fri May 21, 2004 11:48 am
by Domarius
You use getTransformedBoundingBox, instead of getBoundingBox, simple. (read the help :) )

Posted: Fri May 21, 2004 12:06 pm
by jox
Great, even better :)

Well, sometimes there are handy functions available where you need them (just have to find them).
Sometimes not, like getParent() for example (just have to implement them). :)

Posted: Fri May 21, 2004 10:17 pm
by luvcraft
well I feel stupid... and I also feel the need to write good documentation. :)X

Thanks for the help!

Posted: Sat May 22, 2004 12:19 am
by luvcraft
so I did the transformedboundingbox thing, and I still have the exact same problem -- the box will be attached to the most-recently-created node that's visible -- except NOW, the box floats way off behind and below whichever node it's attached to, which makes it even less useful. :(

Also, for some reason, the box is brown, regardless of what color I tell it to be.

Posted: Sat May 22, 2004 8:47 am
by jox
@luvcraft.

1. If you use the TranformedBoundingBox, then you might have to reset the absolute tranformation of the driver to zero beforehand.

Code: Select all

driver->setTransform(video::ETS_WORLD, core::matrix4()); // identity matrix
2. To get the color right you might have to set the material of the driver first. A while ago I posted an example on how to do that:
http://irrlicht.sourceforge.net/phpBB2/ ... php?t=2266

Hope this helps,
greets,
jox

Posted: Mon May 24, 2004 4:47 am
by luvcraft
unfortunately, the box is still floating in the same place behind the character. I'm thinking some of the box's attributes are getting mixed up, since when I turn the character the box's dimensions change.

Posted: Mon May 24, 2004 9:18 am
by jox
Have you tried ISceneNode::setDebugDataVisible()? It also shows the bounding boxes.

Posted: Mon May 24, 2004 10:29 am
by Domarius
luvcraft wrote:so I did the transformedboundingbox thing, and I still have the exact same problem -- the box will be attached to the most-recently-created node that's visible -- except NOW, the box floats way off behind and below whichever node it's attached to, which makes it even less useful. :(

Also, for some reason, the box is brown, regardless of what color I tell it to be.
Well for me, transformedBoundingBox was the answer, and fixed the exact same problem you initially described.
This must be related to some other error then, which I don't know of.

However, are you viewing the real bounding box? A testing thing I use, is to use getTransformedBoundingBox, and use "drawCube" or whatever it is, to draw it, so I can see exactly where it is.

Maybe that setDebugDataVisible does the same thing, but easier, but I haven't used it (never knew about it :) )

BTW, I think the help is fine; the "transformedboundingbox" feature is a function of SceneNode (or whatever), so when I was having trouble with the bounding box of a scene node, I knew exactly where to look in the help, and I saw that function next to "getBoundingBox".