Only a few triangles are hit by ray

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
tobmaster
Posts: 9
Joined: Fri Feb 27, 2015 6:48 am

Only a few triangles are hit by ray

Post by tobmaster »

Hello everybody,

I've already searched different forums but couldn't find any solution for this topic.

I have a scenenode with a camera behind it (3rd Person View).
I perform a ray for detecting things in front of the character:

Code: Select all

        core::line3d<f32> ray;
        core::vector2d<s32> pos;
        //Pixel festlegen:
        pos.Y = 300;    //Damit der Ray ein bisschen weiter oben anzielt
        pos.X = 800;
 
        ray = collMan->getRayFromScreenCoordinates(pos,Camera);
        core::vector3df intersection;
        core::triangle3df hitTriangle;
        scene::ISceneNode * selectedSceneNode = collMan->getSceneNodeAndCollisionPointFromRay(ray,intersection, hitTriangle); 
Code for detecting the scenenode which is hit:

Code: Select all

        if(selectedSceneNode)
        {
            bill->setPosition(intersection);
 
            // We need to reset the transform before doing our own rendering.
            driver->setTransform(video::ETS_WORLD, core::matrix4());
            driver->setMaterial(material);
            driver->draw3DTriangle(hitTriangle, video::SColor(0,255,0,0));  
 
        }
My problem is that it seems that only a few triangles of a scenenode in front of me are clickable.

For example if you look at this screenshot:

Image
The red dot is my ray. Only a few triangles of the character react on my clickEvent. Most of the reacting triangles are in the area of the head or shoulders, only a few triangles in the lower area react.

Another SceneNode I imported is only hardly clickable. I have to perform a lot of clicks on different triangles of the scenenode to get a reaction from it.

I don't think that my ClickEvent is wrong.

Things I tried:
- Recalculate the outside of the 3d-object via Blender
- tried different driver types
- changed rotation/size of the scenenodes

If I increase the size of the scenenodes, more and other triangles are getting clickable.

I just can't get it working correctly.

Does somebody have any ideas what I can do to solve this problem?

Thanks a lot,
tobmaster
thanhle
Posts: 325
Joined: Wed Jun 12, 2013 8:09 am

Re: Only a few triangles are hit by ray

Post by thanhle »

Have you carefully follow the collision example? I think that works fine to your need.

Regards
Thanh
Foaly
Posts: 142
Joined: Tue Apr 15, 2014 8:45 am
Location: Germany

Re: Only a few triangles are hit by ray

Post by Foaly »

Well, I really don't know what could be wrong in your case. It could be anything.

How are you creating the triangle selectors? Maybe that's wrong.

Are you using the .x -format for your meshes? Because when I used it, the collisions were always wrong.
I'm not sure whether that was a problem with the exporter, but maybe you've got the same problem.
tobmaster
Posts: 9
Joined: Fri Feb 27, 2015 6:48 am

Re: Only a few triangles are hit by ray

Post by tobmaster »

@thanhle:
Yes I basically created my game with the tutorial.
The problem is that the tutorial doesn't include mouse events.

@Foaly:
Yes that's exactly my problem (:
It could be a lot of things but I ran out of ideas what I could try next.
I use .obj-Files for my meshes.

Best Regards,
tobmaster
tobmaster
Posts: 9
Joined: Fri Feb 27, 2015 6:48 am

Re: Only a few triangles are hit by ray

Post by tobmaster »

I compared my program with the example "Collision".

Somehow I didn't implement the part with:

Code: Select all

enum
{
    // I use this ISceneNode ID to indicate a scene node that is
    // not pickable by getSceneNodeAndCollisionPointFromRay()
    ID_IsNotPickable = 0,
 
    // I use this flag in ISceneNode IDs to indicate that the
    // scene node can be picked by ray selection.
    IDFlag_IsPickable = 1 << 0,
 
    // I use this flag in ISceneNode IDs to indicate that the
    // scene node can be highlighted.  In this example, the
    // homonids can be highlighted, but the level mesh can't.
    IDFlag_IsHighlightable = 1 << 1
};
I thought this would be optional to implement.

Now I can click on meshes in a fps-Example.
I will implement this tomorrow in my 3d-game and tell you the results.

Thanks and best regards,
tobmaster
tobmaster
Posts: 9
Joined: Fri Feb 27, 2015 6:48 am

Re: Only a few triangles are hit by ray

Post by tobmaster »

Just implementing the code with the IDs didn't solve the problem.

Now I took the Collision Example and copied my code in there.
Now it works.

Something was wrong in my old project, but I couldn't find out, what it was.

Best regards,

tobmaster
Post Reply