Skip to content

Instantly share code, notes, and snippets.

@HybridEidolon
Created October 27, 2012 18:05
Show Gist options
  • Save HybridEidolon/3965540 to your computer and use it in GitHub Desktop.
Save HybridEidolon/3965540 to your computer and use it in GitHub Desktop.
minimum translation vector between aabb's
vec_t Col_RectRect(const rectangle_t* a, const rectangle_t* b) {
vec_t ret;
float left, right, top, bottom;
// zero the vector
ret.x = 0;
ret.y = 0;
// axis
left = b->min.x - a->max.x;
right = b->max.x - a->min.x;
bottom = b->min.y - a->max.y;
top = b->max.y - a->min.y;
if (abs(left) > right) {
ret.x = right;
} else {
ret.x = left;
}
if (abs(bottom) > top) {
ret.y = top;
} else {
ret.y = bottom;
}
if (abs(ret.x) <= abs(ret.y)) {
ret.y = 0;
} else {
ret.x = 0;
}
return ret;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment