-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Prevent pitching when zooming into terrain #12280
Conversation
…ding with terrain
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Testing this out, it seems that the change exacerbates clipping through terrain.
Screen.Recording.2022-10-18.at.3.04.42.PM.mov
Thanks for testing this @SnailBones! I'll look into this (didn't come across this previously). Any specific settings you are using? |
I can reproduce this reliably by going to http://localhost:9966/debug/terrain-debug.html#15.24/35.147619/-106.425675/83.6/85 and panning the map forward. On |
@SnailBones @karimnaaji Fixed failing unit test - pitch needed to be reset from the previous unit test. Camera under terrain issue fixed while dragging. One trade off is if you zoom forcefully downwards into terrain it will bounce back a couple times - this is because we need to reposition the camera back before hitting terrain which prevents clipping through terrain.. We can create an issue for smoother close zooming in terrain to address later but it is better than automatically pitching and is otherwise relatively smooth. |
@@ -1599,7 +1599,7 @@ class Transform { | |||
const pos = this._computeCameraPosition(mercPixelsPerMeter); | |||
|
|||
const elevationAtCamera = elevation.getAtPointOrZero(new MercatorCoordinate(...pos)); | |||
const minHeight = this._minimumHeightOverTerrain() * Math.cos(degToRad(this._maxPitch)); | |||
const minHeight = this._minimumHeightOverTerrain() * Math.cos(degToRad(85)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the reason for hard-coding this value? Maybe add context in a comment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a comment. In maps with maxPitch set to less than 85, fast-zooming past terrain is exasperated since it would adjust the camera position too early. Hard-coding this value to 85 instead of maxPitch reduces this experience in these cases
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since Math.cos(degToRad(85))
< Math.cos(degToRad(0))
, should we use the upper bound of the possible values in order to keep a constant minHeigh
safe bound? That would mean directly using:
const minHeight = this._minimumHeightOverTerrain();
Since Math.cos(degToRad(0))
is 1. Would that work or lead to issues in practice?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The initial experience of using minHeight = this._minimumHeightOverTerrain()
is a bit more jarring. if you bounce into the terrain it pushes the camera farther up and away. It also allowed for the camera to go under the terrain. I'll look into why
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: If this is the correct value, should we consider hard coding the result in order to avoid an unnecessary cos()
operation?
const minHeight = this._minimumHeightOverTerrain() * Math.cos(degToRad(85)); | |
const cosMaxPitch = 0.08715560745961583 | |
const minHeight = this._minimumHeightOverTerrain() * cosMaxPitch; |
Though, have you experimented with other values to see if you the behavior can be smoother?
Co-authored-by: Aidan H <[email protected]>
Fixes #10197.
Previously, constraining camera altitude adjusted the camera z position to be positioned above the terrain (see line #1676) and then adjusts the pitch with camera orientation (see line #1685). This change removes these lines, and just ensures that the camera positions are a safe distance away from the terrain when the camera height is lower than the terrain height.
Before:
Screen.Recording.2022-10-18.at.12.48.03.PM.mov
After:
Screen.Recording.2022-10-18.at.12.47.08.PM.mov
Launch Checklist
mapbox-gl-js
changelog:<changelog>Allow zooming into terrain without unintended pitching.</changelog>