made animations extremely precise

master
Vectozavr 2021-11-02 01:38:57 +07:00
parent 50e4c506a0
commit 5b8698af03
4 changed files with 15 additions and 14 deletions

View File

@ -10,11 +10,11 @@ using namespace std;
int main() { int main() {
Shooter game; Shooter game;
//game.create(1280, 720, ShooterConsts::PROJECT_NAME); game.create(1280, 720, ShooterConsts::PROJECT_NAME);
//game.create(1920, 1080, ShooterConsts::PROJECT_NAME, true, Consts::BACKGROUND_COLOR, sf::Style::Fullscreen); //game.create(1920, 1080, ShooterConsts::PROJECT_NAME, true, Consts::BACKGROUND_COLOR, sf::Style::Fullscreen);
//game.create(2048, 1152, ShooterConsts::PROJECT_NAME, true); //game.create(2048, 1152, ShooterConsts::PROJECT_NAME, true);
game.create(3072, 1920, ShooterConsts::PROJECT_NAME, true, Consts::BACKGROUND_COLOR, sf::Style::Fullscreen); //game.create(3072, 1920, ShooterConsts::PROJECT_NAME, true, Consts::BACKGROUND_COLOR, sf::Style::Fullscreen);
return 0; return 0;
} }

View File

@ -21,8 +21,7 @@ private:
return; return;
} }
_object.lock()->rotateLeft(-_object.lock()->angleLeftUpLookAt().x()); _object.lock()->rotateLeft(_rotationValue*dprogress());
_object.lock()->rotateLeft(_rotationValue*(progress()));
} }
public: public:

View File

@ -17,26 +17,17 @@ bool Animation::updateState() {
// linear normalized time: // linear normalized time:
_dtime = Time::deltaTime() / _duration; _dtime = Time::deltaTime() / _duration;
if(_time + _dtime > 1.0) {
_dtime = 1.0 - _time;
_finished = true;
}
switch (_intType) { switch (_intType) {
case InterpolationType::Bezier: case InterpolationType::Bezier:
_progress = Interpolation::Bezier(Consts::BEZIER[0], Consts::BEZIER[1], _time);
_dprogress = Interpolation::dBezier(Consts::BEZIER[0], Consts::BEZIER[1], _time, _dtime); _dprogress = Interpolation::dBezier(Consts::BEZIER[0], Consts::BEZIER[1], _time, _dtime);
break; break;
case InterpolationType::Bouncing: case InterpolationType::Bouncing:
_progress = Interpolation::Bouncing(_time);
_dprogress = Interpolation::dBouncing(_time, _dtime); _dprogress = Interpolation::dBouncing(_time, _dtime);
break; break;
case InterpolationType::Linear: case InterpolationType::Linear:
_progress = Interpolation::Linear(_time);
_dprogress = Interpolation::dLinear(_time, _dtime); _dprogress = Interpolation::dLinear(_time, _dtime);
break; break;
case InterpolationType::Cos: case InterpolationType::Cos:
_progress = Interpolation::Cos(_time);
_dprogress = Interpolation::dCos(_time, _dtime); _dprogress = Interpolation::dCos(_time, _dtime);
break; break;
default: default:
@ -44,7 +35,16 @@ bool Animation::updateState() {
"Animation::updateState: unknown interpolation type " + std::to_string(static_cast<int>(_intType))}; "Animation::updateState: unknown interpolation type " + std::to_string(static_cast<int>(_intType))};
} }
_time += _dtime; if (_time + _dtime > 1.0) {
_dtime = 1.0 - _time;
_time = 1.0;
_dprogress = 1.0 - _progress;
_progress = 1.0;
_finished = true;
} else {
_time += _dtime;
_progress += _dprogress;
}
if (_looped == LoopOut::Continue && _time > 0.5) { if (_looped == LoopOut::Continue && _time > 0.5) {
_time = 0.5; _time = 0.5;

View File

@ -55,6 +55,8 @@ public:
[[nodiscard]] double dprogress() const { return _dprogress; } [[nodiscard]] double dprogress() const { return _dprogress; }
void stop() { _finished = true; } void stop() { _finished = true; }
[[nodiscard]] bool isFinished() const { return _finished; }
}; };
#endif //INC_3DZAVR_ANIMATION_H #endif //INC_3DZAVR_ANIMATION_H