feat: add firstpersoncontroller
This commit is contained in:
+8
-8
@@ -131,6 +131,12 @@ void App::run()
|
||||
|
||||
imguiPass.handleEvent(event);
|
||||
|
||||
const bool mouseEvent =
|
||||
event.type == SDL_MOUSEBUTTONDOWN ||
|
||||
event.type == SDL_MOUSEBUTTONUP ||
|
||||
event.type == SDL_MOUSEMOTION ||
|
||||
event.type == SDL_MOUSEWHEEL;
|
||||
|
||||
if (event.type == SDL_QUIT)
|
||||
{
|
||||
isRunning = false;
|
||||
@@ -149,19 +155,13 @@ void App::run()
|
||||
}
|
||||
}
|
||||
|
||||
const bool mouseEvent =
|
||||
event.type == SDL_MOUSEBUTTONDOWN ||
|
||||
event.type == SDL_MOUSEBUTTONUP ||
|
||||
event.type == SDL_MOUSEMOTION ||
|
||||
event.type == SDL_MOUSEWHEEL;
|
||||
|
||||
const bool keyboardEvent =
|
||||
event.type == SDL_KEYDOWN ||
|
||||
event.type == SDL_KEYUP ||
|
||||
event.type == SDL_TEXTINPUT;
|
||||
|
||||
const bool capturedByImgui =
|
||||
(mouseEvent && imguiPass.wantsMouse()) ||
|
||||
(mouseEvent && !InputManager::GetInstance().IsMouseCaptured() && imguiPass.wantsMouse()) ||
|
||||
(keyboardEvent && imguiPass.wantsKeyboard());
|
||||
|
||||
if (!capturedByImgui)
|
||||
@@ -176,7 +176,7 @@ void App::run()
|
||||
}
|
||||
}
|
||||
|
||||
if (!isRunning) break;
|
||||
if (!isRunning) break;
|
||||
|
||||
// Consume SDL events before updating the base camera so held and
|
||||
// newly pressed inputs are applied in the same frame.
|
||||
|
||||
@@ -114,7 +114,7 @@ void Camera::SetRotation(const glm::vec2& yawPitchRadians) {
|
||||
SetRotation(yawPitchRadians.x, yawPitchRadians.y);
|
||||
}
|
||||
|
||||
void Camera::SetTarget(const glm::vec3& target) {
|
||||
void Camera::SetTarget(const glm::vec3&) {
|
||||
}
|
||||
|
||||
void Camera::ClearTarget() {
|
||||
|
||||
@@ -124,6 +124,11 @@ void ImguiPass::beginFrame() {
|
||||
|
||||
ImGui_ImplVulkan_NewFrame();
|
||||
ImGui_ImplSDL2_NewFrame();
|
||||
|
||||
if (SDL_GetRelativeMouseMode() == SDL_TRUE) {
|
||||
ImGui::GetIO().MousePos = ImVec2(-FLT_MAX, -FLT_MAX);
|
||||
}
|
||||
|
||||
ImGui::NewFrame();
|
||||
|
||||
frameBegun = true;
|
||||
|
||||
@@ -46,11 +46,11 @@ void InputManager::BeginFrame() {
|
||||
|
||||
m_textInput.clear();
|
||||
|
||||
// Update mouse delta based on last known position
|
||||
m_mouseDX = m_mouseX - m_prevMouseX;
|
||||
m_mouseDY = m_mouseY - m_prevMouseY;
|
||||
m_prevMouseX = m_mouseX;
|
||||
m_prevMouseY = m_mouseY;
|
||||
// Relative mouse accumulators are filled during SDL event processing
|
||||
// and consumed by game code each frame. Reset them here (before events
|
||||
// are processed) so this frame accumulates fresh deltas.
|
||||
m_mouseRelDX = 0;
|
||||
m_mouseRelDY = 0;
|
||||
|
||||
// Clear controller "edge" sets + snapshot axes
|
||||
for (auto& [id, pad]: m_pads) {
|
||||
@@ -60,6 +60,12 @@ void InputManager::BeginFrame() {
|
||||
}
|
||||
}
|
||||
|
||||
void InputManager::SetMouseCaptured(bool captured) {
|
||||
if (captured == m_MouseCaptured) return;
|
||||
m_MouseCaptured = captured;
|
||||
SDL_SetRelativeMouseMode(captured ? SDL_TRUE : SDL_FALSE);
|
||||
}
|
||||
|
||||
void InputManager::AddController(int deviceIndex) {
|
||||
if (!SDL_IsGameController(deviceIndex)) return;
|
||||
|
||||
@@ -134,6 +140,8 @@ bool InputManager::ProcessEvent(const SDL_Event& e) {
|
||||
case SDL_MOUSEMOTION: {
|
||||
m_mouseX = e.motion.x;
|
||||
m_mouseY = e.motion.y;
|
||||
m_mouseRelDX += e.motion.xrel;
|
||||
m_mouseRelDY += e.motion.yrel;
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user