Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[glfw] add animated annotations to glfw app for debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
ansis committed Jan 11, 2018
1 parent bd7e625 commit bb46c86
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
27 changes: 27 additions & 0 deletions platform/glfw/glfw_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -506,6 +531,8 @@ void GLFWView::run() {
if (animateRouteCallback)
animateRouteCallback(map);

updateAnimatedAnnotations();

activate();

rendererFrontend->render();
Expand Down
5 changes: 5 additions & 0 deletions platform/glfw/glfw_view.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,18 @@ class GLFWView : public mbgl::RendererBackend, public mbgl::MapObserver {
void addRandomLineAnnotations(int count);
void addRandomShapeAnnotations(int count);
void addRandomCustomPointAnnotations(int count);
void addAnimatedAnnotation();
void updateAnimatedAnnotations();

void clearAnnotations();
void popAnnotation();

mbgl::AnnotationIDs annotationIDs;
std::vector<std::string> spriteIDs;

mbgl::AnnotationIDs animatedAnnotationIDs;
std::vector<double> animatedAnnotationAddedTimes;

private:
void toggle3DExtrusions(bool visible);

Expand Down

0 comments on commit bb46c86

Please sign in to comment.