Данный код позволяет получать сущности, находящиеся под курсором мыши. Полезно для разработки системы выбора юнитов в стратегии реального времени. 
 Code
EntityId GetMouseEntityID() 
 { 
  static ray_hit hit; 
  float x, y, xMouse, yMouse, zMouse = 0.0f; 
   
  if(!gEnv->pHardwareMouse || !gEnv->pRenderer || !gEnv->p3DEngine || !gEnv->pSystem  
                    || !gEnv->pEntitySystem || !g_pGame->GetIGameFramework()) 
   return 0; 
   
  IActor *pClientActor = g_pGame->GetIGameFramework()->GetClientActor(); 
   
  if (!pClientActor) 
   return 0; 
   
  gEnv->pHardwareMouse->GetHardwareMouseClientPosition(&x,&y); 
  y = gEnv->pRenderer->GetHeight() - y; 
   
  gEnv->pRenderer->UnProjectFromScreen(x, y, 0.0f,&xMouse,&yMouse,&zMouse); 
   
  static const unsigned int flags = rwi_stop_at_pierceable|rwi_colltype_any; 
   
  float  fRange = gEnv->p3DEngine->GetMaxViewDistance(); 
  Vec3  vCamPos = gEnv->pSystem->GetViewCamera().GetPosition(); 
  Vec3     vDir = (Vec3(xMouse,yMouse,zMouse) - vCamPos).GetNormalizedSafe(); 
   
  IPhysicalEntity *pPhysicalEnt = pClientActor->GetEntity() ? pClientActor->GetEntity()->GetPhysics() : NULL; 
   
  if(!pPhysicalEnt) 
   return 0; 
   
  if (gEnv->pPhysicalWorld &&  
          gEnv->pPhysicalWorld->RayWorldIntersection(vCamPos, vDir * fRange, ent_all, flags, &hit, 1, pPhysicalEnt)) 
  { 
   if (gEnv->p3DEngine->RefineRayHit(&hit, vDir * fRange)) 
   {  
    if (IEntity *pEntity = gEnv->pEntitySystem->GetEntityFromPhysics(hit.pCollider)) 
    { 
     return pEntity->GetId(); 
    } 
   }  
  }  
   
  return 0; 
 }