From 6eed8de736ff18a2aed65cd9ba62c6a7b5d18c59 Mon Sep 17 00:00:00 2001 From: Paweł Redman Date: Thu, 21 Dec 2017 11:29:41 +0100 Subject: Vastly improve following. --- src/common.hpp | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'src/common.hpp') diff --git a/src/common.hpp b/src/common.hpp index 7221b44..87706c8 100644 --- a/src/common.hpp +++ b/src/common.hpp @@ -266,13 +266,16 @@ namespace interface { float em; struct { + v2f_t zero_point_s = v2f_t(0, 0); v2f_t center = v2f_t(0, 0); - int target_zoom = 3; - float zoom = 3.0f; + + int zoom = 3; + float zoom_s = 3.0f; + bool panning = false; sf::Vector2f pan_ref; + bool following = true; - v2f_t follow_center = v2f_t(0, 0); } camera; struct { @@ -290,6 +293,8 @@ namespace interface { double perf_hist[10] = {0}; size_t perf_hist_index = 0; + void start_following(void); + void stop_following(void); public: state_t(sf::RenderWindow *window_, game::state_t *game); void tick(double dt); @@ -408,7 +413,14 @@ T bilerp(T a, T b, T c, T d, T x, T y) return lerp(ab, cd, y); } -static inline float expfade(float a, float b, float l, float dt) +template +static inline void expfade(T *a, T b, T l, T dt) +{ + *a = b + (*a - b) * exp(-l * dt); +} + +template +static inline void expfade(vec_t *a, vec_t b, float l, float dt) { - return b + (a - b) * exp(-l * dt); + *a = b + (*a - b) * exp(-l * dt); } -- cgit