Transformed bounding box collision problem

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.
nikoomba
Competition winner
Posts: 22
Joined: Wed Mar 09, 2011 11:35 am

Transformed bounding box collision problem

Post by nikoomba »

Hello everyone!

I'm having some difficulties getting the transformed bounding box collision to work. I've seen several code snippets of this nature:

Code: Select all

bool collision(ISceneNode* one, ISceneNode* two)
{
if(one->getTransformedBoundingBox().intersectsWithBox(two->getTransformedBoundingBox())) {
return (one->getTransformedBoundingBox().intersectsWithBox(two->getTransformedBoundingBox()));
}
return false;
}
This is my personal implementation of that code:

Code: Select all

if(rocket.meshnode->getTransformedBoundingBox().intersectsWithBox(turbine.windfield->getTransformedBoundingBox()))
{
	device->setWindowCaption(L"1");
}
else
{
	device->setWindowCaption(L"0");
}
(Note that rocket.meshnode is a child of rocket.node, and that turbine.windfield is a child of turbine.node)

I can see that the bounding box is correct - I have enabled the debug information - however the code does something along the lines of this:

Black: Mesh(bounding box is the same as mesh, its just the code that doesn't work)
Red: Collision detection
Blue: Arrow signifying the rotation

Image

Can anyone tell me why this does not work, and perhaps point me in the direction of the solution?

I would be much obliged.

Have a good day, everyone!
andreee
Posts: 43
Joined: Thu Feb 09, 2006 11:13 am
Location: Prague

Post by andreee »

Yes, i am having the same problem. The bounding box doesnt rotate, how can i achieve this?

Thank you :)
Dreaming of folk-art at http://www.ambersky.cz
ChaiRuiPeng
Posts: 363
Joined: Thu Dec 16, 2010 8:50 pm
Location: Somewhere in the clouds.. drinking pink lemonade and sunshine..

Post by ChaiRuiPeng »

the red box is the axis aligned bounding box i assume?

that does not rotate. that is why it is ***axis aligned***

it is used for occluding scene nodes or anything else that might need *simple* 'in-view' detection. it should not be used for precision detection.
ent1ty wrote: success is a matter of concentration and desire
Butler Lampson wrote: all problems in Computer Science can be solved by another level of indirection
at a cost measure in computer resources ;)
andreee
Posts: 43
Joined: Thu Feb 09, 2006 11:13 am
Location: Prague

Post by andreee »

So what would be the method of getting the rotated bouning box? node->getBoundingBox() ?
Dreaming of folk-art at http://www.ambersky.cz
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

getTransformedBoundingBox
andreee
Posts: 43
Joined: Thu Feb 09, 2006 11:13 am
Location: Prague

Post by andreee »

http://irrlicht.sourceforge.net/docu/cl ... 779553c716

That also returns an axis-aligned box..
Dreaming of folk-art at http://www.ambersky.cz
ChaiRuiPeng
Posts: 363
Joined: Thu Dec 16, 2010 8:50 pm
Location: Somewhere in the clouds.. drinking pink lemonade and sunshine..

Post by ChaiRuiPeng »

andreee wrote:http://irrlicht.sourceforge.net/docu/cl ... 779553c716

That also returns an axis-aligned box..
'hmmm :shock: it appears so....
Irrlicht documentation wrote:
virtual const core::aabbox3d<f32> irr::scene::ISceneNode::getTransformedBoundingBox ( ) const [inline, virtual]
Get the axis aligned, transformed and animated absolute bounding box of this node.

Returns:
The transformed bounding box.
@hybrid

i think by transformed that means the return object of getTransformedBoundingBox takes into account the nodes transform?

it still says its axis aligned...
ent1ty wrote: success is a matter of concentration and desire
Butler Lampson wrote: all problems in Computer Science can be solved by another level of indirection
at a cost measure in computer resources ;)
shadowslair
Posts: 758
Joined: Mon Mar 31, 2008 3:32 pm
Location: Bulgaria

Post by shadowslair »

