Skip to content
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

Merged
merged 1 commit into from
Dec 5, 2016
Merged

Fix broken map on pitch=0 on some systems #3740

merged 1 commit into from
Dec 5, 2016

Conversation

mourner
Copy link
Member

@mourner mourner commented Dec 5, 2016

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 with 1.5000001192092896, 1.5 as the last values, while Float64Array produces correct 1.5, 1.5. Empirically, I found that the first value never exceeds the second one with proper precision. When it does (which happens even with Float64Array 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

@@ -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]);
Copy link
Contributor

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

Copy link
Member Author

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).

@mourner mourner merged commit 764f80a into master Dec 5, 2016
@mourner mourner deleted the fix-pitch-0 branch December 5, 2016 23:07
ansis added a commit that referenced this pull request Dec 13, 2016
This should fix the issue behind #2270 and remove the need for the hack
added in #3740.
ansis added a commit that referenced this pull request Dec 13, 2016
This should fix the issue behind #2270 and remove the need for the hack
added in #3740.
ansis added a commit that referenced this pull request Dec 13, 2016
This should fix the issue behind #2270 and remove the need for the hack
added in #3740.
@ansis ansis mentioned this pull request Dec 13, 2016
7 tasks
ansis added a commit that referenced this pull request Dec 14, 2016
This should fix the issue behind #2270 and remove the need for the hack
added in #3740.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Map does not render unless pitch is set and map is "tilted"
2 participants