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
+21 -2
View File
@@ -17,6 +17,8 @@
#include <glm/glm.hpp>
#include "Engine/Core/Types.h"
namespace Engine {
class Window;
@@ -78,12 +80,29 @@ namespace Engine {
Middle = 2,
};
// 装配:Application 构造时自动调用(后端 Window 就绪后)
void Init(const Window& window);
// 装配:Application 构造时自动调用(后端 Window 就绪后)。
// 非 const:门面含状态设置(光标捕获),不只是查询
void Init(Window& window);
// 轮询查询(UI 捕获对应输入时返回 false——游戏侧静默)
bool IsKeyDown(Key key);
bool IsMouseButtonDown(MouseButton button);
// ---- 光标捕获(自由视角三件套:隐藏光标 + 无界鼠标增量 +
// 滚轮增量)。语义沿 Window 后端:捕获时光标隐藏、位置锁定
// 窗口中心,GetMouseDelta 出无界增量;重复设置同值无操作 ----
// 隐藏并锁定光标(自由视角/环绕中);false 恢复正常光标
void SetCursorCaptured(bool captured);
bool IsCursorCaptured();
// 帧间光标增量(无界,捕获态下才有意义;窗口尺寸/模式变化
// 由后端参考点重置防跳变)
void GetMouseDelta(f32& dx, f32& dy);
// 滚轮增量(上行 = +1,一档 ≈1):读后清零。UI 捕获鼠标
//(面板悬停)时不累积——滚轮归 ImGui
f32 ConsumeScrollDelta();
}
} // namespace Engine
+5 -5
View File
@@ -26,15 +26,15 @@
namespace Engine {
class Window;
namespace ECS { struct TransformComponent; }
class Camera {
public:
// 输入驱动。flyRequiresRMB=true(编辑器模式):移动键仅在 RMB
// 按住时生效——解决与 Gizmo W/E/R 工具热键的键位冲突(UE 语义:
// 飞行时键盘归相机)。全部写回传入的 transform
void Update(Window& window, ECS::TransformComponent& transform,
// 输入驱动(键鼠查询统一走 Input 门面,零 Window 依赖)。
// flyRequiresRMB=true(编辑器模式):移动键仅在 RMB 按住时生效
// ——解决与 Gizmo W/E/R 工具热键的键位冲突(UE 语义:飞行时
// 键盘归相机)。全部写回传入的 transform
void Update(ECS::TransformComponent& transform,
f32 deltaTime, bool flyRequiresRMB = false);
// 焦点选中(UE frame-selection):pivot 设为 point,相机沿当前
@@ -22,8 +22,6 @@
namespace Engine {
class Window;
class EditorCamera {
public:
EditorCamera()
@@ -38,10 +36,10 @@ namespace Engine {
// 每帧输入驱动(编辑器形态由 Application 调用;游戏形态不调
// 即静止)。flyRequiresRMB 恒 true:编辑器移动键只在 RMB 按住
// 时生效(W/E/R 归 Gizmo,UE 语义)。暂停(timeScale=0)时
// 仍可飞行——调用方传 unscaled dt
void Update(Window& window, f32 deltaTime)
// 仍可飞行——调用方传 unscaled dt。键鼠/光标捕获统一走 Input
void Update(f32 deltaTime)
{
m_Controller.Update(window, m_Transform, deltaTime,
m_Controller.Update(m_Transform, deltaTime,
/*flyRequiresRMB=*/true);
m_Transform.Compose(); // World() 是渲染/Gizmo 读源,随写随算
}