Rectangle to rectangle
We can test if two rectangles intersect by checking for ovap on eaof axis of of the rectangles. Non-oriented rectanglesave two axes each: the X Axis (1, 0) and the Y Axis (01). All axes of the rectangle must overlap for there to be a collision:
Let's assume we have two rectangles, A and B. We know the min and max points of both rectangles. The two rectangles overlap only if both of these conditions are met:
B.min <= A.max
A.min <= B.max
Getting ready
There is no need to make the overlap test into its own function; we're going to write it inline with the rest of the code. This just means instead of writing an Overlap
function, we are going to write the math and comparison out explicitly. We have two rectangles, for each we must check for overlap on the X-Axis and the Y-Axis.
How to do it…
Follow these steps to implement a function which tests for intersection between two non oriented rectangles:
Declare the
RectangleRectangle
collision function inGeometry2D.h
:bool...