From e3f195cf715b5e7f91c54098dade3d557252c46f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Lera=20Elvo=C3=A9?= <yagich@poto.cafe>
Date: Sun, 2 Mar 2025 23:44:58 +0300
Subject: [PATCH] dang

---
 data/scripts/game.lua       |  8 ++++++++
 data/scripts/types/aabb.lua | 38 +++++++++++++++++++++++++++++++++++++
 2 files changed, 46 insertions(+)
 create mode 100644 data/scripts/types/aabb.lua

diff --git a/data/scripts/game.lua b/data/scripts/game.lua
index 3ea7d45..164da4a 100644
--- a/data/scripts/game.lua
+++ b/data/scripts/game.lua
@@ -2,6 +2,12 @@ util = require "util"
 local player = require "classes.player"
 local Vector3 = require "types.vector3"
 local List = require "types.list"
+-- local AABB = require "types.aabb"
+
+-- local test_aabb = AABB.new(
+--   Vector3(-1, -1, -1),
+--   Vector3(1, 1, 1)
+-- )
 
 local Obj = require "classes.obj"
 
@@ -91,4 +97,6 @@ function game_tick()
   cube.rotation.x = cube.rotation.x + 0.01
   cube.rotation.z = cube.rotation.z + 0.01
   cube:draw()
+  
+  -- test_aabb:draw()
 end
diff --git a/data/scripts/types/aabb.lua b/data/scripts/types/aabb.lua
new file mode 100644
index 0000000..2add9b3
--- /dev/null
+++ b/data/scripts/types/aabb.lua
@@ -0,0 +1,38 @@
+local Vector3 = require "types.vector3"
+
+---@class AABB
+local AABB = {
+  min = Vector3(),
+  max = Vector3(),
+}
+
+setmetatable(AABB, AABB)
+
+AABB.__index = AABB
+
+---@param min vectorlike
+---@param max vectorlike
+---@return AABB
+function AABB.new(min, max)
+  min = min or Vector3()
+  max = max or Vector3()
+  local aabb = {
+    min = min,
+    max = max,
+  }
+
+  return setmetatable(aabb, AABB)
+end
+
+function AABB:draw()
+  -- bottom rectangle
+  draw_line_3d{start = self.min, finish = Vector3(self.max.x, self.min.y, self.min.z)}
+  draw_line_3d{start = self.min, finish = Vector3(self.min.x, self.min.y, self.max.z)}
+  draw_line_3d{start = Vector3(self.max.x, self.min.y, self.max.z), finish = Vector3(self.min.x, self.min.y, self.max.z)}
+
+  -- draw_line_3d{start = self.min, finish = Vector3(self.max.x, self.min.y, self.min.z)}
+  -- draw_line_3d{start = self.min, finish = Vector3(self.min.x, self.max.y, self.min.z)}
+  -- draw_line_3d{start = self.min, finish = Vector3(self.min.x, self.min.y, self.max.z)}
+end
+
+return AABB