Created
October 11, 2012 14:17
-
-
Save boboboa32/3872635 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- We keep a running range (min and max) values of the projection, and then use that as our shadow | |
function project(a, axis) | |
axis = normalize(axis) | |
local min = dot(a.vertices[1],axis) | |
local max = min | |
for i,v in ipairs(a.vertices) do | |
local proj = dot(v, axis) -- projection | |
if proj < min then min = proj end | |
if proj > max then max = proj end | |
end | |
return {min, max} | |
end | |
function contains(n, range) | |
local a, b = range[1], range[2] | |
if b < a then a = b; b = range[1] end | |
return n >= a and n <= b | |
end | |
function overlap(a_, b_) | |
if contains(a_[1], b_) then return true | |
elseif contains(a_[2], b_) then return true | |
elseif contains(b_[1], a_) then return true | |
elseif contains(b_[2], a_) then return true | |
end | |
return false | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment