summaryrefslogtreecommitdiff
path: root/src/mbgl/text/collision_index.cpp
diff options
context:
space:
mode:
authorAleksandar Stojiljkovic <aleksandar.stojiljkovic@mapbox.com>2019-05-13 23:02:05 +0300
committerAleksandar Stojiljkovic <aleksandar.stojiljkovic@mapbox.com>2019-05-28 14:38:01 +0300
commit9809c9f8f5583739e07d1a02df4c6cb96dfc4a10 (patch)
treef61c9979ad7943c1975aad6725054b2458c22b36 /src/mbgl/text/collision_index.cpp
parentddb6f749ec8992c363c067b6ad5871b31ccb7b8a (diff)
downloadqtlocation-mapboxgl-9809c9f8f5583739e07d1a02df4c6cb96dfc4a10.tar.gz
[core] Offset viewport center when edge insets are specified
The change is implemented in TransformState::getProjMatrix, the rest of the code is making sure that existing API contracts stay and there are tests verifyingrendering and render query processing only items within screen and given tolerance around screen edges. MapView: don't bake edge insets into relalculated camera center. Keep edge insets as property of camera in TransformState (similar to pitch, zoom, bearing) independent from specified camera center. Interpolate edge insets in animation. iOS Demo app: "Turn On/Off Content Insets" pitch the camera and navigate to convenient location in Denver, where streets are parallel to cardinal directions, to illustrate viewport center offset when edge insets are set. Tests: ViewFrustumCulling: although Annotations are deprecated, queryRenderedFeatures related tests in Annotations would need to get ported and decided to add the edge insets related query tests next to them. Verify frustum culling (render+queryRenderedFeatures) With different camera and edge insets setups. TODO: port Annotations tests. Transform.Padding: Verify that coordinates take proper place on screen after applying edge insets. LocalGlyphRasterizer: verify text rendering when applying padding. Related to #11882: both use projection matrix elements [8] and [9]. Alternative approach to this was to increase and offset map origin so that the screen would be a sub-rectangle in larger map viewport. This approach has a drawback of unecessary processing the items that are outside screen area. Fixes #12107, #12728, navigation-sdks/issues/120
Diffstat (limited to 'src/mbgl/text/collision_index.cpp')
-rw-r--r--src/mbgl/text/collision_index.cpp17
1 files changed, 10 insertions, 7 deletions
diff --git a/src/mbgl/text/collision_index.cpp b/src/mbgl/text/collision_index.cpp
index 88e59bf51c..e3d832a854 100644
--- a/src/mbgl/text/collision_index.cpp
+++ b/src/mbgl/text/collision_index.cpp
@@ -348,25 +348,28 @@ std::pair<float,float> CollisionIndex::projectAnchor(const mat4& posMatrix, cons
std::pair<Point<float>,float> CollisionIndex::projectAndGetPerspectiveRatio(const mat4& posMatrix, const Point<float>& point) const {
vec4 p = {{ point.x, point.y, 0, 1 }};
matrix::transformMat4(p, p, posMatrix);
+ auto offset = transformState.getCenterOffset();
+ auto size = transformState.getSize();
return std::make_pair(
Point<float>(
- (((p[0] / p[3] + 1) / 2) * transformState.getSize().width) + viewportPadding,
- (((-p[1] / p[3] + 1) / 2) * transformState.getSize().height) + viewportPadding
+ (((p[0] / p[3] + 1) / 2) * size.width) + viewportPadding + offset.x,
+ (((-p[1] / p[3] + 1) / 2) * size.height) + viewportPadding + offset.y
),
// See perspective ratio comment in symbol_sdf.vertex
// We're doing collision detection in viewport space so we need
// to scale down boxes in the distance
- 0.5 + 0.5 * (transformState.getCameraToCenterDistance() / p[3])
+ 0.5 + 0.5 * transformState.getCameraToCenterDistance() / p[3]
);
}
Point<float> CollisionIndex::projectPoint(const mat4& posMatrix, const Point<float>& point) const {
vec4 p = {{ point.x, point.y, 0, 1 }};
matrix::transformMat4(p, p, posMatrix);
- return Point<float>(
- (((p[0] / p[3] + 1) / 2) * transformState.getSize().width) + viewportPadding,
- (((-p[1] / p[3] + 1) / 2) * transformState.getSize().height) + viewportPadding
- );
+ auto offset = transformState.getCenterOffset();
+ auto size = transformState.getSize();
+ return Point<float> {
+ static_cast<float>((((p[0] / p[3] + 1) / 2) * size.width) + viewportPadding + offset.x),
+ static_cast<float>((((-p[1] / p[3] + 1) / 2) * size.height) + viewportPadding + offset.y) };
}
} // namespace mbgl