new aabb constructor
This commit is contained in:
parent
1433aa8e40
commit
91c2e1bce1
@ -5,7 +5,7 @@ local List = require "types.list"
|
|||||||
local AABB = require "types.aabb"
|
local AABB = require "types.aabb"
|
||||||
|
|
||||||
local test_aabb = AABB.new(
|
local test_aabb = AABB.new(
|
||||||
Vector3(-1, -1, -1),
|
Vector3(),
|
||||||
Vector3(1, 2, 1)
|
Vector3(1, 2, 1)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@ local Vector3 = require "types.vector3"
|
|||||||
---@class AABB
|
---@class AABB
|
||||||
local AABB = {
|
local AABB = {
|
||||||
min = Vector3(),
|
min = Vector3(),
|
||||||
max = Vector3(),
|
size = Vector3(),
|
||||||
}
|
}
|
||||||
|
|
||||||
local RED = {
|
local RED = {
|
||||||
@ -17,48 +17,52 @@ setmetatable(AABB, AABB)
|
|||||||
|
|
||||||
AABB.__index = AABB
|
AABB.__index = AABB
|
||||||
|
|
||||||
---@param min vectorlike
|
---@param position Vector3
|
||||||
---@param max vectorlike
|
---@param size Vector3
|
||||||
---@return AABB
|
---@return AABB
|
||||||
function AABB.new(min, max)
|
function AABB.new(position, size)
|
||||||
min = min or Vector3()
|
position = position or Vector3()
|
||||||
max = max or Vector3()
|
size = size or Vector3(1, 1, 1)
|
||||||
local aabb = {
|
local aabb = {
|
||||||
min = min,
|
min = position,
|
||||||
max = max,
|
size = size,
|
||||||
}
|
}
|
||||||
|
|
||||||
return setmetatable(aabb, AABB)
|
return setmetatable(aabb, AABB)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function AABB:get_max()
|
||||||
|
return self.min + self.size
|
||||||
|
end
|
||||||
|
|
||||||
function AABB:draw()
|
function AABB:draw()
|
||||||
|
local max = self:get_max()
|
||||||
-- bottom rectangle
|
-- 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(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 = self.min, finish = Vector3(self.min.x, self.min.y, 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 = Vector3(max.x, self.min.y, max.z), finish = Vector3(self.min.x, self.min.y, max.z)}
|
||||||
draw_line_3d{start = Vector3(self.max.x, self.min.y, self.max.z), finish = Vector3(self.max.x, self.min.y, self.min.z)}
|
draw_line_3d{start = Vector3(max.x, self.min.y, max.z), finish = Vector3(max.x, self.min.y, self.min.z)}
|
||||||
-- bottom rectangle diagonal
|
-- bottom rectangle diagonal
|
||||||
draw_line_3d{start = self.min, finish = Vector3(self.max.x, self.min.y, self.max.z), color = RED}
|
draw_line_3d{start = self.min, finish = Vector3(max.x, self.min.y, max.z), color = RED}
|
||||||
-- top rectangle
|
-- top rectangle
|
||||||
draw_line_3d{start = Vector3(self.min.x, self.max.y, self.min.z), finish = Vector3(self.max.x, self.max.y, self.min.z)}
|
draw_line_3d{start = Vector3(self.min.x, max.y, self.min.z), finish = Vector3(max.x, max.y, self.min.z)}
|
||||||
draw_line_3d{start = Vector3(self.min.x, self.max.y, self.min.z), finish = Vector3(self.min.x, self.max.y, self.max.z)}
|
draw_line_3d{start = Vector3(self.min.x, max.y, self.min.z), finish = Vector3(self.min.x, max.y, max.z)}
|
||||||
draw_line_3d{start = Vector3(self.max.x, self.max.y, self.max.z), finish = Vector3(self.min.x, self.max.y, self.max.z)}
|
draw_line_3d{start = Vector3(max.x, max.y, max.z), finish = Vector3(self.min.x, max.y, max.z)}
|
||||||
draw_line_3d{start = Vector3(self.max.x, self.max.y, self.max.z), finish = Vector3(self.max.x, self.max.y, self.min.z)}
|
draw_line_3d{start = Vector3(max.x, max.y, max.z), finish = Vector3(max.x, max.y, self.min.z)}
|
||||||
-- top rectangle diagonal
|
-- top rectangle diagonal
|
||||||
draw_line_3d{start = Vector3(self.max.x, self.max.y, self.max.z), finish = Vector3(self.min.x, self.max.y, self.min.z), color = RED}
|
draw_line_3d{start = Vector3(max.x, max.y, max.z), finish = Vector3(self.min.x, max.y, self.min.z), color = RED}
|
||||||
-- hull
|
-- hull
|
||||||
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, max.y, self.min.z)}
|
||||||
draw_line_3d{start = self.min, finish = Vector3(self.max.x, self.max.y, self.min.z), color = RED}
|
draw_line_3d{start = self.min, finish = Vector3(max.x, max.y, self.min.z), color = RED}
|
||||||
|
|
||||||
draw_line_3d{start = Vector3(self.max.x, self.min.y, self.min.z), finish = Vector3(self.max.x, self.max.y, self.min.z)}
|
draw_line_3d{start = Vector3(max.x, self.min.y, self.min.z), finish = Vector3(max.x, max.y, self.min.z)}
|
||||||
draw_line_3d{start = Vector3(self.max.x, self.min.y, self.min.z), finish = Vector3(self.max.x, self.max.y, self.max.z), color = RED}
|
draw_line_3d{start = Vector3(max.x, self.min.y, self.min.z), finish = Vector3(max.x, max.y, max.z), color = RED}
|
||||||
|
|
||||||
draw_line_3d{start = Vector3(self.max.x, self.min.y, self.max.z), finish = Vector3(self.max.x, self.max.y, self.max.z)}
|
draw_line_3d{start = Vector3(max.x, self.min.y, max.z), finish = Vector3(max.x, max.y, max.z)}
|
||||||
draw_line_3d{start = Vector3(self.max.x, self.min.y, self.max.z), finish = Vector3(self.min.x, self.max.y, self.max.z), color = RED}
|
draw_line_3d{start = Vector3(max.x, self.min.y, max.z), finish = Vector3(self.min.x, max.y, max.z), color = RED}
|
||||||
|
|
||||||
draw_line_3d{start = Vector3(self.min.x, self.min.y, self.max.z), finish = Vector3(self.min.x, self.max.y, self.max.z)}
|
|
||||||
draw_line_3d{start = Vector3(self.min.x, self.min.y, self.max.z), finish = Vector3(self.min.x, self.max.y, self.min.z), color = RED}
|
|
||||||
|
|
||||||
|
draw_line_3d{start = Vector3(self.min.x, self.min.y, max.z), finish = Vector3(self.min.x, max.y, max.z)}
|
||||||
|
draw_line_3d{start = Vector3(self.min.x, self.min.y, max.z), finish = Vector3(self.min.x, max.y, self.min.z), color = RED}
|
||||||
end
|
end
|
||||||
|
|
||||||
return AABB
|
return AABB
|
||||||
|
Loading…
Reference in New Issue
Block a user