public void SaveSimulationToJson(string fileName, ProjectileSimulation simulation) { string json = JsonConvert.SerializeObject(simulation); fileName = "./simulations/" + fileName; File.WriteAllText(fileName, json); }
public ProjectileSimulation Simulate() { ProjectileSimulation simulation = new ProjectileSimulation(); simulation.InitialVelocity = projectile.velocity; var positionWithTime = new List <Snapshot>(); double startTime = 0f; //double endtime = 10f; double tick = Utils.GetTickFromFPS(20); var forceGenerator = new GravityForceGenerator(); while (projectile.position.y >= 0) { var snapshot = new Snapshot(projectile.position, startTime); positionWithTime.Add(snapshot); //forceGenerator.applyForce(ref projectile,projectile.mass); projectile.netForce = new Vector(0, 0, 0); projectile.Integrate(tick); startTime += tick; } simulation.Snapshots = positionWithTime; return(simulation); }