[fixed in 1.7] Picking

You discovered a bug in the engine, and you are sure that it is not a problem of your code? Just post it in here. Please read the bug posting guidelines first.
Post Reply
dehseth
Posts: 130
Joined: Wed Dec 09, 2009 11:05 am
Contact:

[fixed in 1.7] Picking

Post by dehseth »

I would like to pick objects with mouse cursor. I have tried getting ray line using getRayFromScreenCoordinates function, and I have used getSceneNodeAndCollisionPointFromRay / getSceneNodeFromRayBB functions. I also find some code pice about getting ray line and tried two different ray-triangle functions from web... Well none of these methods work!

And getSceneNodeFromRayBB picks objects when my camera position is at (0, 20, -25), after rotating my cam to (-1, 20, 25) point this method does not return any scene node...
Seven
Posts: 1034
Joined: Mon Nov 14, 2005 2:03 pm

Post by Seven »

hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Well, I don't see any necessity that a node is picked at (0,20,-25), but not at (-1,20,25). Looks like a pretty different direction. So unless you can specify your problem in more detail, with a failing test application, I'd consider this description simply wrong usage of the properly working methods.
dehseth
Posts: 130
Joined: Wed Dec 09, 2009 11:05 am
Contact:

Post by dehseth »

@Seven I copied this line from sample code in your link but it caused the same problem

Code: Select all

return g_smgr->getSceneCollisionManager()->getSceneNodeFromScreenCoordinatesBB(g_device->getCursorControl()->getPosition(), 0, true); 
@hybrid Let me try to explain what I have got step by step:

my device and globals

Code: Select all

g_device = createDevice(irr::video::E_DRIVER_TYPE::EDT_DIRECT3D9, core::dimension2d<u32>(640, 480));
g_driver = g_device->getVideoDriver();
g_smgr = g_device->getSceneManager();
how did I load objects

Code: Select all

scene::IAnimatedMesh* meshTahta = g_smgr->getMesh(meshFilePath);
m_node = g_smgr->addOctTreeSceneNode(meshTahta->getMesh(0), 0, 1);
camera

Code: Select all

scene::ICameraSceneNode* cam = g_smgr->addCameraSceneNode(0, core::vector3df(0, 20, -25), core::vector3df(0,0,0));
cam->setNearValue(0.1f);
cam->setPosition(core::vector3df(0, 20, -25));
cam->setTarget(core::vector3df(0, 0, 0));
how did I rotate camera

Code: Select all

if (keys[irr::KEY_KEY_W])
			{
				core::vector3df m = cam->getTarget() - cam->getPosition();
				m.normalize();
				m *= 0.05f;
				cam->setPosition(cam->getPosition() + m);
			}
			else if (keys[irr::KEY_KEY_S])
			{
				core::vector3df m = cam->getPosition() - cam->getTarget();
				m.normalize();
				m *= 0.05f;
				cam->setPosition(cam->getPosition() + m);
			}
			else if (keys[irr::KEY_KEY_A])
			{
				core::vector3df m = cam->getTarget() - cam->getPosition();
				m.normalize();
				m.rotateXZBy(90);
				m.Y = 0;
				m *= 0.05f;
				cam->setPosition(cam->getPosition() + m);
			}
			else if (keys[irr::KEY_KEY_D])
			{
				core::vector3df m = cam->getTarget() - cam->getPosition();
				m.normalize();
				m.rotateXZBy(-90);
				m.Y = 0;
				m *= 0.05f;
				cam->setPosition(cam->getPosition() + m);
			}
piece selecting

Code: Select all

if (selectedPiece) 
{
	selectedPiece->getMaterial(0).Wireframe = false;
	selectedPiece->setDebugDataVisible(scene::E_DEBUG_SCENE_TYPE::EDS_OFF);
}
			
if ((selectedPiece = GetRayCastNode(pieces, cam))) 
{
	//getSceneNodeFromRayBB(ray);
	selectedPiece->getMaterial(0).Wireframe = true;
 selectedPiece->setDebugDataVisible(scene::E_DEBUG_SCENE_TYPE::EDS_BBOX);
}

And GetRayCastNode function is

Code: Select all

return g_smgr->getSceneCollisionManager()->getSceneNodeFromScreenCoordinatesBB(g_device->getCursorControl()->getPosition(), 0, false); 
After rotating cam selection does not work.. I am using 1.6v. If you need code I can provide... Thanks...
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

Just wondering as it looks a little suspicious - do you really want assignment here or is that a type and you wanted == to compare the resulting node with selectedPiece?
dehseth wrote:

Code: Select all

		
if ((selectedPiece = GetRayCastNode(pieces, cam))) 
In any case - having a minimal code example which can be compiled to reproduce the problem certainly always helps. And it's easier and less work for you to write that, as you already have that bug, as it would be for us.
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
dehseth
Posts: 130
Joined: Wed Dec 09, 2009 11:05 am
Contact:

Post by dehseth »

@CuteAlien Ok I will try to write a small code and generate this.

And for the code you may think it as:

Code: Select all

if ((selectedPiece = GetRayCastNode(pieces, cam)) != NULL) 
dehseth
Posts: 130
Joined: Wed Dec 09, 2009 11:05 am
Contact:

Post by dehseth »

Ok I have uploaded sample file and code. You can download it from here: http://www.2shared.com/file/10853547/57 ... rDemo.html

I am using v1.6. The demo exe file is compiled in DEBUG mode. If you cannot run it you can compile the source code. When running exe file, you can pick object successfully; after rotating camera upto 180 degrees using keys A or D, you won't be able to pick the object with mouse cursor..
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

This is fixed in Irrlicht 1.7. Just tested your code.
dehseth
Posts: 130
Joined: Wed Dec 09, 2009 11:05 am
Contact:

Post by dehseth »

Ok thank you hybrid.. When can I have the v1.7? Do you know the release date? I rather use release than SVN... :D
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

1.7 release should be in February.
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
Post Reply