/SolarSystem.Wpf/SystemController.cs
C# | 67 lines | 58 code | 9 blank | 0 comment | 2 complexity | dee0188a11093b934f0a614541916bfa MD5 | raw file
Possible License(s): BSD-3-Clause
- using SharpGL;
- using SharpGL.SceneGraph.Assets;
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Text;
-
- namespace SolarSystem.Wpf
- {
- public class SystemController
- {
- private System system;
- private Normalizer normalizer;
- private Dictionary<Body, Texture> bodyTextures;
-
- public SystemController(System system, Normalizer normalizer)
- {
- this.system = system;
- this.normalizer = normalizer;
- bodyTextures = new Dictionary<Body, Texture>();
- }
-
- public void Render(OpenGL gl)
- {
- foreach (var body in system.Bodies)
- DrawBody(gl, body);
- }
-
- private void DrawBody(OpenGL gl, Body body)
- {
- gl.PushMatrix();
- gl.Translate(normalizer.NormalizePosition(body.Position[0]), 0, normalizer.NormalizePosition(body.Position[1]));
-
- var quad = gl.NewQuadric();
-
- if (bodyTextures.ContainsKey(body))
- {
- var texture = bodyTextures[body];
- texture.Bind(gl);
- }
-
- gl.Color(1f, 1f, 1f);
- gl.Rotate(90, 1.0f, 0.0f, 0.0f);
- gl.Rotate(body.Rotation, 0.0f, 0.0f, 1.0f);
- gl.QuadricTexture(quad, 1);
- gl.Sphere(quad, normalizer.NormalizeRadius(body.Radius), 20, 20);
- gl.PopMatrix();
- gl.BindTexture(OpenGL.GL_TEXTURE_2D, 0);
- }
-
- public void LoadBodyTextures(OpenGL gl)
- {
- foreach (var body in system.Bodies)
- {
- var textureFileName = String.Format(@"Textures\{0}_map.jpg", body.Name);
-
- if (File.Exists(textureFileName))
- {
- var texture = new Texture();
- texture.Create(gl, textureFileName);
- bodyTextures.Add(body, texture);
- }
- }
- }
- }
- }