collision detection between two models

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.
Post Reply
mariusz_p
Posts: 15
Joined: Tue Jan 06, 2004 9:37 pm

collision detection between two models

Post by mariusz_p »

I'm wondering how to do a collision detection between two models. For example i have two players - and i wan't to check if they touches each other.
mariusz_p
Posts: 15
Joined: Tue Jan 06, 2004 9:37 pm

Post by mariusz_p »

hmm. Nobody knows the answer?
schick
Posts: 230
Joined: Tue Oct 07, 2003 3:55 pm
Location: Germany
Contact:

models = ISceneNodes

Post by schick »

If your models are handled using the ISceneNode, just get the BoundingBox of those two nodes and check if they intersect.

Code: Select all


// can be a meshnode or whatever...
ISceneNode* node1;
ISceneNode* node2;

if( node1->getBoundingBox().intersectsWithBox(node2->getBoundingBox()))
{
  // collision detected
}

For more information see:

http://irrlicht.sourceforge.net/docu/cl ... box3d.html

If you want to use advanced collision detection read the ODE (physic engine) tutorial, it uses OPCODE (collision detection engine) to calculate the collisions.
mariusz_p
Posts: 15
Joined: Tue Jan 06, 2004 9:37 pm

Post by mariusz_p »

Thanx a lot. I'm new in irrlicht so my question can be little lame ;)

I think that i won't need advanced physics.

Back to collision detection. I thought that i could use something like in collision detection example. i mean let the irrlicht handle the collisions and don't let the two models go thu each other like in examples (you cannot walk thu the wall) but i don't know how to do this right now.

I would be very gratefull if someone would give me a clue :)
Robomaniac
Posts: 602
Joined: Sat Aug 23, 2003 2:03 am
Location: Pottstown, PA
Contact:

Post by Robomaniac »

Answer* http://irrlicht.sourceforge.net/phpBB2/ ... =collision; thats your answer.

--The Robomaniac
schick
Posts: 230
Joined: Tue Oct 07, 2003 3:55 pm
Location: Germany
Contact:

aint the tutorial clear enough...

Post by schick »

Just read the tutorial carefully again... it really should give you enough knowledge to solve your problem.

Well, you asked i try to give a short answer. There are many ways to come along with collision. As you want Irrlicht to handle the collision detection, just use the example in the tutorial :-).

You just create a triangle selector of the first node and add a collision response animator to the 2nd one. Thats all. I would create the triangleselector out of the BoundingBox of the node, not the mesh itself ( really reducing the triangles).

Code: Select all

// the two nodes
ISceneNode* node1;
ISceneNode* node2;

// the triangle selector
ITriangleSelector* selector1;
// the collision response animator 
ISceneNodeAnimator* anim2;

// creating the traingle selector out of the bb
selector1 = smgr->createTriangleSelectorFromBoundingBox( node1);
// the same as in the tutorial
node1->setTriangleSelector(selector1);
selector1->drop();

// adding a collision response node
anim2 =  smgr->createCollisionResponseAnimator(
		selector1, 
                node2,
                core::vector3df(30,50,30), // radius
		core::vector3df(0,-100,0),  // gravity
                100.0f, // acceleration                 
		core::vector3df(0,50,0)); // position

node2->addAnimator(anim2);
amin2->drop();

mariusz_p
Posts: 15
Joined: Tue Jan 06, 2004 9:37 pm

Post by mariusz_p »

thx. I'll try this. I must check the whole collision system more carefully. Just to clearify this a little bit - does it really matter if i create triangle selector in node1 and check against node2, or if i create selector from node2 and check it against node1? In other words, cani reverse the nodes?

If i understand it good - if i want to check cd against multiple object i have to create selector and collisionresponse for each of the objects?
schick
Posts: 230
Joined: Tue Oct 07, 2003 3:55 pm
Location: Germany
Contact:

Post by schick »

mariusz_p wrote:if i want to check cd against multiple object i have to create selector and collisionresponse for each of the objects?
Yupp, just create the triangle selector for the object you want to collide with and a response animator for the one which is used to move around.
Post Reply