Hey,
What’s the best way to use the cameras frustum to check the visibility of a set of actors? Or points etc?
Been looking around but not finding anything that useful.
Thanks
Hey,
What’s the best way to use the cameras frustum to check the visibility of a set of actors? Or points etc?
Been looking around but not finding anything that useful.
Thanks
Shameless bump!
Sorry for being so obvious, but you might try tracing from each actor position to your POV (camera position), then checking if the trace was unsuccessful (nothing occludes the visibility) and it lays within the frustum cone. This is an ugly hack, I might guess, but I am not familiar with Unreal’s graphical pipeline.
If you stick to Tracing, Rama has this covered in a tutorial: https://wiki.unrealengine.com/Trace_Functions
Thanks for the info, the trace approach is an option, but all I really care about is whether or not the actors bounds are inside, intersecting or outside of the six planes of the frustum, so even if there is something in the way I’d like to know the result of that check.
You’d need to do at least two traces per actor as well since I’d need to trace to the min/max of their bounding box.
Is there anyway to actually get the planes of the camera frustum? Can just do a simple point plane check.
Will take another look when I can.
Haven’t tried it yet, but I am guessing these functions are what I want:
Will check it out, but think that’ll do it, cheers.
You can do it like this:
bool IsInFrustum( AActor* Actor)
{
ULocalPlayer* LocalPlayer = GetWorld()->GetFirstLocalPlayerFromController();
if (LocalPlayer != nullptr && LocalPlayer->ViewportClient != nullptr && LocalPlayer->ViewportClient->Viewport)
{
FSceneViewFamilyContext ViewFamily(FSceneViewFamily::ConstructionValues(
LocalPlayer->ViewportClient->Viewport,
GetWorld()->Scene,
LocalPlayer->ViewportClient->EngineShowFlags)
.SetRealtimeUpdate(true));
FVector ViewLocation;
FRotator ViewRotation;
FSceneView* SceneView = LocalPlayer->CalcSceneView(&ViewFamily, ViewLocation, ViewRotation, LocalPlayer->ViewportClient->Viewport);
if (SceneView != nullptr)
{
return SceneView->ViewFrustum.IntersectSphere(
Actor->GetActorLocation(), Actor->GetSimpleCollisionRadius());
}
}
return false
}
works perfectly
Amazing. This worked perfectly
double plus upvote
I’d love to see a Blueprint solution of the code above if anyone is up to it…
What setup/includes are needed for this to work? VS flags LocalPlayer as an incomplete class type (which I think is due to a missing include), among other errors
Sir, could you give me a blueprint’s version about this method?
Rellay need this one now
For future people.
This checks if a point is within a camera’s frustum using only blueprints.
Here is an example of it stacked within a system to choose the most optimal cctv camera.