From 3b998a1f250157fb64eb8dd45f1938c99cd1c3a5 Mon Sep 17 00:00:00 2001 From: David Coeurjolly Date: Tue, 1 Mar 2022 14:29:22 +0100 Subject: [PATCH] anim --- 4-LaplacianSmoothing/c++/displayOBJ.cpp | 33 ++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/4-LaplacianSmoothing/c++/displayOBJ.cpp b/4-LaplacianSmoothing/c++/displayOBJ.cpp index c998578..fa8c9e5 100644 --- a/4-LaplacianSmoothing/c++/displayOBJ.cpp +++ b/4-LaplacianSmoothing/c++/displayOBJ.cpp @@ -13,6 +13,32 @@ using namespace geometrycentral::surface; std::unique_ptr mesh; std::unique_ptr geometry; +int counter=0; + +void oneStep() +{ + for(size_t i = 0; i < mesh->nVertices(); ++i) + geometry->vertexPositions[i] = geometry->vertexPositions[i] + Vector3::constant(0.01*sin(i*counter/(2.0*M_PI))); +} + +bool go=false; + +void myCallback() +{ + if (ImGui::Button("Go!")) + go= !go; + + if (go) + { + oneStep(); + polyscope::getSurfaceMesh("Input obj")->updateVertexPositions(geometry->vertexPositions); + // polyscope::screenshot(); + } + counter++; +} + + + int main(int argc, char **argv) { // Initialize polyscope @@ -27,8 +53,13 @@ int main(int argc, char **argv) { mesh->getFaceVertexList(), polyscopePermutations(*mesh)); + + geometry->requireVertexPositions(); + + // Specify the callback + polyscope::state::userCallback = myCallback; + // Give control to the polyscope gui polyscope::show(); - return EXIT_SUCCESS; }