Page 1 of 1

Collision between nodes (using triangles ?)

Posted: Tue Jun 30, 2009 2:51 pm
by PsYkO57
Hello !

I'm having trouble with Irrlicht collisions. I would like to detect when a node (a mesh) collides with another node (another mesh).

The best solutions suitable that I've found is using bouding boxes :

http://irrlicht.sourceforge.net/phpBB2/ ... =collision

But I would like to have something more precise, like when you're using createCollisionResponseAnimator : a createOctTreeTriangleSelector.

But I've only found a collision detection method between a TriangleSelector and a Sphere... but not between 2 TriangleSelector.

Does anyone have a solution?
Thanks!

Posted: Thu Jul 02, 2009 8:05 pm
by Vandal
Use physics engine or collision library

Posted: Fri Jul 03, 2009 8:10 am
by wing64

Code: Select all

bool collision(ISceneNode* one, ISceneNode* two) {
	aabbox3d<f32> b1, b2;

	b1 = one->getBoundingBox ();
	b2 = two->getBoundingBox ();

	one->getRelativeTransformation().transformBoxEx( b1 );
	two->getRelativeTransformation().transformBoxEx( b2 );
	return b1.intersectsWithBox( b2 );
}

Posted: Mon Jul 06, 2009 11:55 am
by PsYkO57
Re,

--------------------------------------------------------
Code:
bool collision(ISceneNode* one, ISceneNode* two) {
aabbox3d<f32> b1, b2;

b1 = one->getBoundingBox ();
b2 = two->getBoundingBox ();

one->getRelativeTransformation().transformBoxEx( b1 );
two->getRelativeTransformation().transformBoxEx( b2 );
return b1.intersectsWithBox( b2 );
}
--------------------------------------------------------

That's the code I'm using.

"Use physics engine or collision library"

Ok. Any other way? And where do I find the collision library?

Thank you!

Posted: Fri Jul 10, 2009 7:30 am
by PsYkO57
Little up? :)

I really need this information and can't find it :/

Thanks! :)

Posted: Fri Jul 10, 2009 8:10 am
by Katsankat
The code is ok... So what's wrong? Rogerborg went away with his crystal ball... You dont necessarly need another lib for simple collisions.

Posted: Fri Jul 10, 2009 8:10 am
by Halifax
First of all, you are using the relative transformation matrix to transform the box. If your node is the child to another node, this transformation is not guaranteed to be absolute. Thus you need to derive your transformation matrix from the concatenation of your relative transformation and the transformations of your parents, grandparents, etc.

Thus, this is the correct code (given the code you have above):

Code: Select all

bool collision( ISceneNode* sn1, ISceneNode* sn2 ) {
	aabbox3d<f32> b1 = sn1->getBoundingBox();
	aabbox3d<f32> b2 = sn2->getBoundingBox();

	sn1->getAbsoluteTransformation().transformBoxEx( b1 );
	sn2->getAbsoluteTransformation().transformBoxEx( b2 );
	
	return b1.intersectsWithBox( b2 );
}
Luckily you have a function that already does all this for you:

Code: Select all

bool collision( ISceneNode* sn1, ISceneNode* sn2 ) {
	aabbox3d<f32> b1 = sn1->getTransformedBoundingBox();
	aabbox3d<f32> b2 = sn2->getTransformedBoundingBox();

	return b1.intersectsWithBox( b2 );
}
and this can be shortened to a convenient one-liner:

Code: Select all

bool collision( ISceneNode* sn1, ISceneNode* sn2 ) {
	return sn1->getTransformedBoundingBox().intersectsWithBox( sn2->getTransformedBoundingBox() );
}

Posted: Fri Jul 10, 2009 8:18 am
by PsYkO57
Hello Halifax, and thank you for your great answer.

But, as I said, this is the code i'm using now. I'm looking for something more precise, because this is only collision detection with bounding boxes.

I would like to be able to detect a collision between two nodes using the triangles. Is that possible? If yes, how? Using what functions/lib?

Thanks again.

Posted: Fri Jul 10, 2009 9:14 am
by wildrj
Hmm id say the easiest ways for better collision would be to use one of the wrappers around ode or physx.

irrOde:http://irrlicht.sourceforge.net/phpBB2/ ... hp?t=33292

irrPhysx:chris.j.mash.googlepages.com/irrphysx

You could also try bullet but im not sure if there is a irr wrapper around it.

Posted: Fri Jul 10, 2009 11:54 am
by Nadro
Fisrt node is static, but second is dynamic? Why You can't use standard shapes for Your dynamic object?

If You need more presision in colision, so TriangleMesh vs TraingleMesh You should use external physic engine (in irrlicht it's not supported I think, but I don't use built-in Irrlicht physic, so maybe I'm wrong). I'm using Bullet, so in this engine You can use:
btCompoundShape (with multiple convex hull, look on ConvexDecomposition example) - better solution
btGimpactShape
This is two avaiable solution in Bullet for TriangleMesh vs TriangleMesh, but I don't know why You need thats precision.

Posted: Fri Jul 10, 2009 12:38 pm
by Halifax
Maybe you should enumerate why exactly you need full triangle-mesh to triangle-mesh PsYkO57. Because it is not the most effective, or fastest way, to test for collision. Most games never use full triangle-mesh to triangle-mesh collision.

Posted: Fri Jul 10, 2009 3:43 pm
by PsYkO57
First, thank you all for your answers :)

Both nodes can be dynamic, or one dynamic one static. I need that kind of precision because I'm actually not developing a game, but a 3D view for a simulation software (train, factory, ...).
Sometimes, I need to be very precise because, for example, the simulation have to detect when an object is in contact with a sensor. The object can have holes int it, be of any shape...

That's why I'm looking for precision, and not boxes :)
Moreover, if I have a precise collision API, I'll be able to detect collision first on the bouding boxes of the 2 objets, and if there's a collision, I'll look more precisely on the triangles.

Thanks again.

Posted: Sat Jul 11, 2009 6:09 am
by Halifax
Okay, PsYkO57, thanks for that clarification. Now that we know that, the best option is a physics engine. I would choose from one of the following: Bullet, PhysX, Newton, or ODE. There are also the following wrappers: IrrPhysX or IrrODE.