using System.Collections.Generic; namespace PhysicsEngine { public class WorldModel { public List Bodies { get; private set; } = new(); public List Constraints { get; private set; } = new(); public List GlobalForces = new(); private readonly Solver _solver = new(); public WorldModel() { GlobalForces.Add(GravityForce.Apply); GlobalForces.Add(DragForce.Apply); } public void AddBody(Body body) { if (!Bodies.Contains(body)) { Bodies.Add(body); } } public void RemoveBody(Body body) { Bodies.Remove(body); } public void AddConstraint(Constraint constraint) { if (!Constraints.Contains(constraint)) { Constraints.Add(constraint); } } public void RemoveConstraint(Constraint constraint) { Constraints.Remove(constraint); } public void Step(float dt) { _solver.Step(dt, Bodies, Constraints, GlobalForces, 8); } } }