RobLoach / RobLoach/raylib-libretro
Fix Rotation with Pointer and Lightgun Devices
Nobody has claimed this yet.
- Dominant language
- C
- Stars
- 38
- Forks
- 8
- PR merge metrics
- No merged PRs in 30d
Description
The rotation applied at draw time — DrawLibretroTint (and DrawLibretroPro/DrawLibretroEx) rotate the framebuffer texture on screen via DrawTexturePro. But the input side, LibretroInputState, maps the mouse straight from raw screen coordinates into the core's native (unrotated) coordinate space:
RETRO_DEVICE_POINTER (2260-2262) — GetMouseX()/GetScreenWidth() → [-1, 1]
RETRO_DEVICE_LIGHTGUN screen X/Y (2194-2197) — same
The core thinks in its own framebuffer space. Once you visually rotate the display, screen-space no longer lines up with core-space, so a pointer/lightgun tap lands in the wrong place. To be correct, the screen→core transform needs to invert the display rotation:
0°: (cx, cy) = ( sx, sy)
90° CW: (cx, cy) = ( sy, -sx)
180°: (cx, cy) = (-sx, -sy)
270° CW: (cx, cy) = (-sy, sx)
For the relative mouse (RETRO_DEVICE_ID_MOUSE_X/Y and lightgun X/Y deltas at 2172-2175), the deltas should strictly also be rotated, but it matters far less — relative motion is rarely used with display rotation, and most cores don't expect it.
Two caveats worth noting, since they compound the pointer problem:
The mapping already uses full screen width/height, not the actual letterboxed destination rect that DrawLibretroTint computes (visW/visH). So absolute pointing is already off whenever there are letterbox bars — rotation just makes it more visibly wrong (and 90/270 swaps which axis the bars are on).
A fully correct fix would map mouse → dest-rect → un-rotate → normalize, which means the input code needs access to the same dest-rect/rotation math DrawLibretroTint does.
Fix it.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in raylib-libretro.h at LibretroInputState and the RETRO_DEVICE_POINTER/lightgun mappings around lines 2087, 2172-2197, then compare them with DrawLibretroTint and its visW/visH destination-rect calculation around lines 2986-3009. Trace the existing rotation and letterboxing math first; done means absolute pointer and lightgun coordinates align across all four rotations and letterboxed displays.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c
- Domain
- computer-graphics, game-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100