Page 1 of 1

3D Picking (Not Picking)

Posted: Sun Feb 13, 2005 9:49 pm
by JasonW
I am having and issue where my picking routine is not picking an entity I have in my scene. basically it is just a scenen with a single mesh (ninja) and a mouse cursor thanks to CEGUI. I do not get any errors at all just no pick when the mouse is over the mesh in the rendering window ?? please find snippets below:

void Pick(Real MouseX,Real MouseY,Camera* mCamera,SceneManager* mSceneMgr)
{
// Start a new ray query
Ray cameraRay = mCamera->getCameraToViewportRay( MouseX, MouseY );
RaySceneQuery *raySceneQuery = mSceneMgr->createRayQuery( cameraRay );
raySceneQuery->setSortByDistance(true,1);
RaySceneQueryResult& result = raySceneQuery->execute();

MovableObject *mCurrMO = NULL;
RaySceneQueryResult::iterator it = result.begin();
std::list< RaySceneQueryResultEntry >::iterator rayIterator;

if (it != result.end())
{
mCurrMO = it->movable;
}
else
{
mCurrMO = NULL;
}
raySceneQuery->clearResults( );
mSceneMgr->destroyQuery( raySceneQuery );
}

Now MouseX and MouseY are just "e->getRelX()" and "e->getRelY()" passed from my mouse listener.
I have tried both ST_GENERIC and ST_EXTERIOR_FAR without success.

My model is just added to the scenen in my create scene function...
void GameApplication::createScene()
{
mModel = mSceneMgr->createEntity("TestModel","ninja.mesh");
mModelNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
mModelNode->attachObject(mModel);
mSceneMgr->setAmbientLight(ColourValue(0.5,0.5,0.5));
}

As hopefully you can see... nothing much extravegant going on here just a simple mesh and trying to get a mouseover type effect... just can't pick it...
To test I set a break point at "mCurrMO = it->movable;" and it NEVER gets called... the result list is always empty.

Posted: Sun Feb 13, 2005 10:00 pm
by tuan kuranes
Try with a IntersectionSceneQuery instead of RaySceneQuery.

Posted: Sun Feb 13, 2005 10:08 pm
by Clay
Try calling MouseX, MouseY with getX, getY instead of getRelX, getRelY.

Also, loop through the results:

Code: Select all

for (it = result.begin( ); it != result.end( ); it++)
  if (it->movable)
    mCurrMO = it->movable;

Posted: Sun Feb 13, 2005 11:37 pm
by JasonW
Fantastic - Thankyou clay..

I was passing getRelX instead of getX... such a stupid oversite that caused me hours of frustration..... a big thumbs up...

Posted: Mon Feb 14, 2005 12:11 am
by Clay
No problem. Be sure to read through the second and third intermediate tutorials http://ogrewiki.digitalsentience.com/in ... _Tutorials if the wiki ever comes back up.

It gives usage for ray scene queries for object and terrain selection, as well as using getRelX/Y for doing a mouse-look. (Though it looks like you already have this stuff down anyway.)