Problem with MFC and 3D picking
Posted: Sun Feb 13, 2005 4:29 pm
I've got Ogre to render in a MFC picture control and now I want to do 3D picking in the Ogre view, but there is an very confusing problem. The picking ray of my viewport doesn't come out straight in front of the viewport, it comes out of the right side of the viewport (I assume at 90 degrees). The result is, that if an object is on the right side of the camera/viewport, my "picking" method will return "TRUE".
Here is the picking method (mouse coordinates [int x, int y] are global screen coordinates):
Somebody an idea what's going wrong, please help.
Thx, stoneCold
Here is the picking method (mouse coordinates [int x, int y] are global screen coordinates):
Code: Select all
bool COgreFramework::picking(int x, int y, String &ausgabe)
{
// Start a new ray query
Ogre::Ray cameraRay = mCamera->getCameraToViewportRay( x, y);
Ogre::RaySceneQuery *raySceneQuery = mSceneMgr->createRayQuery( cameraRay );
raySceneQuery->execute( );
Ogre::RaySceneQueryResult result = raySceneQuery->getLastResults( );
Ogre::MovableObject *closestObject = NULL;
float closestDistance = LONG_MAX; //used to be real
std::list< Ogre::RaySceneQueryResultEntry >::iterator rayIterator;
for ( rayIterator = result.begin( ); rayIterator != result.end( ); rayIterator++ )
{
if ( ( *rayIterator ).distance < closestDistance && ( *rayIterator ).distance > 0.1f )
{
closestObject = ( *rayIterator ).movable;
closestDistance = ( *rayIterator ).distance;
}
}
bool intersects;
// No object clicked
if ( closestObject == NULL )
{
intersects = false;
}
else
{
Ogre::Entity *TestEntity = NULL;
ausgabe = closestObject->getMovableType() + closestObject->getName();
if(closestObject->getMovableType()=="Entity")
{
intersects = true;
TestEntity = (Entity *)closestObject;
}
}
raySceneQuery->clearResults( );
mSceneMgr->destroyQuery( raySceneQuery );
return intersects;
}
Thx, stoneCold