MousePicking

CaseyB

22-11-2006 05:33:49

I am trying to mouse pick using the code from the Wiki and it keeps returning world fragments as renderables. Here's how I'm going the query:if (e->getButtonID() & MouseEvent::BUTTON0_MASK) // Left mouse Button
{
// Setup the ray scene query
Ray mouseRay = mCamera->getCameraToViewportRay( e->getX(), e->getY() );
mRaySceneQuery->setRay( mouseRay );
mRaySceneQuery->setSortByDistance( true );

// Execute query
RaySceneQueryResult &result = mRaySceneQuery->execute();
RaySceneQueryResult::iterator itr;

// loop through the results
for ( itr = result.begin( ); itr != result.end(); itr++ )
{
if (itr->worldFragment) // Is this result a WorldFragment?
{
Vector3 location = itr->worldFragment->singleIntersection;
cout << "World Fragment " + Ogre::StringConverter::toString(location);
}
else if (itr->movable) // Is this result a MovableObject?
{
cout << "I'm a Mesh!";
}
}
}
And I was suprised to see that my world fragment code was never being called and when I step through I see that I picked an object that came back as a movable that was called "1.1.2.3Rend" and I am guessing that's terrain. I am using Dagon and the PLSM2 from CVS.

tuan kuranes

29-11-2006 15:13:39

Did you try to use query masks ?

You should anyway really used them instead of doing some if(itr->movable) aftewards, as it will save some CPU cost (list insertion, list sort)

CaseyB

29-11-2006 15:29:13

I did, I can't remember anymore exactly which mask I used, but it ended up returning nothing when picked. I've switched to using the OctreeSceneManager for that project because it doesn't have all that much terrain.