We have seen in previous article 8 how to perform pixel collision.
Altough it worked perfectly, it only worked on non rotated shapes.
But in some cases, your shape will rotate (like a car in a racing game – see article « A racing car game »).
To perform pixel collision for a rotated shape, here below the steps :
-you first need to draw a rotated rectangle around your shape
-you then need to draw a bounding rectanle around that rotated rectangle (also called AABB : Axis Aligned Bounding Box)
-finally you can check whether 2 AABB intersects, and if so, if in the intersected region, we have 2 non transparent pixels (colliding) or not
The source code : XNA_DEMO_18
Note : the project contains a class named primitives2d which is used only to draw lines/rectangles around my objects.
Lets illustrate this with some screenshots.
Lets rotate our rectangle along with my rocket
Despite bounding boxes intersecting, we dont detect collision yet
Here we go ! In the intersection region, there are 2 non transparent pixels