Compute a fractional animation step for every frame.

This step is used to interpolate animations.
This commit is contained in:
2018-02-13 11:09:04 +01:00
parent 74cf511436
commit c033f08d04
2 changed files with 22 additions and 0 deletions

View File

@@ -9,6 +9,8 @@
#include <string>
#include <utility>
#include <vector>
#include <ratio>
#include <chrono>
namespace fmri
{
@@ -155,4 +157,22 @@ namespace fmri
*/
std::default_random_engine& rng();
/**
*
* @tparam Duration Duration type of length
* @param length
* @return
*/
template<class Duration>
float getAnimationStep(const Duration &length) {
using namespace std::chrono;
static auto startingPoint = steady_clock::now();
const auto modified_length = duration_cast<steady_clock::duration>(length);
auto step = (steady_clock::now() - startingPoint) % modified_length;
return static_cast<float>(step.count()) / static_cast<float>(modified_length.count());
}
}