PDA

View Full Version : Picking a scene node in Irrlicht from mouse coordinates



BigBMan
01-05-2011, 09:20 AM
I've found a number of posts on the Irrlicht forum on how to do this (http://irrlicht.sourceforge.net/phpBB2/viewtopic.php?t=37720&highlight=getscenenodeandcollisionpointfromray), but it doesn't seem to be working correctly.

Has anyone successfully found a collision node/triangle/point from a tap/click?

Here's my signal handler for a click:



void OnViewOverStart(VariantList *pVList)
{
CL_Vec2i v2fPos = pVList->m_variant[0].GetVector2();
LogMsg("VeiwOverStart: %x, %x", v2fPos.x, v2fPos.y);

// convert to Irrlicht friendly struct
irr::core::position2di mousePos(v2fPos.x, v2fPos.y);

// get our scene manager
scene::ISceneManager* pSceneMgr = GetIrrlichtManager()->GetScene();
scene::ISceneCollisionManager* pCollMgr = pSceneMgr->getSceneCollisionManager();

// get the ray from the screen point
irr::core::line3df collRay;

collRay = pCollMgr->getRayFromScreenCoordinates(mousePos, pSceneMgr->getActiveCamera()); // this appears to be getting unique values

// get the collision
core::vector3df collPoint;
core::triangle3df collTriangle;
scene::ISceneNode* pNode = 0;

pNode = pCollMgr->getSceneNodeAndCollisionPointFromRay(collRay, collPoint, collTriangle); // I'm always getting null here

if( pNode )
LogMsg(" Selected Node: %s", pNode->getName());
else
{
pNode = pCollMgr->getSceneNodeFromScreenCoordinatesBB(mousePos,0,tru e); // but this is returning a node... ***
if( pNode )
LogMsg(" Selected Node: %s", pNode->getName());
}

LogMsg(" Selected Point: %f, %f, %f", collPoint.X, collPoint.Y, collPoint.Z);
}

BigBMan
01-07-2011, 05:14 PM
Still having problems with this. I think it's coming down to the function getRayFromScreenCoordinates. I'm noticing a few suspicious things stepping into that function:

1. I'm in landscape mode, but Irrlicht uses the device's natural screen space, so I have to pass x, y values in reverse.

2. When getRayFromScreenCoordinates calculates intersection values of the far plane, the "up-to-down" line doesn't seem right. One of the x, y, z values should be zero (my camera does not rotate along z so the line should be straight up and down).

3. My camera is not registering as Orthogonal, but based on some very elementary debugging (just rendering a node at the start/end points), it seems that my collision ray is going through the center of the view frustum near plane.

Has anyone got the Irrlicht Quake tutorial on collision working? That's where I'm headed next. Any help would be greatly appreciated!!!

Seth
01-09-2011, 08:20 PM
Hmm, sorry haven't done anything with picking yet. Might run into it a bit later though!

BigBMan
01-09-2011, 09:50 PM
Darn :(

I'm rendering spheres for the start/end of the collision ray and it appears the function is not interpreting the right aspect ratio or fov. I get results near to where I'm pointing, but the ray is definitely skewed somehow.