private static void ComputePolygonSeperation(ref Vector2 v1, ref Vector2 v2, PolygonShape polygonB, float radius, out EPAxis axis) { // PolygonB separation axis.Type = EPAxisType.EdgeB; axis.Index = 0; axis.Separation = float.MinValue; for (int i = 0; i < polygonB.Vertices.Count; ++i) { float s1 = Vector2.Dot(polygonB.Normals[i], v1 - polygonB.Vertices[i]); float s2 = Vector2.Dot(polygonB.Normals[i], v2 - polygonB.Vertices[i]); float s = Math.Min(s1, s2); if (s > axis.Separation) { axis.Index = i; axis.Separation = s; if (s > radius) { break; } } } }
private static void ComputeEdgeSeperation(ref Vector2 v1, ref Vector2 n, PolygonShape polygonB, out EPAxis axis) { // EdgeA separation axis.Type = EPAxisType.EdgeA; axis.Index = 0; axis.Separation = Vector2.Dot(n, polygonB.Vertices[0] - v1); for (int i = 1; i < polygonB.Vertices.Count; ++i) { float s = Vector2.Dot(n, polygonB.Vertices[i] - v1); if (s < axis.Separation) { axis.Separation = s; } } }