From 01d89bfc66d8ebe6a7f5b3b10fa32cd036b89b64 Mon Sep 17 00:00:00 2001 From: Vectozavr <60608292+vectozavr@users.noreply.github.com> Date: Mon, 1 Nov 2021 21:48:26 +0700 Subject: [PATCH] made animations extremely precise --- Player.cpp | 6 ++++-- engine/animation/Animation.cpp | 11 +++++++++-- engine/animation/Interpolation.h | 7 +++++-- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/Player.cpp b/Player.cpp index 9c8ca55..90f69ae 100644 --- a/Player.cpp +++ b/Player.cpp @@ -86,8 +86,10 @@ void Player::addWeapon(std::shared_ptr weapon) { _weapons.back()->setReloadCallBack([this]() { Timeline::animate(AnimationListTag("reload_weapon"), std::make_shared(_weapons[_selectedWeapon], - 2 * Consts::PI, - _weapons[_selectedWeapon]->reloadTime() / 2)); + 10 * Consts::PI, + _weapons[_selectedWeapon]->reloadTime() / 2, + Animation::LoopOut::None, + Animation::InterpolationType::Linear)); }); // add call back function to create fire traces diff --git a/engine/animation/Animation.cpp b/engine/animation/Animation.cpp index 2dbe2c2..ab13b75 100644 --- a/engine/animation/Animation.cpp +++ b/engine/animation/Animation.cpp @@ -16,7 +16,14 @@ bool Animation::updateState() { // linear normalized time: _dtime = Time::deltaTime() / _duration; - _time += _dtime; + + if(_time + _dtime < 1.0) { + _time += _dtime; + } else { + _dtime = 1.0 - _time; + _time = 1.0 - _dtime; + _finished = true; + } if (_looped == LoopOut::Continue && _time > 0.5) { _time = 0.5; @@ -46,5 +53,5 @@ bool Animation::updateState() { update(); - return (_time < 1) || _looped == LoopOut::Cycle; + return !_finished; } diff --git a/engine/animation/Interpolation.h b/engine/animation/Interpolation.h index 06033ca..6e7e5dc 100644 --- a/engine/animation/Interpolation.h +++ b/engine/animation/Interpolation.h @@ -29,9 +29,12 @@ namespace Interpolation { }; double Interpolation::Linear(double t) { - if (t < 0) + if (t < 0) { t = -t; - return ((int) trunc(t) % 2) ? 1.0 - (t - trunc(t)) : (t - trunc(t)); + } + int integer = static_cast(t); + + return (integer % 2) ? 1.0 - (t - integer) : (t - integer); } double Interpolation::Cos(double t) {