Selection of a simple node using mouse

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
ariaci

Selection of a simple node using mouse

Post by ariaci »

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
Boogle
Posts: 162
Joined: Fri Nov 21, 2003 3:16 pm
Location: Toronto, Canada

Post by Boogle »

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).
ariaci

That's no problem but how do I get triangles out of a node?

Post by ariaci »

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:

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");
}
What's wrong with this code?
Boogle
Posts: 162
Joined: Fri Nov 21, 2003 3:16 pm
Location: Toronto, Canada

Post by Boogle »

I would use smgr->createTriangleSelector(mesh,node) to get your selector, then attach it to the node using node->setTriangleSelector(). The documentation has more info on the createTriangleSelector method.
rt
Posts: 150
Joined: Sun Nov 30, 2003 6:54 am
Location: canada
Contact:

Re: That's no problem but how do I get triangles out of a no

Post by rt »

ariaci wrote: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");
}
What's wrong with this code?
how about

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();
		}
Boogle
Posts: 162
Joined: Fri Nov 21, 2003 3:16 pm
Location: Toronto, Canada

Post by Boogle »

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.
rt
Posts: 150
Joined: Sun Nov 30, 2003 6:54 am
Location: canada
Contact:

Post by rt »

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.
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.
ariaci

Everything ok but ...

Post by ariaci »

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
Post Reply