make translate property zoom independent

if you want a zoom-dependent translation, you can use a function

refs #189
This commit is contained in:
Konstantin Käfer
2014-05-13 16:48:23 +02:00
parent 7447b03ee7
commit 05a330f347
6 changed files with 19 additions and 22 deletions

View File

@@ -88,7 +88,7 @@ public:
bool needsAnimation() const;
private:
void setupShaders();
void translateLayer(std::array<float, 2> translation, bool reverse = false);
void translateLayer(std::array<float, 2> translation, const Tile::ID &id, bool reverse = false);
void prepareTile(const Tile& tile);
void useProgram(uint32_t program);

View File

@@ -7,6 +7,7 @@
#include <llmr/util/timer.hpp>
#include <llmr/util/time.hpp>
#include <llmr/util/clip_ids.hpp>
#include <llmr/util/constants.hpp>
#include <cassert>
#include <algorithm>
@@ -170,17 +171,13 @@ void Painter::renderTileLayer(const Tile& tile, const LayerDescription &layer_de
}
}
void Painter::translateLayer(std::array<float, 2> translation, bool reverse) {
void Painter::translateLayer(const std::array<float, 2> translation, const Tile::ID &id, bool reverse) {
if (translation[0] || translation[1]) {
if (reverse) {
translation[0] *= -1;
translation[1] *= -1;
}
matrix::translate(matrix,
matrix,
translation[0] / map.getState().getPixelRatio(),
translation[1] / map.getState().getPixelRatio(),
0);
const int direction = reverse ? -1 : 1;
// TODO: Get rid of the 8 (scaling from 4096 to tile size)
const double factor = direction * ((double)(1 << id.z)) / map.getState().getScale() /
map.getState().getPixelRatio() * (4096.0 / util::tileSize);
matrix::translate(matrix, matrix, translation[0] * factor, translation[1] * factor, 0);
}
}

View File

@@ -35,7 +35,7 @@ void Painter::renderFill(FillBucket& bucket, const std::string& layer_name, cons
stroke_color = fill_color;
}
translateLayer(properties.translate);
translateLayer(properties.translate, id);
// Because we're drawing top-to-bottom, and we update the stencil mask
// below, we have to draw the outline first (!)
@@ -139,5 +139,5 @@ void Painter::renderFill(FillBucket& bucket, const std::string& layer_name, cons
bucket.drawVertices(*outlineShader);
}
translateLayer(properties.translate, true);
translateLayer(properties.translate, id, true);
}

View File

@@ -4,7 +4,7 @@
using namespace llmr;
void Painter::renderLine(LineBucket& bucket, const std::string& layer_name, const Tile::ID& /*id*/) {
void Painter::renderLine(LineBucket& bucket, const std::string& layer_name, const Tile::ID& id) {
// Abort early.
if (pass == Opaque) return;
if (!bucket.hasData()) return;
@@ -33,7 +33,7 @@ void Painter::renderLine(LineBucket& bucket, const std::string& layer_name, cons
float dash_length = properties.dash_array[0];
float dash_gap = properties.dash_array[1];
translateLayer(properties.translate);
translateLayer(properties.translate, id);
glDepthRange(strata, 1.0f);
@@ -88,5 +88,5 @@ void Painter::renderLine(LineBucket& bucket, const std::string& layer_name, cons
bucket.drawLines(*lineShader);
}
translateLayer(properties.translate, true);
translateLayer(properties.translate, id, true);
}

View File

@@ -5,7 +5,7 @@
using namespace llmr;
void Painter::renderPoint(PointBucket& bucket, const std::string& layer_name, const Tile::ID& /*id&*/) {
void Painter::renderPoint(PointBucket& bucket, const std::string& layer_name, const Tile::ID& id) {
// Abort early.
if (!bucket.hasData()) return;
if (pass == Opaque) return;
@@ -17,7 +17,7 @@ void Painter::renderPoint(PointBucket& bucket, const std::string& layer_name, co
const PointProperties& properties = point_properties_it->second;
if (!properties.enabled) return;
translateLayer(properties.translate);
translateLayer(properties.translate, id);
Color color = properties.color;
color[0] *= properties.opacity;
@@ -76,5 +76,5 @@ void Painter::renderPoint(PointBucket& bucket, const std::string& layer_name, co
bucket.drawPoints(*pointShader);
}
translateLayer(properties.translate, true);
translateLayer(properties.translate, id, true);
}

View File

@@ -4,7 +4,7 @@
using namespace llmr;
void Painter::renderText(TextBucket& bucket, const std::string& layer_name, const Tile::ID& /*id*/) {
void Painter::renderText(TextBucket& bucket, const std::string& layer_name, const Tile::ID& id) {
// Abort early.
if (pass == Opaque) return;
if (!bucket.hasData()) return;
@@ -16,7 +16,7 @@ void Painter::renderText(TextBucket& bucket, const std::string& layer_name, cons
const TextProperties& properties = text_properties_it->second;
if (!properties.enabled) return;
translateLayer(properties.translate);
translateLayer(properties.translate, id);
mat4 exMatrix;
matrix::copy(exMatrix, projMatrix);
@@ -110,5 +110,5 @@ void Painter::renderText(TextBucket& bucket, const std::string& layer_name, cons
glDepthRange(strata + strata_epsilon, 1.0f);
bucket.drawGlyphs(*textShader);
translateLayer(properties.translate, true);
translateLayer(properties.translate, id, true);
}