mirror of
https://github.com/antopilo/Nuake.git
synced 2026-09-15 20:08:54 +03:00
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:
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user