I have spent a few hours on this, and I haven’t really came up with a solution.
Say I have a chest with several objects inside, and I want to know if these objects can be interacted by the player. I want it to be easy for the player to interact with several objects in a small radius around the center of the screen, ordering from nearest to the center to furthest. That way I could have a player grab several items without having to directly look at each one. Sorting the objects is no problem since I can just transform all object to screen space and sort them that way.
So far, I’ve filtered potential candidates with the following:
Urho3D::PODVector<Urho3D::Node*> results;
GetScene()->GetChildrenWithComponent<GameItem>(results, true);
for(Urho3D::PODVector<Urho3D::Node*>::Iterator itr = results.Begin(); itr != results.End(); itr++)
{
float distance = (_cameraNode->GetPosition() - (*itr)->GetPosition()).Length();
Urho3D::BoundingBox box = (*itr)->GetComponent<Urho3D::StaticModel>()->GetBoundingBox();
box.Transform((*itr)->GetTransform());
if( Urho3D::INSIDE == camera->GetFrustum().IsInsideFast(box) && distance <= 3.0f)
{
debugRenderer->AddBoundingBox((*itr)->GetComponent<Urho3D::StaticModel>()->GetBoundingBox(), (*itr)->GetTransform(), Urho3D::Color::GREEN, false);
}
}
Any ideas?