Compute a fractional animation step for every frame.
This step is used to interpolate animations.
This commit is contained in:
@@ -26,6 +26,7 @@ struct
|
||||
vector<vector<LayerData>>::iterator currentData;
|
||||
vector<unique_ptr<LayerVisualisation>> layerVisualisations;
|
||||
vector<unique_ptr<ActivityAnimation>> 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[])
|
||||
|
||||
@@ -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