diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2023-12-08 16:01:35 +0100 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2023-12-09 05:12:04 +0100 |
commit | 04baf8662c1b4266423fba4141b4b244ad7e05bf (patch) | |
tree | 2d5ebc8cb384e819d26d5115b651f046e9205215 /src | |
parent | 217292f6da87bf4fba3d6590b3a337ba152c2ff7 (diff) |
w
Diffstat (limited to 'src')
-rw-r--r-- | src/chunk-walls.cpp | 116 | ||||
-rw-r--r-- | src/chunk.hpp | 2 | ||||
-rw-r--r-- | src/wall-atlas.cpp | 2 |
3 files changed, 80 insertions, 40 deletions
diff --git a/src/chunk-walls.cpp b/src/chunk-walls.cpp index b71616f2..1bc0c376 100644 --- a/src/chunk-walls.cpp +++ b/src/chunk-walls.cpp @@ -20,7 +20,7 @@ using Wall::Group_; namespace { constexpr Vector2 half_tile = TILE_SIZE2*.5f; -constexpr float tile_height = TILE_SIZE.z(); +constexpr float X = half_tile.x(), Y = half_tile.y(), Z = TILE_SIZE.z(); } // namespace @@ -32,73 +32,113 @@ void chunk::ensure_alloc_walls() // ----------------------- -// overlay north -template<> std::array<Vector3, 4> chunk::make_wall_vertex_data<Group_::overlay, false>(Vector2 center, float depth) +// corner left +template<> std::array<Vector3, 4> chunk::make_wall_vertex_data<Group_::corner_L, false>(float) { - return wall_quad_N(Vector3(center, tile_height), TILE_SIZE); + constexpr float x_offset = (float)((unsigned)X)/2u; + return {{ + { X, -Y, Z }, + { X, -Y, 0 }, + { x_offset + -X, -Y, Z }, + { x_offset + -X, -Y, 0 }, + }}; } -// overlay west -template<> std::array<Vector3, 4> chunk::make_wall_vertex_data<Group_::overlay, true>(Vector2 center, float depth) +// corner right +template<> std::array<Vector3, 4> chunk::make_wall_vertex_data<Group_::corner_R, true>(float) { - return wall_quad_W(Vector3(center, tile_height), TILE_SIZE); + constexpr float y_offset = Y - (float)((unsigned)Y)/2u; + return {{ + {-X, -Y, Z }, + {-X, -Y, 0 }, + {-X, -Y + y_offset, Z }, + {-X, -Y + y_offset, 0 }, + }}; } -// corner left -template<> std::array<Vector3, 4> chunk::make_wall_vertex_data<Group_::corner_L, false>(Vector2 center, float depth) +// wall north +template<> std::array<Vector3, 4> chunk::make_wall_vertex_data<Group_::wall, false>(float) { - constexpr float x = half_tile.x(), y = half_tile.y(), z = tile_height; - constexpr float x_offset = (float)(int)x; return {{ - { x + center.x(), -y + center.y(), z + 0 }, - { x + center.x(), -y + center.y(), 0 }, - { x_offset + -x + center.x(), -y + center.y(), z + 0 }, - { x_offset + -x + center.x(), -y + center.y(), 0 }, + { X, -Y, Z }, + { X, -Y, 0 }, + {-X, -Y, Z }, + {-X, -Y, 0 }, }}; } -// corner right -template<> std::array<Vector3, 4> chunk::make_wall_vertex_data<Group_::corner_R, true>(Vector2 center, float depth) +// wall west +template<> std::array<Vector3, 4> chunk::make_wall_vertex_data<Group_::wall, true>(float) { - constexpr float x = half_tile.x(), y = half_tile.y(), z = tile_height; return {{ - {-x + center.x(), y + center.y(), z + 0 }, - {-x + center.x(), y + center.y(), 0 }, - {-x + center.x(), -y + center.y(), z + 0 }, - {-x + center.x(), -y + center.y(), 0 }, + {-X, Y, Z }, + {-X, Y, 0 }, + {-X, -Y, Z }, + {-X, -Y, 0 }, }}; } -// wall north -template<> std::array<Vector3, 4> chunk::make_wall_vertex_data<Group_::wall, false>(Vector2 center, float depth) +// overlay north +template<> std::array<Vector3, 4> chunk::make_wall_vertex_data<Group_::overlay, false>(float depth) { - return wall_quad_N(Vector3(center, tile_height), TILE_SIZE); + return make_wall_vertex_data<Wall::Group_::wall, false>(depth); } -// wall west -template<> std::array<Vector3, 4> chunk::make_wall_vertex_data<Group_::wall, true>(Vector2 center, float depth) +// overlay west +template<> std::array<Vector3, 4> chunk::make_wall_vertex_data<Group_::overlay, true>(float depth) { - return wall_quad_W(Vector3(center, tile_height), TILE_SIZE); + return make_wall_vertex_data<Wall::Group_::wall, true>(depth); } // side north -template<> std::array<Vector3, 4> chunk::make_wall_vertex_data<Group_::side, false>(Vector2 center, float depth) +template<> std::array<Vector3, 4> chunk::make_wall_vertex_data<Group_::side, false>(float depth) { - constexpr float x = half_tile.x(), y = half_tile.y(), z = tile_height; - auto left = Vector2{x + center.x(), -y + center.y() }, - right = Vector2{left.x(), left.y() - depth }; + auto left = Vector2{X, -Y }, + right = Vector2{left.x(), left.y() - depth }; return {{ - { right.x(), right.y(), z + 0 }, - { right.x(), right.y(), 0 }, - { left.x(), left.y(), z + 0 }, - { left.x(), left.y(), 0 }, + { right.x(), right.y(), Z }, + { right.x(), right.y(), 0 }, + { left.x(), left.y(), Z }, + { left.x(), left.y(), 0 }, }}; } // side west -template<> std::array<Vector3, 4> chunk::make_wall_vertex_data<Group_::side, true>(Vector2 center, float depth) +template<> std::array<Vector3, 4> chunk::make_wall_vertex_data<Group_::side, true>(float depth) +{ + auto right = Vector2{ X, Y }; + auto left = Vector2{ right.x() - depth, right.y() }; + return {{ + { right.x(), right.y(), Z }, + { right.x(), right.y(), 0 }, + { left.x(), left.y(), Z }, + { left.x(), left.y(), 0 }, + }}; +} + +// top north +template<> std::array<Vector3, 4> chunk::make_wall_vertex_data<Group_::top, false>(float depth) { - constexpr float x = half_tile.x(), y = half_tile.y(), z = tile_height; + auto top_right = Vector2{X , Y - depth }, + bottom_right = Vector2{top_right.x(), Y }, + top_left = Vector2{-X, top_right.y() }, + bottom_left = Vector2{top_left.x(), bottom_right.y() }; + // br tr + // tr tl + // bl br + // tl bl + return {{ + { top_right.x(), top_right.y(), Z }, + { top_left.x(), top_left.y(), Z }, + { bottom_right.x(), bottom_right.y(), Z }, + { bottom_left.x(), bottom_left.y(), Z } + }}; +} + +// top west +template<> std::array<Vector3, 4> chunk::make_wall_vertex_data<Group_::top, true>(float depth) +{ + } // ----------------------- diff --git a/src/chunk.hpp b/src/chunk.hpp index 32d72d77..243230df 100644 --- a/src/chunk.hpp +++ b/src/chunk.hpp @@ -135,7 +135,7 @@ private: bool empty() const { return count_N == 0 && count_W == 0; } }; - template<Wall::Group_ G, bool IsWest> static std::array<Vector3, 4> make_wall_vertex_data(Vector2 center, float depth); + template<Wall::Group_ G, bool IsWest> static std::array<Vector3, 4> make_wall_vertex_data(float depth); Pointer<ground_stuff> _ground; Pointer<wall_stuff> _walls; diff --git a/src/wall-atlas.cpp b/src/wall-atlas.cpp index d617f341..e637007d 100644 --- a/src/wall-atlas.cpp +++ b/src/wall-atlas.cpp @@ -43,7 +43,7 @@ wall_atlas::wall_atlas(wall_atlas_def def, String path, const ImageView2D& img) : _dir_array{std::move(def.direction_array)}, _frame_array{std::move(def.frames)}, _info{std::move(def.header)}, _path{std::move(path)}, - _direction_map{def.direction_map } + _direction_map{def.direction_map} { _texture.setLabel(_path) .setWrapping(GL::SamplerWrapping::ClampToEdge) |