Shooting (from demo) collisions

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
jhend60
Posts: 44
Joined: Mon Oct 27, 2008 10:11 am
Location: behind you
Contact:

Shooting (from demo) collisions

Post 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.
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post 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.
Image Image Image
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post 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);
//...
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post 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.
Image Image Image
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post 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.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
jhend60
Posts: 44
Joined: Mon Oct 27, 2008 10:11 am
Location: behind you
Contact:

ok

Post 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.
Post Reply