From f3997025fd4785606fe4f8b05037e9463c5be7da Mon Sep 17 00:00:00 2001 From: SmallJoker Date: Fri, 3 Aug 2018 00:25:37 +0200 Subject: Smoothed yaw rotation for objects (#6825) --- src/content_cao.h | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'src/content_cao.h') diff --git a/src/content_cao.h b/src/content_cao.h index d2c8d772e..cd58681bb 100644 --- a/src/content_cao.h +++ b/src/content_cao.h @@ -34,25 +34,31 @@ struct Nametag; SmoothTranslator */ +template struct SmoothTranslator { - v3f vect_old; - v3f vect_show; - v3f vect_aim; - f32 anim_counter = 0; + T val_old; + T val_current; + T val_target; f32 anim_time = 0; f32 anim_time_counter = 0; bool aim_is_end = true; SmoothTranslator() = default; - void init(v3f vect); + void init(T current); - void update(v3f vect_new, bool is_end_position=false, float update_interval=-1); + void update(T new_target, bool is_end_position = false, + float update_interval = -1); void translate(f32 dtime); }; +struct SmoothTranslatorWrapped : SmoothTranslator +{ + void translate(f32 dtime); +}; + class GenericCAO : public ClientActiveObject { private: @@ -76,7 +82,8 @@ private: v3f m_acceleration; float m_yaw = 0.0f; s16 m_hp = 1; - SmoothTranslator pos_translator; + SmoothTranslator pos_translator; + SmoothTranslatorWrapped yaw_translator; // Spritesheet/animation stuff v2f m_tx_size = v2f(1,1); v2s16 m_tx_basepos; -- cgit v1.2.3