I found a rather nice & fast algorithm Minkowski Sums . It has been used in RiverCityRansomUnderground game.
I translated it into Lua. Now testing
Upd: I've hecked up the vectors stuff....
Code: Select all
function MinkowskiCheckCollision(ax, ay, aw, ah, bx, by, bw, bh)
local mt = ay - by - bh
local mb = ay + ah - by
local ml = ax - bx - bw
local mr = ax + aw - bx
local px, py = 0, 0
if (mr >= 0 and ml <= 0 and mt >= 0 and mb <= 0) then
local min = -100000
if (math.abs(ml) < min) then
min = math.abs(ml)
--penetration = glm(ml, 0)
px = ml
end
if (math.abs(mr) < min) then
min = math.abs(mr)
--penetration = glm(mr, 0)
px = mr
end
if (math.abs(mt) < min) then
min = math.abs(mt)
--penetration = glm(0, mt)
py = mt
end
if (math.abs(mb) < min) then
min = math.abs(mb)
--penetration = glm(0, mb)
py = mb
end
return true, px, py
end
return false, px, py
end
http://spaderthomas.com/post/2018/08/25/minkowski/
(there is a source code as well https://blog.hamaluik.ca/posts/simple-a ... ifference/ )
I'm migrating from the Bump and HC collision detection libs. (they are a bottle neck in my project. they take ~40% of CPU)
So this stuff might be a bingo.
----
Off-topic: Also found Differ - A Separating Axis Theorom collision library for haxe
https://github.com/snowkit/differ