#include "BlockMesh.hpp"
#include "EntityMesh.hpp"
-#include "OutlineMesh.hpp"
+#include "PrimitiveMesh.hpp"
#include "SkyBoxMesh.hpp"
#include "SpriteMesh.hpp"
+#include "../geometry/primitive.hpp"
+
#include <algorithm>
#include <iostream>
}
-void OutlineMesh::Update(const Buffer &buf) noexcept {
+void PrimitiveMesh::Buffer::FillRect(
+ float w, float h,
+ const glm::vec4 &color,
+ const glm::vec2 &pivot
+) {
+ Clear();
+ Reserve(4, 6);
+
+ vertices.emplace_back( -pivot.x, -pivot.y, 0.0f);
+ vertices.emplace_back(w-pivot.x, -pivot.y, 0.0f);
+ vertices.emplace_back( -pivot.x, h-pivot.y, 0.0f);
+ vertices.emplace_back(w-pivot.x, h-pivot.y, 0.0f);
+
+ colors.resize(4, color);
+
+ 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
if (buf.colors.size() < buf.vertices.size()) {
- std::cerr << "OutlineMesh: not enough colors!" << std::endl;
+ std::cerr << "PrimitiveMesh: not enough colors!" << std::endl;
}
#endif
}
-void OutlineMesh::Draw() noexcept {
+void PrimitiveMesh::DrawLines() noexcept {
glEnable(GL_LINE_SMOOTH);
glLineWidth(2.0f);
vao.DrawLineElements();
}
+void PrimitiveMesh::DrawTriangles() noexcept {
+ vao.DrawTriangleElements();
+}
+
void SkyBoxMesh::LoadUnitBox() {
Buffer buffer;