fixes
This commit is contained in:
parent
f842a445d7
commit
627ef13727
4 changed files with 45 additions and 31 deletions
|
|
@ -62,27 +62,28 @@ namespace Crafter {
|
|||
std::vector<Keyframe<T>> keyframes;
|
||||
std::uint_fast32_t currentFrame;
|
||||
std::chrono::time_point<std::chrono::high_resolution_clock> startedAt;
|
||||
std::chrono::duration<double> accumulated;
|
||||
Animation(std::vector<Keyframe<T>>&& keyframes) : keyframes(std::move(keyframes)) {}
|
||||
void Start(std::chrono::time_point<std::chrono::high_resolution_clock> time) {
|
||||
currentFrame = 0;
|
||||
accumulated = std::chrono::duration<double>(0);
|
||||
startedAt = time;
|
||||
}
|
||||
T Play(std::chrono::time_point<std::chrono::high_resolution_clock> time) {
|
||||
std::chrono::duration<double> elapsed = time - startedAt;
|
||||
std::chrono::duration<double> accumulated(0);
|
||||
|
||||
for (std::uint_fast32_t i = currentFrame; i < keyframes.size(); ++i) {
|
||||
accumulated += keyframes[i].duration;
|
||||
if (elapsed < accumulated) {
|
||||
std::chrono::duration<double> frameStartTime = accumulated - keyframes[i].duration;
|
||||
auto t = (elapsed - frameStartTime) / keyframes[i].duration.count();
|
||||
for (; currentFrame < keyframes.size(); ++currentFrame) {
|
||||
if (elapsed < accumulated + keyframes[currentFrame].duration) {
|
||||
std::chrono::duration<double> frameStartTime = accumulated;
|
||||
auto t = (elapsed - frameStartTime) / keyframes[currentFrame].duration.count();
|
||||
|
||||
currentFrame = i;
|
||||
return LerpTuple(
|
||||
keyframes[i].startValues,
|
||||
keyframes[i].endValues,
|
||||
keyframes[currentFrame].startValues,
|
||||
keyframes[currentFrame].endValues,
|
||||
t.count()
|
||||
);
|
||||
} else {
|
||||
accumulated += keyframes[currentFrame].duration;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue