collision detection on moving node

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
Caelor
Posts: 1
Joined: Wed Oct 24, 2007 11:15 am

collision detection on moving node

Post by Caelor »

Hi,

I am quite new to Irrlicht and i am trying to make a simple game of a mesh with a hole in it moving towards the player. It is my intention to let the player pass through the hole.

Now i needed somekind of detection of collision.

However as i attached the triangle selector to the moving node, which has been animated by a flystraight animator. With the player currently consisting of a few sphere nodes attached to a collision response animator that should reacts to the moving mesh. Due to the shape of the moving mesh i cannot attach the triangle selector to the player and use the collision response animator on the moving mesh.

The collision didn't seem to happen so i tested and simplified it a bit and to see what happened, i used a fps camera with attached collision response animator to fly through the scene and check for collisions.

It seems as long as the Mesh wass moving, the collision detection didn't happen. As soon as the moving mesh is stationary it works.

Anyone have any idea how i can solve this problem and have collision detection working when the mesh with triangle selector is still moving?

Some of my code (which i think are important to the problem i face).

Code: Select all

//The moving mesh:

blck = smgr->getMesh("media/block01.x");
block = smgr->addOctTreeSceneNode(blck,0,-1,256,false);
........
irr::scene::ISceneNodeAnimator *anim;
//create movement animation
anim = smgr->createFlyStraightAnimator(block->getPosition(), irr::core::vector3df(0,20.0,-10.0), irr::u32(5000),false);
block->addAnimator(anim);
anim->drop();
			
//create collision selector
selector2 = smgr->createOctTreeTriangleSelector(blck->getMesh(0),block,128);
block->setTriangleSelector(selector2);
selector2->drop();

//The player
for(int i=0; i < 5; i++){
  node[i] = smgr->addSphereSceneNode(1,16,0,-1,irr::core::vector3df(posAvatar[i][0],
  posAvatar[i][1],posAvatar[i][2]));

  //create the collision response animator
  collision[i] = smgr->createCollisionResponseAnimator(selector2,node[i],
  irr::core::vector3df(2.0,2.0,2.0), //radius of collission detection
  irr::core::vector3df(0,0,0),	    //gravity of collision
  irr::core::vector3df(0,0,0));      //elipsoid translation

  //attach the collision response animator to the node
  node[i]->addAnimator(collision[i]);
  collision[i]->drop();
  }
Thanks for any advice, suggestions in advance.
mikeee
Posts: 9
Joined: Tue Feb 14, 2006 3:15 pm
Location: Germany

Post by mikeee »

Oh I got exacty the same problem and its somehow related to .X file format.
(im not 100% sure about this) but when im trying collision detection with MD2s then it works ok! !
Only .X wont work - no colision detection at all:(
The difference is that im using

Code: Select all

if (node->getTransformedBoundingBox().intersectsWithBox( node2->getTransformedBoundingBox()) )   .............

instead of CollisionResponseAnimator.


anyone ?

-mike
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

Just a quick note. The box returned by getTransformedBoundingBox() isn't accurate when the node is rotated. You can use getBoundingBox() and the matrix function transformBoxEx() to get an accurate bounding box.
mikeee
Posts: 9
Joined: Tue Feb 14, 2006 3:15 pm
Location: Germany

Post by mikeee »

@vitek - thx for info about transformBoxEx() but im still confused..

Dunno why, but ".X" importer seems not to work properly.
I did some tests and here it is:

Its simple animation (just moving one mesh in Y axis /vertical/ )

mesh filetype : X
As you can see, there is no debug-box (bounding-box) visible at all

Image
[/img]





and now the SAME mesh and SAME code but MD2 format:
Image
[/img]


everything is ok, red-box covers the whole mesh!



So I changed manually the size of the bounding-box and here is the resut:
.X file but with modified bounding-box
Image
[/img]

Of corse the BB has now 20x20x20 and it doesn't match to the mesh


There is the code : (not very elegant, but its for tests only)

Code: Select all

// ..
// ..

 if (node)
{
    //-- get the "original" b-box from mesh
    EBox = node->getBoundingBox(); 
    node->getAbsoluteTransformation().transformBoxEx(EBox);
   //-- this SOHOUD be enoght to find collisions 

    //------------------------------------
    //--let's enlage it a bit manually
    EBox.MinEdge.X =  EBox.MinEdge.X -10;
    EBox.MinEdge.Y =  EBox.MinEdge.Y -10;
    EBox.MinEdge.Z =  EBox.MinEdge.Z -10;

    EBox.MaxEdge.X =  EBox.MaxEdge.X +10;
    EBox.MaxEdge.Y =  EBox.MaxEdge.Y +10;
    EBox.MaxEdge.Z =  EBox.MaxEdge.Z +10;
    //-- without these 6 lines above, the EBox has size "0 , 0,  0" !!!!
    //------------------------------------


   //--ok,  check the collision now
   if (EBox.intersectsWithBox(WBox)) 
   {
        //-- got it !
   }


   //-- don't care about WBox  
   //--WBox is just another simple b-box (its from 3DS file, works ok always)
 

}

I use "Panda exporter" for X files, maybe there is something wrong with it?
Im trying other settings while exporting to X, without sucess so far...
Post Reply