Collision between nodes (using triangles ?)

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
PsYkO57
Posts: 7
Joined: Wed Jun 24, 2009 12:28 pm

Collision between nodes (using triangles ?)

Post 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!
Vandal
Posts: 14
Joined: Fri Jun 12, 2009 3:44 am

Post by Vandal »

Use physics engine or collision library
wing64
Competition winner
Posts: 242
Joined: Wed Jul 23, 2008 2:35 am
Location: Thailand
Contact:

Post 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 );
}
PsYkO57
Posts: 7
Joined: Wed Jun 24, 2009 12:28 pm

Post 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!
PsYkO57
Posts: 7
Joined: Wed Jun 24, 2009 12:28 pm

Post by PsYkO57 »

Little up? :)

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

Thanks! :)
Katsankat
Posts: 178
Joined: Sun Mar 12, 2006 4:15 am
Contact:

Post 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.
Halifax
Posts: 1424
Joined: Sun Apr 29, 2007 10:40 pm
Location: $9D95

Post 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() );
}
TheQuestion = 2B || !2B
PsYkO57
Posts: 7
Joined: Wed Jun 24, 2009 12:28 pm

Post 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.
wildrj
Posts: 301
Joined: Thu Mar 23, 2006 12:49 am
Location: Texas/ Cyberspace
Contact:

Post 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.
http://wild.deathtouchstudios.com << My gamedev blog
<Programming is a way of life>
If at first you don't succeed press the delete key till you do :)
Nadro
Posts: 1648
Joined: Sun Feb 19, 2006 9:08 am
Location: Warsaw, Poland

Post 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.
Library helping with network requests, tasks management, logger etc in desktop and mobile apps: https://github.com/GrupaPracuj/hermes
Halifax
Posts: 1424
Joined: Sun Apr 29, 2007 10:40 pm
Location: $9D95

Post 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.
TheQuestion = 2B || !2B
PsYkO57
Posts: 7
Joined: Wed Jun 24, 2009 12:28 pm

Post 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.
Halifax
Posts: 1424
Joined: Sun Apr 29, 2007 10:40 pm
Location: $9D95

Post 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.
TheQuestion = 2B || !2B
Post Reply