Input facade: add cursor capture, mouse delta and scroll delta

SetCursorCaptured / IsCursorCaptured / GetMouseDelta / ConsumeScrollDelta
now route through the Input facade, so the editor camera no longer takes
a Window& at all: Camera::Update and EditorCamera::Update lose their
window parameter and SandboxApp calls Update(dt) directly. App layer
now has zero Window/GLFW usage for input - everything goes through
Engine::Input.
This commit is contained in:
2026-10-05 11:45:57 +08:00
parent 641b255cb2
commit a3037cd401
6 changed files with 69 additions and 24 deletions
+32 -3
View File
@@ -10,11 +10,12 @@ namespace Engine {
namespace {
// Application 生命周期内有效(成员析构序:Input 无状态依赖,
// 仅 Application::Run 期间被查询)
const Window* s_Window = nullptr;
// 仅 Application::Run 期间被查询)。非 const:门面含
// 光标捕获等状态设置,不只查询
Window* s_Window = nullptr;
}
void Init(const Window& window)
void Init(Window& window)
{
s_Window = &window;
}
@@ -31,5 +32,33 @@ namespace Engine {
s_Window->IsMouseButtonPressed(static_cast<int>(button));
}
void SetCursorCaptured(const bool captured)
{
if (s_Window != nullptr)
{
s_Window->SetCursorCaptured(captured);
}
}
bool IsCursorCaptured()
{
return s_Window != nullptr && s_Window->IsCursorCaptured();
}
void GetMouseDelta(f32& dx, f32& dy)
{
if (s_Window != nullptr)
{
s_Window->GetMouseDelta(dx, dy);
return;
}
dx = dy = 0.0f;
}
f32 ConsumeScrollDelta()
{
return s_Window != nullptr ? s_Window->ConsumeScrollDelta() : 0.0f;
}
}
} // namespace Engine
+7 -7
View File
@@ -27,7 +27,7 @@ namespace Engine {
}
}
void Camera::Update(Window& window, ECS::TransformComponent& transform,
void Camera::Update(ECS::TransformComponent& transform,
const f32 deltaTime, const bool flyRequiresRMB)
{
// ---- 输入模式(UE Scene view 语义):RMB=自由视角(鼠标转向
@@ -41,13 +41,13 @@ namespace Engine {
if (wantLook || wantOrbit)
{
if (!window.IsCursorCaptured())
if (!Input::IsCursorCaptured())
{
window.SetCursorCaptured(true);
Input::SetCursorCaptured(true);
}
f32 mouseDX = 0, mouseDY = 0;
window.GetMouseDelta(mouseDX, mouseDY);
Input::GetMouseDelta(mouseDX, mouseDY);
if (mouseDX != 0 || mouseDY != 0)
{
@@ -105,9 +105,9 @@ namespace Engine {
}
}
}
else if (window.IsCursorCaptured())
else if (Input::IsCursorCaptured())
{
window.SetCursorCaptured(false);
Input::SetCursorCaptured(false);
}
// 基向量由(可能已更新的)实体旋转决定(本地 -Z 为视线方向)
@@ -130,7 +130,7 @@ namespace Engine {
// ---- 滚轮推拉:有 pivot 时改环绕距离(指数步进,近处精细/
// 远处大步);无 pivot 时沿视线平移 ----
const f32 wheel = window.ConsumeScrollDelta();
const f32 wheel = Input::ConsumeScrollDelta();
if (m_MouseLookEnabled && wheel != 0.0f)
{
if (m_HasPivot)