Bounding boxes dont follow nodes?

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Mauc

Bounding boxes dont follow nodes?

Post 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 ?
jox
Bug Slayer
Posts: 726
Joined: Thu Apr 22, 2004 6:55 pm
Location: Germany

Post 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...
jox
Bug Slayer
Posts: 726
Joined: Thu Apr 22, 2004 6:55 pm
Location: Germany

Post 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)); 
jox
Bug Slayer
Posts: 726
Joined: Thu Apr 22, 2004 6:55 pm
Location: Germany

Post by jox »

Oops sorry, I accidentaly named the matrix and the material both "m". This is of course stupid. Name them differently... ;)
mAUC

Post by mAUC »

Thanks ! :)
luvcraft
Posts: 23
Joined: Sun Apr 25, 2004 1:00 am
Location: Albuquerque, NM

Post 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.
jox
Bug Slayer
Posts: 726
Joined: Thu Apr 22, 2004 6:55 pm
Location: Germany

Post 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));
Domarius
Posts: 178
Joined: Thu Mar 11, 2004 9:51 am
Location: Brisbane, QLD, Australia

Post by Domarius »

You use getTransformedBoundingBox, instead of getBoundingBox, simple. (read the help :) )
jox
Bug Slayer
Posts: 726
Joined: Thu Apr 22, 2004 6:55 pm
Location: Germany

Post 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). :)
luvcraft
Posts: 23
Joined: Sun Apr 25, 2004 1:00 am
Location: Albuquerque, NM

Post by luvcraft »

well I feel stupid... and I also feel the need to write good documentation. :)X

Thanks for the help!
luvcraft
Posts: 23
Joined: Sun Apr 25, 2004 1:00 am
Location: Albuquerque, NM

Post 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.
jox
Bug Slayer
Posts: 726
Joined: Thu Apr 22, 2004 6:55 pm
Location: Germany

Post 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
luvcraft
Posts: 23
Joined: Sun Apr 25, 2004 1:00 am
Location: Albuquerque, NM

Post 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.
jox
Bug Slayer
Posts: 726
Joined: Thu Apr 22, 2004 6:55 pm
Location: Germany

Post by jox »

Have you tried ISceneNode::setDebugDataVisible()? It also shows the bounding boxes.
Domarius
Posts: 178
Joined: Thu Mar 11, 2004 9:51 am
Location: Brisbane, QLD, Australia

Post 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".
Post Reply