3

I think swept means determining if objects will collide at some point, not just whether they are currently colliding, but if I'm wrong tell me.

I have objects with bounded boxes that are aligned on an axis. The boxes of objects can be different sizes, but they are always rectangular.

I've tried and tried to figure out an algorithm to determine if two moving AABB objects will collide at some point, but I am having a really hard time. I read a question on here about determining the time intervals when the two objects will pass at some point, and I didn't have a problem visualizing it, but implementing it was another story. It seems like there are too many exceptions, and it doesn't seem like I am doing it correctly.

The objects are only able to move in straight lines (though obviously they can change direction, e.g. turn around, but they are always on the axis. If they try to turn off the axis then it just doesn't work), and are bound to the axis. Their bounded boxes don't rotate or do anything like that. Velocity can change, but it doesn't matter since the point of the method is to determine whether, given the objects' current state, they are on a "collision course". If you need any more information let me know.

If someone could provide some pseudocode (or real code) that would be great. I read a document called Intersection of Convex Objects: The Method of Separating Axes but I didn't understand some of the pseudocode in it (what does Union mean)?

Any help is appreciated, thanks.

4

1 回答 1

1

当发生碰撞时,盒子会接触到一侧。您可以检查它们是否会接触成对的边(LR、RL、UD、DU)。

如果它可以简化问题,您可以翻译这些框,使第一个框位于原点并且不移动。

类似于以下代码:

dLR = B.L - A.R;
dRL = A.L - B.R;
dUD = B.U - A.D;
dDU = A.U - B.D;

vX = A.xV - B.xV;
vY = A.yV - B.yV;

tLR = dLR / vX;
tRL =-dRL / vX;
tUD = dUD / vY;
tDU =-dDU / vY;

hY = dUD + dDU; //combined height
hX = dLR + dRL;

if((tLR > 0) && (abs(dDU + vY*tLR) < hY)) return true;
if((tRL > 0) && (abs(dUD - vY*tRL) < hY)) return true;
if((tUD > 0) && (abs(dRL + vX*tUD) < hX)) return true;
if((tDU > 0) && (abs(dLR - vX*tDU) < hX)) return true;
return false;
于 2010-08-02T03:41:07.563 回答