-
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
Fix broken map on pitch=0 on some systems #3740
Conversation
@@ -408,6 +408,9 @@ class Transform { | |||
mat4.perspective(m, 2 * Math.atan((this.height / 2) / this.altitude), this.width / this.height, 0.1, farZ); | |||
mat4.translate(m, m, [0, 0, -this.altitude]); | |||
|
|||
// a hack around https://github.com/mapbox/mapbox-gl-js/issues/2270 | |||
m[14] = Math.min(m[14], m[15]); |
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 rewards of this not-100%-understood fix outweigh the severity of the bug & risks of the fix in my mind.
Out of curiosity, is there any intuitive meaning of elements 14 and 15 in the transformation matrix? Can we anticipate any cases where elements 14 and 15 might end up with very different values? cc @ansis
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.
There seem to be no intuitive meaning since the perspective projection math is a bit involved, but at this point of position matrix calculation, m[15]
always equals the altitude value (1.5
), and m[14]
represents translation along Z axis (which always seems to be <=1.5
).
Fixes #2270 by making sure a floating point error does not accumulate into a broken projection matrix.
When pitch = 0, a
Float32Array
perspective matrix would end up with1.5000001192092896, 1.5
as the last values, whileFloat64Array
produces correct1.5, 1.5
. Empirically, I found that the first value never exceeds the second one with proper precision. When it does (which happens even withFloat64Array
on some systems), the map disappears. So while I don't fully grasp the math behind this, this hack seems to fix the pitch=0 bug.cc @ansis @jfirebaugh @lucaswoj