summaryrefslogtreecommitdiffstats
path: root/src/location/maps
diff options
context:
space:
mode:
authorPaolo Angelelli <paolo.angelelli@qt.io>2017-03-16 15:47:41 +0100
committerPaolo Angelelli <paolo.angelelli@qt.io>2017-03-22 11:13:49 +0000
commitbf356670158e95e4ba7fbeea774964e535bf6886 (patch)
treeaa958d92645d947cad89db8aad79a55b1ca7c9c9 /src/location/maps
parente405d931678510d9f6f92d27a7834cb683665a5d (diff)
Fix for projection mismatch when aspect ratio < 1.0
This patch fixes an incorrect computation of the projection matrices and thus a mismatch in projections between mbgl vs the other plugins when the window A/R is less than 1.0. Task-number: QTBUG-59417 Change-Id: Ib03eaa4c877a00c9281c335f859c854d6db632c0 Reviewed-by: Bruno de Oliveira Abinader <brunoabinader@gmail.com> Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
Diffstat (limited to 'src/location/maps')
-rw-r--r--src/location/maps/qgeocameratiles.cpp17
-rw-r--r--src/location/maps/qgeoprojection.cpp16
-rw-r--r--src/location/maps/qgeotiledmapscene.cpp9
3 files changed, 13 insertions, 29 deletions
diff --git a/src/location/maps/qgeocameratiles.cpp b/src/location/maps/qgeocameratiles.cpp
index 75d4512e..327d54b3 100644
--- a/src/location/maps/qgeocameratiles.cpp
+++ b/src/location/maps/qgeocameratiles.cpp
@@ -297,7 +297,7 @@ Frustum QGeoCameraTilesPrivate::createFrustum(double viewExpansion) const
apertureSize = tan(QLocationUtils::radians(m_camera.fieldOfView()) * 0.5);
QDoubleVector3D center = m_sideLength * QWebMercator::coordToMercator(m_camera.center());
- double f = qMin(m_screenSize.width(), m_screenSize.height());
+ double f = m_screenSize.height();
double z = std::pow(2.0, m_camera.zoomLevel() - m_intZoomLevel) * m_tileSize; // between 1 and 2 * m_tileSize
@@ -339,19 +339,12 @@ Frustum QGeoCameraTilesPrivate::createFrustum(double viewExpansion) const
// This used to fix the (half) field of view at 45 degrees
// half because this assumed that viewSize = 2*nearPlane x 2*nearPlane
viewExpansion *= apertureSize;
- if (aspectRatio > 1.0) {
- hhn = viewExpansion * nearPlane;
- hwn = hhn * aspectRatio;
- hhf = viewExpansion * farPlane;
- hwf = hhf * aspectRatio;
- } else {
- hwn = viewExpansion * nearPlane;
- hhn = hwn / aspectRatio;
+ hhn = viewExpansion * nearPlane;
+ hwn = hhn * aspectRatio;
- hwf = viewExpansion * farPlane;
- hhf = hwf / aspectRatio;
- }
+ hhf = viewExpansion * farPlane;
+ hwf = hhf * aspectRatio;
QDoubleVector3D d = center - eye;
d.normalize();
diff --git a/src/location/maps/qgeoprojection.cpp b/src/location/maps/qgeoprojection.cpp
index 81f3a947..4e5f1979 100644
--- a/src/location/maps/qgeoprojection.cpp
+++ b/src/location/maps/qgeoprojection.cpp
@@ -329,7 +329,7 @@ void QGeoProjectionWebMercator::setupCamera()
m_sideLength = (1 << intZoomLevel) * defaultTileSize;
m_center = m_centerMercator * m_sideLength;
- double f = 1.0 * qMin(m_viewportWidth, m_viewportHeight);
+ double f = m_viewportHeight;
double z = std::pow(2.0, m_cameraData.zoomLevel() - intZoomLevel) * defaultTileSize;
double altitude = f / (2.0 * z);
// Also in mercator space
@@ -402,16 +402,10 @@ void QGeoProjectionWebMercator::setupCamera()
double aspectRatio = 1.0 * m_viewportWidth / m_viewportHeight;
- m_halfWidth = m_aperture;
+ m_halfWidth = m_aperture * aspectRatio;
m_halfHeight = m_aperture;
- double verticalAperture = m_aperture;
- if (aspectRatio > 1.0) {
- m_halfWidth *= aspectRatio;
- } else if (aspectRatio > 0.0 && aspectRatio < 1.0) {
- m_halfHeight /= aspectRatio;
- verticalAperture /= aspectRatio;
- }
- double verticalHalfFOV = QLocationUtils::degrees(atan(verticalAperture));
+
+ double verticalHalfFOV = QLocationUtils::degrees(atan(m_aperture));
QDoubleMatrix4x4 cameraMatrix;
cameraMatrix.lookAt(m_eye, m_center, m_up);
@@ -452,7 +446,7 @@ void QGeoProjectionWebMercator::setupCamera()
double verticalEstateToSkip = 0;
if (maxRayElevation < verticalHalfFOV) {
maxHalfAperture = tan(QLocationUtils::radians(maxRayElevation));
- verticalEstateToSkip = 1.0 - maxHalfAperture / verticalAperture;
+ verticalEstateToSkip = 1.0 - maxHalfAperture / m_aperture;
}
m_minimumUnprojectableY = verticalEstateToSkip * 0.5 * m_viewportHeight; // verticalEstateToSkip is relative to half aperture
diff --git a/src/location/maps/qgeotiledmapscene.cpp b/src/location/maps/qgeotiledmapscene.cpp
index 3711841d..d38eec39 100644
--- a/src/location/maps/qgeotiledmapscene.cpp
+++ b/src/location/maps/qgeotiledmapscene.cpp
@@ -350,7 +350,7 @@ void QGeoTiledMapScenePrivate::updateTileBounds(const QSet<QGeoTileSpec> &tiles)
void QGeoTiledMapScenePrivate::setupCamera()
{
// NOTE: The following instruction is correct only because WebMercator is a square projection!
- double f = 1.0 * qMin(m_screenSize.width(), m_screenSize.height());
+ double f = m_screenSize.height();
// Using fraction of zoom level, z varies between [ m_tileSize , 2 * m_tileSize [
double z = std::pow(2.0, m_cameraData.zoomLevel() - m_intZoomLevel) * m_tileSize;
@@ -431,11 +431,8 @@ void QGeoTiledMapScenePrivate::setupCamera()
double aspectRatio = 1.0 * m_screenSize.width() / m_screenSize.height();
float halfWidth = 1 * apertureSize;
float halfHeight = 1 * apertureSize;
- if (aspectRatio > 1.0) {
- halfWidth *= aspectRatio;
- } else if (aspectRatio > 0.0f && aspectRatio < 1.0f) {
- halfHeight /= aspectRatio;
- }
+ halfWidth *= aspectRatio;
+
m_projectionMatrix.setToIdentity();
m_projectionMatrix.frustum(-halfWidth, halfWidth, -halfHeight, halfHeight, nearPlane, farPlane);
}