The idea of utilising a radius is great, I have added that to my collison detection routine.
private static bool TestRadiusRadius(Shape s1, Shape s2) { // Calculate squared distance between centres Vector2 v = s1.Position - s2.Position; float distance_Squared = Vector2.Dot(v, v); float radius_Sum = s1.Radius + s2.Radius; float radius_Sum_Squared = radius_Sum * radius_Sum; // Spheres intersect if squared distance is less than squared sum of radii if (distance_Squared < radius_Sum_Squared) { return true; } return false; }
The AABB OBB optimisation I read stated:
Quote:
It can really pay off to transform rectangle B into rectangle A’s local space. In order to do this, you should maintain these rectangles in local space and then transform rectangle B into world space and then by the inverse of rectangle A’s world space transform to put rectangle B into rectangle A’s local space. Then, translate both rectangles equally so that rectangle A is centered about the x and y axes. This means that two of the four axes that you need to project vectors onto are the unit (x and y) axes. Simply check for overlap between the x values of the corners of both rectangles and between the y values of the corners of both rectangles. With this solution you only have to actually project the vectors onto arbitrary axes twice, instead of four times.
I'm not sure how beneficial this would be because I would have to create a new AABB based and set its World Transform to the inverse of the OBB's World Transform.
// Transform a into b's local space Matrix m = Matrix.Invert(b.World_Transform); // Translate both boxes to the origin Vector2 p = a.Position - b.Position; CD_AABB2D c = new CD_AABB2D(p, a.Width, a.Height); c.World_Transform = m;
Do I just have to test the following 4 axes if I don't do this:
[AABB]:
a.MinPoint.X - a.MaxPoint.X;
a.MinPoint.Y - a.MaxPoint.Y;
[OBB]:
b.UL - b.LL
b.UL - b.UR
Or are my axes of separation incorrect?
Thank you.