/SolarSystem.Wpf/Skybox.cs
C# | 109 lines | 87 code | 16 blank | 6 comment | 0 complexity | 34bdfde211c481eed3de3e327a5147a1 MD5 | raw file
Possible License(s): BSD-3-Clause
- using SharpGL;
- using SharpGL.SceneGraph.Assets;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
-
- namespace SolarSystem.Wpf
- {
- public class Skybox
- {
- private Double height;
- private Double length;
- private Double width;
- private Texture[] textures;
-
- public Skybox(Double height, Double length, Double width)
- {
- this.height = height;
- this.length = length;
- this.width = width;
- this.textures = new Texture[6];
- }
-
- public void LoadTextures(OpenGL gl)
- {
- textures[0] = new Texture();
- textures[0].Create(gl, @"Textures\skybox_front.jpg");
-
- textures[1] = new Texture();
- textures[1].Create(gl, @"Textures\skybox_back.jpg");
-
- textures[2] = new Texture();
- textures[2].Create(gl, @"Textures\skybox_left.jpg");
-
- textures[3] = new Texture();
- textures[3].Create(gl, @"Textures\skybox_right.jpg");
-
- textures[4] = new Texture();
- textures[4].Create(gl, @"Textures\skybox_top.jpg");
-
- textures[5] = new Texture();
- textures[5].Create(gl, @"Textures\skybox_bottom.jpg");
- }
-
- public void Render(OpenGL gl, Double centerX, Double centerY, Double centerZ)
- {
- var x = centerX - width / 2;
- var y = centerY - height / 2;
- var z = centerZ - length / 2;
-
- // Front
- textures[0].Bind(gl);
- gl.Begin(OpenGL.GL_QUADS);
- gl.TexCoord(0.0f, 0.0f); gl.Vertex(x, y, z + length);
- gl.TexCoord(0.0f, 1.5f); gl.Vertex(x, y + height, z + length);
- gl.TexCoord(1.5f, 1.5f); gl.Vertex(x + width, y + height, z + length);
- gl.TexCoord(1.5f, 0.0f); gl.Vertex(x + width, y, z + length);
- gl.End();
-
- // Back
- textures[1].Bind(gl);
- gl.Begin(OpenGL.GL_QUADS);
- gl.TexCoord(1.5f, 0.0f); gl.Vertex(x + width, y, z);
- gl.TexCoord(1.5f, 1.5f); gl.Vertex(x + width, y + height, z);
- gl.TexCoord(0.0f, 1.5f); gl.Vertex(x, y + height, z);
- gl.TexCoord(0.0f, 0.0f); gl.Vertex(x, y, z);
- gl.End();
-
- // Left
- textures[2].Bind(gl);
- gl.Begin(OpenGL.GL_QUADS);
- gl.TexCoord(0.0f, 1.5f); gl.Vertex(x, y + height, z);
- gl.TexCoord(1.5f, 1.5f); gl.Vertex(x, y + height, z + length);
- gl.TexCoord(1.5f, 0.0f); gl.Vertex(x, y, z + length);
- gl.TexCoord(0.0f, 0.0f); gl.Vertex(x, y, z);
- gl.End();
-
- // Right
- textures[3].Bind(gl);
- gl.Begin(OpenGL.GL_QUADS);
- gl.TexCoord(0.0f, 0.0f); gl.Vertex(x + width, y, z);
- gl.TexCoord(1.5f, 0.0f); gl.Vertex(x + width, y, z + length);
- gl.TexCoord(1.5f, 1.5f); gl.Vertex(x + width, y + height, z + length);
- gl.TexCoord(0.0f, 1.5f); gl.Vertex(x + width, y + height, z);
- gl.End();
-
- // Up
- textures[4].Bind(gl);
- gl.Begin(OpenGL.GL_QUADS);
- gl.TexCoord(0.0f, 0.0f); gl.Vertex(x + width, y + height, z);
- gl.TexCoord(1.5f, 0.0f); gl.Vertex(x + width, y + height, z + length);
- gl.TexCoord(1.5f, 1.5f); gl.Vertex(x, y + height, z + length);
- gl.TexCoord(0.0f, 1.5f); gl.Vertex(x, y + height, z);
- gl.End();
-
- //// Down
- textures[5].Bind(gl);
- gl.Begin(OpenGL.GL_QUADS);
- gl.TexCoord(0.0f, 0.0f); gl.Vertex(x, y, z);
- gl.TexCoord(1.5f, 0.0f); gl.Vertex(x, y, z + length);
- gl.TexCoord(1.5f, 1.5f); gl.Vertex(x + width, y, z + length);
- gl.TexCoord(0.0f, 1.5f); gl.Vertex(x + width, y, z);
- gl.End();
-
- gl.BindTexture(OpenGL.GL_TEXTURE_2D, 0);
- }
- }
- }