/// <summary> /// Take a time step. This performs collision detection, integration, /// and constraint solution. /// </summary> /// <param name="dt">The amount of time to simulate, this should not vary.</param> /// <param name="velocityIterations">For the velocity constraint solver.</param> /// <param name="positionIteration">For the positionconstraint solver.</param> public void Step(float dt, int velocityIterations, int positionIteration) { int height; height = _contactManager._broadPhase.ComputeHeight(); // If new fixtures were added, we need to find the new contacts. if ((_flags & WorldFlags.NewFixture) != 0) { _contactManager.FindNewContacts(); _flags &= ~WorldFlags.NewFixture; } _flags |= WorldFlags.Locked; TimeStep step = new TimeStep(); step.Dt = dt; step.VelocityIterations = velocityIterations; step.PositionIterations = positionIteration; if (dt > 0.0f) { step.Inv_Dt = 1.0f / dt; } else { step.Inv_Dt = 0.0f; } step.DtRatio = _inv_dt0 * dt; step.WarmStarting = _warmStarting; // Update contacts. This is where some contacts are destroyed. _contactManager.Collide(); // Integrate velocities, solve velocity constraints, and integrate positions. if (step.Dt > 0.0f) { Solve(step); } // Handle TOI events. if (_continuousPhysics && step.Dt > 0.0f) { SolveTOI(step); } if (step.Dt > 0.0f) { _inv_dt0 = step.Inv_Dt; } _flags &= ~WorldFlags.Locked; }