Skip to content

Commit 1bf29d3

Browse files
author
Adrien GIVRY
committed
Focusing now consider the bounding sphere of actors
Previously the focus distance was fixed for ModelRenderers. Now it is based on the BoundingSphere of the ModelRenderer. Light focus distance has also been changed to avoid infinite lights to make the user travel to infinite when focused.
1 parent e3249b8 commit 1bf29d3

1 file changed

Lines changed: 9 additions & 28 deletions

File tree

Sources/Overload/OvEditor/src/OvEditor/Core/CameraController.cpp

Lines changed: 9 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ OvEditor::Core::CameraController::CameraController
3535

3636
float GetActorFocusDist(OvCore::ECS::Actor& p_actor)
3737
{
38-
float distance = 5.0f;
38+
float distance = 4.0f;
3939

4040
if (p_actor.IsActive())
4141
{
@@ -80,33 +80,14 @@ float GetActorFocusDist(OvCore::ECS::Actor& p_actor)
8080

8181
if (auto modelRenderer = p_actor.GetComponent<OvCore::ECS::Components::CModelRenderer>())
8282
{
83-
distance = std::max(distance, 10.0f);
84-
}
85-
86-
if (auto ambientBoxLight = p_actor.GetComponent<OvCore::ECS::Components::CAmbientBoxLight>())
87-
{
88-
distance = std::max(distance, std::max
89-
(
90-
std::max
91-
(
92-
ambientBoxLight->GetSize().x,
93-
ambientBoxLight->GetSize().y
94-
),
95-
ambientBoxLight->GetSize().z
96-
) * 1.5f);
97-
}
98-
99-
if (auto ambientSphereLight = p_actor.GetComponent<OvCore::ECS::Components::CAmbientSphereLight>())
100-
{
101-
distance = std::max(distance, std::max
102-
(
103-
std::max
104-
(
105-
ambientSphereLight->GetRadius(),
106-
ambientSphereLight->GetRadius()
107-
),
108-
ambientSphereLight->GetRadius()
109-
) * 1.5f);
83+
const bool hasCustomBoundingSphere = modelRenderer->GetFrustumBehaviour() == OvCore::ECS::Components::CModelRenderer::EFrustumBehaviour::CULL_CUSTOM;
84+
const bool hasModel = modelRenderer->GetModel();
85+
const auto boundingSphere = hasCustomBoundingSphere ? &modelRenderer->GetCustomBoundingSphere() : hasModel ? &modelRenderer->GetModel()->GetBoundingSphere() : nullptr;
86+
const auto& actorPosition = p_actor.transform.GetWorldPosition();
87+
const auto& actorScale = p_actor.transform.GetWorldScale();
88+
const auto scaleFactor = std::max(std::max(actorScale.x, actorScale.y), actorScale.z);
89+
90+
distance = std::max(distance, boundingSphere ? (boundingSphere->radius + OvMaths::FVector3::Length(boundingSphere->position)) * scaleFactor * 2.0f : 10.0f);
11091
}
11192

11293
for (auto child : p_actor.GetChildren())

0 commit comments

Comments
 (0)