Collision detection for arbitrary dimensions, positioned and rotated rectangles in XNA

I am working with xna in C # and in my game I will have loads of spaceships flying all over the place. They will each have arbitrary rotation, size and position in space, and I need a method to determine when they collide. Ideally, the method should take two rectangles, two twins, and two Vector2s for size, rotation, and position, respectively, and return a boolean indicating whether or not they intersect.

+2


source to share


3 answers


Take a look at these links:

An overview of collision detection Collision detection
matrices
Putting collision detection into practice



They show you a way to do pixel-based collision detection that is more accurate than rectangular for irregularly shaped objects.

+3


source


You might also consider using this solution without issue and integrating something like the Farseer Physics Engine:
http://farseerphysics.codeplex.com/



+2


source


These rectangles that you describe are called OBB (Oriented Bounding Boxes)

The way to make collisions between them is to use the "dividing axis theorem"

A really good page describing it in detail with lots of images can be found here

+1


source







All Articles