Compute a fractional animation step for every frame.
This step is used to interpolate animations.
This commit is contained in:
@@ -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());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user