summaryrefslogtreecommitdiffhomepage
path: root/tile-atlas.hpp
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2022-10-02 00:36:34 +0200
committerStanislaw Halik <sthalik@misaki.pl>2022-10-02 00:36:34 +0200
commit742579ca2fce1effe942928f5b94401e1e723f34 (patch)
treeba11651aecd68edc12d3f5c69c04b6c2f6c2ee79 /tile-atlas.hpp
parent3dc6362599e85c9978ec4e9676ebcda3ab52beaf (diff)
foo
Diffstat (limited to 'tile-atlas.hpp')
-rw-r--r--tile-atlas.hpp16
1 files changed, 13 insertions, 3 deletions
diff --git a/tile-atlas.hpp b/tile-atlas.hpp
index 855214b8..f03afa71 100644
--- a/tile-atlas.hpp
+++ b/tile-atlas.hpp
@@ -10,17 +10,18 @@ struct tile_atlas final
using vertex_array_type = std::array<Vector3, 4>;
tile_atlas(const ImageView2D& img, Vector2i dims);
- std::array<Vector2, 4> texcoords_for_id(int id) const;
+ std::array<Vector2, 4> texcoords_for_id(std::size_t 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<UnsignedShort, 6> indices(int N);
+ static constexpr std::array<UnsignedShort, 6> indices(std::size_t N);
GL::Texture2D& texture() { return tex_; }
- constexpr int size() const { return dims_.product(); }
+ constexpr std::size_t size() const { return (std::size_t)dims_.product(); }
constexpr Vector2i tile_size() const { return tile_size_; }
+ tile_atlas() = default;
tile_atlas(const tile_atlas&) = delete;
tile_atlas& operator=(const tile_atlas&) = delete;
private:
@@ -28,4 +29,13 @@ private:
Vector2i size_, dims_, tile_size_;
};
+constexpr std::array<UnsignedShort, 6> tile_atlas::indices(std::size_t N)
+{
+ using u16 = UnsignedShort;
+ return { /* 3--1 1 */
+ (u16)(0+N*4), (u16)(1+N*4), (u16)(2+N*4), /* | / /| */
+ (u16)(2+N*4), (u16)(1+N*4), (u16)(3+N*4), /* |/ / | */
+ }; /* 2 2--0 */
+}
+
} // namespace Magnum::Examples