Skip to content

fix(view): Improve setup of default camera pitch and angle#2546

Merged
xezon merged 8 commits intoTheSuperHackers:mainfrom
xezon:xezon/fix-camera-pitch-angle
Apr 13, 2026
Merged

fix(view): Improve setup of default camera pitch and angle#2546
xezon merged 8 commits intoTheSuperHackers:mainfrom
xezon:xezon/fix-camera-pitch-angle

Conversation

@xezon
Copy link
Copy Markdown

@xezon xezon commented Apr 7, 2026

This change decouples the default camera pitch and angle from the camera origin point. The default pitch can be changed with a debug key mapping.

Previously, the user pitch started at 0 which actually refers to a real pitch of 37.5 because that is what TheGlobalData->m_cameraPitch is set to.

TODO

  • Replicate in Generals

@xezon xezon added this to the Camera Improvements milestone Apr 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 Apr 7, 2026
// TheSuperHackers @tweak To preserve the original scripted camera values, offset them by default ones.
constexpr const Real DefaultPitch = DEG_TO_RADF(37.5f);
constexpr const Real DefaultAngle = DEG_TO_RADF(0.0f);
pitch = -pitch + DefaultPitch;
Copy link
Copy Markdown
Author

@xezon xezon Apr 7, 2026

Choose a reason for hiding this comment

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

-pitch because we changed the axis direction of pitch in a earlier change.

I did not get to test this function however, because I did not find a cutscene where this is called.

@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented Apr 7, 2026

Greptile Summary

This PR decouples the default camera pitch/angle from the camera origin point in the buildCameraPosition calculation. Previously, m_defaultPitch started at 0 and the origin was computed using TheGlobalData->m_cameraPitch at runtime; now the origin is fixed at the compile-time constants ViewDefaultPitchRadians/ViewDefaultYawRadians, and the live pitch is offset relative to them. A new debug key mapping (Ctrl+,) and setDefaultPitch API are added to allow runtime adjustment. The three previously-flagged blocking issues (duplicate constant, undefined identifiers, wrong constant for angle offset) all appear resolved in the current HEAD.

Confidence Score: 5/5

Safe to merge; all previously-flagged P0/P1 issues are resolved and the only remaining finding is a P2 clarity concern.

The three prior blocking issues (duplicate constant, undefined identifiers, wrong constant for angle offset) are all addressed in the current HEAD. The one new finding — the ignored angle parameter in setDefaultView — is a pre-existing design decision and does not introduce any new runtime defect. All remaining findings are P2 or lower.

Generals/Code/GameEngine/Source/GameClient/InGameUI.cpp and its GeneralsMD mirror — the angle argument passed to setDefaultView is silently ignored.

Important Files Changed

Filename Overview
Core/GameEngine/Include/GameClient/View.h Adds ViewDefaultPitchRadians/ViewDefaultYawRadians constants and setDefaultPitch/getDefaultPitch/getDefaultAngle/userSetDefaultPitch API; single clean definition, no duplicate.
Core/GameEngine/Source/GameClient/View.cpp Initialises default angle/pitch from GlobalData and copies to active angle/pitch; adds setDefaultPitch with CLAMP_VIEW_PITCH guard; dead assignment m_angle = 0.0f at line 95 is immediately overwritten at line 107.
Core/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cpp Replaces runtime GlobalData lookups in buildCameraPosition with compile-time constants; subtracts default from live pitch/angle in rotation matrices; adds W3DView::setDefaultPitch override; setDefaultView routes through setDefaultPitch properly.
Generals/Code/GameEngine/Source/GameClient/InGameUI.cpp Passes GlobalData pitch/yaw to setDefaultView; the angle argument is silently dropped inside W3DView::setDefaultView (commented-out assignment), so the yaw value has no runtime effect.
GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp Same change as Generals counterpart; angle parameter to setDefaultView is silently ignored in W3DView::setDefaultView.
Generals/Code/GameEngine/Source/GameLogic/ScriptEngine/ScriptActions.cpp Adds PRESERVE_RETAIL_SCRIPTED_CAMERA offset block; pitch correctly uses pitch constant and angle correctly uses yaw constant (0), so no axis cross-contamination.
Generals/Code/GameEngine/Source/GameClient/MessageStream/LookAtXlat.cpp Adds m_isPitchingToDefault state and debug block to adjust default pitch with mouse drag; consistently initialised and reset.

