From fff33ed7e71cf8bde24f7aa4bb37d0b0d9e19585 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Wed, 10 Jan 2018 16:47:08 -0500 Subject: [glfw] add animated annotations to glfw app for debugging --- platform/glfw/glfw_view.cpp | 27 +++++++++++++++++++++++++++ platform/glfw/glfw_view.hpp | 5 +++++ 2 files changed, 32 insertions(+) diff --git a/platform/glfw/glfw_view.cpp b/platform/glfw/glfw_view.cpp index 8fc2fba283..3988419265 100644 --- a/platform/glfw/glfw_view.cpp +++ b/platform/glfw/glfw_view.cpp @@ -288,6 +288,7 @@ void GLFWView::onKey(GLFWwindow *window, int key, int /*scancode*/, int action, case GLFW_KEY_8: view->addRandomShapeAnnotations(10); break; case GLFW_KEY_9: view->addRandomShapeAnnotations(100); break; case GLFW_KEY_0: view->addRandomShapeAnnotations(1000); break; + case GLFW_KEY_M: view->addAnimatedAnnotation(); break; } } } @@ -379,12 +380,36 @@ void GLFWView::addRandomShapeAnnotations(int count) { } } +void GLFWView::addAnimatedAnnotation() { + const double started = glfwGetTime(); + animatedAnnotationIDs.push_back(map->addAnnotation(mbgl::SymbolAnnotation { { 0, 0 } , "default_marker" })); + animatedAnnotationAddedTimes.push_back(started); +} + +void GLFWView::updateAnimatedAnnotations() { + const double time = glfwGetTime(); + for (size_t i = 0; i < animatedAnnotationIDs.size(); i++) { + auto dt = time - animatedAnnotationAddedTimes[i]; + + const double period = 10; + const double x = dt / period * 360 - 180; + const double y = std::sin(dt/ period * M_PI * 2.0) * 80; + map->updateAnnotation(animatedAnnotationIDs[i], mbgl::SymbolAnnotation { {x, y }, "default_marker" }); + } +} + void GLFWView::clearAnnotations() { for (const auto& id : annotationIDs) { map->removeAnnotation(id); } annotationIDs.clear(); + + for (const auto& id : animatedAnnotationIDs) { + map->removeAnnotation(id); + } + + animatedAnnotationIDs.clear(); } void GLFWView::popAnnotation() { @@ -506,6 +531,8 @@ void GLFWView::run() { if (animateRouteCallback) animateRouteCallback(map); + updateAnimatedAnnotations(); + activate(); rendererFrontend->render(); diff --git a/platform/glfw/glfw_view.hpp b/platform/glfw/glfw_view.hpp index 35f17b723a..d5acf697f7 100644 --- a/platform/glfw/glfw_view.hpp +++ b/platform/glfw/glfw_view.hpp @@ -78,6 +78,8 @@ private: void addRandomLineAnnotations(int count); void addRandomShapeAnnotations(int count); void addRandomCustomPointAnnotations(int count); + void addAnimatedAnnotation(); + void updateAnimatedAnnotations(); void clearAnnotations(); void popAnnotation(); @@ -85,6 +87,9 @@ private: mbgl::AnnotationIDs annotationIDs; std::vector spriteIDs; + mbgl::AnnotationIDs animatedAnnotationIDs; + std::vector animatedAnnotationAddedTimes; + private: void toggle3DExtrusions(bool visible); -- cgit v1.2.1