diff --git a/res/content/base/scripts/hud.lua b/res/content/base/scripts/hud.lua index 9807e8b2..d85e3201 100644 --- a/res/content/base/scripts/hud.lua +++ b/res/content/base/scripts/hud.lua @@ -1,8 +1,12 @@ +local DROP_FORCE = 8 +local DROP_INIT_VEL = {0, 3, 0} + function on_hud_open() input.add_callback("player.drop", function () local pid = hud.get_player() local pvel = {player.get_vel(pid)} local eid = entity.test() - entity.set_vel(eid, vec3.add(vec3.mul(player.get_dir(pid), {8, 8, 8}), vec3.add(pvel, {0, 3, 0}))) + local throw_force = vec3.mul(player.get_dir(pid), DROP_FORCE) + entity.set_vel(eid, vec3.add(throw_force, vec3.add(pvel, DROP_INIT_VEL))) end) end diff --git a/src/graphics/render/WorldRenderer.cpp b/src/graphics/render/WorldRenderer.cpp index c7722fc9..fdc5d82a 100644 --- a/src/graphics/render/WorldRenderer.cpp +++ b/src/graphics/render/WorldRenderer.cpp @@ -215,8 +215,6 @@ void WorldRenderer::renderBlockSelection(Camera* camera, Shader* linesShader) { ? block->rt.hitboxes[selection.vox.state.rotation] : block->hitboxes; - linesShader->use(); - linesShader->uniformMatrix("u_projview", camera->getProjView()); lineBatch->lineWidth(2.0f); for (auto& hitbox: hitboxes) { const glm::vec3 center = glm::vec3(pos) + hitbox.center(); @@ -226,6 +224,17 @@ void WorldRenderer::renderBlockSelection(Camera* camera, Shader* linesShader) { lineBatch->line(point, point+norm*0.5f, glm::vec4(1.0f, 0.0f, 1.0f, 1.0f)); } } +} + +void WorldRenderer::renderLines(Camera* camera, Shader* linesShader) { + linesShader->use(); + linesShader->uniformMatrix("u_projview", camera->getProjView()); + if (player->selection.vox.id != BLOCK_VOID) { + renderBlockSelection(camera, linesShader); + } + if (player->debug) { + level->entities->renderDebug(*lineBatch); + } lineBatch->render(); } @@ -313,9 +322,9 @@ void WorldRenderer::draw( ctx.setDepthTest(true); ctx.setCullFace(true); renderLevel(ctx, camera, settings); - // Selected block - if (player->selection.vox.id != BLOCK_VOID && hudVisible){ - renderBlockSelection(camera, linesShader); + // Debug lines + if (hudVisible){ + renderLines(camera, linesShader); } } diff --git a/src/graphics/render/WorldRenderer.hpp b/src/graphics/render/WorldRenderer.hpp index af8eeaff..1b58ea3f 100644 --- a/src/graphics/render/WorldRenderer.hpp +++ b/src/graphics/render/WorldRenderer.hpp @@ -48,6 +48,8 @@ class WorldRenderer { /// @param camera active camera /// @param linesShader shader used void renderBlockSelection(Camera* camera, Shader* linesShader); + + void renderLines(Camera* camera, Shader* linesShader); /// @brief Render all debug lines (chunks borders, coord system guides) /// @param context graphics context diff --git a/src/objects/Entities.cpp b/src/objects/Entities.cpp index a608dded..b4218fe9 100644 --- a/src/objects/Entities.cpp +++ b/src/objects/Entities.cpp @@ -5,6 +5,7 @@ #include "../physics/Hitbox.hpp" #include "../physics/PhysicsSolver.hpp" #include "../graphics/render/ModelBatch.hpp" +#include "../graphics/core/LineBatch.hpp" #include "../graphics/core/Model.hpp" #include "../maths/FrustumCulling.hpp" @@ -54,6 +55,14 @@ void Entities::updatePhysics(float delta){ } } +void Entities::renderDebug(LineBatch& batch) { + batch.lineWidth(1.0f); + auto view = registry.view(); + for (auto [entity, transform, hitbox] : view.each()) { + batch.box(hitbox.position, hitbox.halfsize * 2.0f, glm::vec4(1.0f)); + } +} + void Entities::render(Assets* assets, ModelBatch& batch, Frustum& frustum) { auto view = registry.view(); auto model = assets->get("cube"); diff --git a/src/objects/Entities.hpp b/src/objects/Entities.hpp index f51f59bb..431cf98f 100644 --- a/src/objects/Entities.hpp +++ b/src/objects/Entities.hpp @@ -24,6 +24,7 @@ struct Transform { class Level; class Assets; +class LineBatch; class ModelBatch; class Frustum; class Rig; @@ -60,6 +61,8 @@ class Entities { public: Entities(Level* level); void updatePhysics(float delta); + + void renderDebug(LineBatch& batch); void render(Assets* assets, ModelBatch& batch, Frustum& frustum); entityid_t drop(glm::vec3 pos);