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<vector<LayerData>>::iterator currentData;
|
||||||
vector<unique_ptr<LayerVisualisation>> layerVisualisations;
|
vector<unique_ptr<LayerVisualisation>> layerVisualisations;
|
||||||
vector<unique_ptr<ActivityAnimation>> animations;
|
vector<unique_ptr<ActivityAnimation>> animations;
|
||||||
|
float animationStep = 0;
|
||||||
} rendererData;
|
} rendererData;
|
||||||
|
|
||||||
static void loadSimulationData(const Options &options)
|
static void loadSimulationData(const Options &options)
|
||||||
@@ -153,6 +154,7 @@ static void idleFunc()
|
|||||||
checkGLErrors();
|
checkGLErrors();
|
||||||
glutPostRedisplay();
|
glutPostRedisplay();
|
||||||
throttleIdleFunc();
|
throttleIdleFunc();
|
||||||
|
rendererData.animationStep = getAnimationStep(std::chrono::seconds(5));
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
|
|||||||
@@ -9,6 +9,8 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <ratio>
|
||||||
|
#include <chrono>
|
||||||
|
|
||||||
namespace fmri
|
namespace fmri
|
||||||
{
|
{
|
||||||
@@ -155,4 +157,22 @@ namespace fmri
|
|||||||
*/
|
*/
|
||||||
std::default_random_engine& rng();
|
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