Pseudo-code for Swept AABB Collision

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

I have objects with limited frames that are aligned along the axis. Boxes of objects can be of different sizes, but they are always rectangular.

I tried and tried to figure out an algorithm to determine if two moving AABB objects would collide for some time, but it’s really hard for me. I read here the question of determining the time intervals when two objects will pass at some point, and I did not have a problem with the visualization, but the implementation of this was a different story. It seems like there are too many exceptions, and it looks like I'm doing it right.

Objects can only move in straight lines (although, obviously, they can change direction, for example, rotate, but they are always on the axis. If they try to turn off the axis, this simply does not work) and are connected to the axis. Their limited boxes don't spin or do anything like that. The speed may vary, but it does not matter, since the point of the method is to determine whether they are in the current state of objects in the "collision course". If you need more information, let me know.

If someone can provide some pseudo code (or real code) that will be great. I read a document called Intersection of convex objects: a method of separating axes , but I did not understand some of its pseudo-codes (what does the Union do)?

Any help is appreciated, thanks.

+3
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;
+1

Source: https://habr.com/ru/post/1757595/


All Articles