fix earthquakes in perspective view
Use higher precision for matrix calculations so that the map does not jump around while zooming.
This commit is contained in:
@@ -27,18 +27,18 @@
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
typedef std::array<float, 16> mat4;
|
||||
typedef std::array<double, 16> mat4;
|
||||
|
||||
namespace matrix {
|
||||
|
||||
void identity(mat4& out);
|
||||
void ortho(mat4& out, float left, float right, float bottom, float top, float near, float far);
|
||||
void perspective(mat4& out, float fovy, float aspect, float near, float far);
|
||||
void ortho(mat4& out, double left, double right, double bottom, double top, double near, double far);
|
||||
void perspective(mat4& out, double fovy, double aspect, double near, double far);
|
||||
void copy(mat4& out, const mat4& a);
|
||||
void translate(mat4& out, const mat4& a, float x, float y, float z);
|
||||
void rotate_x(mat4& out, const mat4& a, float rad);
|
||||
void rotate_z(mat4& out, const mat4& a, float rad);
|
||||
void scale(mat4& out, const mat4& a, float x, float y, float z);
|
||||
void translate(mat4& out, const mat4& a, double x, double y, double z);
|
||||
void rotate_x(mat4& out, const mat4& a, double rad);
|
||||
void rotate_z(mat4& out, const mat4& a, double rad);
|
||||
void scale(mat4& out, const mat4& a, double x, double y, double z);
|
||||
void multiply(mat4& out, const mat4& a, const mat4& b);
|
||||
|
||||
}
|
||||
|
||||
@@ -36,10 +36,16 @@ public:
|
||||
location = MBGL_CHECK_ERROR(glGetUniformLocation(shader.program, name));
|
||||
}
|
||||
|
||||
void operator=(const T& t) {
|
||||
if (current != t) {
|
||||
current = t;
|
||||
bind(t);
|
||||
void operator=(const std::array<double, C*R>& t) {
|
||||
bool dirty = false;
|
||||
for (unsigned int i = 0; i < C*R; i++) {
|
||||
if (current[i] != t[i]) {
|
||||
current[i] = t[i];
|
||||
dirty = true;
|
||||
}
|
||||
}
|
||||
if (dirty) {
|
||||
bind(current);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -33,8 +33,8 @@ void matrix::identity(mat2& out) {
|
||||
out[3] = 1.0f;
|
||||
}
|
||||
|
||||
void matrix::rotate(mat2& out, const mat2& a, float rad) {
|
||||
float a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3],
|
||||
void matrix::rotate(mat2& out, const mat2& a, double rad) {
|
||||
double a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3],
|
||||
s = std::sin(rad),
|
||||
c = std::cos(rad);
|
||||
out[0] = a0 * c + a2 * s;
|
||||
@@ -43,8 +43,8 @@ void matrix::rotate(mat2& out, const mat2& a, float rad) {
|
||||
out[3] = a1 * -s + a3 * c;
|
||||
};
|
||||
|
||||
void matrix::scale(mat2& out, const mat2& a, float v0, float v1) {
|
||||
float a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3];
|
||||
void matrix::scale(mat2& out, const mat2& a, double v0, double v1) {
|
||||
double a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3];
|
||||
out[0] = a0 * v0;
|
||||
out[1] = a1 * v0;
|
||||
out[2] = a2 * v1;
|
||||
|
||||
@@ -27,13 +27,13 @@
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
typedef std::array<float, 4> mat2;
|
||||
typedef std::array<double, 4> mat2;
|
||||
|
||||
namespace matrix {
|
||||
|
||||
void identity(mat2& out);
|
||||
void rotate(mat2& out, const mat2& a, float rad);
|
||||
void scale(mat2& out, const mat2& a, float v0, float v1);
|
||||
void rotate(mat2& out, const mat2& a, double rad);
|
||||
void scale(mat2& out, const mat2& a, double v0, double v1);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,8 +38,8 @@ void matrix::identity(mat3& out) {
|
||||
out[8] = 1.0f;
|
||||
}
|
||||
|
||||
void matrix::translate(mat3& out, const mat3& a, float x, float y) {
|
||||
float a00 = a[0], a01 = a[1], a02 = a[2],
|
||||
void matrix::translate(mat3& out, const mat3& a, double x, double y) {
|
||||
double a00 = a[0], a01 = a[1], a02 = a[2],
|
||||
a10 = a[3], a11 = a[4], a12 = a[5],
|
||||
a20 = a[6], a21 = a[7], a22 = a[8];
|
||||
|
||||
@@ -56,8 +56,8 @@ void matrix::translate(mat3& out, const mat3& a, float x, float y) {
|
||||
out[8] = x * a02 + y * a12 + a22;
|
||||
}
|
||||
|
||||
void matrix::rotate(mat3& out, const mat3& a, float rad) {
|
||||
float s = std::sin(rad),
|
||||
void matrix::rotate(mat3& out, const mat3& a, double rad) {
|
||||
double s = std::sin(rad),
|
||||
c = std::cos(rad),
|
||||
a00 = a[0],
|
||||
a01 = a[1],
|
||||
@@ -82,7 +82,7 @@ void matrix::rotate(mat3& out, const mat3& a, float rad) {
|
||||
out[8] = a22;
|
||||
};
|
||||
|
||||
void matrix::scale(mat3& out, const mat3& a, float x, float y) {
|
||||
void matrix::scale(mat3& out, const mat3& a, double x, double y) {
|
||||
out[0] = x * a[0];
|
||||
out[1] = x * a[1];
|
||||
out[2] = x * a[2];
|
||||
|
||||
@@ -27,14 +27,14 @@
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
typedef std::array<float, 9> mat3;
|
||||
typedef std::array<double, 9> mat3;
|
||||
|
||||
namespace matrix {
|
||||
|
||||
void identity(mat3& out);
|
||||
void translate(mat3& out, const mat3& a, float x, float y);
|
||||
void rotate(mat3& out, const mat3& a, float rad);
|
||||
void scale(mat3& out, const mat3& a, float x, float y);
|
||||
void translate(mat3& out, const mat3& a, double x, double y);
|
||||
void rotate(mat3& out, const mat3& a, double rad);
|
||||
void scale(mat3& out, const mat3& a, double x, double y);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,8 +45,8 @@ void matrix::identity(mat4& out) {
|
||||
out[15] = 1.0f;
|
||||
}
|
||||
|
||||
void matrix::ortho(mat4& out, float left, float right, float bottom, float top, float near, float far) {
|
||||
float lr = 1.0f / (left - right),
|
||||
void matrix::ortho(mat4& out, double left, double right, double bottom, double top, double near, double far) {
|
||||
double lr = 1.0f / (left - right),
|
||||
bt = 1.0f / (bottom - top),
|
||||
nf = 1.0f / (near - far);
|
||||
out[0] = -2.0f * lr;
|
||||
@@ -67,8 +67,8 @@ void matrix::ortho(mat4& out, float left, float right, float bottom, float top,
|
||||
out[15] = 1.0f;
|
||||
}
|
||||
|
||||
void matrix::perspective(mat4& out, float fovy, float aspect, float near, float far) {
|
||||
float f = 1.0f / std::tan(fovy / 2.0f),
|
||||
void matrix::perspective(mat4& out, double fovy, double aspect, double near, double far) {
|
||||
double f = 1.0f / std::tan(fovy / 2.0f),
|
||||
nf = 1.0f / (near - far);
|
||||
out[0] = f / aspect;
|
||||
out[1] = 0.0f;
|
||||
@@ -107,14 +107,14 @@ void matrix::copy(mat4& out, const mat4& a) {
|
||||
out[15] = a[15];
|
||||
}
|
||||
|
||||
void matrix::translate(mat4& out, const mat4& a, float x, float y, float z) {
|
||||
void matrix::translate(mat4& out, const mat4& a, double x, double y, double z) {
|
||||
if (&a == &out) {
|
||||
out[12] = a[0] * x + a[4] * y + a[8] * z + a[12];
|
||||
out[13] = a[1] * x + a[5] * y + a[9] * z + a[13];
|
||||
out[14] = a[2] * x + a[6] * y + a[10] * z + a[14];
|
||||
out[15] = a[3] * x + a[7] * y + a[11] * z + a[15];
|
||||
} else {
|
||||
float a00, a01, a02, a03,
|
||||
double a00, a01, a02, a03,
|
||||
a10, a11, a12, a13,
|
||||
a20, a21, a22, a23;
|
||||
|
||||
@@ -133,8 +133,8 @@ void matrix::translate(mat4& out, const mat4& a, float x, float y, float z) {
|
||||
}
|
||||
}
|
||||
|
||||
void matrix::rotate_x(mat4& out, const mat4& a, float rad) {
|
||||
float s = std::sin(rad),
|
||||
void matrix::rotate_x(mat4& out, const mat4& a, double rad) {
|
||||
double s = std::sin(rad),
|
||||
c = std::cos(rad),
|
||||
a10 = a[4],
|
||||
a11 = a[5],
|
||||
@@ -167,8 +167,8 @@ void matrix::rotate_x(mat4& out, const mat4& a, float rad) {
|
||||
out[11] = a23 * c - a13 * s;
|
||||
}
|
||||
|
||||
void matrix::rotate_z(mat4& out, const mat4& a, float rad) {
|
||||
float s = std::sin(rad),
|
||||
void matrix::rotate_z(mat4& out, const mat4& a, double rad) {
|
||||
double s = std::sin(rad),
|
||||
c = std::cos(rad),
|
||||
a00 = a[0],
|
||||
a01 = a[1],
|
||||
@@ -201,7 +201,7 @@ void matrix::rotate_z(mat4& out, const mat4& a, float rad) {
|
||||
out[7] = a13 * c - a03 * s;
|
||||
}
|
||||
|
||||
void matrix::scale(mat4& out, const mat4& a, float x, float y, float z) {
|
||||
void matrix::scale(mat4& out, const mat4& a, double x, double y, double z) {
|
||||
out[0] = a[0] * x;
|
||||
out[1] = a[1] * x;
|
||||
out[2] = a[2] * x;
|
||||
@@ -221,13 +221,13 @@ void matrix::scale(mat4& out, const mat4& a, float x, float y, float z) {
|
||||
}
|
||||
|
||||
void matrix::multiply(mat4& out, const mat4& a, const mat4& b) {
|
||||
float a00 = a[0], a01 = a[1], a02 = a[2], a03 = a[3],
|
||||
double a00 = a[0], a01 = a[1], a02 = a[2], a03 = a[3],
|
||||
a10 = a[4], a11 = a[5], a12 = a[6], a13 = a[7],
|
||||
a20 = a[8], a21 = a[9], a22 = a[10], a23 = a[11],
|
||||
a30 = a[12], a31 = a[13], a32 = a[14], a33 = a[15];
|
||||
|
||||
// Cache only the current line of the second matrix
|
||||
float b0 = b[0], b1 = b[1], b2 = b[2], b3 = b[3];
|
||||
double b0 = b[0], b1 = b[1], b2 = b[2], b3 = b[3];
|
||||
out[0] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;
|
||||
out[1] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;
|
||||
out[2] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;
|
||||
|
||||
Reference in New Issue
Block a user