mirror of
https://github.com/1bardesign/batteries.git
synced 2024-11-22 14:14:36 +00:00
clarified position/halfsize for aabbs and provided conversion functions from xywh to pos/hs representation
closes #60
This commit is contained in:
parent
49df9d9743
commit
84d4e39622
@ -264,6 +264,13 @@ end
|
|||||||
|
|
||||||
------------------------------------------------------------------------------
|
------------------------------------------------------------------------------
|
||||||
-- axis aligned bounding boxes
|
-- axis aligned bounding boxes
|
||||||
|
--
|
||||||
|
-- pos is the centre position of the box
|
||||||
|
-- hs is the half-size of the box
|
||||||
|
-- eg for a 10x8 box, vec2(5, 4)
|
||||||
|
--
|
||||||
|
-- we use half-sizes to keep these routines as fast as possible
|
||||||
|
-- see intersect.rect_to_aabb for conversion from topleft corner and size
|
||||||
|
|
||||||
--return true on overlap, false otherwise
|
--return true on overlap, false otherwise
|
||||||
function intersect.aabb_point_overlap(pos, hs, v)
|
function intersect.aabb_point_overlap(pos, hs, v)
|
||||||
@ -396,6 +403,18 @@ function intersect.aabb_circle_collide(a_pos, a_hs, b_pos, b_rad, into)
|
|||||||
return result
|
return result
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--convert raw x, y, w, h rectangle components to aabb vectors
|
||||||
|
function intersect.rect_raw_to_aabb(x, y, w, h)
|
||||||
|
local hs = vec2(w, h):scalar_mul_inplace(0.5)
|
||||||
|
local pos = vec2(x, y):vector_add_inplace(hs)
|
||||||
|
return pos, hs
|
||||||
|
end
|
||||||
|
|
||||||
|
--convert (x, y), (w, h) rectangle vectors to aabb vectors
|
||||||
|
function intersect.rect_to_aabb(pos, size)
|
||||||
|
return intersect.rect_raw_to_aabb(pos.x, pos.y, size.x, size.y)
|
||||||
|
end
|
||||||
|
|
||||||
--check if a point is in a polygon
|
--check if a point is in a polygon
|
||||||
--point is the point to test
|
--point is the point to test
|
||||||
--poly is a list of points in order
|
--poly is a list of points in order
|
||||||
|
Loading…
Reference in New Issue
Block a user