rigidbody, forces and collision testing
This commit is contained in:
50
PhysicsEngine/Physics/WorldModel.cs
Normal file
50
PhysicsEngine/Physics/WorldModel.cs
Normal file
@@ -0,0 +1,50 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace PhysicsEngine
|
||||
{
|
||||
public class WorldModel
|
||||
{
|
||||
public List<Body> Bodies { get; private set; } = new();
|
||||
public List<Constraint> Constraints { get; private set; } = new();
|
||||
public List<GlobalForce> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user