diff options
author | Michal Klocek <michal.klocek@theqtcompany.com> | 2015-04-28 12:10:16 +0200 |
---|---|---|
committer | Michal Klocek <michal.klocek@theqtcompany.com> | 2015-05-21 08:13:12 +0000 |
commit | 52b887a8004029cf18942b5d16b1dcf396feabc0 (patch) | |
tree | f2d44efd150ce1deb413d7cd1eccdbd1547e76be /src | |
parent | c40da252cf5ccdc5b5d2ce30b0f7f272e3d1c5bf (diff) | |
download | qtlocation-52b887a8004029cf18942b5d16b1dcf396feabc0.tar.gz |
Unify zoom calculations
Make camera calculations in qgeocameratiles and qgeomapscene
more obvious. Use the same fractions.
Change-Id: I4f156bb894eb2c606df97308ebd1b637408d9f2d
Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/location/maps/qgeocameratiles.cpp | 5 | ||||
-rw-r--r-- | src/location/maps/qgeomapscene.cpp | 23 |
2 files changed, 9 insertions, 19 deletions
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) { |