#include "SkyBoxMesh.hpp"
#include "SpriteMesh.hpp"
+#include "../model/geometry.hpp"
+
#include <algorithm>
#include <iostream>
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
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();
}
}