Initial implementation of gyro aim

This commit is contained in:
Irastris
2026-04-12 01:15:52 -04:00
parent d481a23c49
commit b5bb6bf53a
11 changed files with 241 additions and 8 deletions
+31 -1
View File
@@ -5,6 +5,8 @@
#include "ImGuiConsole.hpp"
#include "ImGuiMenuGame.hpp"
#include <SDL3/SDL.h>
namespace dusk {
void ImGuiMenuGame::windowInputViewer() {
if (!m_showInputViewer) {
@@ -258,9 +260,37 @@ namespace dusk {
size.y = 130 * scale;
ImGui::Dummy(size);
SDL_Gamepad* pad = SDL_GetGamepadFromPlayerIndex(0);
if (pad != nullptr && SDL_GamepadHasSensor(pad, SDL_SENSOR_GYRO)) {
ImGui::Separator();
ImGui::TextUnformatted("Gyro");
constexpr float kBarScale = 4.0f;
auto bar = [kBarScale](const char* label, float v) {
const float a = std::fabs(v);
const float t = std::min(1.f, a / kBarScale);
char overlay[32];
snprintf(overlay, sizeof(overlay), "%s %+.3f", label, v);
ImGui::ProgressBar(t, ImVec2(-1, 0), overlay);
};
if (SDL_SetGamepadSensorEnabled(pad, SDL_SENSOR_GYRO, true)) {
float gyro[3];
if (SDL_GetGamepadSensorData(pad, SDL_SENSOR_GYRO, gyro, 3)) {
bar("X", gyro[0]);
bar("Y", gyro[1]);
bar("Z", gyro[2]);
}
} else {
bar("X", 0.f);
bar("Y", 0.f);
bar("Z", 0.f);
}
}
ShowCornerContextMenu(m_inputOverlayCorner, 0);
}
ImGui::End();
}
} // namespace dusk
} // namespace dusk