Hi!
I want to code a program where I can select a rendered node by mouse. Is there a way to do this fast and easy?
I suggested to code my own class inherited from IEventReceiver and ISceneNode. But this doesn't work for me because the IEventReceiver isn't able to find this node.
Anybody knows a way to do this?
Thanx
Selection of a simple node using mouse
The ISceneCollisionManager has some methods to help you with this. You can get the collision manager through smgr->getCollisionManager(); The getSceneNodeFromScreenCoordinatesBB method will give you the scene node based on node's bounding box. The getRayFromScreenCoordinates method will give you a ray which you can then use for more accurate detection (you can then use getCollisionPoint on various scene nodes with your ray to determine if the ray from the screen position hit any of the node's triangles).
That's no problem but how do I get triangles out of a node?
Everything works good but now there ist the problem that the given node isn't able to give me triangles.
the getCollisionPoint-method also needs an selector. I tried to use the given irr::scene::CTriangleSelector. But after implementing no triangles appeared in this selector. Why?
I tried the following code:
What's wrong with this code?
the getCollisionPoint-method also needs an selector. I tried to use the given irr::scene::CTriangleSelector. But after implementing no triangles appeared in this selector. Why?
I tried the following code:
Code: Select all
scene::ISceneNode* pNode = NULL;
scene::ISceneCollisionManager* pCollisionMgn = (irr::scene::CSceneManager*)smgr)->getSceneCollisionManager();
if (pCollisionMgn)
{
irr::scene::CTriangleSelector selector(myNode);
core::line3d<f32> ray = pCollisionMgn->getRayFromScreenCoordinates(
core::position2d<s32>(event.MouseInput.X, event.MouseInput.Y),
smgr->getActiveCamera());
core::vector3df vector;
core::triangle3df triangle;
if (pCollisionMgn->getCollisionPoint(ray, &selector, vector, triangle))
os::Printer::print("Left mouse button left up");
}
Re: That's no problem but how do I get triangles out of a no
how aboutariaci wrote:But after implementing no triangles appeared in this selector. Why?
I tried the following code:What's wrong with this code?Code: Select all
scene::ISceneNode* pNode = NULL; scene::ISceneCollisionManager* pCollisionMgn = (irr::scene::CSceneManager*)smgr)->getSceneCollisionManager(); if (pCollisionMgn) { irr::scene::CTriangleSelector selector(myNode); core::line3d<f32> ray = pCollisionMgn->getRayFromScreenCoordinates( core::position2d<s32>(event.MouseInput.X, event.MouseInput.Y), smgr->getActiveCamera()); core::vector3df vector; core::triangle3df triangle; if (pCollisionMgn->getCollisionPoint(ray, &selector, vector, triangle)) os::Printer::print("Left mouse button left up"); }
Code: Select all
irr::core::vector3df intersection;
irr::core::triangle3df tri;
irr::scene::ITriangleSelector* wselector = NULL;
if (myNode->isVisible()) {
wselector = smgr->createTriangleSelectorFromBoundingBox(myNode);
if (smgr->getSceneCollisionManager()->getCollisionPoint(ray, wselector, intersection, tri)) {
wselector->drop();
return intersection;
}
wselector->drop();
}
true, but with the selector you can retrive the intersection point between the mesh and ray, instead of just the node. this can be helpful if you want to 'drag' the node around on a plane using the mouse.Boogle wrote:Yes.. however if you use CreateFromBoundingBox, this will have the same effect as the getSceneNodeFromScreenCoordinatesBB call, and the getSceneNodeFromScreenCoordinatesBB call does not require you to create a selector.
Everything ok but ...
No problem to implement this code but now the click is only registered if I'm using fullscreen. In windowed mode the click is also recognized but I have to click outside the object.
Why? To test the implementation I used the original code of the CustomSceneNode and modified it with my own event receiver. In this receiver I tried to cut the ray of the active camera and the current mouse screen position with the bounding of the node. But it doesn't work in windowed mode.
Can anybody help me?
Now my second problem. How do I get a Mesh out of a single Node? Have I to fill it myself with triangle and node information like a loader?
Thanx for all information!
ariaci
Why? To test the implementation I used the original code of the CustomSceneNode and modified it with my own event receiver. In this receiver I tried to cut the ray of the active camera and the current mouse screen position with the bounding of the node. But it doesn't work in windowed mode.
Can anybody help me?
Now my second problem. How do I get a Mesh out of a single Node? Have I to fill it myself with triangle and node information like a loader?
Thanx for all information!
ariaci