I am trying to calculate the exact collision time of two axis-aligned bounding boxes (aabb) as fast as possible (in the sense of CPU time).
- I have all the required information (aabb min, max, center, etc., velocity vector, and so on)
- My aabbs are not rotating, so they have linear velocity
- The aabbs can be both moving, only one of them might be moving, or they both might be steady
My current approach creates lines from one of the boxes’ corners and checks the collision among the planes of the other box (you can see the algorithm below); however it takes 6 times longer than I can afford. So, I am trying to find a faster algorithm; however, I couldn’t have managed, yet.
My current “slow” algorithm:
- Add velocity of Aaabb to Baabb and assume Aaabb is steady and Baabb is moving
- Calculate the corner positions of Baabb
- For each corner of Baabb, perform the line-plane intersection with Aaabb’s each 6 planes (I use the line-intersection formulate (algebraic form) on Wikipedia) to check if there is an intersection.
- If a corner of Baabb intersects with a plane of Aaabb, verify the intersection point is behind the other 5 planes of Aaabb
- Keep the smallest value of d and return