summary refs log tree commit diff
path: root/src/GFX/Util/Primitives.cpp
diff options
context:
space:
mode:
authorMel <einebeere@gmail.com>2024-02-06 02:09:17 +0100
committerMel <einebeere@gmail.com>2024-02-06 02:09:17 +0100
commitc61e09ce986fa99debea040a7c0ac42749ad8052 (patch)
tree177b39f7f692723cb4ace8392349f3f8f0d2192b /src/GFX/Util/Primitives.cpp
parent091bf9e418ffdcf36e1735ed78d544f3d1b86785 (diff)
downloadmeowcraft-c61e09ce986fa99debea040a7c0ac42749ad8052.tar.zst
meowcraft-c61e09ce986fa99debea040a7c0ac42749ad8052.zip
Render outlines on currently targeted blocks
Diffstat (limited to 'src/GFX/Util/Primitives.cpp')
-rw-r--r--src/GFX/Util/Primitives.cpp26
1 files changed, 25 insertions, 1 deletions
diff --git a/src/GFX/Util/Primitives.cpp b/src/GFX/Util/Primitives.cpp
index 4b44864..daceb79 100644
--- a/src/GFX/Util/Primitives.cpp
+++ b/src/GFX/Util/Primitives.cpp
@@ -1,4 +1,5 @@
 #include "Primitives.hpp"
+#include "../../Math/Grid.hpp"
 
 namespace MC::GFX::Util::Primitives {
 
@@ -104,4 +105,27 @@ BoxPrimitive box(AABB aabb, FaceSet faces) {
     return box;
 }
 
-}
\ No newline at end of file
+LineBoxPrimitive line_box(AABB aabb) {
+    auto [min, max] = aabb;
+
+    auto cube = Math::cube_cell_from_point(min, max - min);
+
+    using P = Vector<3, F32>;
+    decltype(LineBoxPrimitive::positions) positions = {{
+        P(cube.front_top_left()), P(cube.front_top_right()),
+        P(cube.front_bottom_left()), P(cube.front_bottom_right()),
+        P(cube.back_top_left()), P(cube.back_top_right()),
+        P(cube.back_bottom_left()), P(cube.back_bottom_right()),
+    }};
+
+    decltype(LineBoxPrimitive::indices) indices = {{
+        0, 1, 1, 3, 3, 2, 2, 0, // Front
+        4, 5, 5, 7, 7, 6, 6, 4, // Back
+        0, 4, 1, 5, 2, 6, 3, 7, // Sides
+    }};
+
+    // TODO: Allow Primitives to not have normals.
+    return {positions, {{}}, indices};
+}
+
+}