/// <summary> /// Bounces the asteroids based on their mass **Very buggy, needs work** /// </summary> /// <param name="object1"></param> /// <param name="object2"></param> protected void BounceObjects(GameObject object1, GameObject object2) { // Found from the center of mass formula // (M1*V1 + M2*V2) / (M1 + M2) // M = Mass V = Velocity Vector2 cOfMass = (object1._mass * object1.Speed + object2._mass * object2.Speed) / (object1._mass + object2._mass); Vector2 normal1 = object2.Origin - object1.Origin; normal1.Normalize(); Vector2 normal2 = object1.Origin - object2.Origin; normal2.Normalize(); object1.Speed -= cOfMass; object1.Speed = Vector2.Reflect(object1.Speed, normal1); object1.Speed += cOfMass; object2.Speed -= cOfMass; object2.Speed = Vector2.Reflect(object2.Speed, normal2); object2.Speed += cOfMass; }
/// <summary> /// Gets if two rectangles are colliding /// </summary> /// <param name="other"></param> /// <returns></returns> public bool Colliding(GameObject other) { return this.Bounds.Intersects(other.Bounds); }