Skip to content

fix(lookat): Fix mouse anchor and direction issue for camera pitch#2421

Merged
xezon merged 1 commit intoTheSuperHackers:mainfrom
xezon:xezon/fix-camera-pitch-input
Mar 8, 2026
Merged

fix(lookat): Fix mouse anchor and direction issue for camera pitch#2421
xezon merged 1 commit intoTheSuperHackers:mainfrom
xezon:xezon/fix-camera-pitch-input

Conversation

@xezon
Copy link

@xezon xezon commented Mar 7, 2026

This change fixes the mouse anchor and direction issue for the camera pitch.

The camera can be pitched in Debug with the Comma key.

@xezon xezon added this to the Camera Improvements milestone Mar 7, 2026
@xezon xezon added Minor Severity: Minor < Major < Critical < Blocker Gen Relates to Generals ZH Relates to Zero Hour Fix Is fixing something, but is not user facing labels Mar 7, 2026
@greptile-apps
Copy link

greptile-apps bot commented Mar 7, 2026

Greptile Summary

This PR fixes three related bugs in the debug camera pitch feature (activated via the Comma key), ensuring the mouse anchor is properly initialized, the pitch direction matches mouse movement, and the rotation axis in 3D space is correct.

Changes:

  • LookAtXlat.cpp: Initializes m_anchor = m_currentPos when MSG_META_DEMO_BEGIN_ADJUST_PITCH is received, preventing a stale anchor from causing a sudden pitch jump on the first mouse movement.
  • LookAtXlat.cpp: Negates the pitch delta (- angle instead of + angle) so that dragging the mouse in a given direction produces the expected camera pitch response.
  • W3DView.cpp: Corrects the pitch rotation axis from the right vector (1, 0, 0) to the left vector (-1, 0, 0) and updates the comment accordingly, fixing the 3D rotation direction.
  • LookAtXlat.cpp: Adds disp = DESTROY_MESSAGE to MSG_META_DEMO_BEGIN_ADJUST_FOV and MSG_META_DEMO_END_ADJUST_FOV, matching the existing pattern for the pitch equivalents and preventing key events from leaking to subsequent handlers.

Confidence Score: 5/5

  • This PR is safe to merge — all changes are small, well-scoped debug-mode fixes with no production-path risk.
  • All four changes are minimal, targeted, and logically consistent. The anchor initialization prevents a stale-anchor jump, the sign flip and axis flip are complementary corrections that together restore expected pitch behaviour, and the DESTROY_MESSAGE additions for FOV messages follow the established pattern already used for pitch messages. No new APIs, no structural changes, and the affected code paths are guarded by RTS_DEBUG.
  • No files require special attention.

Sequence Diagram

sequenceDiagram
    participant User
    participant LookAtXlat
    participant TacticalView
    participant W3DView

    User->>LookAtXlat: MSG_META_DEMO_BEGIN_ADJUST_PITCH (Comma key)
    Note over LookAtXlat: m_isPitching = true<br/>m_anchor = m_currentPos ✅ (new fix)
    LookAtXlat-->>User: DESTROY_MESSAGE

    User->>LookAtXlat: MSG_RAW_MOUSE_MOVE (drag)
    Note over LookAtXlat: angle = Scale * (currentPos.y - anchor.y)<br/>pitch -= angle ✅ (direction fixed)
    LookAtXlat->>TacticalView: userSetPitch(getPitch() - angle)
    LookAtXlat->>LookAtXlat: m_anchor = currentPos

    TacticalView->>W3DView: buildCameraPosition(pitch)
    Note over W3DView: pitchTransform = Matrix3D((-1,0,0), pitch) ✅ (axis fixed)
    W3DView-->>TacticalView: updated sourcePos/targetPos

    User->>LookAtXlat: MSG_META_DEMO_END_ADJUST_PITCH (Comma key release)
    Note over LookAtXlat: m_isPitching = false
    LookAtXlat-->>User: DESTROY_MESSAGE
Loading

Last reviewed commit: e69dfce

Copy link

@Skyaero42 Skyaero42 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good

@xezon xezon merged commit a19d38f into TheSuperHackers:main Mar 8, 2026
24 checks passed
@xezon xezon deleted the xezon/fix-camera-pitch-input branch March 8, 2026 20:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Fix Is fixing something, but is not user facing Gen Relates to Generals Minor Severity: Minor < Major < Critical < Blocker ZH Relates to Zero Hour

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants