/SolarSystem.Wpf/OrbitsController.cs
C# | 51 lines | 41 code | 10 blank | 0 comment | 0 complexity | da910d3e1b821bcd3055aceef6691125 MD5 | raw file
Possible License(s): BSD-3-Clause
- using SharpGL;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
-
- namespace SolarSystem.Wpf
- {
- public class OrbitsController
- {
- public Boolean AllOrbitsComplete { get { return orbits.Values.All(o => o.IsClosed); } }
-
- private System system;
- private Normalizer normalizer;
- private Dictionary<Body, Orbit> orbits;
-
- public OrbitsController(System system, Normalizer normalizer)
- {
- this.system = system;
- this.normalizer = normalizer;
-
- orbits = new Dictionary<Body, Orbit>();
-
- foreach (var body in system.Bodies)
- orbits.Add(body, new Orbit());
- }
-
- public void RecordPositions()
- {
- foreach (var body in system.Bodies)
- orbits[body].AddPoint(body.Position);
- }
-
- public void Render(OpenGL gl)
- {
- foreach (var body in system.Bodies)
- DrawOrbit(gl, body);
- }
-
- private void DrawOrbit(OpenGL gl, Body body)
- {
- gl.Color(1f, 0.84f, 0f);
- gl.Begin(OpenGL.GL_LINE_STRIP);
-
- foreach (var position in orbits[body].Points)
- gl.Vertex(normalizer.NormalizePosition(position[0]), 0, normalizer.NormalizePosition(position[1]));
-
- gl.End();
- }
- }
- }