diff options
| author | Jean-Philippe Bruyère <jp_bruyere@hotmail.com> | 2022-07-17 20:26:28 +0200 |
|---|---|---|
| committer | Jean-Philippe Bruyère <jp_bruyere@hotmail.com> | 2022-07-17 20:26:28 +0200 |
| commit | 9d786ab096ed36ea384e03ee5cea498790e31eec (patch) | |
| tree | adee54b5b90a35238d5794e9ffd3ebcf65798a06 /Samples/AnimTest/Animation/PathAnimation.cs | |
| parent | 57daad000aa31c7bcfa1f76b90d40da5a21da041 (diff) | |
wip
Diffstat (limited to 'Samples/AnimTest/Animation/PathAnimation.cs')
| -rw-r--r-- | Samples/AnimTest/Animation/PathAnimation.cs | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/Samples/AnimTest/Animation/PathAnimation.cs b/Samples/AnimTest/Animation/PathAnimation.cs new file mode 100644 index 00000000..54c30e9a --- /dev/null +++ b/Samples/AnimTest/Animation/PathAnimation.cs @@ -0,0 +1,53 @@ +// Copyright (c) 2015-2021 Jean-Philippe Bruyère <jp_bruyere@hotmail.com> +// +// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) + +using System; +using System.Numerics; + +namespace vke +{ + public class PathAnimation : Animation<Vector3> + { + Path path; + int stepCount, currentStep; + + #region CTOR + public PathAnimation(Object instance, string _propertyName, Path _path, int _stepCount = 20) + : base(instance, _propertyName) + { + path = _path; + stepCount = _stepCount; + } + + #endregion + + bool smooth = true; + + float smoothedStep (float step) => (-MathF.Cos (step * MathF.PI) + 1)/2.0f; + + public override void Process() + { + currentStep++; + + float t = (float)currentStep / (float)stepCount; + if (smooth) + t = smoothedStep (t); + + Vector3 pos = path.GetStep (t); + setValue(pos); + + if (currentStep < stepCount) + return; + + AnimationList.Remove(this); + RaiseAnimationFinishedEvent (); + } + + public override string ToString () + { + return string.Format ("{0}:->{1}:{2}",base.ToString(),TargetValue,Step); + } + } +} + |