diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2024-11-15 16:09:12 +0100 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2024-11-15 16:09:12 +0100 |
commit | 6b271f37e740210e5c85324f88706ad5cf4487ba (patch) | |
tree | b04b3978926bd2915fbf71573c229907ab2b6ad0 | |
parent | 2f9498dd93c1c5dde6ec19b73795631f1cb0cfa2 (diff) |
src/chunk-walls: factor out common formulas
-rw-r--r-- | src/chunk-walls.cpp | 85 |
1 files changed, 50 insertions, 35 deletions
diff --git a/src/chunk-walls.cpp b/src/chunk-walls.cpp index 59e0e915..3e62920e 100644 --- a/src/chunk-walls.cpp +++ b/src/chunk-walls.cpp @@ -45,13 +45,19 @@ using Wall::Frame; template<typename T> using Vec2_ = VectorTypeFor<2, T>; template<typename T> using Vec3_ = VectorTypeFor<3, T>; +template<typename F, uint32_t N> +struct minmax_v +{ + VectorTypeFor<N, F> min, max; +}; + template<Group_ G, bool IsWest, typename F = float> -constexpr std::array<Vec3_<F>, 4> get_quad(F depth) +constexpr std::array<Vec3_<F>, 4> get_quadʹ(minmax_v<F, 3> bounds, F d) { static_assert(G < Group_::COUNT); - constexpr auto half_tile = Vec2_<F>(TILE_SIZE2*.5f); - constexpr auto X = half_tile.x(), Y = half_tile.y(), Z = F(TILE_SIZE.z()); + const auto x0 = bounds.min.x(), y0 = bounds.min.y(), z0 = bounds.min.z(), + x1 = bounds.max.x(), y1 = bounds.max.y(), z1 = bounds.max.z(); switch (G) { @@ -60,67 +66,76 @@ constexpr std::array<Vec3_<F>, 4> get_quad(F depth) case wall: if (!IsWest) return {{ - { X, -Y, 0 }, - { X, -Y, Z }, - {-X, -Y, 0 }, - {-X, -Y, Z }, + { x1, y0, z0 }, + { x1, y0, z1 }, + { x0, y0, z0 }, + { x0, y0, z1 }, }}; else return {{ - {-X, -Y, 0 }, - {-X, -Y, Z }, - {-X, Y, 0 }, - {-X, Y, Z }, + { x0, y0, z0 }, + { x0, y0, z1 }, + { x0, y1, z0 }, + { x0, y1, z1 }, }}; case side: if (!IsWest) return {{ - { X, -Y - depth, 0 }, - { X, -Y - depth, Z }, - { X, -Y, 0 }, - { X, -Y, Z }, + { x1, y0 - d, z0 }, + { x1, y0 - d, z1 }, + { x1, y0, z0 }, + { x1, y0, z1 }, }}; else return {{ - { -X, Y, 0 }, - { -X, Y, Z }, - { -X - depth, Y, 0 }, - { -X - depth, Y, Z }, + { x0, y1, z0 }, + { x0, y1, z1 }, + { x0 - d, y1, z0 }, + { x0 - d, y1, z1 }, }}; case top: if (!IsWest) return {{ - { -X, -Y - depth, Z }, - { X, -Y - depth, Z }, - { -X, -Y, Z }, - { X, -Y, Z }, + { x0, y0 - d, z1 }, + { x1, y0 - d, z1 }, + { x0, y0, z1 }, + { x1, y0, z1 }, }}; else return {{ - { -X, -Y, Z }, - { -X, Y, Z }, - { -X - depth, -Y, Z }, - { -X - depth, Y, Z }, + { x0, y0, z1 }, + { x0, y1, z1 }, + { x0 - d, y0, z1 }, + { x0 - d, y1, z1 }, }}; case corner: if (!IsWest) return {{ - {-X, -Y, 0 }, - {-X, -Y, Z }, - {-X - depth, -Y, 0 }, - {-X - depth, -Y, Z }, + { x0, y0, z0 }, + { x0, y0, z1 }, + { x0 - d, y0, z0 }, + { x0 - d, y0, z1 }, }}; else return {{ - {-X, -Y - depth, 0 }, - {-X, -Y - depth, Z }, - {-X, -Y, 0 }, - {-X, -Y, Z }, + { x0, y0 - d, z0 }, + { x0, y0 - d, z1 }, + { x0, y0, z0 }, + { x0, y0, z1 }, }}; } std::unreachable(); } +template<Group_ G, bool IsWest, typename F = float> +constexpr std::array<Vec3_<F>, 4> get_quad(F d) +{ + constexpr auto half_tile = Vec2_<F>(TILE_SIZE2*.5f); + constexpr auto X = half_tile.x(), Y = half_tile.y(), Z = F(TILE_SIZE.z()); + + return get_quadʹ<G, IsWest, F>({ { -X, -Y, 0, }, { X, Y, Z, }, }, d); +} + template<bool IsWest> CutResult<Int>::rect get_wall_rect(local_coords tile) { |