From ae838b397b6e5ca85d30fe1a8b9ccbb74864a7a6 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Fri, 8 Jul 2016 16:23:13 -0700 Subject: [core] Move translatedMatrix to RenderTile --- src/mbgl/renderer/render_tile.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'src/mbgl/renderer/render_tile.cpp') diff --git a/src/mbgl/renderer/render_tile.cpp b/src/mbgl/renderer/render_tile.cpp index 513515ddf0..5c7c491be0 100644 --- a/src/mbgl/renderer/render_tile.cpp +++ b/src/mbgl/renderer/render_tile.cpp @@ -1,5 +1,34 @@ #include +#include namespace mbgl { +using namespace style; + +mat4 RenderTile::translatedMatrix(const std::array& translation, + TranslateAnchorType anchor, + const TransformState& state) const { + if (translation[0] == 0 && translation[1] == 0) { + return matrix; + } + + mat4 vtxMatrix; + + if (anchor == TranslateAnchorType::Viewport) { + const double sin_a = std::sin(-state.getAngle()); + const double cos_a = std::cos(-state.getAngle()); + matrix::translate(vtxMatrix, matrix, + id.pixelsToTileUnits(translation[0] * cos_a - translation[1] * sin_a, state.getZoom()), + id.pixelsToTileUnits(translation[0] * sin_a + translation[1] * cos_a, state.getZoom()), + 0); + } else { + matrix::translate(vtxMatrix, matrix, + id.pixelsToTileUnits(translation[0], state.getZoom()), + id.pixelsToTileUnits(translation[1], state.getZoom()), + 0); + } + + return vtxMatrix; +} + } // namespace mbgl -- cgit v1.2.1