diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2024-01-10 23:44:34 +0100 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2024-01-11 00:13:19 +0100 |
commit | 8858725782129203b14b214b57d6bb8a9adff37c (patch) | |
tree | 203bb49c0d09c40f37dff14b6c12761a56d53262 | |
parent | c70fcc94727fa21dd5024031610fb98858de4716 (diff) |
fix wall bounding box
-rw-r--r-- | editor/draw.cpp | 2 | ||||
-rw-r--r-- | src/chunk-collision.cpp | 4 | ||||
-rw-r--r-- | src/tile-bbox.hpp | 16 |
3 files changed, 10 insertions, 12 deletions
diff --git a/editor/draw.cpp b/editor/draw.cpp index 445c1866..c9f82cdd 100644 --- a/editor/draw.cpp +++ b/editor/draw.cpp @@ -130,8 +130,10 @@ void app::draw_collision_boxes() const auto* rtree = c.rtree(); rtree->Search(min2f, max2f, [&](object_id data, const rect_type& rect) { [[maybe_unused]] auto x = std::bit_cast<collision_data>(data); +#if 1 if (x.tag == (uint64_t)collision_type::geometry) return true; +#endif Vector2 start(rect.m_min[0], rect.m_min[1]), end(rect.m_max[0], rect.m_max[1]); auto size = (end - start); auto center = Vector3(start + size*.5f, 0.f); diff --git a/src/chunk-collision.cpp b/src/chunk-collision.cpp index d95a6a9b..4f94df6b 100644 --- a/src/chunk-collision.cpp +++ b/src/chunk-collision.cpp @@ -53,13 +53,13 @@ void chunk::ensure_passability() noexcept auto tile = operator[](i); if (const auto* atlas = tile.wall_north_atlas().get()) { - auto [min, max] = wall_north(i); + auto [min, max] = wall_north(i, atlas->info().depth); auto id = make_id(collision_type::geometry, atlas->info().passability, TILE_COUNT+i+1); _rtree.Insert(min.data(), max.data(), id); } if (const auto* atlas = tile.wall_west_atlas().get()) { - auto [min, max] = wall_west(i); + auto [min, max] = wall_west(i, atlas->info().depth); auto id = make_id(collision_type::geometry, atlas->info().passability, TILE_COUNT*2+i+1); _rtree.Insert(min.data(), max.data(), id); } diff --git a/src/tile-bbox.hpp b/src/tile-bbox.hpp index ba61f0bf..7f8a05b8 100644 --- a/src/tile-bbox.hpp +++ b/src/tile-bbox.hpp @@ -7,10 +7,6 @@ namespace floormat { -namespace { -constexpr float wall_depth = 8, wall_depth_2 = wall_depth*.5f; -} // namespace - constexpr Vector2 tile_start(size_t k) { constexpr auto half_tile = Vector2(TILE_SIZE2)/2; @@ -32,16 +28,16 @@ constexpr Pair<Vector2, Vector2> whole_tile(size_t k) return { min, min + TILE_SIZE2, }; } -constexpr Pair<Vector2, Vector2> wall_north(size_t k) +constexpr Pair<Vector2, Vector2> wall_north(size_t k, float wall_depth) { - auto min = tile_start(k) - Vector2(0, wall_depth_2); - return { min, min + Vector2(TILE_SIZE2[0], wall_depth), }; + auto min = tile_start(k) - Vector2{0, wall_depth}; + return { min, min + Vector2{TILE_SIZE2.x(), wall_depth}, }; } -constexpr Pair<Vector2, Vector2> wall_west(size_t k) +constexpr Pair<Vector2, Vector2> wall_west(size_t k, float wall_depth) { - auto min = tile_start(k) - Vector2(wall_depth_2, 0); - return { min, min + Vector2(wall_depth, TILE_SIZE2[1]), }; + auto min = tile_start(k) - Vector2{wall_depth, 0}; + return { min, min + Vector2{wall_depth, TILE_SIZE2.y()}, }; } } // namespace floormat |