PageRenderTime 45ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/SolarSystem.Wpf/OrbitsController.cs

https://bitbucket.org/efouts/solarsystem
C# | 51 lines | 41 code | 10 blank | 0 comment | 0 complexity | da910d3e1b821bcd3055aceef6691125 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. using SharpGL;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. namespace SolarSystem.Wpf
  7. {
  8. public class OrbitsController
  9. {
  10. public Boolean AllOrbitsComplete { get { return orbits.Values.All(o => o.IsClosed); } }
  11. private System system;
  12. private Normalizer normalizer;
  13. private Dictionary<Body, Orbit> orbits;
  14. public OrbitsController(System system, Normalizer normalizer)
  15. {
  16. this.system = system;
  17. this.normalizer = normalizer;
  18. orbits = new Dictionary<Body, Orbit>();
  19. foreach (var body in system.Bodies)
  20. orbits.Add(body, new Orbit());
  21. }
  22. public void RecordPositions()
  23. {
  24. foreach (var body in system.Bodies)
  25. orbits[body].AddPoint(body.Position);
  26. }
  27. public void Render(OpenGL gl)
  28. {
  29. foreach (var body in system.Bodies)
  30. DrawOrbit(gl, body);
  31. }
  32. private void DrawOrbit(OpenGL gl, Body body)
  33. {
  34. gl.Color(1f, 0.84f, 0f);
  35. gl.Begin(OpenGL.GL_LINE_STRIP);
  36. foreach (var position in orbits[body].Points)
  37. gl.Vertex(normalizer.NormalizePosition(position[0]), 0, normalizer.NormalizePosition(position[1]));
  38. gl.End();
  39. }
  40. }
  41. }