2021-09-13 15:53:43 +03:00
|
|
|
//
|
|
|
|
// Created by Иван Ильин on 27.01.2021.
|
|
|
|
//
|
|
|
|
|
|
|
|
#include "Animation.h"
|
|
|
|
|
|
|
|
bool Animation::updateState() {
|
|
|
|
if(!_started) {
|
|
|
|
_startAnimationPoint = Time::time();
|
|
|
|
_endAnimationPoint = _startAnimationPoint + _duration;
|
|
|
|
_started = true;
|
|
|
|
return _duration != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
_timeOld = _time;
|
|
|
|
// linear normalized time:
|
|
|
|
_time = (Time::time() - _startAnimationPoint)/(_endAnimationPoint - _startAnimationPoint);
|
|
|
|
|
2021-10-09 13:41:12 +03:00
|
|
|
if(_looped != LoopOut::Continue || _time < 0.5)
|
2021-09-13 15:53:43 +03:00
|
|
|
_dtime = _time - _timeOld;
|
|
|
|
else {
|
|
|
|
_time = _timeOld;
|
|
|
|
//_intType = linear;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (_intType) {
|
2021-10-09 13:41:12 +03:00
|
|
|
case InterpolationType::bezier:
|
2021-09-13 15:53:43 +03:00
|
|
|
_p = Interpolation::Bezier(_bezier[0], _bezier[1], _time);
|
|
|
|
_dp = Interpolation::dBezier(_bezier[0], _bezier[1], _time, _dtime);
|
|
|
|
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
|
|
|
}
|