[fixed in 1.7] Picking
[fixed in 1.7] Picking
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...
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...
-
- Admin
- Posts: 14143
- Joined: Wed Apr 19, 2006 9:20 pm
- Location: Oldenburg(Oldb), Germany
- Contact:
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.
@Seven I copied this line from sample code in your link but it caused the same problem
@hybrid Let me try to explain what I have got step by step:
my device and globals
how did I load objects
camera
how did I rotate camera
piece selecting
And GetRayCastNode function is
After rotating cam selection does not work.. I am using 1.6v. If you need code I can provide... Thanks...
Code: Select all
return g_smgr->getSceneCollisionManager()->getSceneNodeFromScreenCoordinatesBB(g_device->getCursorControl()->getPosition(), 0, true);
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();
Code: Select all
scene::IAnimatedMesh* meshTahta = g_smgr->getMesh(meshFilePath);
m_node = g_smgr->addOctTreeSceneNode(meshTahta->getMesh(0), 0, 1);
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));
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);
}
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);
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?
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.dehseth wrote:Code: Select all
if ((selectedPiece = GetRayCastNode(pieces, cam)))
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
@CuteAlien Ok I will try to write a small code and generate this.
And for the code you may think it as:
And for the code you may think it as:
Code: Select all
if ((selectedPiece = GetRayCastNode(pieces, cam)) != NULL)
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..
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..
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
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm