public FastestCollision DoTheFastestCollision(List <GameObject> MovingGameObjects) { // Precalculate intersecting areas var PossibleCollisionGroups = Booster.CheckAll(MovingGameObjects); // 2. For each intersecting area calculate precise collision details, if any FastestCollision fastestCollision = null; CollisionResponse collisionResponse; foreach (var TestingGroup in PossibleCollisionGroups) { foreach (var testing in TestingGroup.GetPossibleCollidingObjects()) { IPhysicControl SecondCrossTest = testing.GetSecondary(); var PrimaryDisplacements = testing.GetPrimary().GetDisplacements(); var SecondaryDisplacements = SecondCrossTest.GetDisplacements(); CollisionSimplifiedScenario Scenario; Scenario = DisplacementSimplifier.Simplify (PrimaryDisplacements, SecondaryDisplacements); if (Scenario == null) { continue; } collisionResponse = CollisionStrategy.Test(Scenario); if (collisionResponse != null) { if (fastestCollision == null || fastestCollision.CollisionDeltaTime > collisionResponse.CollisionDeltaTime) { fastestCollision = new FastestCollision( collisionResponse, SecondCrossTest.GameObject ); } } } } if (fastestCollision != null) { fastestCollision.GameObject.Hit(fastestCollision.CollisionResponse); } return(fastestCollision); }
public void ThenCollisionSimplifierShouldRemoveTheirDisplacements() { DisplacementSimplifier simplifierInstance = new DisplacementSimplifier(); LinearDisplacement DisplacementA = null; LinearDisplacement DisplacementB = null; if (Context.World.TryGetObject("bodyA", out GameObject gameObject)) { DisplacementA = new LinearDisplacement(gameObject.Velocity, gameObject.Position, 1); } if (Context.World.TryGetObject("bodyB", out gameObject)) { DisplacementB = new LinearDisplacement(gameObject.Velocity, gameObject.Position, 1); } var simplified = simplifierInstance.Simplify(DisplacementA, DisplacementB); Assert.IsNull(simplified); }