Skip to main content

History: ThreeDeeObjectPicking

Source of version: 2

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

{CODE(wrap="1", colors="c++")} 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();
{CODE}
((Category:Code Snippet))
((Category:Input))


        

History

Information Version
Thu 22 of Mar, 2012 14:30 GMT-0000 gr1ever Added my version of 3d-object picking and an example of dragging 7
Sat 02 of Jan, 2010 08:11 GMT-0000 jacmoe [rollback version 4] 6
Thu 22 of Mar, 2012 14:05 GMT-0000 gr1ever 5
Fri 25 of Dec, 2009 01:35 GMT-0000 jacmoe 3
Fri 25 of Dec, 2009 01:35 GMT-0000 jacmoe 2
Sun 19 of Oct, 2008 10:47 GMT-0000 Spacegaier Added category 1