Problem with picking in 1.7.1

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
kulesz
Posts: 4
Joined: Thu Feb 18, 2010 6:29 pm

Problem with picking in 1.7.1

Post by kulesz »

Hi,

I'm new to Irrlicht (just a few days). I've managed to do some mesh rendering, terrain and mouse/keyboard input. Now I have a problem with mouse picking.
What I do is (skipped some texture code, camera and so on):

Init all the stuff

Code: Select all

device=createDevice( video::EDT_DIRECT3D9, dimension2d<u32>(SCREEN_W, SCREEN_H), 16, true, true, true, 0);
if (!(device))  return 1;
driver = device->getVideoDriver();
smgr = device->getSceneManager();
guienv = device->getGUIEnvironment();
device->setEventReceiver(&eventReciever);
Load mesh and add the node

Code: Select all

IAnimatedMesh* kobita_mesh = smgr->getMesh("media\\models\\kaplica.obj");
        IAnimatedMeshSceneNode* kobita_node = smgr->addAnimatedMeshSceneNode( kobita_mesh);
Set up the terrain

Code: Select all

scene::ITerrainSceneNode* terrain = smgr->addTerrainSceneNode(
                "MWM-CraterIsleHight.png",
                0,                                      // parent node
                -1,                                     // node id
                core::vector3df(0.f, 0.f, 0.f),         // position
                core::vector3df(0.f, 0.f, 0.f),         // rotation
                core::vector3df(60.f, 4.0f, 60.f),      // scale
                video::SColor ( 255, 255, 255, 255 ),   // vertexColor
                3,                                      // maxLOD
                scene::ETPS_17,                         // patchSize
                4                                      // smoothFactor
                );
Do some collision stuff

Code: Select all

ITriangleSelector* s = smgr->createOctreeTriangleSelector(kobita_mesh,
                                kobita_node, 32);
                kobita_node->setTriangleSelector(s);
                s->drop();

		scene::ISceneCollisionManager* collMan = smgr->getSceneCollisionManager();
And in render loop

Code: Select all

irr::scene::ISceneNode* selectedSceneNode = collMan->getSceneNodeFromScreenCoordinatesBB(irr::core::position2di(eventReciever.mouseX(),eventReciever.mouseX()), 0, false, 0);

x=selectedSceneNode->getPosition().X;
y=selectedSceneNode->getPosition().Y;
z=selectedSceneNode->getPosition().Z;
While I'm moving over the terrain and hovering mouse over the mesh, nothing happens. The x,y,z variables should show the node's position, but they don't. It works only sometimes, in a very close range to the node, but not always and only in certain positions/orientations. Also, x,y,x shows some random, 100+ numbers in certain areas of terrain.
Could anyone can help me with it? I can upload a full code, if someone have some time to look at.
Thanks in advance...

Kulesz
Bate
Posts: 364
Joined: Sun Nov 01, 2009 11:39 pm
Location: Germany

Post by Bate »

you used mouse X for x and y :)

Code: Select all

collMan->getSceneNodeFromScreenCoordinatesBB(irr::core::position2di(eventReciever.mouseX(),eventReciever.mouseX()), 0, false, 0);
try this:

Code: Select all

collMan->getSceneNodeFromScreenCoordinatesBB(device->getCursorControl()->getPosition(), 0, false, 0);
maybe that's already enough
Never take advice from someone who likes to give advice, so take my advice and don't take it.
kulesz
Posts: 4
Joined: Thu Feb 18, 2010 6:29 pm

Post by kulesz »

Thanks for quick reply... Tried your help, but it's still the same effect :-/
Tutorial example 7 compiles and works ok.
blAaarg
Posts: 94
Joined: Tue Mar 02, 2010 9:11 pm
Location: SoCal

Post by blAaarg »

I don't know that this will solve your problem as your description of it seems like some other things may be going on. But if you're trying to find where on your node your mouse is hovering,

Code: Select all

getSceneNodeFromScreenCoordinatesBB()
will only get you the scene node itself, and it only has one position it can return: it's own. You may want to try

Code: Select all

getCollisionPoint()
or

Code: Select all

getSceneNodeAndCollisionPointFromRay()
"Computers don't make mistakes! What they do they do on purpose!!"

-Dale Gribble
scarypajamas
Posts: 15
Joined: Tue Sep 01, 2009 11:36 pm

Post by scarypajamas »

blAaarg wrote:I don't know that this will solve your problem as your description of it seems like some other things may be going on.
I just wanted to say, I had the exact same problem as kulesz did. My code, WITHOUT ANY CHANGES, worked fine when I compiled and linked with irrlicht 1.6.1, but BROKE when I compiled and linked with irrlicht 1.7.1. So I'm not sure it's a problem with our code per-say, unless its a bug we are exploiting with irrlicht that was patched with 1.7.1...

In any case, I fixed the problem by ripping the following 2 functions from irrlicht 1.6.1 getSceneNodeAndCollisionPointFromRay and getPickedNodeBB in CSceneCollisionManager.cpp and pasted them over the new one's in 1.7.1
Post Reply