"Object picking" is taking a 2D point on the screen (say, the user's finger), and determining where in the game world they are pointing or what object they are touching. This is performed by projecting the screen space point onto the near plane and then casting a ray out the camera eye.
The Bork3D Game Engine utilizes Bullet, so raycasting a trivial task if your models are loaded in the physics world. Here are some code snippets from Anytime Golf that perform the "placement picking" when you touch and drag on the guide pointer (the red arrow in the center of the screen).
// Convert a screen space point to a world space point on the near plane using InverseProject() btVector3 screenp(m_guideScreenPoint.m_x, m_guideScreenPoint.m_y, 0.0f); btVector3 worldp = RGL.InverseProject(screenp); // Retrieve the position of the camera eye btVector3 eyep = RGL.GetEye(); // Cast a ray from the eye through the near plane onto the terrain btVector3 result; bool found = m_terrain.CastToTerrain(eyep, worldp, result);
bool RBTerrain::CastToTerrain(const btVector3 &start, const btVector3 &end, btVector3 &result)
{
btVector3 vec = end - start;
vec *= 1000.0f;
btDiscreteDynamicsWorld *world = RudePhysics::GetInstance()->GetWorld();
btCollisionWorld::ClosestRayResultCallback cb(start, vec);
world->rayTest(start, vec, cb);
if(!cb.hasHit())
// We did not hit the terrain
return false;
// We hit the terrain!
result = cb.m_hitPointWorld;
return true;
}
To turn this into a "picker" just modify the rayTest to return the object that was hit.