-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #83 from newo-2001/animation-refactor
- Loading branch information
Showing
73 changed files
with
295 additions
and
291 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#include "animation.h" | ||
|
||
namespace Impacto { | ||
|
||
void Animation::AddDelta(float dt) { | ||
float duration = | ||
Direction == +AnimationDirection::In ? DurationIn : DurationOut; | ||
|
||
switch (LoopMode) { | ||
case AnimationLoopMode::Stop: { | ||
float endProgress = Direction == +AnimationDirection::In ? 1.0f : 0.0f; | ||
|
||
Progress = std::clamp(Progress + Direction * dt / duration, 0.0f, 1.0f); | ||
if (Progress == endProgress) State = AnimationState::Stopped; | ||
return; | ||
} | ||
case AnimationLoopMode::Loop: { | ||
// E.g. Progress = 1.04 => Progress = 0.04 | ||
Progress += Direction * dt / duration; | ||
Progress -= std::floor(Progress); | ||
return; | ||
} | ||
case AnimationLoopMode::ReverseDirection: { | ||
// E.g. Progress = 1.04 => Progress = 0.96 | ||
float cycleDuration = DurationIn + DurationOut; | ||
|
||
float time = Progress * duration; | ||
if (Direction == +AnimationDirection::Out) { | ||
time = cycleDuration - time; | ||
} | ||
|
||
time = std::fmod(time + dt, cycleDuration); | ||
|
||
if (time < DurationIn) { | ||
Progress = time / DurationIn; | ||
Direction = AnimationDirection::In; | ||
} else { | ||
Progress = 1.0f - (time - DurationIn) / DurationOut; | ||
Direction = AnimationDirection::Out; | ||
} | ||
|
||
return; | ||
} | ||
} | ||
} | ||
|
||
} // namespace Impacto |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.