fix(view): Improve setup of default camera pitch and angle#2546
fix(view): Improve setup of default camera pitch and angle#2546xezon merged 8 commits intoTheSuperHackers:mainfrom
Conversation
| // 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; |
There was a problem hiding this comment.
-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.
|
| 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
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
6b73359 to
2d1e47c
Compare
|
Rebased |
|
Replicated in Generals without conflicts |
|
Good to go! |
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_cameraPitchis set to.TODO