Skip to content

Commit

Permalink
CameraController Improvement and select entity change
Browse files Browse the repository at this point in the history
  • Loading branch information
VTui22 committed Sep 12, 2023
1 parent 0c49ac5 commit 8d8f316
Showing 1 changed file with 16 additions and 17 deletions.
33 changes: 16 additions & 17 deletions Engine/Source/Editor/UILayers/SceneView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,11 @@ void SceneView::PickSceneMesh(float regionWidth, float regionHeight)
}
}
}

pSceneWorld->SetSelectedEntity(nearestEntity);
//If the ray does not hit the AABB, then selectEntity remains unchanged.
if (nearestEntity != engine::INVALID_ENTITY)
{
pSceneWorld->SetSelectedEntity(nearestEntity);
}
}

void SceneView::Update()
Expand All @@ -332,21 +335,6 @@ void SceneView::Update()
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0.0f, 0.0f));
auto flags = ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse;
ImGui::Begin(GetName(), &m_isEnable, flags);
if (engine::Input::Get().IsMouseLBPressed())
{
ImVec2 windowSize = ImGui::GetWindowSize();
ImVec2 windowPos = ImGui::GetWindowPos();
ImVec2 mousePos = ImGui::GetMousePos();
cd::Vec2f rightDown(windowPos.x + windowSize.x, windowPos.y + windowSize.y);
if (mousePos.x > windowPos.x && mousePos.x < rightDown.x() && mousePos.y > windowPos.y && mousePos.y < rightDown.y() && !m_isTerrainEditMode)
{
m_pCameraController->SetIsInViewScene(true);
}
else
{
m_pCameraController->SetIsInViewScene(false);
}
}
// Draw top menu buttons which include ImGuizmo operation modes, ViewCamera settings.
UpdateToolMenuButtons();

Expand All @@ -366,6 +354,9 @@ void SceneView::Update()
pCameraComponent->SetAspect(static_cast<float>(regionWidth) / static_cast<float>(regionHeight));
}
}
ImVec2 windowPos = ImGui::GetWindowPos();
ImVec2 mousePos = ImGui::GetMousePos();
cd::Vec2f rightDown(windowPos.x + regionSize.x, windowPos.y + regionSize.y);

// Check if mouse hover on the area of SceneView so it can control.
ImVec2 cursorPosition = ImGui::GetCursorPos();
Expand Down Expand Up @@ -399,6 +390,14 @@ void SceneView::Update()

m_isMouseDownFirstTime = false;
PickSceneMesh(regionWidth, regionHeight);
if (mousePos.x > windowPos.x && mousePos.x < rightDown.x() && mousePos.y > windowPos.y && mousePos.y < rightDown.y() && !m_isTerrainEditMode)
{
m_pCameraController->SetIsInViewScene(true);
}
else
{
m_pCameraController->SetIsInViewScene(false);
}
}
else
{
Expand Down

0 comments on commit 8d8f316

Please sign in to comment.