private CollisionCollection DetectCollisions() { CollisionCollection collisions = new CollisionCollection(); for (int i = 0; i < objects.Count; i++) { for (int j = i + 1; j < objects.Count; j++) { PhysicsObject obj1 = objects[i]; PhysicsObject obj2 = objects[j]; Vector2 mtv; if (obj1.IntersectsWith(obj2, out mtv)) { Vector2 normal = mtv.Normalize(); float penetration = mtv.Length; Vector2[] support1 = GetSupportPoints(obj1.Polygon, -normal); Vector2[] support2 = GetSupportPoints(obj2.Polygon, normal); VectorPair[] pairs = GetContactPoints(support1, support2); collisions.AddCollisionPair(obj1, obj2, pairs, -normal, penetration, false); collisions.AddCollisionPair(obj2, obj1, pairs, normal, penetration, true); } } } return(collisions); }
private void Dispose(bool disposing) { if (disposing) { objects.Clear(); objects = null; if (collisions != null) { collisions.Clear(); } collisions = null; GameEngine.QueryComponent <GameLoop>().Components.Remove(this); } }
private void Step(float dt) { collisions = DetectCollisions(); if (GravityEnabled) { ApplyGravity(); } for (int i = 0; i < objects.Count; i++) { objects[i].UpdateVelocity(dt); } //for (int i = 0; i < 7; i++) ApplyImpulses(dt); for (int i = 0; i < objects.Count; i++) { objects[i].UpdatePosition(dt); } }