所以我想知道,检测AABB与AABB碰撞的最快方法是什么,其中AABB的结构基于最小点和最大点?
使用Javascript:
function Point(x, y) {
this.x = x || 0;
this.y = y || 0;
}
function AABB(min, max) {
this.min = min || new Point();
this.max = max || new Point();
}
AABB.prototype.intersects = function(other) {
???
}
答案 0 :(得分:1)
刚刚发现o_O
这是最快的解决方案:
AABB.prototype.intersects = function(other) {
return !(
this.max.X < other.min.X ||
this.max.Y < other.min.Y ||
this.min.X > other.max.X ||
this.min.Y > other.max.Y
);
}