[glfw] add animated annotations to glfw app for debugging

This commit is contained in:
Ansis Brammanis
2018-01-10 16:47:08 -05:00
committed by Ansis Brammanis
parent 68159f8d01
commit fff33ed7e7
2 changed files with 32 additions and 0 deletions

View File

@@ -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();

View File

@@ -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<std::string> spriteIDs;
mbgl::AnnotationIDs animatedAnnotationIDs;
std::vector<double> animatedAnnotationAddedTimes;
private:
void toggle3DExtrusions(bool visible);