diff options
author | Kelly Rauchenberger <fefferburbia@gmail.com> | 2018-06-06 16:44:25 -0400 |
---|---|---|
committer | Kelly Rauchenberger <fefferburbia@gmail.com> | 2018-06-06 16:44:25 -0400 |
commit | 456122f5f0086ed0dbe1b784266b96e9624aa8e1 (patch) | |
tree | e67b3715b579164e92b9ce4c99d5ce676ae05596 /src/renderer.cpp | |
parent | d851eae8e7cb4192dcd7213dd1a8b60064156b15 (diff) | |
download | ether-456122f5f0086ed0dbe1b784266b96e9624aa8e1.tar.gz ether-456122f5f0086ed0dbe1b784266b96e9624aa8e1.tar.bz2 ether-456122f5f0086ed0dbe1b784266b96e9624aa8e1.zip |
zooming fixes
when zooming out, the view center stays the same (shifted by map edges). when zooming in, the view center becomes the player position at the start of zoom. the boundary of player movement is now also set to the target view area at start of zoom.
Diffstat (limited to 'src/renderer.cpp')
-rw-r--r-- | src/renderer.cpp | 41 |
1 files changed, 26 insertions, 15 deletions
diff --git a/src/renderer.cpp b/src/renderer.cpp index eddd11d..9d3af97 100644 --- a/src/renderer.cpp +++ b/src/renderer.cpp | |||
@@ -288,22 +288,33 @@ void Renderer::render( | |||
288 | 288 | ||
289 | SDL_SetRenderTarget(ren_.get(), nullptr); | 289 | SDL_SetRenderTarget(ren_.get(), nullptr); |
290 | 290 | ||
291 | if (!game.zooming) | 291 | SDL_Rect zoomRect; |
292 | |||
293 | std::tie(zoomRect.x, zoomRect.y, zoomRect.w, zoomRect.h) = | ||
294 | calculateZoomRect(game); | ||
295 | |||
296 | SDL_RenderCopy(ren_.get(), canvas.get(), &zoomRect, nullptr); | ||
297 | SDL_RenderPresent(ren_.get()); | ||
298 | } | ||
299 | |||
300 | std::tuple<int, int, int, int> Renderer::calculateZoomRect(const Game& game) | ||
301 | { | ||
302 | int x = game.map.getTrueX(game.curBoundX) * TILE_WIDTH; | ||
303 | int y = game.map.getTrueY(game.curBoundY) * TILE_HEIGHT; | ||
304 | int w = game.curZoom * TILE_WIDTH * ZOOM_X_FACTOR; | ||
305 | int h = game.curZoom * TILE_HEIGHT * ZOOM_Y_FACTOR; | ||
306 | |||
307 | if (game.zooming) | ||
292 | { | 308 | { |
293 | SDL_RenderCopy(ren_.get(), canvas.get(), nullptr, nullptr); | 309 | double interp = |
294 | } else { | 310 | static_cast<double>(game.zoomProgress) / |
295 | // TODO: zooming back in to the player | 311 | static_cast<double>(game.zoomLength); |
296 | SDL_Rect zoomRect { | 312 | |
297 | ((game.maxZoom - game.curZoom) * TILE_WIDTH + game.zoomProgress) | 313 | x = (x - game.lastZoomLeft) * interp + game.lastZoomLeft; |
298 | * ZOOM_X_FACTOR / 2, | 314 | y = (y - game.lastZoomTop) * interp + game.lastZoomTop; |
299 | ((game.maxZoom - game.curZoom) * TILE_HEIGHT + game.zoomProgress) | 315 | w = (w - game.lastZoomWidth) * interp + game.lastZoomWidth; |
300 | * ZOOM_Y_FACTOR / 2, | 316 | h = (h - game.lastZoomHeight) * interp + game.lastZoomHeight; |
301 | (game.curZoom * TILE_WIDTH - game.zoomProgress) * ZOOM_X_FACTOR, | ||
302 | (game.curZoom * TILE_HEIGHT - game.zoomProgress) * ZOOM_Y_FACTOR | ||
303 | }; | ||
304 | |||
305 | SDL_RenderCopy(ren_.get(), canvas.get(), &zoomRect, nullptr); | ||
306 | } | 317 | } |
307 | 318 | ||
308 | SDL_RenderPresent(ren_.get()); | 319 | return {x, y, w, h}; |
309 | } | 320 | } |