summaryrefslogtreecommitdiff
path: root/src/mbgl/map/transform_state.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mbgl/map/transform_state.cpp')
-rw-r--r--src/mbgl/map/transform_state.cpp20
1 files changed, 11 insertions, 9 deletions
diff --git a/src/mbgl/map/transform_state.cpp b/src/mbgl/map/transform_state.cpp
index c740e6e87d..0cda016efa 100644
--- a/src/mbgl/map/transform_state.cpp
+++ b/src/mbgl/map/transform_state.cpp
@@ -44,11 +44,13 @@ void TransformState::getProjMatrix(mat4& projMatrix, uint16_t nearZ, bool aligne
// Calculate z distance of the farthest fragment that should be rendered.
const double furthestDistance = std::cos(M_PI / 2 - getPitch()) * topHalfSurfaceDistance + cameraToCenterDistance;
+
// Add a bit extra to avoid precision problems when a fragment's distance is exactly `furthestDistance`
const double farZ = furthestDistance * 1.01;
const double aspect = double(size.width) / size.height;
- matrix::perspective(projMatrix, getFieldOfView(), aspect, nearZ, farZ);
+ // Double FOV breaks here: https://github.com/mapbox/mapbox-gl-native/issues/12506
+ matrix::perspective(projMatrix, static_cast<float>(getFieldOfView()), aspect, nearZ, farZ);
const bool flippedY = viewportMode == ViewportMode::FlippedY;
matrix::scale(projMatrix, projMatrix, 1, flippedY ? 1 : -1, 1);
@@ -260,7 +262,7 @@ double TransformState::getMaxPitch() const {
#pragma mark - Rotation
-float TransformState::getBearing() const {
+double TransformState::getBearing() const {
return bearing;
}
@@ -268,15 +270,15 @@ void TransformState::setBearing(double bearing_) {
bearing = bearing_;
}
-float TransformState::getFieldOfView() const {
+double TransformState::getFieldOfView() const {
return fov;
}
-float TransformState::getCameraToCenterDistance() const {
+double TransformState::getCameraToCenterDistance() const {
return 0.5 * size.height / std::tan(fov / 2.0);
}
-float TransformState::getPitch() const {
+double TransformState::getPitch() const {
return pitch;
}
@@ -374,7 +376,7 @@ LatLng TransformState::screenCoordinateToLatLng(const ScreenCoordinate& point, L
mat4 TransformState::coordinatePointMatrix(double z) const {
mat4 proj;
getProjMatrix(proj);
- float s = Projection::worldSize(scale) / std::pow(2, z);
+ double s = Projection::worldSize(scale) / zoomScale(z);
matrix::scale(proj, proj, s, s, 1);
matrix::multiply(proj, getPixelMatrix(), proj);
return proj;
@@ -449,7 +451,7 @@ void TransformState::setLatLngZoom(const LatLng& latLng, double zoom) {
constrainToViewport();
}
-float TransformState::getCameraToTileDistance(const UnwrappedTileID& tileID) const {
+double TransformState::getCameraToTileDistance(const UnwrappedTileID& tileID) const {
mat4 projectionMatrix;
getProjMatrix(projectionMatrix);
mat4 tileProjectionMatrix;
@@ -461,11 +463,11 @@ float TransformState::getCameraToTileDistance(const UnwrappedTileID& tileID) con
return projectedCenter[3];
}
-float TransformState::maxPitchScaleFactor() const {
+double TransformState::maxPitchScaleFactor() const {
if (size.isEmpty()) {
return {};
}
- auto latLng = screenCoordinateToLatLng({ 0, static_cast<float>(getSize().height) });
+ auto latLng = screenCoordinateToLatLng({ 0, static_cast<double>(getSize().height) });
mat4 mat = coordinatePointMatrix(getZoom());
Point<double> pt = Projection::project(latLng, scale) / util::tileSize;
vec4 p = {{ pt.x, pt.y, 0, 1 }};