ThreeDeeObjectPicking         3D object picking from a Win32 aplication
Print

This could be used for 3D object picking from a Win32 aplication, I use it from a OnMouseMove callback :

RECT rc;
 this->GetClientRect(&rc);
 int width    = rc.right - rc.left;
 int height    = rc.bottom - rc.top;
 float tx = (float)(1.0f / width) * cpt.x;
 float ty = (float)(1.0f / height) * cpt.y;
 Camera *pCam = ogreEngine::getSingletonPtr()->getCurrentCamera();
 // calc the ray using normalised screen coordinates [0-1]
 Ray ray = pCam->getCameraToViewportRay(tx - 0.5, 0.5 - ty);
 // Set up the ray query
 if (!mpRayQuery)
     mpRayQuery = ogreEngine::getSingletonPtr()->getSceneManager()->createRayQuery(ray);
 else
     mpRayQuery->setRay(ray); // update ray
 // Sort by distance, and say we're only interested in the first hit
 mpRayQuery->setSortByDistance(true, 1);
 // Execute
 RaySceneQueryResult res = mpRayQuery->execute();
 RaySceneQueryResult::iterator it = res.begin();
 if (it != res.end())
 {
     mCurrMO = it->movable;
     this->updateProgressListeners("mouse : " + mCurrMO->getName());
 }
 else
 {
     this->updateProgressListeners("mouse : " + StringConverter::toString(tx) + "x" + StringConverter::toString(ty));
     mCurrMO = NULL;
 }
 mpRayQuery->clearResults();

 


Contributors to this page: jacmoe111451 points  and Spacegaier3733 points  .
Page last modified on Saturday 02 of January, 2010 08:11:49 GMT by jacmoe111451 points .


The content on this page is licensed under the terms of the Creative Commons Attribution-ShareAlike License.
As an exception, any source code contributed within the content is released into the Public Domain.