Win a copy of The Way of the Web Tester: A Beginner's Guide to Automating Tests this week in the Testing forum!

trying to understand this collision algorithm

Nick George
Ranch Hand
Posts: 815
I almost understand this algorithm for axis-aligned bounding box sweep tests:

However I have a few problems:

1) VECTOR u_0(0,0,0);
//first times of overlap along each axis

VECTOR u_1(1,1,1);
//last times of overlap along each axis

These seem to me like they should be reversed. If one imagines box B moving away from box A, all of the tests in the main for loop will fail. Thus, we will get to the return statement, and the max of u_0 will be less than the min of u_1.

2) I'm using the current position rather than the previous position as A and B, because that's what my program is set up to have. I justify this in my mind by saying this just tests if they will collide in the next frame, rather that if they did collide in the previous frame. If frames are 16 millis, it doesn't feel like it'd make much of a difference.

3) This will tell me when the next collision will occur. Is it then my responsibility to say if that will occur in the next frame?

Thanks,
Nick

Jeremy Tartaglia
Ranch Hand
Posts: 62
I'll take a closer look at this tomorrow, but in answer to your first question, that would make sense to me. If B is moving away from A, from A's perspective, all the tests should fail. B and A will never collide. B has to be moving toward A in some aspect (x, y, or z) in order for any collision to possibly occur.

But I might've misunderstood the algorithm.