Skip to content

fix(view): Introduce PRESERVE_RETAIL_SCRIPTED_CAMERA and fix or improve camera offset and zoom calculations#2524

Merged
xezon merged 3 commits intoTheSuperHackers:mainfrom
xezon:xezon/fix-camera-offset
Apr 7, 2026
Merged

fix(view): Introduce PRESERVE_RETAIL_SCRIPTED_CAMERA and fix or improve camera offset and zoom calculations#2524
xezon merged 3 commits intoTheSuperHackers:mainfrom
xezon:xezon/fix-camera-offset

Conversation

@xezon
Copy link
Copy Markdown

@xezon xezon commented Apr 2, 2026

This change is quite a bit complicated.

PRESERVE_RETAIL_SCRIPTED_CAMERA

Introduces a new PRESERVE_RETAIL_SCRIPTED_CAMERA preprocessor macro to preserve the original look of the scripted camera. Most importantly the initial ground level is cached and used during scripted camera movements.

Camera Offset

The camera offset is now freshly calculated inside W3DView::buildCameraPosition, instead of various other locations, to make sure that it is always correctly built when the camera pitch or angle changes.

Camera Zoom

The camera zoom was changed from originally

initialGroundLevel + TheGlobalData->m_cameraHeight

to

currentGroundLevel + TheGlobalData->m_maxCameraHeight

This effectively means that the camera zoom range is now 0 to 1. Originally it was 0 to N, where N would generally be 1.33 or higher. This was confusing. The new setup gives a much better expectation for what a zoom value represents. 0.5 now means half way zoomed from max possible height to ground.

Known issues

  • Viewing Bookmark position twice over elevation change looks buggy
  • Replay Camera looks buggy on elevation changes
  • Replay Camera zoom from legacy Single Player replays will no longer represent the height correctly (will not be fixed because it is too complicated to maintain this level of backwards compatibility)

TODO

  • Replicate in Generals

@xezon xezon added this to the Camera Improvements milestone Apr 2, 2026
@xezon xezon added Enhancement Is new feature or request Major 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 2, 2026
@greptile-apps
Copy link
Copy Markdown

greptile-apps bot commented Apr 2, 2026

Greptile Summary

This PR introduces PRESERVE_RETAIL_SCRIPTED_CAMERA, a new preprocessor macro to preserve the original scripted camera behavior (using the initial ground level), and refactors camera offset/zoom calculations into dedicated helper methods (getCameraOffsetZ, getDesiredHeight, getDesiredZoom, getMaxHeight, getMaxZoom) that consolidate previously scattered logic in buildCameraPosition. The zoom range is now normalized to [0, 1] relative to m_maxCameraHeight rather than the old m_cameraHeight-based range.

Confidence Score: 5/5

Safe to merge; changes are well-scoped behind a compile-time macro with only a P2 style finding.

All findings are P2 (stale year in comment dates). No logic bugs, missing guards, or correctness issues were found. The refactoring correctly consolidates camera offset math and the PRESERVE_RETAIL_SCRIPTED_CAMERA path is consistently guarded.

No files require special attention.

Important Files Changed

Filename Overview
Core/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cpp Core camera logic refactored: offset calc moved into buildCameraPosition, five new helper methods added, m_cameraOffset member removed; contains P2 stale-year comment dates.
Core/GameEngineDevice/Include/W3DDevice/GameClient/W3DView.h Removes m_cameraOffset member, adds m_initialGroundLevel under PRESERVE_RETAIL_SCRIPTED_CAMERA guard, and declares five new private helper methods.
Core/GameEngine/Include/Common/GameDefines.h Adds PRESERVE_RETAIL_SCRIPTED_CAMERA macro definition, consistent with existing PRESERVE_RETAIL_BEHAVIOR pattern.
Generals/Code/GameEngine/Include/Common/GlobalData.h Guards m_cameraHeight member with PRESERVE_RETAIL_SCRIPTED_CAMERA; no other changes.
Generals/Code/GameEngine/Source/Common/GlobalData.cpp Guards CameraHeight INI parse entry and default initializer with PRESERVE_RETAIL_SCRIPTED_CAMERA.
GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h Same m_cameraHeight guard as the Generals counterpart, applied to Zero Hour GlobalData.
GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp Same CameraHeight INI guard as the Generals counterpart, applied to Zero Hour GlobalData.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[buildCameraPosition] --> B[getCameraOffsetZ]
    B --> C{m_isUserControlled?}
    C -- No / PRESERVE_RETAIL --> D[m_initialGroundLevel + m_cameraHeight]
    C -- Yes --> E[m_groundLevel + m_maxCameraHeight]
    A --> F[Apply zoom / FOV]
    G[setZoom] --> H[getDesiredZoom]
    H --> I[getDesiredHeight / getCameraOffsetZ]
    J[setZoomToDefault] --> K[getMaxZoom]
    K --> L[getMaxHeight / getCameraOffsetZ]
    M[initHeightForMap] --> N[Store m_initialGroundLevel]

Loading
Prompt To Fix All With AI
This is a comment left during a code review.
Path: Core/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cpp
Line: 649

Comment:
**Stale dates in new comments**

The newly added comment in `getCameraOffsetZ()` references `04/12/2025` and the comment in `getDesiredHeight()` (line 666) references `06/12/2025`. Both are from 2025, prior to the current year (2026). Please update these to 2026.

**Rule Used:** What: Flag newly created code comments that refere... ([source](https://app.greptile.com/review/custom-context?memory=fd72a556-4fd8-4db4-8b08-8e51516a64ad))

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

Reviews (3): Last reviewed commit: "Fix zoom setup mistakes" | Re-trigger Greptile

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.

This looks good

@xezon xezon force-pushed the xezon/fix-camera-offset branch from 4e40bc8 to 0ac21f0 Compare April 6, 2026 18:33
@xezon
Copy link
Copy Markdown
Author

xezon commented Apr 6, 2026

Replicated in Generals without conflicts.

@xezon xezon merged commit 476a57c into TheSuperHackers:main Apr 7, 2026
23 checks passed
@xezon xezon deleted the xezon/fix-camera-offset branch April 7, 2026 16:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Enhancement Is new feature or request Fix Is fixing something, but is not user facing Gen Relates to Generals Major 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