From 52b887a8004029cf18942b5d16b1dcf396feabc0 Mon Sep 17 00:00:00 2001 From: Michal Klocek Date: Tue, 28 Apr 2015 12:10:16 +0200 Subject: Unify zoom calculations Make camera calculations in qgeocameratiles and qgeomapscene more obvious. Use the same fractions. Change-Id: I4f156bb894eb2c606df97308ebd1b637408d9f2d Reviewed-by: Alex Blasche --- src/location/maps/qgeocameratiles.cpp | 5 ++--- src/location/maps/qgeomapscene.cpp | 23 +++++++---------------- 2 files changed, 9 insertions(+), 19 deletions(-) (limited to 'src') diff --git a/src/location/maps/qgeocameratiles.cpp b/src/location/maps/qgeocameratiles.cpp index 8023adcd..33c140ee 100644 --- a/src/location/maps/qgeocameratiles.cpp +++ b/src/location/maps/qgeocameratiles.cpp @@ -322,9 +322,9 @@ Frustum QGeoCameraTilesPrivate::createFrustum(double fieldOfViewGradient) const QDoubleVector3D center = m_sideLength * QGeoProjection::coordToMercator(m_camera.center()); center.setZ(0.0); - double f = qMin(m_screenSize.width(), m_screenSize.height()) / (1.0 * m_tileSize); + double f = qMin(m_screenSize.width(), m_screenSize.height()); - double z = std::pow(2.0, m_camera.zoomLevel() - m_intZoomLevel); + double z = std::pow(2.0, m_camera.zoomLevel() - m_intZoomLevel) * m_tileSize; double altitude = f / (2.0 * z); QDoubleVector3D eye = center; @@ -337,7 +337,6 @@ Frustum QGeoCameraTilesPrivate::createFrustum(double fieldOfViewGradient) const double nearPlane = 1 / (4.0 * m_tileSize ); double farPlane = altitude + 1.0; - double aspectRatio = 1.0 * m_screenSize.width() / m_screenSize.height(); double hn,wn,hf,wf = 0.0; diff --git a/src/location/maps/qgeomapscene.cpp b/src/location/maps/qgeomapscene.cpp index 83b964f7..b9774221 100644 --- a/src/location/maps/qgeomapscene.cpp +++ b/src/location/maps/qgeomapscene.cpp @@ -456,31 +456,21 @@ void QGeoMapScenePrivate::setupCamera() double f = 1.0 * qMin(screenSize_.width(), screenSize_.height()); // fraction of zoom level - double z = std::pow(2.0, cameraData_.zoomLevel() - intZoomLevel_); + double z = std::pow(2.0, cameraData_.zoomLevel() - intZoomLevel_) * tileSize_; // calculate altitdue that allows the visible map tiles // to fit in the screen correctly (note that a larger f will cause // the camera be higher, resulting in gray areas displayed around // the tiles) - double altitude = scaleFactor_ * f / (2.0 * z); - - double aspectRatio = 1.0 * screenSize_.width() / screenSize_.height(); - - double a = f / (z * tileSize_); + double altitude = f / (2.0 * z) ; // mercatorWidth_ and mercatorHeight_ define the ratio for // mercator and screen coordinate conversion, // see mercatorToItemPosition() and itemPositionToMercator() - if (aspectRatio > 1.0) { - mercatorHeight_ = a; - mercatorWidth_ = a * aspectRatio; - } else { - mercatorWidth_ = a; - mercatorHeight_ = a / aspectRatio; - } + mercatorHeight_ = screenSize_.height() / z; + mercatorWidth_ = screenSize_.width() / z; // calculate center - double edge = scaleFactor_ * tileSize_; // first calculate the camera center in map space in the range of 0 <-> sideLength (2^z) @@ -526,7 +516,7 @@ void QGeoMapScenePrivate::setupCamera() // calculate eye QDoubleVector3D eye = center; - eye.setZ(altitude); + eye.setZ(altitude * edge); // calculate up @@ -555,12 +545,13 @@ void QGeoMapScenePrivate::setupCamera() // near plane and far plane double nearPlane = 1.0; - double farPlane = 4.0 * edge; + double farPlane = (altitude + 1.0) * edge; cameraUp_ = up; cameraCenter_ = center; cameraEye_ = eye; + double aspectRatio = 1.0 * screenSize_.width() / screenSize_.height(); float halfWidth = 1; float halfHeight = 1; if (aspectRatio > 1.0) { -- cgit v1.2.1