Sequence Diagram

sequenceDiagram
    participant Init as InGameUI::init/reset
    participant WV as W3DView::setDefaultView
    participant V as View::setDefaultPitch
    participant BCP as W3DView::buildCameraPosition

    Init->>WV: setDefaultView(DEG_TO_RADF(cameraPitch), DEG_TO_RADF(cameraYaw), 1.0f)
    note over WV: angle param is ignored (commented-out assignment)
    WV->>V: setDefaultPitch(pitch)
    V-->>V: clamp(0.1deg, pitch, 89.9deg) → m_defaultPitch
    WV-->>WV: m_cameraAreaConstraintsValid=false, m_recalcCamera=true

    note over BCP: Per-frame camera rebuild
    BCP->>BCP: sourcePos set using ViewDefaultPitchRadians constant (37.5deg)
    BCP->>BCP: pitchTransform = pitch - ViewDefaultPitchRadians
    BCP->>BCP: angleTransform = angle - ViewDefaultYawRadians (0deg, no-op)
    BCP->>BCP: Rotate sourcePos by pitch then angle transforms
Loading
Prompt To Fix All With AI
This is a comment left during a code review.
Path: Generals/Code/GameEngine/Source/GameClient/InGameUI.cpp
Line: 1346-1350

Comment:
**`angle` argument to `setDefaultView` is silently ignored**

`W3DView::setDefaultView` accepts a `pitch`, `angle`, and `maxHeight` parameter, but the `angle` assignment (`m_defaultAngle = ...`) has been commented out since the original EA code ("MDC - we no longer want to rotate maps"). As a result, the `DEG_TO_RADF(TheGlobalData->m_cameraYaw)` value computed here has no runtime effect — `m_defaultAngle` is only ever written in `View::init()`. The same applies to the mirror call in `reset()` and the identical change in `GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp`.

If restoring the default yaw on `init`/`reset` is intentional, `W3DView::setDefaultView` needs a corresponding `setDefaultAngle` path. If it is not needed, passing a literal `0.0f` (as before) would avoid implying that the yaw is being set.

How can I resolve this? If you propose a fix, please make it concise.

Reviews (8): Last reviewed commit: "Replicate in Generals" | Re-trigger Greptile

Comment thread Core/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cpp Outdated
Comment thread Core/GameEngine/Source/GameClient/View.cpp
Comment thread GeneralsMD/Code/GameEngine/Source/Common/MessageStream.cpp
Comment thread GeneralsMD/Code/GameEngine/Include/GameClient/LookAtXlat.h Outdated
Comment thread GeneralsMD/Code/GameEngine/Include/GameClient/LookAtXlat.h Outdated
Comment thread GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp
Comment thread GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp
Comment thread GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/LookAtXlat.cpp Outdated
Comment thread GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/LookAtXlat.cpp Outdated
Comment thread Core/GameEngine/Source/GameClient/View.cpp
Comment thread Core/GameEngine/Include/GameClient/View.h Outdated
Comment thread Core/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cpp Outdated
Comment thread GeneralsMD/Code/GameEngine/Source/GameLogic/ScriptEngine/ScriptActions.cpp Outdated
Comment thread Core/GameEngine/Source/GameClient/View.cpp Outdated
Comment thread Core/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cpp Outdated
@xezon xezon force-pushed the xezon/fix-camera-pitch-angle branch from 6b73359 to 2d1e47c Compare April 12, 2026 14:36
@xezon
Copy link
Copy Markdown
Author

xezon commented Apr 12, 2026

Rebased

Copy link
Copy Markdown

@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
Copy link
Copy Markdown
Author

xezon commented Apr 13, 2026

Replicated in Generals without conflicts

@Skyaero42
Copy link
Copy Markdown

Good to go!

@xezon xezon changed the title fix(view): Change setup of default camera pitch and angle fix(view): Improve setup of default camera pitch and angle Apr 13, 2026
@xezon xezon merged commit a1d7325 into TheSuperHackers:main Apr 13, 2026
17 checks passed
@xezon xezon deleted the xezon/fix-camera-pitch-angle branch April 13, 2026 20:16
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.

3 participants