move tile size to constants.hpp

This commit is contained in:
Konstantin Käfer
2014-02-13 17:34:08 +01:00
parent 2f32d1585d
commit b0357e8ea7
4 changed files with 30 additions and 14 deletions

View File

@@ -69,9 +69,6 @@ private:
double min_scale = pow(2, 0);
double max_scale = pow(2, 20);
// tile size
const int32_t size = 512;
// cache values for spherical mercator math
double zc, Bc, Cc;

View File

@@ -0,0 +1,16 @@
#ifndef LLMR_UTIL_CONSTANTS
#define LLMR_UTIL_CONSTANTS
#include <cmath>
#include "vec.hpp"
namespace llmr {
namespace util {
static const float tileSize = 256.0f;
}
}
#endif

View File

@@ -1,4 +1,5 @@
#include <llmr/map/transform.hpp>
#include <llmr/util/constants.hpp>
#include <llmr/util/mat4.hpp>
#include <llmr/util/math.hpp>
#include <cstdio>
@@ -108,7 +109,7 @@ void Transform::setScaleXY(double new_scale, double xn, double yn, double durati
animations.emplace_front(y, yn, y, duration);
}
const double s = scale * size;
const double s = scale * util::tileSize;
zc = s / 2;
Bc = s / 360;
Cc = s / (2 * M_PI);
@@ -151,7 +152,7 @@ void Transform::setLonLat(double lon, double lat, double duration) {
void Transform::setLonLatZoom(double lon, double lat, double zoom, double duration) {
double new_scale = pow(2.0, zoom);
const double s = new_scale * size;
const double s = new_scale * util::tileSize;
zc = s / 2;
Bc = s / 360;
Cc = s / (2 * M_PI);
@@ -174,18 +175,18 @@ void Transform::getLonLatZoom(double& lon, double& lat, double& zoom) const {
}
double Transform::pixel_x() const {
const double center = (width - scale * size) / 2;
const double center = (width - scale * util::tileSize) / 2;
return center + x;
}
double Transform::pixel_y() const {
const double center = (height - scale * size) / 2;
const double center = (height - scale * util::tileSize) / 2;
return center + y;
}
void Transform::matrixFor(mat4& matrix, const vec3<int32_t>& id) const {
const double tile_scale = pow(2, id.z);
const double tile_size = scale * size / tile_scale;
const double tile_size = scale * util::tileSize / tile_scale;
matrix::identity(matrix);
@@ -195,8 +196,9 @@ void Transform::matrixFor(mat4& matrix, const vec3<int32_t>& id) const {
matrix::translate(matrix, matrix, pixel_x() + id.x * tile_size, pixel_y() + id.y * tile_size, 0);
// TODO: Get rid of the 8 (scaling from 4096 to 512 px tile size);
matrix::scale(matrix, matrix, scale / tile_scale / 8, scale / tile_scale / 8, 1);
// TODO: Get rid of the 8 (scaling from 4096 to tile size);
float factor = scale / tile_scale / (4096.0f / util::tileSize);
matrix::scale(matrix, matrix, factor, factor, 1);
// Clipping plane
matrix::translate(matrix, matrix, 0, 0, -1);
@@ -231,8 +233,8 @@ void Transform::mapCornersToBox(uint32_t z, box& b) const {
const double w_2 = width / 2;
const double h_2 = height / 2;
const double ss_1 = ref_scale / (scale * size);
const double ss_2 = (scale * size) / 2;
const double ss_1 = ref_scale / (scale * util::tileSize);
const double ss_2 = (scale * util::tileSize) / 2;
// Calculate the corners of the map view. The resulting coordinates will be
// in fractional tile coordinates.

View File

@@ -1,4 +1,5 @@
#include <llmr/style/properties.hpp>
#include <llmr/util/constants.hpp>
#include <cassert>
@@ -30,8 +31,8 @@ float functions::stops(float z, const std::vector<float>& stops) {
// We need an even number of stop values.
if (stops.size() % 2 != 0) return 0;
// Accounts for us rendering tiles at 512x512, so our zoom levels are shifted by 1.
z += 1;
// Accounts for us rendering tiles at another size, so our zoom levels are shifted appropriately.
z += util::tileSize / 256.0f;
bool smaller = false;
float smaller_z, smaller_val;