Bah... the bbox class is named aabbox for a reason. It always represents an aabbox in local space. The getTransformedBBox() returns the aabbox in WS, meaning it applies node rotation and translation to its original, local-spaced bbox and returns the tightest aabb (again) in WS. You cannot use it for narrow collisions/intersections, unless you transform every single vertex or use it with some transformation or transform only some of the vertices and calculate the others. What you need to do is to get the aabb in object(model, local etc.) space where it`s usually the tighest volume and perform a SAT (separating axis) test or some other method, but it is much slower of course. And yeah, Irrlicht doesn`t provide such, so you`ll need to implement it yourself.
"Although we walk on the ground and step in the mud... our dreams and endeavors reach the immense skies..."
andreee
Posts: 43
Joined: Thu Feb 09, 2006 11:13 am
Location: Prague

Post by andreee »

or maybe something like this:
box = node->getTransformedBBox();
playerBox = playerNode->getTransformedBBox();
playerBox->setRotation(1.0f, playerNode->getRotation().Y, 1.0f);
for each box corner check if isPointInside().

But that would not cover situations when a node hits another with a corner, then maybe check for points inside reversed..
Dreaming of folk-art at http://www.ambersky.cz
shadowslair
Posts: 758
Joined: Mon Mar 31, 2008 3:32 pm
Location: Bulgaria

Post by shadowslair »

andreee wrote:playerBox->setRotation(1.0f, playerNode->getRotation().Y, 1.0f);
In your example playerBox is an aabbox. I don`t think you can call setRotation() on it.

As I already said, there`re a few options, but checking all vertices, edges and case combinations is definitely not the best of them...

EDIT: I don`t get what`s the purpose of the "1.0f"-s X and Z components either. Plus, the setRotation() uses a core::vector3df as parameter. If you want to pan sth you`d call:

Code: Select all

node->setRotation(core::vector3df(0, playerNode->getRotation().Y, 0));
Last edited by shadowslair on Wed Mar 23, 2011 7:59 pm, edited 2 times in total.
"Although we walk on the ground and step in the mud... our dreams and endeavors reach the immense skies..."
andreee
Posts: 43
Joined: Thu Feb 09, 2006 11:13 am
Location: Prague

Post by andreee »

Well, i would first check for bounding boxes, then for a more precise detection i would check the corners. In my project, i have only boxes colliding (all rotated only around Y axis). I don't think it is necessary to use a physics engine to check collision of two boxes..

Is there a variable type that would store a rotated box?
Dreaming of folk-art at http://www.ambersky.cz
shadowslair
Posts: 758
Joined: Mon Mar 31, 2008 3:32 pm
Location: Bulgaria

Post by shadowslair »

andreee wrote:Is there a variable type that would store a rotated box?

Code: Select all

struct SRotatedBox
{
	core::aabbox3df Box;			   // the local-spaced aabbox
	core::matrix4 Transformation;	// the transf matrix used for transforming stuff from LS to WS, and from WS to LS (via inverse)
};
:lol:
"Although we walk on the ground and step in the mud... our dreams and endeavors reach the immense skies..."
hayate
Posts: 43
Joined: Mon Feb 16, 2009 9:38 pm
Location: Brescia, Italy

Post by hayate »

Why don't you add an invisible cube (or another simple geometry) as child of your node and then use this to do a more accurate collision detection after the first check with the AABBox?
Sorry for my awful english ^_^'
Image
shadowslair
Posts: 758
Joined: Mon Mar 31, 2008 3:32 pm
Location: Bulgaria

Post by shadowslair »

Why on earth would he do that...? :?
"Although we walk on the ground and step in the mud... our dreams and endeavors reach the immense skies..."
ChaiRuiPeng
Posts: 363
Joined: Thu Dec 16, 2010 8:50 pm
Location: Somewhere in the clouds.. drinking pink lemonade and sunshine..

Post by ChaiRuiPeng »

hayate wrote:Why don't you add an invisible cube (or another simple geometry) as child of your node and then use this to do a more accurate collision detection after the first check with the AABBox?
or better yet use bullet collision. you can just compile the collision module.
i think its really silly to go through all this trouble trying to force irrlicht into doing things it isnt really designed too much for (collision detection)
it is really easy and that is what i am using for my simple little box playground :)
ent1ty wrote: success is a matter of concentration and desire
Butler Lampson wrote: all problems in Computer Science can be solved by another level of indirection
at a cost measure in computer resources ;)
Post Reply