diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2024-09-09 14:52:02 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2024-09-20 16:08:47 +0200 |
commit | ff19c8dd4acba3a390aea358f12b2a4e9676dfb6 (patch) | |
tree | 96a499b822e9cb0ea70a76816b0f3d397e2e336e | |
parent | 40868868dd7ba77099637a23140bf90f9148c34d (diff) |
src: add exact calculations for wall hole rendering
-rw-r--r-- | src/tile-bbox.hpp | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/src/tile-bbox.hpp b/src/tile-bbox.hpp index 755004d2..6d2228b1 100644 --- a/src/tile-bbox.hpp +++ b/src/tile-bbox.hpp @@ -8,11 +8,12 @@ namespace floormat { template<typename T = float> -constexpr Vector2 tile_start(size_t k) +constexpr VectorTypeFor<2, T> tile_start(size_t k) { - constexpr auto half_tile = VectorTypeFor<2,T>(tile_size_xy/2); + using Vec2 = VectorTypeFor<2,T>; + constexpr auto half_tile = Vec2{tile_size_xy/2}; const local_coords coord{k}; - return TILE_SIZE2 * VectorTypeFor<2,T>(coord) - half_tile; + return Vec2(TILE_SIZE2) * Vec2(coord) - half_tile; } constexpr Pair<Vector2i, Vector2i> scenery_tile(local_coords local, Vector2b offset, Vector2b bbox_offset, Vector2ub bbox_size) @@ -31,24 +32,27 @@ constexpr Pair<VectorTypeFor<2,T>, VectorTypeFor<2,T>> whole_tile(size_t k) } template<typename T = float> -constexpr Pair<VectorTypeFor<2,T>, VectorTypeFor<2,T>> wall_north(size_t k, float wall_depth) +constexpr Pair<VectorTypeFor<2,T>, VectorTypeFor<2,T>> wall_north(size_t k, T wall_depth) { - auto min = tile_start<T>(k) - VectorTypeFor<2,T>{0, wall_depth}; - return { min, min + VectorTypeFor<2,T>{TILE_SIZE2.x(), wall_depth} }; + using Vec2 = VectorTypeFor<2,T>; + auto min = tile_start<T>(k) - Vec2{0, wall_depth}; + return { min, min + Vec2{tile_size_xy, wall_depth} }; } template<typename T = float> -constexpr Pair<VectorTypeFor<2,T>, VectorTypeFor<2,T>> wall_west(size_t k, float wall_depth) +constexpr Pair<VectorTypeFor<2,T>, VectorTypeFor<2,T>> wall_west(size_t k, T wall_depth) { - auto min = tile_start<T>(k) - VectorTypeFor<2,T>{wall_depth, 0}; - return { min, min + VectorTypeFor<2,T>{wall_depth, TILE_SIZE2.y()} }; + using Vec2 = VectorTypeFor<2,T>; + auto min = tile_start<T>(k) - Vec2{wall_depth, 0}; + return { min, min + Vec2{wall_depth, tile_size_xy} }; } template<typename T = float> -constexpr Pair<VectorTypeFor<2,T>, VectorTypeFor<2,T>> wall_pillar(size_t k, float wall_depth) +constexpr Pair<VectorTypeFor<2,T>, VectorTypeFor<2,T>> wall_pillar(size_t k, T wall_depth) { - auto min = tile_start<T>(k) - VectorTypeFor<2,T>{wall_depth, 0}; - return { min - VectorTypeFor<2,T>{0, wall_depth}, min + VectorTypeFor<2,T>{wall_depth, TILE_SIZE2.y()} }; + using Vec2 = VectorTypeFor<2,T>; + auto min = tile_start<T>(k) - Vec2{wall_depth, 0}; + return { min - Vec2{0, wall_depth}, min + Vec2{wall_depth, tile_size_xy} }; } } // namespace floormat |