vectozavr-shooter/engine/animation/Animation.cpp

40 lines
1.1 KiB
C++
Raw Normal View History

2021-09-13 15:53:43 +03:00
//
// Created by Иван Ильин on 27.01.2021.
//
#include "Animation.h"
bool Animation::updateState() {
if(!_started) {
_started = true;
return _duration != 0;
}
// linear normalized time:
_dtime = Time::deltaTime()/_duration;
_time += _dtime;
2021-09-13 15:53:43 +03:00
if(_looped == LoopOut::Continue && _time > 0.5)
_time = 0.5;
2021-09-13 15:53:43 +03:00
switch (_intType) {
2021-10-09 13:41:12 +03:00
case InterpolationType::bezier:
_p = Interpolation::Bezier(*_bezier[0], *_bezier[1], _time);
_dp = Interpolation::dBezier(*_bezier[0], *_bezier[1], _time, _dtime);
2021-09-13 15:53:43 +03:00
break;
2021-10-09 13:41:12 +03:00
case InterpolationType::bouncing:
2021-09-13 15:53:43 +03:00
_p = Interpolation::Bouncing(_time);
_dp = Interpolation::dBouncing(_time, _dtime);
break;
2021-10-09 13:41:12 +03:00
case InterpolationType::linear:
2021-09-13 15:53:43 +03:00
_p = Interpolation::Linear(_time);
_dp = Interpolation::dLinear(_time, _dtime);
break;
2021-10-09 13:41:12 +03:00
case InterpolationType::cos:
2021-09-13 15:53:43 +03:00
_p = Interpolation::Cos(_time);
_dp = Interpolation::dCos(_time, _dtime);
break;
}
2021-10-09 13:41:12 +03:00
return (_time < 1) || _looped == LoopOut::Cycle;
2021-09-13 15:53:43 +03:00
}