This commit is contained in:
Lera Elvoé 2025-03-02 23:44:58 +03:00
parent 342c98e915
commit e3f195cf71
Signed by: yagich
SSH Key Fingerprint: SHA256:6xjGb6uA7lAVcULa7byPEN//rQ0wPoG+UzYVMfZnbvc
2 changed files with 46 additions and 0 deletions

View File

@ -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

View File

@ -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