bugfix(view): Fix and improve camera area constraints and camera pivoting#2480
bugfix(view): Fix and improve camera area constraints and camera pivoting#2480xezon wants to merge 2 commits intoTheSuperHackers:mainfrom
Conversation
|
| Filename | Overview |
|---|---|
| Core/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cpp | Core of the PR: refactors camera area constraints and pivot tracking into dedicated methods; has a stale date comment (2025) and a duplicate //--- separator. |
| Core/Libraries/Source/WWVegas/WWMath/wwmath.h | Adds Inverse_Lerp (float and double overloads); lacks a division-by-zero guard for the a == b case. |
| Core/Libraries/Include/Lib/BaseType.h | Adds zero() helpers and isInRegion() to several structs; renames Region3D::isInRegionWithZ to isInRegion with no remaining callers of the old name. |
| Core/GameEngineDevice/Include/W3DDevice/GameClient/W3DView.h | Declares resetPivotToGround() override, new private helpers, and m_recalcCameraConstraintsAfterScrolling. |
| Core/GameEngine/Include/GameClient/View.h | Adds resetPivotToGround() virtual method and userResetPivotToGround() user-action wrapper to the base View interface. |
Prompt To Fix All With AI
This is a comment left during a code review.
Path: Core/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cpp
Line: 1419
Comment:
**Date in comment references prior year (2025)**
The inline date `26/10/2025` in this annotation is from 2025, which is prior to the current year (2026). Per project convention, code comments should not reference dates prior to the current year.
```suggestion
// TheSuperHackers @bugfix xezon 26/10/2026 The camera area constraints are now recalculated when
```
**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.
---
This is a comment left during a code review.
Path: Core/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cpp
Line: 2455-2456
Comment:
**Duplicate separator line**
There are two consecutive `//---` separator lines between `initHeightForMap()` and `resetPivotToGround()`. This appears to be a copy-paste artifact — only a single separator is used elsewhere in the file.
```suggestion
//-------------------------------------------------------------------------------------------------
void W3DView::resetPivotToGround( void )
```
How can I resolve this? If you propose a fix, please make it concise.
---
This is a comment left during a code review.
Path: Core/Libraries/Source/WWVegas/WWMath/wwmath.h
Line: 278-285
Comment:
**`Inverse_Lerp` has no guard against division by zero**
When `a == b`, `(b - a)` is `0` and the function produces `NaN`/`Inf`. The current call site in `movePivotToGround()` passes compile-time constants (`DEG_TO_RADF(15.f)` vs `DEG_TO_RADF(30.f)`) so it is always safe there, but as a new general-purpose API it is a latent footgun for future callers. Consider adding a safety guard:
```cpp
WWINLINE float WWMath::Inverse_Lerp(float a, float b, float v)
{
const float denom = b - a;
return denom != 0.0f ? (v - a) / denom : 0.0f;
}
WWINLINE double WWMath::Inverse_Lerp(double a, double b, float v)
{
const double denom = b - a;
return denom != 0.0 ? (v - a) / denom : 0.0;
}
```
How can I resolve this? If you propose a fix, please make it concise.Reviews (6): Last reviewed commit: "bugfix(view): Fix and improve camera piv..." | Re-trigger Greptile
04d2b61 to
8d78c38
Compare
Mauller
left a comment
There was a problem hiding this comment.
I don't see any major issues at first glance, but i would perform some replay checking due to the new initialisation of class variables.
f56249d to
7092cdf
Compare
7092cdf to
9c4e01a
Compare
|
Replicated in Generals with conflict |
Merge with Rebase
The camera area constraints are now recalculated when the camera zoom changes, for example because of terrain elevation changes in the camera's view. The camera will be smoothly pushed away from the constraints, but not while the user is scrolling, to make the scrolling along the map border a pleasant experience. This behavior ensures that the view can reach and see all areas of the map, and especially the bottom map border. The camera can now also be moved a bit closer to the map edges. All this is very useful to avoid issues where some units or structures are not possible to get into the view, for example a Chinook at a Supply at the top edge of a map (TheSuperHackers/GeneralsRankedMaps#7). Or a Dozer at the bottom edge of a valley on Defcon 6.
Additionally the camera pivoting was fixed. The camera now repositions correctly towards its ground pivot instead of zooming to a pivot that is not aligned to the terrain ground. User facing this looks identical, but technically it is different. Scrolling to different locations of the map will now keep the camera pivot always correctly centered to the ground. It is no longer necessary to press Numpad 5 to recenter the pivot.
This change also implicitly fixes the broken scripted camera in the USA 01 intro, which was introduced by change #2291.
Known issues
The scripted camera will not always position perfectly at the original locations when the ground pivot was changed. This will be fixed in a future change.
TODO