Advanced picking question

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
kendric
Posts: 71
Joined: Tue May 29, 2007 9:05 pm

Advanced picking question

Post by kendric »

In the collision tutorial it shows how to pick a scene node and how to pick a triangle from the world map. But what I need to do is pick a triangle from everything in the game.

What I want to do is to be able to pick the thing the user is pointing at, determine what it is, and then process on that, and add a bullet hole or blood splat etc.

The problem I see is that using getSceneNodeFromRayBB seemingly doesn't see world gemoetry(I was able to pick a character that was behind a wall) and in addition that function doesn't tell me where the hit location was for me to put a bullet hole

Using getCollisionPoint gives me the location and a triangle. The problem here is 2 things. One, how do i tell which scene node the triangle is attached to, and 2, do I have to create a triangle selector for each scene node seperatly and then do a check on them all, and compare the distances returned from each one to get the closest? I don't see how you can create a triangle selector and then add other scene nodes to it or something to get some global one.

If anyone has any ideas on how to do this I would be gratefull for some input.
CuteAlien
Admin
Posts: 9694
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

You can add all triangle selectors into a IMetaTriangleSelector.
This might be a little more comfortable than checking each triangle selector and comparing distances, but I doubt that it's faster. Doing that the way you described it is just a single loop anyway.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
kendric
Posts: 71
Joined: Tue May 29, 2007 9:05 pm

Post by kendric »

Thanks.
Can anyone say if this is normally how you would detect where a bullet hit?
Also do I have to do a scene node check as well as the triangle to get the scene node that was hit or can you get the node from a triangle as well?

Finally I will want to put a decal of some kind at the x,y,z that the hit happens at. How would I know which scene node to attach it to, ie I would want to attach it to the finger that was hit lets say, and not the whole scene node that you get back from the collision functions.
CuteAlien
Admin
Posts: 9694
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

I've not yet done bullets in Irrlicht, so maybe someone else can give better feedback. Still...

I guess you can do bullets that way if it's fast enough. To be sure do a simple test with as many tracelines and objects as you will need at the same time in your game.

I don't see right now a way to get the node from the selector, so I suppose you will have to keep that connection yourself. In this case using metatriangleselectors is probably not such a good idea and just looping all selectors will work better.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
kendric
Posts: 71
Joined: Tue May 29, 2007 9:05 pm

Post by kendric »

Well
I started to implement this and then I realized something..
I will have to remake a triangle selector for every scene node every single time i want to fire a bullet since their animations will be changing, and you use animation frame to build a triangle selector.

This sounds like I am doing something wrong. Consider if you have 100 enemies on the map. You fire a gun that fires fairly quickly. Thats making 100 triangle selectors each time, and running a ray trace on each one.

That sounds like a lot of cpu usage since you won't have any reuseability. I suppose you could store off a triangle selector for each frame of animation and use those but that also sounds wastefull.

There has to be a better way to solve this common problem of seeing if they hit anything without using scene node selector since that doesn't tell you where you hit.
kendric
Posts: 71
Joined: Tue May 29, 2007 9:05 pm

Post by kendric »

Ok i think I know how to do this effectively.

Do a getSceneNodeFromRayBB
If you found a scene node, do
getCollisionPoint on the world gemoetry(fixed so you can save off the selector for speed)
Then compare the distance of the world collision with the scene node(for some reason you can see through walls with getSceneNodeFromRayBB rather then having it return the wall scene node, either that or I am doing something wrong)
If the scene node in question is closer then the distance to the collision of the wall, do a getCollisionPoint to the scene node and generate a triangle selector for that scene node. Then get the hit location as an x,y,z

This gives you the xyz of either the map or the scene node your ray is pointing at. You only have to create 1 triangle selector, use 2 triangle selectors and do 1 scene node ray.

The only thing I don't know still is how to do something with the tirangle\xyz you get back such as put a bullet hole\blood splat.

If anyone sees a problem with this I am all ears.
Dorth
Posts: 931
Joined: Sat May 26, 2007 11:03 pm

Post by Dorth »

First off, not sure to understand what you mean by that. Maybe give a code snippet as an example?

Also, what you might want to do is take your triangle, move the three corners you get by multiplying the normal by a little number and adding it to each corners and put another triangle there, transparently textured with blood splatter, etc., either that or use the impact point and do the same with the normal of the triangle, place a model of impact or whatever, a textured quad, etc. there and orient it, once more, with the normal.

From there on, the animation job is for you to do. Making that object child to the joint it,s animated from is probably the best way. To find that, I'd say you'll need to use another collision check with boxes hanged between your joints or something of the like. Maybe there's some way in Irrlicht to know which triangle of the model it is, in which case make a file listing them all with parent nodes or give them ranges.

Anyway, knock yourself out but always remember, imagination and creativity is a big part of coding ;)
Post Reply