I was reading this tutorial on swept AABB collision detection, and I was confused by this piece of code:
// find the earliest/latest times of collision
float entryTime = std::max(xEntry, yEntry);
float exitTime = std::min(xExit, yExit);
The tutorial says this about this code:
entryTime
will tell use when the collision first occurred andexitTime
will tell us when it exited the object from the other side. This can be useful for certain effects, but at the moment, we just need it to calculate if a collision occurred at all.
So if entryTime
is supposed to be the first time a collision occured, then why is max
being used to determine the first time of collision? Shouldn't min
be used instead? If max
is used, then the highest value will be returned. The highest value would be the time of the last collision. Obviously this must be the correct way of doing this, but I'm not understanding it. If you are trying to find the first axis to collide, it would seem intuitive that you use min
.