diff --git a/include/llmr/map/map.hpp b/include/llmr/map/map.hpp index ada84f05b..93614a4f6 100644 --- a/include/llmr/map/map.hpp +++ b/include/llmr/map/map.hpp @@ -47,12 +47,16 @@ public: void setLonLatZoom(double lon, double lat, double zoom, double duration = 0); void getLonLatZoom(double &lon, double &lat, double &zoom) const; void resetZoom(); + void startScaling(); + void stopScaling(); /* rotation */ void rotateBy(double cx, double cy, double sx, double sy, double ex, double ey, double duration = 0); void setAngle(double angle, double cx = -1, double cy = -1, double duration = 0); double getAngle() const; void resetNorth(); + void startRotating(); + void stopRotating(); void toggleDebug(); diff --git a/include/llmr/map/transform.hpp b/include/llmr/map/transform.hpp index 56a5a8be9..a0a6003ee 100644 --- a/include/llmr/map/transform.hpp +++ b/include/llmr/map/transform.hpp @@ -61,6 +61,9 @@ public: float pixelRatio = 1; + bool rotating = false; + bool scaling = false; + private: double x = 0, y = 0; // pixel values of the map center in the current scale double angle = 0; diff --git a/ios/MBXViewController.mm b/ios/MBXViewController.mm index a687350af..040c05803 100644 --- a/ios/MBXViewController.mm +++ b/ios/MBXViewController.mm @@ -236,6 +236,7 @@ class MBXMapView if (pinch.state == UIGestureRecognizerStateBegan) { + mapView->map.startScaling(); self.scale = mapView->map.getScale(); } else if (pinch.state == UIGestureRecognizerStateChanged) @@ -258,6 +259,7 @@ class MBXMapView } else if (pinch.state == UIGestureRecognizerStateEnded) { + mapView->map.stopScaling(); if (fabsf(pinch.velocity) < 20) return; @@ -270,6 +272,9 @@ class MBXMapView mapView->map.scaleBy(new_scale / scale, [pinch locationInView:pinch.view].x, [pinch locationInView:pinch.view].y, duration); } + else if (pinch.state == UIGestureRecognizerStateCancelled) { + mapView->map.stopScaling(); + } [self updateRender]; } @@ -280,12 +285,17 @@ class MBXMapView if (rotate.state == UIGestureRecognizerStateBegan) { + mapView->map.startRotating(); self.angle = mapView->map.getAngle(); } else if (rotate.state == UIGestureRecognizerStateChanged) { mapView->map.setAngle(self.angle + rotate.rotation, [rotate locationInView:rotate.view].x, [rotate locationInView:rotate.view].y); } + else if (rotate.state == UIGestureRecognizerStateEnded || rotate.state == UIGestureRecognizerStateCancelled) + { + mapView->map.stopRotating(); + } [self updateRender]; } diff --git a/src/map/map.cpp b/src/map/map.cpp index 35dcb471f..e81bba058 100644 --- a/src/map/map.cpp +++ b/src/map/map.cpp @@ -77,6 +77,15 @@ void Map::scaleBy(double ds, double cx, double cy, double duration) { settings.persist(); } +void Map::startScaling() { + transform.scaling = true; +} + +void Map::stopScaling() { + transform.scaling = false; + +} + void Map::rotateBy(double cx, double cy, double sx, double sy, double ex, double ey, double duration) { transform.rotateBy(cx, cy, sx, sy, ex, ey, duration); update(); @@ -85,6 +94,14 @@ void Map::rotateBy(double cx, double cy, double sx, double sy, double ex, double settings.persist(); } +void Map::startRotating() { + transform.rotating = true; +} + +void Map::stopRotating() { + transform.rotating = false; +} + void Map::setLonLat(double lon, double lat, double duration) { transform.setLonLat(lon, lat, duration); update(); @@ -93,7 +110,7 @@ void Map::setLonLat(double lon, double lat, double duration) { settings.persist(); } -void Map::getLonLat(double &lon, double &lat) const { +void Map::getLonLat(double& lon, double& lat) const { transform.getLonLat(lon, lat); } @@ -107,7 +124,7 @@ void Map::setLonLatZoom(double lon, double lat, double zoom, double duration) { settings.persist(); } -void Map::getLonLatZoom(double &lon, double &lat, double &zoom) const { +void Map::getLonLatZoom(double& lon, double& lat, double& zoom) const { transform.getLonLatZoom(lon, lat, zoom); } diff --git a/src/renderer/painter.cpp b/src/renderer/painter.cpp index 28847b83e..169d3b127 100644 --- a/src/renderer/painter.cpp +++ b/src/renderer/painter.cpp @@ -400,9 +400,10 @@ void Painter::renderPoint(PointBucket& bucket, const std::string& layer_name, co ImagePosition imagePos = style.sprite->getPosition(sized_image, false); useProgram(pointShader->program); + style.sprite->bind(transform.rotating || transform.scaling); pointShader->setMatrix(matrix); pointShader->setColor(color); - const float pointSize = ceil(properties.size); + const float pointSize = properties.size * 1.4142135623730951; #if defined(GL_ES_VERSION_2_0) pointShader->setSize(pointSize); #else @@ -410,7 +411,6 @@ void Painter::renderPoint(PointBucket& bucket, const std::string& layer_name, co #endif pointShader->setPointTopLeft({{ imagePos.tl.x, imagePos.tl.y }}); pointShader->setPointBottomRight({{ imagePos.br.x, imagePos.br.y }}); - style.sprite->bind(true); bucket.drawPoints(*pointShader); } diff --git a/src/shader/point.fragment.glsl b/src/shader/point.fragment.glsl index dcd45cc69..89a8c1ca7 100644 --- a/src/shader/point.fragment.glsl +++ b/src/shader/point.fragment.glsl @@ -1,4 +1,4 @@ -#define root2 1.42 +#define root2 1.4142135623730951 uniform sampler2D u_image; uniform vec2 u_tl; @@ -16,10 +16,5 @@ void main() { (1.0 - step(1.0, pos.x)) * (1.0 - step(1.0, pos.y)); vec4 color = texture2D(u_image, mix(u_tl, u_br, pos)) * inbounds; - - if (u_color.a > 0.0) { - gl_FragColor = u_color * color.a; - } else { - gl_FragColor = vec4(color.rgb * color.a, color.a); - } + gl_FragColor = color; } diff --git a/src/shader/shaders.cpp b/src/shader/shaders.cpp index e62527813..84a0bf083 100644 --- a/src/shader/shaders.cpp +++ b/src/shader/shaders.cpp @@ -26,6 +26,6 @@ const shader_source llmr::shaders[SHADER_COUNT] = { }, { "attribute vec2 a_pos;\n\nuniform mat4 u_matrix;\nuniform float u_size;\n\nvoid main() {\n gl_Position = u_matrix * vec4(a_pos, 0, 1);\n gl_PointSize = u_size;\n}\n", - "#define root2 1.42\n\nuniform sampler2D u_image;\nuniform vec2 u_tl;\nuniform vec2 u_br;\nuniform vec4 u_color;\n\nuniform vec2 pos;\nuniform float inbounds;\nuniform vec4 color;\n\nvoid main() {\n vec2 pos = (gl_PointCoord * 2.0 - 1.0) * root2 / 2.0 + 0.5;\n\n float inbounds = step(0.0, pos.x) * step(0.0, pos.y) *\n (1.0 - step(1.0, pos.x)) * (1.0 - step(1.0, pos.y));\n\n vec4 color = texture2D(u_image, mix(u_tl, u_br, pos)) * inbounds;\n\n if (u_color.a > 0.0) {\n gl_FragColor = u_color * color.a;\n } else {\n gl_FragColor = vec4(color.rgb * color.a, color.a);\n }\n}\n", + "#define root2 1.4142135623730951\n\nuniform sampler2D u_image;\nuniform vec2 u_tl;\nuniform vec2 u_br;\nuniform vec4 u_color;\n\nuniform vec2 pos;\nuniform float inbounds;\nuniform vec4 color;\n\nvoid main() {\n vec2 pos = (gl_PointCoord * 2.0 - 1.0) * root2 / 2.0 + 0.5;\n\n float inbounds = step(0.0, pos.x) * step(0.0, pos.y) *\n (1.0 - step(1.0, pos.x)) * (1.0 - step(1.0, pos.y));\n\n vec4 color = texture2D(u_image, mix(u_tl, u_br, pos)) * inbounds;\n gl_FragColor = color;\n}\n", } };