Page 1 of 1

Shooting (from demo) collisions

Posted: Fri Nov 07, 2008 6:38 am
by jhend60
Hi all
I have got shooting to work (finally) and have a small problem (two actually, this post focuses on one).
The collision with the main ground mesh (from irr) is working fine now, but I am trying to add another collision detection with a standard 3ds mesh. I have added the object and everything, I just don't have the correct code for this. I have also tried adding another triangle selector (using this mesh only) and putting it in this code:
// get intersection point with map

if (smgr->getSceneCollisionManager()->getCollisionPoint(
line, *triangleselector*, end, triangle))
{
//Do stuff here if collision is met


}

But changing it to work with my other 3d object. This does not seem to work, as any code passed does not seem to work. What have I done wrong here? I am using exact code from the demo tutorial with shooting.
All I am aiming to do is make my sphere change colour when hit by a bullet.

Posted: Fri Nov 07, 2008 8:20 am
by JP
You want to use a IMetaTriangleSelector instead of a ITriangleSelector. Look this up in the API/docs and search the forum as it's a problem that's been covered many times before so you should find a good answer.

Posted: Fri Nov 07, 2008 10:46 am
by rogerborg
JP wrote:You want to use a IMetaTriangleSelector instead of a ITriangleSelector.
Mmm, not necessarily. Using getCollisionPoint() with a meta triangle selector wouldn't tell you which scene node was hit, which is a limitation that I intend to address after 1.5 is cut.

The code posted looks reasonable, but it really depends on how you're creating the triangle selector. We'll need to see that code. If you're loading a 3ds mesh, then it should be something like:

Code: Select all

IAnimatedMesh * animatedMesh = smgr->getMesh("your_mesh.3ds");
IAnimatedMeshSceneNode * node = smgr->addAnimatedMeshSceneNode(animatedMesh);

// Note: we need to get an IMesh from the IAnimatedMesh
ITriangleSelector triangleSelector = smgr->createTriangleSelector(animatedMesh->getMesh(0), node);
//...

Posted: Fri Nov 07, 2008 11:09 am
by JP
Ahh yes, my bad for not paying attention to the requirements :lol:

I guess in that case you'd kinda have to check each triangle selector of interest individually...

Although aren't you using a physics engine jhend60? in which case you might be better off using functions from that rather than creating extra triangle selectors to do it within irrlilcht.

Posted: Fri Nov 07, 2008 11:42 am
by rogerborg
JP wrote:I guess in that case you'd kinda have to check each triangle selector of interest individually...
Indeed, which is pretty sub-optimal. You'll really want to do a ray/BB test on each node before doing the triangle selector check.

ok

Posted: Fri Nov 07, 2008 9:58 pm
by jhend60
I have decided to use the irrlicht basic collision detections as Newton got a little bit bulky. I am using simple collision detection from irrlicht, and have used pretty much exact code from the demo. I think I must use collision detection with the LINE formed by the shooting function, instead of the bullet itself. I already have collision with the ground mesh and the bullet working, but cannot seem to replicate this effect on another object.