From eec6b8e4030fdf766e28df546cda2bc0c01ce51c Mon Sep 17 00:00:00 2001 From: Vsevolod Kremianskii Date: Sat, 15 May 2021 11:45:03 +0700 Subject: [PATCH] Reimplement AABB debugging --- src/engine/graphics/mesh/meshes.cpp | 16 ++++++++-------- src/engine/scene/scenegraph.cpp | 17 +++++++++++++++++ 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/src/engine/graphics/mesh/meshes.cpp b/src/engine/graphics/mesh/meshes.cpp index 14a8b8c7..457f60fd 100644 --- a/src/engine/graphics/mesh/meshes.cpp +++ b/src/engine/graphics/mesh/meshes.cpp @@ -181,14 +181,14 @@ static const VertexAttributes g_cubemapAttributes { 8 * sizeof(float), 0, 3 * si // AABB static const vector g_aabbVertices = { - -0.5f, -0.5f, -0.5f, - -0.5f, -0.5f, 0.5f, - -0.5f, 0.5f, 0.5f, - -0.5f, 0.5f, -0.5f, - 0.5f, 0.5f, 0.5f, - 0.5f, 0.5f, -0.5f, - 0.5f, -0.5f, -0.5f, - 0.5f, -0.5f, 0.5f + -0.5f, -0.5f, 0.0f, + -0.5f, -0.5f, 1.0f, + -0.5f, 0.5f, 1.0f, + -0.5f, 0.5f, 0.0f, + 0.5f, 0.5f, 1.0f, + 0.5f, 0.5f, 0.0f, + 0.5f, -0.5f, 0.0f, + 0.5f, -0.5f, 1.0f }; static const vector g_aabbIndices = { diff --git a/src/engine/scene/scenegraph.cpp b/src/engine/scene/scenegraph.cpp index dadfd3bc..03c727ad 100644 --- a/src/engine/scene/scenegraph.cpp +++ b/src/engine/scene/scenegraph.cpp @@ -19,6 +19,8 @@ #include +#include "glm/gtx/transform.hpp" + #include "../graphics/mesh/meshes.h" #include "node/cameranode.h" @@ -38,6 +40,8 @@ namespace scene { static constexpr float kMaxGrassDistance = 16.0f; +static const bool g_debugAABB = false; + SceneGraph::SceneGraph(const GraphicsOptions &opts) : _opts(opts) { } @@ -312,6 +316,19 @@ void SceneGraph::draw(bool shadowPass) { mesh->drawSingle(false); } + if (g_debugAABB) { + for (auto &root : _roots) { + glm::mat4 transform(root->absoluteTransform()); + transform *= glm::scale(root->aabb().getSize()); + + ShaderUniforms uniforms(_uniformsPrototype); + uniforms.combined.general.model = move(transform); + + Shaders::instance().activate(ShaderProgram::SimpleColor, uniforms); + Meshes::instance().getAABB()->draw(); + } + } + // Render transparent meshes for (auto &mesh : _transparentMeshes) { mesh->drawSingle(false);