diff options
author | Rémi Verschelde <remi@verschelde.fr> | 2021-10-11 22:55:01 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-11 22:55:01 +0200 |
commit | 9ed4f8367b29204b89f9feaf86727b24396fb180 (patch) | |
tree | 8c41815399d8eff5746ac17464ebb34d82b0a747 /scene/resources/animation.h | |
parent | 5edfdc53ebb97616a6a72031b2e28ec7865d6ab8 (diff) | |
parent | 372ba7666304805abe8641487c97899f9bdd97af (diff) | |
download | redot-engine-9ed4f8367b29204b89f9feaf86727b24396fb180.tar.gz |
Merge pull request #48332 from TokageItLab/implement-ping-pong
Diffstat (limited to 'scene/resources/animation.h')
-rw-r--r-- | scene/resources/animation.h | 30 |
1 files changed, 19 insertions, 11 deletions
diff --git a/scene/resources/animation.h b/scene/resources/animation.h index 9a410bd566..032b1a9277 100644 --- a/scene/resources/animation.h +++ b/scene/resources/animation.h @@ -60,7 +60,12 @@ public: UPDATE_DISCRETE, UPDATE_TRIGGER, UPDATE_CAPTURE, + }; + enum LoopMode { + LOOP_NONE, + LOOP_LINEAR, + LOOP_PINGPONG, }; private: @@ -184,7 +189,8 @@ private: int _insert(double p_time, T &p_keys, const V &p_value); template <class K> - inline int _find(const Vector<K> &p_keys, double p_time) const; + + inline int _find(const Vector<K> &p_keys, double p_time, bool p_backward = false) const; _FORCE_INLINE_ Animation::TransformKey _interpolate(const Animation::TransformKey &p_a, const Animation::TransformKey &p_b, real_t p_c) const; @@ -200,7 +206,7 @@ private: _FORCE_INLINE_ real_t _cubic_interpolate(const real_t &p_pre_a, const real_t &p_a, const real_t &p_b, const real_t &p_post_b, real_t p_c) const; template <class T> - _FORCE_INLINE_ T _interpolate(const Vector<TKey<T>> &p_keys, double p_time, InterpolationType p_interp, bool p_loop_wrap, bool *p_ok) const; + _FORCE_INLINE_ T _interpolate(const Vector<TKey<T>> &p_keys, double p_time, InterpolationType p_interp, bool p_loop_wrap, bool *p_ok, bool p_backward = false) const; template <class T> _FORCE_INLINE_ void _track_get_key_indices_in_range(const Vector<T> &p_array, double from_time, double to_time, List<int> *p_indices) const; @@ -210,15 +216,16 @@ private: double length = 1.0; real_t step = 0.1; - bool loop = false; + LoopMode loop_mode = LOOP_NONE; + int pingponged = 0; // bind helpers private: - Array _transform_track_interpolate(int p_track, double p_time) const { + Array _transform_track_interpolate(int p_track, double p_time, bool p_backward = false) const { Vector3 loc; Quaternion rot; Vector3 scale; - transform_track_interpolate(p_track, p_time, &loc, &rot, &scale); + transform_track_interpolate(p_track, p_time, &loc, &rot, &scale, p_backward); Array ret; ret.push_back(loc); ret.push_back(rot); @@ -324,26 +331,26 @@ public: void track_set_interpolation_loop_wrap(int p_track, bool p_enable); bool track_get_interpolation_loop_wrap(int p_track) const; - Error transform_track_interpolate(int p_track, double p_time, Vector3 *r_loc, Quaternion *r_rot, Vector3 *r_scale) const; + Error transform_track_interpolate(int p_track, double p_time, Vector3 *r_loc, Quaternion *r_rot, Vector3 *r_scale, bool p_backward = false) const; Variant value_track_interpolate(int p_track, double p_time) const; - void value_track_get_key_indices(int p_track, double p_time, double p_delta, List<int> *p_indices) const; + void value_track_get_key_indices(int p_track, double p_time, double p_delta, List<int> *p_indices, int p_pingponged = 0) const; void value_track_set_update_mode(int p_track, UpdateMode p_mode); UpdateMode value_track_get_update_mode(int p_track) const; - void method_track_get_key_indices(int p_track, double p_time, double p_delta, List<int> *p_indices) const; + void method_track_get_key_indices(int p_track, double p_time, double p_delta, List<int> *p_indices, int p_pingponged = 0) const; Vector<Variant> method_track_get_params(int p_track, int p_key_idx) const; StringName method_track_get_name(int p_track, int p_key_idx) const; void copy_track(int p_track, Ref<Animation> p_to_animation); - void track_get_key_indices_in_range(int p_track, double p_time, double p_delta, List<int> *p_indices) const; + void track_get_key_indices_in_range(int p_track, double p_time, double p_delta, List<int> *p_indices, int p_pingponged = 0) const; void set_length(real_t p_length); real_t get_length() const; - void set_loop(bool p_enabled); - bool has_loop() const; + void set_loop_mode(LoopMode p_loop_mode); + LoopMode get_loop_mode() const; void set_step(real_t p_step); real_t get_step() const; @@ -359,5 +366,6 @@ public: VARIANT_ENUM_CAST(Animation::TrackType); VARIANT_ENUM_CAST(Animation::InterpolationType); VARIANT_ENUM_CAST(Animation::UpdateMode); +VARIANT_ENUM_CAST(Animation::LoopMode); #endif |