From fab23ff0b70f338fcaeadf11d3855e705e0be6be Mon Sep 17 00:00:00 2001 From: Paweł Redman Date: Tue, 19 Dec 2017 20:23:29 +0100 Subject: Smooth camera following. --- src/game/interface.cpp | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) (limited to 'src/game/interface.cpp') diff --git a/src/game/interface.cpp b/src/game/interface.cpp index 41e2365..0ffdbab 100644 --- a/src/game/interface.cpp +++ b/src/game/interface.cpp @@ -39,6 +39,15 @@ void state_t::tick(double dt) view_size.y = view_scale * size.y / size.x; } + if (game->selected_units.size() && camera.following) { + for (entity_t *ent : game->selected_units) + follow_center += ent->render_bounds.center(); + follow_center /= game->selected_units.size(); + + camera.follow_center[0] = expfade(camera.follow_center[0], follow_center[0], dt, 25); + camera.follow_center[1] = expfade(camera.follow_center[1], follow_center[1], dt, 25); + } + view_center = camera.center; if (camera.following) @@ -156,17 +165,6 @@ void state_t::tick(double dt) } } - if (game->selected_units.size() && camera.following) { - for (entity_t *ent : game->selected_units) - follow_center += ent->render_bounds.center(); - follow_center /= game->selected_units.size(); - - - camera.follow_center = follow_center; - //camera.follow_center[0] = expfade(camera.follow_center[0], follow_center[0], dt, 5); - //camera.follow_center[1] = expfade(camera.follow_center[1], follow_center[1], dt, 5); - } - // Compute this _after_ the setView above. wmouse = window->mapPixelToCoords(sf::Mouse::getPosition(*window)); -- cgit