From 5c9863cf0998b5f1b6107ce09b54cd3e8b484221 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Fri, 30 Sep 2022 18:48:50 +0200 Subject: . --- tile-atlas.hpp | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 tile-atlas.hpp (limited to 'tile-atlas.hpp') diff --git a/tile-atlas.hpp b/tile-atlas.hpp new file mode 100644 index 00000000..855214b8 --- /dev/null +++ b/tile-atlas.hpp @@ -0,0 +1,31 @@ +#pragma once +#include +#include +#include + +namespace Magnum::Examples { + +struct tile_atlas final +{ + using vertex_array_type = std::array; + + tile_atlas(const ImageView2D& img, Vector2i dims); + std::array texcoords_for_id(int id) const; + static vertex_array_type floor_quad(Vector3 center, Vector2 size); + static vertex_array_type wall_quad_S(Vector3 center, Vector3 size); + static vertex_array_type wall_quad_E(Vector3 center, Vector3 size); + static vertex_array_type wall_quad_N(Vector3 center, Vector3 size); + static vertex_array_type wall_quad_W(Vector3 center, Vector3 size); + static std::array indices(int N); + GL::Texture2D& texture() { return tex_; } + constexpr int size() const { return dims_.product(); } + constexpr Vector2i tile_size() const { return tile_size_; } + + tile_atlas(const tile_atlas&) = delete; + tile_atlas& operator=(const tile_atlas&) = delete; +private: + GL::Texture2D tex_; + Vector2i size_, dims_, tile_size_; +}; + +} // namespace Magnum::Examples -- cgit v1.2.3