Skip to content

Commit

Permalink
Camera point focus (#379)
Browse files Browse the repository at this point in the history
  • Loading branch information
VTui22 authored Sep 8, 2023
1 parent 780fded commit 93fc8a9
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
10 changes: 10 additions & 0 deletions Engine/Source/Editor/UILayers/EntityList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,16 @@ void EntityList::DrawEntity(engine::SceneWorld* pSceneWorld, engine::Entity enti
}
}
}
else
{
if (engine::TransformComponent* pTransform = pSceneWorld->GetTransformComponent(entity))
{
if (m_pCameraController)
{
m_pCameraController->CameraFocus(pTransform->GetTransform().GetTranslation());
}
}
}
}
}

Expand Down
15 changes: 11 additions & 4 deletions Engine/Source/Runtime/Display/CameraController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -365,21 +365,28 @@ void CameraController::CameraFocus(const cd::AABB& aabb)
m_movementSpeed = aabb.Size().Length() * 1.5f;
}

void CameraController::CameraFocus(const cd::Vec3f& position)
{
m_isMoving = true;
m_eyeDestination = position - m_lookAt * m_distanceFromLookAt;
}

void CameraController::Moving()
{
if (m_isMoving)
{
if (cd::Math::IsSmallThan((m_eye - m_eyeDestination).Length(), 0.01f))
{
m_isMoving = false;
return;
}
cd::Direction eyeMove = (m_eye - m_eyeDestination).Normalize();
float stepDistance = (m_eye - m_eyeDestination).Length() / 5.0f;
m_eye = m_eye - eyeMove * stepDistance;

SynchronizeTrackingCamera();
ControllerToCamera();

if (cd::Math::IsSmallThan((m_eye - m_eyeDestination).Length(), 0.01f))
{
m_isMoving = false;
}
}
}

Expand Down
7 changes: 4 additions & 3 deletions Engine/Source/Runtime/Display/CameraController.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class CameraController final

// Double Click entity,camera will focus
void CameraFocus(const cd::AABB& aabb);
void CameraFocus(const cd::Vec3f& position);

// Implement the effect of a translation animation.
void Moving();
Expand Down Expand Up @@ -94,9 +95,9 @@ class CameraController final
float m_mouseScroll = 0.0f;

cd::Vec3f m_lookAtPoint = cd::Vec3f::Zero();
cd::Vec3f m_lookAt;
cd::Vec3f m_up;
cd::Vec3f m_eye;
cd::Vec3f m_lookAt = cd::Vec3f(0.0f, 1.0f, 0.0f);
cd::Vec3f m_up = cd::Vec3f(0.0f, 0.0f, 1.0f);
cd::Vec3f m_eye = cd::Vec3f::Zero();
cd::Vec3f m_eyeDestination; // This is for focusing animation
cd::Vec3f m_lookAtDestination;

Expand Down

0 comments on commit 93fc8a9

Please sign in to comment.