Precise collision detection with an asteroid
We did this last because there is a more complicated final step. As in the border detection, we will need to translate and rotate our object's vertices. However this time, we will need to do it for two objects.
Furthermore, once we rotated and translated the asteroid's vertices, we will need to handle them in pairs of vertices that form a line. These are lines that we will test against each and every vertex from the other object. This test is of course our crossing number method that we discussed.
We need to do all of this within the body of the if (distance < cp1.radius + cp2.radius) { ...}
, where we previously just set the collided
Boolean to true
.
There is quite a lot of code, so we will split it into ...
Get Android Game Programming by Example now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.