get node under mouse (problem)
get node under mouse (problem)
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)?
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)?
Re: get node under mouse (problem)
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.
If the algorithm works *sometimes* then it's likely something else is the problem.
Re: get node under mouse (problem)
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
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
Re: get node under mouse (problem)
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?
(and using latest irr from svn)
If it somehow related how you setup collision selectors?
Re: get node under mouse (problem)
Code: Select all
vect3d hitPoint;
triangle3df hitTriangle;
irr::core::line3d<f32> ray=www.coll->getRayFromScreenCoordinates(mouse);
hit=www.coll->getSceneNodeAndCollisionPointFromRay(ray,hitPoint,hitTriangle);
The coll is setup like this:
Code: Select all
scene::ISceneCollisionManager* coll;
coll=smgr->getSceneCollisionManager();
Re: get node under mouse (problem)
Maybe you should use a more recent copy of irrlicht.
See this post:
http://irrlicht.sourceforge.net/forum/v ... =4&t=48637
Regards,
smso
See this post:
http://irrlicht.sourceforge.net/forum/v ... =4&t=48637
Regards,
smso
Re: get node under mouse (problem)
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;
}
Re: get node under mouse (problem)
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
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Re: get node under mouse (problem)
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.
returns the terrainNode or a single (anways the same) node. All other nodes are ignored... Dont know what to do now.
Re: get node under mouse (problem)
That function uses the bounding boxes. So the first thing you should check is if your bounding boxes are correct.
Re: get node under mouse (problem)
the boxes are fine (they are drawn to check). Also, projectiles can hit the nodes alright using
but the other things does only work with a single node+terrain
Code: Select all
const core::aabbox3d<f32> targetBox = uu->node->getTransformedBoundingBox();
if(targetBox.isPointInside(hitter->pos))