getSceneNodeFromCameraBB cant get node at distance

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
Carnafex
Posts: 15
Joined: Wed Sep 05, 2007 1:32 am
Location: Sydney, Australia

getSceneNodeFromCameraBB cant get node at distance

Post by Carnafex »

Heya everyone!

I've just started a new project, and was only a little bit in when I ran into a strange little problem when using the getSceneNodeFromCameraBB to select the scene node that you're looking at. It simply doesnt work unless you're really close to the scenenode (about 1.0f away or so, pretty much has to fill the screen before it works)

The code that I currently have is real simple, just a turn off the lighting on the selected node with a mouse click:

The node I've created is like this:

Code: Select all

scene::ISceneNode * node = smgr->addSphereSceneNode();
		node->setPosition(core::vector3df(0,0,30));
		node->setMaterialTexture(0, driver->getTexture("Data/Graphics/rockwall.bmp"));
		node->setMaterialFlag(video::EMF_LIGHTING, false);
		node->setDebugDataVisible(true);
		node->setID(333);
And the selection code is like this:

Code: Select all

bool OnEvent(const SEvent & event)
{	
	if (event.EventType == EET_MOUSE_INPUT_EVENT && event.MouseInput.Event == irr::EMIE_LMOUSE_PRESSED_DOWN)
	{	
		//get the selected node
		scene::ISceneNode* selected = 0;
		selected = smgr->getSceneCollisionManager()->getSceneNodeFromCameraBB(smgr->getActiveCamera(),0,true);
		
		if (selected) {
			char s[64];
			sprintf(s, "ID: %i", selected->getID());
			device->getLogger()->log(s);
			selected->setMaterialFlag(video::EMF_LIGHTING, true);
		}
		return true;
	}
The camera is the inbuilt Irrlicht FPS camera, with no special settings outside the default.

When clicking on the node, if you're close, you get the ID displayed to the output, otherwise you always get -1.
I can't see anything out of the ordinary so far, it just doesnt seem to work if you're further than 1f away.
I have searched through the forums already to seem if anyone else had a similar problem, and I get the same effect even with the following:
* if I set the camera to be a debugobject, and then set ignore debug to true on the getSceneNodeFromCameraBB
* use bit masking
* use getSceneNodeFromRayBB instead
* use a different type of scenenode

Any ideas as to what this might be, or am I just missing something obvious?
pippy3
Posts: 155
Joined: Tue Dec 15, 2009 7:32 am

Post by pippy3 »

getSceneNodeFromCameraBB will get a ray cast from the camera, not the mouse point.


You'll have to use getSceneNodeFromRayBB and input the mouse position to make a ray to get the object the user clicked on.

In irrlicht 1.5.* I've had problems with accuracy using this method, though it might be fixed in 1.7.*.
Carnafex
Posts: 15
Joined: Wed Sep 05, 2007 1:32 am
Location: Sydney, Australia

Post by Carnafex »

Thanks for the reply, and sorry for my late one, I've been trying out a few methods to see what else I can do.

I switched over to trying to use getSceneNodeFromRayBB, but it had the same effect, in that the camera had to be right next to the target before the mouse would select it, so unfortunately no luck there.
I also switched over to using getSceneNodeFromCameraBB again, but instead used the mouse click to trigger the event only (as opposed to using the cursor), and I still have to smush the camera right against the node to trigger it.

I think I'll try one of the older compiled versions of Irrlicht that I have, and give that a shot. Hopefully I can nut this one out :)
Post Reply