public static void RunDispach(Manafold manafold, Shape shape1, Shape shape2) { if (!valuePairs.ContainsKey(new Tuple <Type, Type>(shape1.GetType(), shape2.GetType()))) { throw new Exception("Unresolvable Collision between types" + shape1.GetType().Name + " and " + shape2.GetType().Name); } valuePairs[new Tuple <Type, Type>(shape1.GetType(), shape2.GetType())]?.Invoke(manafold); }
public static void BoundingBoxvsBoundingBox(Manafold manafold) { BoundingBox A = manafold.bodyA.shape.GetAABB(); BoundingBox B = manafold.bodyB.shape.GetAABB(); vector2 ABVector = B.Position - A.Position; vector2 AMid = A.Center(); vector2 BMid = B.Center(); float OverlapX = AMid.X + BMid.X - Math.Abs(ABVector.X); if (OverlapX > 0) { float OverlapY = AMid.Y + BMid.Y - Math.Abs(ABVector.Y); if (OverlapY > 0) { if (OverlapX > OverlapY) { if (ABVector.X > 0) { manafold.Normal = new vector2(1, 0); } else { manafold.Normal = new vector2(-1, 0); } manafold.Penetration = OverlapX; } else { if (ABVector.Y > 0) { manafold.Normal = new vector2(0, 1); } else { manafold.Normal = new vector2(0, -1); } manafold.Penetration = OverlapY; } } } //if ((A.Max.X < B.Min.X) || (A.Min.X > B.Max.X)) return; //if ((A.Max.Y < B.Min.Y) || (A.Min.Y > B.Max.Y)) return; }