diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2022-10-17 16:37:25 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2022-10-17 16:37:25 +0200 |
commit | d9f58950e8cd58b7048f5f505db91323e0237063 (patch) | |
tree | 43f4eacd4cf0a025d6bf45b346d52ac60a2c4cb1 /src | |
parent | 1291f836ede29c23aea7bea20998105aa9fbea84 (diff) |
a
Diffstat (limited to 'src')
-rw-r--r-- | src/camera-offset.cpp | 27 | ||||
-rw-r--r-- | src/camera-offset.hpp | 18 |
2 files changed, 45 insertions, 0 deletions
diff --git a/src/camera-offset.cpp b/src/camera-offset.cpp new file mode 100644 index 00000000..47cb690d --- /dev/null +++ b/src/camera-offset.cpp @@ -0,0 +1,27 @@ +#include "camera-offset.hpp" +#include "shaders/tile-shader.hpp" + +namespace floormat { + +with_shifted_camera_offset::with_shifted_camera_offset(tile_shader& shader, std::int32_t x, std::int32_t y) : + with_shifted_camera_offset{shader, chunk_coords{std::int16_t(x), std::int16_t(y)}} +{ + ASSERT(std::abs(x) < (1 << 15) && std::abs(y) < (1 << 15)); +} + +with_shifted_camera_offset::with_shifted_camera_offset(tile_shader& shader, const chunk_coords c) : + s{shader}, + orig_offset(shader.camera_offset()) +{ + const auto offset = tile_shader::project({float(c.x)*TILE_MAX_DIM*TILE_SIZE[0], + float(c.y)*TILE_MAX_DIM*TILE_SIZE[1], + 0}); + s.set_camera_offset(orig_offset + offset); +} + +with_shifted_camera_offset::~with_shifted_camera_offset() +{ + s.set_camera_offset(orig_offset); +} + +} // namespace floormat diff --git a/src/camera-offset.hpp b/src/camera-offset.hpp new file mode 100644 index 00000000..da07cec0 --- /dev/null +++ b/src/camera-offset.hpp @@ -0,0 +1,18 @@ +#pragma once +#include "src/global-coords.hpp" + +namespace floormat { + +struct tile_shader; + +struct with_shifted_camera_offset final +{ + explicit with_shifted_camera_offset(tile_shader& shader, std::int32_t, std::int32_t); + explicit with_shifted_camera_offset(tile_shader& shader, chunk_coords c); + ~with_shifted_camera_offset(); +private: + tile_shader& s; // NOLINT + Vector2 orig_offset; +}; + +} // namespace floormat |