Added mouse picking for selecting entities

- Added entity id uniform to the gbuffer
- Added entity id to RenderList
- Added selecting when clicking on an entity
This commit is contained in:
Antoine Pilote
2023-07-06 18:50:29 -04:00
parent 3b6eac356b
commit 57bce04d23
6 changed files with 34 additions and 9 deletions

View File

@@ -231,11 +231,29 @@ namespace Nuake {
tc.SetGlobalTransform(transform);
}
}
if (m_IsHoveringViewport && Input::IsMouseButtonPressed(GLFW_MOUSE_BUTTON_1) && !ImGuizmo::IsUsing())
{
const auto windowPosNuake = Vector2(windowPos.x, windowPos.y);
auto& gbuffer = Engine::GetCurrentScene()->mSceneRenderer->GetGBuffer();
auto pixelPos = Input::GetMousePosition() - windowPosNuake;
pixelPos.y = gbuffer.GetSize().y - pixelPos.y; // imgui coords are inverted on the Y axis
gbuffer.Bind();
if (const int result = gbuffer.ReadPixel(3, pixelPos); result >= 0)
{
Selection = EditorSelection(Entity{ (entt::entity)result, Engine::GetCurrentScene().get() });
}
gbuffer.Unbind();
}
}
else
{
ImGui::PopStyleVar();
}
ImGui::End();
}