From 6e35a531c79ec2fbb4d7835ec808e421781f0564 Mon Sep 17 00:00:00 2001 From: Vectozavr <60608292+vectozavr@users.noreply.github.com> Date: Mon, 1 Nov 2021 23:04:10 +0700 Subject: [PATCH] made animations extremely precise --- Player.cpp | 6 +++--- Shooter.cpp | 1 + engine/animation/Animation.cpp | 28 ++++++++++++++++------------ engine/animation/Animation.h | 1 - 4 files changed, 20 insertions(+), 16 deletions(-) diff --git a/Player.cpp b/Player.cpp index 90f69ae..38812e6 100644 --- a/Player.cpp +++ b/Player.cpp @@ -86,10 +86,10 @@ void Player::addWeapon(std::shared_ptr weapon) { _weapons.back()->setReloadCallBack([this]() { Timeline::animate(AnimationListTag("reload_weapon"), std::make_shared(_weapons[_selectedWeapon], - 10 * Consts::PI, - _weapons[_selectedWeapon]->reloadTime() / 2, + 4 * Consts::PI, + _weapons[_selectedWeapon]->reloadTime()/2, Animation::LoopOut::None, - Animation::InterpolationType::Linear)); + Animation::InterpolationType::Cos)); }); // add call back function to create fire traces diff --git a/Shooter.cpp b/Shooter.cpp index 2a1a662..687cd99 100644 --- a/Shooter.cpp +++ b/Shooter.cpp @@ -15,6 +15,7 @@ #include "engine/animation/ARotateRelativePoint.h" #include "engine/animation/ATranslateToPoint.h" #include "engine/animation/AWait.h" +#include "engine/animation/ATranslate.h" using namespace std; diff --git a/engine/animation/Animation.cpp b/engine/animation/Animation.cpp index ab13b75..3d035b8 100644 --- a/engine/animation/Animation.cpp +++ b/engine/animation/Animation.cpp @@ -17,18 +17,6 @@ bool Animation::updateState() { // linear normalized time: _dtime = Time::deltaTime() / _duration; - 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; - } - switch (_intType) { case InterpolationType::Bezier: _progress = Interpolation::Bezier(Consts::BEZIER[0], Consts::BEZIER[1], _time); @@ -51,6 +39,22 @@ bool Animation::updateState() { "Animation::updateState: unknown interpolation type " + std::to_string(static_cast(_intType))}; } + if(_time + _dtime < 1.0) { + _time += _dtime; + } else { + _dtime = 1.0 - _time; + _time = 1.0; + _dprogress = 1 - _progress; + _progress = 1.0; + update(); + _finished = true; + return false; + } + + if (_looped == LoopOut::Continue && _time > 0.5) { + _time = 0.5; + } + update(); return !_finished; diff --git a/engine/animation/Animation.h b/engine/animation/Animation.h index 8748963..0c99bd1 100644 --- a/engine/animation/Animation.h +++ b/engine/animation/Animation.h @@ -20,7 +20,6 @@ public: }; enum class LoopOut { None, - Cycle, Continue }; private: