diff options
author | Seth Traverse <technotraverse@gmail.com> | 2021-04-20 10:23:31 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-20 19:23:31 +0200 |
commit | 16e5b39e1dbe503684effb11f4b87a641c3e43e6 (patch) | |
tree | 50d8ba701784ecb2d9d235bd97e20200cef1fb40 /src/client/hud.cpp | |
parent | 0077982fb78a8ed39a90da03c0898d12583fed64 (diff) | |
download | minetest-16e5b39e1dbe503684effb11f4b87a641c3e43e6.tar.gz minetest-16e5b39e1dbe503684effb11f4b87a641c3e43e6.tar.bz2 minetest-16e5b39e1dbe503684effb11f4b87a641c3e43e6.zip |
Add a key to toggle map block bounds (#11172)
It's often useful to know where the map block boundaries are for doing server admin work and the like.
Adds three modes: single mapblock, range of 5, and disabled.
Diffstat (limited to 'src/client/hud.cpp')
-rw-r--r-- | src/client/hud.cpp | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/src/client/hud.cpp b/src/client/hud.cpp index 6d332490c..c58c7e822 100644 --- a/src/client/hud.cpp +++ b/src/client/hud.cpp @@ -862,6 +862,54 @@ void Hud::drawSelectionMesh() } } +void Hud::toggleBlockBounds() +{ + m_block_bounds_mode = static_cast<BlockBoundsMode>(m_block_bounds_mode + 1); + + if (m_block_bounds_mode >= BLOCK_BOUNDS_MAX) { + m_block_bounds_mode = BLOCK_BOUNDS_OFF; + } +} + +void Hud::drawBlockBounds() +{ + if (m_block_bounds_mode == BLOCK_BOUNDS_OFF) { + return; + } + + video::SMaterial old_material = driver->getMaterial2D(); + driver->setMaterial(m_selection_material); + + v3s16 pos = player->getStandingNodePos(); + + v3s16 blockPos( + floorf((float) pos.X / MAP_BLOCKSIZE), + floorf((float) pos.Y / MAP_BLOCKSIZE), + floorf((float) pos.Z / MAP_BLOCKSIZE) + ); + + v3f offset = intToFloat(client->getCamera()->getOffset(), BS); + + s8 radius = m_block_bounds_mode == BLOCK_BOUNDS_ALL ? 2 : 0; + + v3f halfNode = v3f(BS, BS, BS) / 2.0f; + + for (s8 x = -radius; x <= radius; x++) + for (s8 y = -radius; y <= radius; y++) + for (s8 z = -radius; z <= radius; z++) { + v3s16 blockOffset(x, y, z); + + aabb3f box( + intToFloat((blockPos + blockOffset) * MAP_BLOCKSIZE, BS) - offset - halfNode, + intToFloat(((blockPos + blockOffset) * MAP_BLOCKSIZE) + (MAP_BLOCKSIZE - 1), BS) - offset + halfNode + ); + + driver->draw3DBox(box, video::SColor(255, 255, 0, 0)); + } + + driver->setMaterial(old_material); +} + void Hud::updateSelectionMesh(const v3s16 &camera_offset) { m_camera_offset = camera_offset; |