Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CameraController Improvement and select entity change #385

Merged
merged 6 commits into from
Sep 16, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
T-rvw marked this conversation as resolved.
Show resolved Hide resolved
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