]> git.localhorst.tv Git - blank.git/commitdiff
render entity bounds in debug mode
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Thu, 29 Oct 2015 15:05:01 +0000 (16:05 +0100)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Thu, 29 Oct 2015 15:06:32 +0000 (16:06 +0100)
src/client/client.cpp
src/graphics/PrimitiveMesh.hpp
src/graphics/mesh.cpp
src/standalone/MasterState.cpp
src/world/World.hpp
src/world/world.cpp

index 8bd0ae3db1a6c76d7546cd568d823e2ef616f709..5a34976358d8ee74cc4826b464a7d9ff9668a8e6 100644 (file)
@@ -193,6 +193,9 @@ void InteractiveState::Render(Viewport &viewport) {
        if (master.GetConfig().video.world) {
                chunk_renderer.Render(viewport);
                world.Render(viewport);
+               if (master.GetConfig().video.debug) {
+                       world.RenderDebug(viewport);
+               }
                sky.Render(viewport);
        }
        hud.Render(viewport);
index 1aa3cce58acf417e6605fe82f99c2d473845ed1c..013bf37bde34175c57b0d13c773fa11334eb3cda 100644 (file)
@@ -10,6 +10,8 @@
 
 namespace blank {
 
+struct AABB;
+
 class PrimitiveMesh {
 
 public:
@@ -52,6 +54,11 @@ public:
                        const glm::vec2 &pivot = glm::vec2(0.0f)
                );
 
+               void OutlineBox(
+                       const AABB &,
+                       const glm::vec4 &color = glm::vec4(0.0f)
+               );
+
        };
 
        using VAO = VertexArray<ATTRIB_COUNT>;
index 3aa631eb77e5e266f156d9516e75760ed92f5c28..4a63d99c8f56a2f87612e4dd83748abe90324971 100644 (file)
@@ -4,6 +4,8 @@
 #include "SkyBoxMesh.hpp"
 #include "SpriteMesh.hpp"
 
+#include "../model/geometry.hpp"
+
 #include <algorithm>
 #include <iostream>
 
@@ -90,6 +92,28 @@ void PrimitiveMesh::Buffer::FillRect(
        indices.assign({ 0, 2, 1, 1, 2, 3 });
 }
 
+void PrimitiveMesh::Buffer::OutlineBox(const AABB &box, const glm::vec4 &color) {
+       Clear();
+       Reserve(8, 24);
+
+       vertices.emplace_back(box.min.x, box.min.y, box.min.z);
+       vertices.emplace_back(box.min.x, box.min.y, box.max.z);
+       vertices.emplace_back(box.min.x, box.max.y, box.min.z);
+       vertices.emplace_back(box.min.x, box.max.y, box.max.z);
+       vertices.emplace_back(box.max.x, box.min.y, box.min.z);
+       vertices.emplace_back(box.max.x, box.min.y, box.max.z);
+       vertices.emplace_back(box.max.x, box.max.y, box.min.z);
+       vertices.emplace_back(box.max.x, box.max.y, box.max.z);
+
+       colors.resize(8, color);
+
+       indices.assign({
+               0, 1, 1, 3, 3, 2, 2, 0, // left
+               4, 5, 5, 7, 7, 6, 6, 4, // right
+               0, 4, 1, 5, 3, 7, 2, 6, // others
+       });
+}
+
 
 void PrimitiveMesh::Update(const Buffer &buf) noexcept {
 #ifndef NDEBUG
index 71117e29a4e4b3232a91105afc29bc6949e7b362..e802703d85908779fd4dd2f4dc0a298d4c239ae6 100644 (file)
@@ -162,6 +162,9 @@ void MasterState::Render(Viewport &viewport) {
        if (config.video.world) {
                chunk_renderer.Render(viewport);
                world.Render(viewport);
+               if (config.video.debug) {
+                       world.RenderDebug(viewport);
+               }
                sky.Render(viewport);
        }
        hud.Render(viewport);
index e29474e99f47af5e164943a4965fd896cbc2ee17..7ee5f4306a228260f172d594c8776056020fcb6d 100644 (file)
@@ -101,6 +101,7 @@ public:
        void Update(Entity &, float dt);
 
        void Render(Viewport &);
+       void RenderDebug(Viewport &);
 
 private:
        using EntityHandle = std::list<Entity>::iterator;
index 3f5740e21f75d8755d84003ef8882874c642828c..f472da94f2f20a46cfe9d6a1f16fb4c0fbe629e7 100644 (file)
@@ -666,7 +666,27 @@ void World::Render(Viewport &viewport) {
        entity_prog.SetFogDensity(fog_density);
 
        for (Entity &entity : entities) {
-               entity.Render(entity.Transform(players.front().GetEntity().ChunkCoords()), entity_prog);
+               glm::mat4 M(entity.Transform(players.front().GetEntity().ChunkCoords()));
+               if (!CullTest(entity.Bounds(), entity_prog.GetVP() * M)) {
+                       entity.Render(M, entity_prog);
+               }
+       }
+}
+
+namespace {
+
+PrimitiveMesh::Buffer debug_buf;
+
+}
+
+void World::RenderDebug(Viewport &viewport) {
+       PrimitiveMesh debug_mesh;
+       PlainColor &prog = viewport.WorldColorProgram();
+       for (const Entity &entity : entities) {
+               debug_buf.OutlineBox(entity.Bounds(), glm::vec4(1.0f, 0.0f, 0.0f, 1.0f));
+               debug_mesh.Update(debug_buf);
+               prog.SetM(entity.Transform(players.front().GetEntity().ChunkCoords()));
+               debug_mesh.DrawLines();
        }
 }