get node under mouse (problem)

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
suliman
Posts: 379
Joined: Sat Sep 23, 2006 2:06 pm

get node under mouse (problem)

Post by suliman »

hi i do this:

ISceneNode * hit=0;
hit=www.coll->getSceneNodeFromScreenCoordinatesBB(mouse);

where mouse is the pos of the cursor. This works very badly and i dont know why. I have plenty of nodes (units) around and only sometimes it actually hits them when pointing over them.

Most of the time no unit node is hit altough plenty of nodes are under the mouse.
Also is it supposed to return the FIRST node it hits (from the camera) or just any?

Something is hit and i guess it stops looking then, but the node normally hit is the terrain and its behind unit-nodes. So why doesnt it find the unit-nodes (it does happen but very seldom and i dont see a pattern)?
Abraxas)
Posts: 227
Joined: Sun Oct 18, 2009 7:24 am

Re: get node under mouse (problem)

Post by Abraxas) »

Often I find the mouse can be over GUI elements and this can cause a problem.

If the algorithm works *sometimes* then it's likely something else is the problem.
suliman
Posts: 379
Joined: Sat Sep 23, 2006 2:06 pm

Re: get node under mouse (problem)

Post by suliman »

i dont have any GUI elements.
What else can be the problem? All code related to this should be that line no?

I found out that it can only hit the terrainSceneNode and a single unit node. Other unit-nodes are never hit. Can this explain anything? I use the function like seen above, no extra params.
Also, should it return the FIRST node hit or the last or any of them? (if several behind eachother). Right now it doesnt work through...

Thanks
mikkis
Posts: 64
Joined: Mon Jan 28, 2013 2:38 pm
Location: Fi

Re: get node under mouse (problem)

Post by mikkis »

Tested getSceneNodeFromScreenCoordinatesBB() (replacing getSceneNodeAndCollisionPointFromRay() call), and it returns nearest node's name under mouse-cursor correctly. Unfortunately I cant help anyway, as I have no idea why it doesnt work for you.
(and using latest irr from svn)

If it somehow related how you setup collision selectors?
suliman
Posts: 379
Joined: Sat Sep 23, 2006 2:06 pm

Re: get node under mouse (problem)

Post by suliman »

Code: Select all

    
    vect3d hitPoint;
    triangle3df hitTriangle;
    irr::core::line3d<f32> ray=www.coll->getRayFromScreenCoordinates(mouse);
    hit=www.coll->getSceneNodeAndCollisionPointFromRay(ray,hitPoint,hitTriangle);
 
tested this as well. this doesnt even hit any of the nodes under the mouse... Not even the terrain.

The coll is setup like this:

Code: Select all

 
    scene::ISceneCollisionManager* coll;
        coll=smgr->getSceneCollisionManager();
 
So i really dont know whats wrong...
smso
Posts: 246
Joined: Fri Jun 04, 2010 3:28 pm
Location: Hong Kong

Re: get node under mouse (problem)

Post by smso »

Maybe you should use a more recent copy of irrlicht.
See this post:
http://irrlicht.sourceforge.net/forum/v ... =4&t=48637

Regards,
smso
mikkis
Posts: 64
Joined: Mon Jan 28, 2013 2:38 pm
Location: Fi

Re: get node under mouse (problem)

Post by mikkis »

I setup scene like this:

Code: Select all

 
   load();    // load scene from .irr file
   selector=createTriangleSelectors();  // I get selector so I can drop it when loading other scene
 
---
 
// well this is actually copied from collision demo (only 1 added line which I needed on different test)
IMetaTriangleSelector *createTriangleSelectors()
{
        // Create a meta triangle selector to hold several triangle selectors.
        IMetaTriangleSelector *meta = sceneManager->createMetaTriangleSelector();
        array<ISceneNode *> nodes;
        sceneManager->getSceneNodesFromType(ESNT_ANY, nodes); // Find all nodes
 
        for (u32 i=0; i < nodes.size(); ++i)
        {
            ISceneNode * node = nodes[i];
            ITriangleSelector * selector = 0;
 
            switch(node->getType())
            {
            case scene::ESNT_ANIMATED_MESH:
                // Because the selector won't animate with the mesh,
                // and is only being used for camera collision, we'll just use an approximate
                // bounding box instead of ((scene::IAnimatedMeshSceneNode*)node)->getMesh(0)
                selector = sceneManager->createTriangleSelectorFromBoundingBox(node);
                break;
 
            case scene::ESNT_MESH:
                selector = sceneManager->createTriangleSelector(((IMeshSceneNode*)node)->getMesh(), node);
                node->setTriangleSelector(selector); //#CHECK why this is needed
 
                node->setID(1);
                break;
 
            case scene::ESNT_TERRAIN:
                selector = sceneManager->createTerrainTriangleSelector((ITerrainSceneNode*)node);
                break;
 
            case scene::ESNT_OCTREE:
                selector = sceneManager->createOctreeTriangleSelector(((IMeshSceneNode*)node)->getMesh(), node);
                break;
 
            default:
                // Don't create a selector for this node type
                break;
            }
 
            if(selector)
            {
                // Add it to the meta selector, which will take a reference to it
                meta->addTriangleSelector(selector);
                // And drop my reference to it, so that the meta selector owns it.
                selector->drop();
            }
        }
        return meta;
}
 
 
CuteAlien
Admin
Posts: 9933
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: get node under mouse (problem)

Post by CuteAlien »

It should return the nearest node. Can't really tell why it fails without a way to debug it with a reproducable scene+code.
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
suliman
Posts: 379
Joined: Sat Sep 23, 2006 2:06 pm

Re: get node under mouse (problem)

Post by suliman »

upgraded to ver 1.8, still same problem:

returns the terrainNode or a single (anways the same) node. All other nodes are ignored... Dont know what to do now.
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Re: get node under mouse (problem)

Post by hendu »

That function uses the bounding boxes. So the first thing you should check is if your bounding boxes are correct.
suliman
Posts: 379
Joined: Sat Sep 23, 2006 2:06 pm

Re: get node under mouse (problem)

Post by suliman »

the boxes are fine (they are drawn to check). Also, projectiles can hit the nodes alright using

Code: Select all

const core::aabbox3d<f32> targetBox = uu->node->getTransformedBoundingBox();
if(targetBox.isPointInside(hitter->pos))
but the other things does only work with a single node+terrain
Post Reply