rpcs3/rpcs3/Input/mouse_gyro_handler.h
Windsurf7 588cf69dad
Some checks are pending
Generate Translation Template / Generate Translation Template (push) Waiting to run
Build RPCS3 / RPCS3 Linux ${{ matrix.os }} ${{ matrix.compiler }} (/rpcs3/.ci/build-linux-aarch64.sh, gcc, rpcs3/rpcs3-ci-jammy-aarch64:1.7, ubuntu-24.04-arm) (push) Waiting to run
Build RPCS3 / RPCS3 Linux ${{ matrix.os }} ${{ matrix.compiler }} (/rpcs3/.ci/build-linux.sh, gcc, rpcs3/rpcs3-ci-jammy:1.7, ubuntu-24.04) (push) Waiting to run
Build RPCS3 / RPCS3 Linux ${{ matrix.os }} ${{ matrix.compiler }} (a1d35836e8d45bfc6f63c26f0a3e5d46ef622fe1, rpcs3/rpcs3-binaries-linux-arm64, /rpcs3/.ci/build-linux-aarch64.sh, clang, rpcs3/rpcs3-ci-jammy-aarch64:1.7, ubuntu-24.04-arm) (push) Waiting to run
Build RPCS3 / RPCS3 Linux ${{ matrix.os }} ${{ matrix.compiler }} (d812f1254a1157c80fd402f94446310560f54e5f, rpcs3/rpcs3-binaries-linux, /rpcs3/.ci/build-linux.sh, clang, rpcs3/rpcs3-ci-jammy:1.7, ubuntu-24.04) (push) Waiting to run
Build RPCS3 / RPCS3 Mac ${{ matrix.name }} (0, 51ae32f468089a8169aaf1567de355ff4a3e0842, rpcs3/rpcs3-binaries-mac, Intel) (push) Waiting to run
Build RPCS3 / RPCS3 Mac ${{ matrix.name }} (1, 8e21bdbc40711a3fccd18fbf17b742348b0f4281, rpcs3/rpcs3-binaries-mac-arm64, Apple Silicon) (push) Waiting to run
Build RPCS3 / RPCS3 Windows (push) Waiting to run
Build RPCS3 / RPCS3 Windows Clang ${{ matrix.arch }} (aarch64, clang, clangarm64, ARM64, windows-11-arm) (push) Waiting to run
Build RPCS3 / RPCS3 Windows Clang ${{ matrix.arch }} (x86_64, clang, clang64, X64, windows-2025) (push) Waiting to run
Build RPCS3 / RPCS3 FreeBSD (push) Waiting to run
Add mouse-based gyro emulation (#18113)
This change adds a hardcoded mouse-based motion sensor emulation
feature, inspired by how Cemu handles mouse-driven gyro input.

While the game window is focused, holding the right mouse button enables
gyro emulation:
- Mouse X movement feeds Motion X
- Mouse Y movement feeds Motion Z
- Mouse Wheel feeds Motion Y

The axis mapping and behavior were tested with the "Spark Runner"
minigame in _Sly Cooper: Thieves in Time_ and _Bentley's Hackpack_.
In accordance with this minigame, a top-down view motion control scheme
relies on the X/Z axes.

While the right mouse button is being held, mouse deltas are captured
via the Qt native event filter and accumulated in the frontend, then
consumed by the pad thread.
On right mouse button release, motion values are reset to the neutral
center to avoid residual drift.

This input path is intentionally independent of pad configuration and
works even when a keyboard-only profile is selected.

This implementation thus resolves issue #13883 by allowing motion-only
gameplay without requiring a physical motion-capable controller.
2026-02-02 09:21:02 +01:00

34 lines
1 KiB
C++

#pragma once
#include "util/types.hpp"
#include "util/atomic.hpp"
#include "Emu/Io/pad_types.h"
class QEvent;
class QWindow;
// Mouse-based motion sensor emulation state.
class mouse_gyro_handler
{
private:
atomic_t<bool> enabled = false; // Whether mouse-based gyro emulation mode has been enabled by using the associated hotkey
atomic_t<bool> active = false; // Whether right mouse button is currently held (gyro active)
atomic_t<bool> reset = false; // One-shot reset request on right mouse button release
atomic_t<s32> gyro_x = DEFAULT_MOTION_X; // Accumulated from mouse X position relative to center
atomic_t<s32> gyro_y = DEFAULT_MOTION_Y; // Accumulated from mouse wheel delta
atomic_t<s32> gyro_z = DEFAULT_MOTION_Z; // Accumulated from mouse Y position relative to center
void set_gyro_active();
void set_gyro_reset();
void set_gyro_xz(s32 off_x, s32 off_y);
void set_gyro_y(s32 steps);
public:
void clear();
bool toggle_enabled();
void handle_event(QEvent* ev, const QWindow& win);
void apply_gyro(const std::shared_ptr<Pad>& pad);
};