From c033f08d04f417e4b29907bf95e72b35cffc8854 Mon Sep 17 00:00:00 2001 From: Bert Peters Date: Tue, 13 Feb 2018 11:09:04 +0100 Subject: [PATCH] Compute a fractional animation step for every frame. This step is used to interpolate animations. --- src/main.cpp | 2 ++ src/utils.hpp | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/main.cpp b/src/main.cpp index 75a50d9..ae15114 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -26,6 +26,7 @@ struct vector>::iterator currentData; vector> layerVisualisations; vector> animations; + float animationStep = 0; } rendererData; static void loadSimulationData(const Options &options) @@ -153,6 +154,7 @@ static void idleFunc() checkGLErrors(); glutPostRedisplay(); throttleIdleFunc(); + rendererData.animationStep = getAnimationStep(std::chrono::seconds(5)); } int main(int argc, char *argv[]) diff --git a/src/utils.hpp b/src/utils.hpp index 4eea72d..dd5964e 100644 --- a/src/utils.hpp +++ b/src/utils.hpp @@ -9,6 +9,8 @@ #include #include #include +#include +#include namespace fmri { @@ -155,4 +157,22 @@ namespace fmri */ std::default_random_engine& rng(); + /** + * + * @tparam Duration Duration type of length + * @param length + * @return + */ + template + float getAnimationStep(const Duration &length) { + using namespace std::chrono; + + static auto startingPoint = steady_clock::now(); + const auto modified_length = duration_cast(length); + + auto step = (steady_clock::now() - startingPoint) % modified_length; + + return static_cast(step.count()) / static_cast(modified_length.count()); + } + }