I've found a number of posts on the Irrlicht forum on how to do this, 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:
Code:
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,true); // 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);
}
Bookmarks