add debug hitboxes render
This commit is contained in:
parent
ee7328dcad
commit
f3c5afa1ab
@ -1,8 +1,12 @@
|
|||||||
|
local DROP_FORCE = 8
|
||||||
|
local DROP_INIT_VEL = {0, 3, 0}
|
||||||
|
|
||||||
function on_hud_open()
|
function on_hud_open()
|
||||||
input.add_callback("player.drop", function ()
|
input.add_callback("player.drop", function ()
|
||||||
local pid = hud.get_player()
|
local pid = hud.get_player()
|
||||||
local pvel = {player.get_vel(pid)}
|
local pvel = {player.get_vel(pid)}
|
||||||
local eid = entity.test()
|
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)
|
||||||
end
|
end
|
||||||
|
|||||||
@ -215,8 +215,6 @@ void WorldRenderer::renderBlockSelection(Camera* camera, Shader* linesShader) {
|
|||||||
? block->rt.hitboxes[selection.vox.state.rotation]
|
? block->rt.hitboxes[selection.vox.state.rotation]
|
||||||
: block->hitboxes;
|
: block->hitboxes;
|
||||||
|
|
||||||
linesShader->use();
|
|
||||||
linesShader->uniformMatrix("u_projview", camera->getProjView());
|
|
||||||
lineBatch->lineWidth(2.0f);
|
lineBatch->lineWidth(2.0f);
|
||||||
for (auto& hitbox: hitboxes) {
|
for (auto& hitbox: hitboxes) {
|
||||||
const glm::vec3 center = glm::vec3(pos) + hitbox.center();
|
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));
|
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();
|
lineBatch->render();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -313,9 +322,9 @@ void WorldRenderer::draw(
|
|||||||
ctx.setDepthTest(true);
|
ctx.setDepthTest(true);
|
||||||
ctx.setCullFace(true);
|
ctx.setCullFace(true);
|
||||||
renderLevel(ctx, camera, settings);
|
renderLevel(ctx, camera, settings);
|
||||||
// Selected block
|
// Debug lines
|
||||||
if (player->selection.vox.id != BLOCK_VOID && hudVisible){
|
if (hudVisible){
|
||||||
renderBlockSelection(camera, linesShader);
|
renderLines(camera, linesShader);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -49,6 +49,8 @@ class WorldRenderer {
|
|||||||
/// @param linesShader shader used
|
/// @param linesShader shader used
|
||||||
void renderBlockSelection(Camera* camera, Shader* linesShader);
|
void renderBlockSelection(Camera* camera, Shader* linesShader);
|
||||||
|
|
||||||
|
void renderLines(Camera* camera, Shader* linesShader);
|
||||||
|
|
||||||
/// @brief Render all debug lines (chunks borders, coord system guides)
|
/// @brief Render all debug lines (chunks borders, coord system guides)
|
||||||
/// @param context graphics context
|
/// @param context graphics context
|
||||||
/// @param camera active camera
|
/// @param camera active camera
|
||||||
|
|||||||
@ -5,6 +5,7 @@
|
|||||||
#include "../physics/Hitbox.hpp"
|
#include "../physics/Hitbox.hpp"
|
||||||
#include "../physics/PhysicsSolver.hpp"
|
#include "../physics/PhysicsSolver.hpp"
|
||||||
#include "../graphics/render/ModelBatch.hpp"
|
#include "../graphics/render/ModelBatch.hpp"
|
||||||
|
#include "../graphics/core/LineBatch.hpp"
|
||||||
#include "../graphics/core/Model.hpp"
|
#include "../graphics/core/Model.hpp"
|
||||||
#include "../maths/FrustumCulling.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<Transform, Hitbox>();
|
||||||
|
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) {
|
void Entities::render(Assets* assets, ModelBatch& batch, Frustum& frustum) {
|
||||||
auto view = registry.view<Transform>();
|
auto view = registry.view<Transform>();
|
||||||
auto model = assets->get<model::Model>("cube");
|
auto model = assets->get<model::Model>("cube");
|
||||||
|
|||||||
@ -24,6 +24,7 @@ struct Transform {
|
|||||||
|
|
||||||
class Level;
|
class Level;
|
||||||
class Assets;
|
class Assets;
|
||||||
|
class LineBatch;
|
||||||
class ModelBatch;
|
class ModelBatch;
|
||||||
class Frustum;
|
class Frustum;
|
||||||
class Rig;
|
class Rig;
|
||||||
@ -60,6 +61,8 @@ class Entities {
|
|||||||
public:
|
public:
|
||||||
Entities(Level* level);
|
Entities(Level* level);
|
||||||
void updatePhysics(float delta);
|
void updatePhysics(float delta);
|
||||||
|
|
||||||
|
void renderDebug(LineBatch& batch);
|
||||||
void render(Assets* assets, ModelBatch& batch, Frustum& frustum);
|
void render(Assets* assets, ModelBatch& batch, Frustum& frustum);
|
||||||
|
|
||||||
entityid_t drop(glm::vec3 pos);
|
entityid_t drop(glm::vec3 pos);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user