public Planet(string databaseName, PlanetParameters parameters, Planet parent, VAO vao, Texture t) : base(vao, t) { this.parent = parent; this.OrbitalOrientation = -1; this.DrawAxisTilt = true; this.DrawOrbit = true; this.AxisTilt = (float)MathHelper.DegreesToRadians(parameters.AxialTilt[databaseName]); this.PlanetRadius = parameters.PlanetRadius[databaseName]; this.DistanceFromParent = parameters.DistanceFromSun[databaseName]; this.RotationalPeriod = parameters.RotationPeriod[databaseName]; this.OrbitalPeriod = parameters.OrbitalPeriod[databaseName]; this.setScale((float)PlanetRadius); if (parent != null) { this.Orbit = new Orbit(this, parent.Translation, this.DistanceFromParent, 120); DrawOrbit = true; } Vector3[] axisVerts = { new Vector3(0, -2, 0), new Vector3(0, 2, 0) }; axisLine = new VAO(axisVerts); }
public Planet(string dataBaseName, PlanetParameters param, Planet parent, MeshVBOs vbos, Texture t, ShaderProgram shader, ShaderProgram lineShader) : base(vbos, t, shader) { this.parent = parent; this.lineShader = lineShader; this.RevolutionOrientation = -1; this.AxisTilt = Matrix4.Identity; this.DrawAxisTilt = true; this.ScenicDistance = param.DFSScenic[dataBaseName]; this.HoursPerRotation = param.RotationPeriod[dataBaseName]; this.AxisTilt = Matrix4.CreateFromAxisAngle(new Vector3(0, 0, -1), (float)MathHelper.DegreesToRadians(param.AxialTilt[dataBaseName])); this.RealisticRadius = param.RadiusRealistic[dataBaseName]; this.ScenicRadius = param.RadiusScenic[dataBaseName]; this.Scale = (float)ScenicRadius; this.OrbitalPeriod = param.OrbitalPeriod[dataBaseName]; this.inclinationAngle = param.InclinationAngle[dataBaseName]; this.longitudeAscendingNode = param.LongitudeAscendingNode[dataBaseName]; this.longitudePerihelion = param.LongitudePerihelion[dataBaseName]; this.eccentricity = param.Eccentricity[dataBaseName]; this.longitudeAscendingNodeRadians = MathHelper.DegreesToRadians(longitudeAscendingNode); this.longitudePerihelionRadians = MathHelper.DegreesToRadians(longitudePerihelion); this.inclinationAngleRadians = MathHelper.DegreesToRadians(inclinationAngle); this.newRadius = 0; this.PeriodAngle = longitudePerihelionRadians; this.eccentricAnomaly = 0; this.createTransform(); if (parent != null) this.Orbit = new Orbit(this, parent.Position, this.ScenicDistance, 360, lineShader, this.inclinationAngle, this.longitudeAscendingNode, this.longitudePerihelion, this.eccentricity); float[] axisVerts = { 0, -2, 0, 0, 2, 0 }; this.axisLine = new VBO<float>(axisVerts, BufferTarget.ArrayBuffer, VBO<float>.PointerType.vertex); }
public Sun(string dataBaseName, PlanetParameters param, Planet parent, MeshVBOs vbos, Texture t, ShaderProgram shader, ShaderProgram lineShader) : base(dataBaseName, param, parent, vbos, t, shader, lineShader) { bufferVerts = new VBO<float>(new float[] { -1, 1, 0, 1, 1, 0, 1, -1, 0, -1, -1, 0 }, BufferTarget.ArrayBuffer, VBO<float>.PointerType.vertex); bufferElems = new VBO<ushort>(new ushort[] { 0, 1, 2, 3 }, BufferTarget.ElementArrayBuffer, VBO<ushort>.PointerType.element); squareUvs = new VBO<float>(new float[] { 0, 1, 1, 1, 1, 0, 0, 0 }, BufferTarget.ArrayBuffer, VBO<float>.PointerType.texCoord); squareVerts = new VBO<float>(new float[] { -2, 2, 0, 2f, 2f, 0, 2f, -2f, 0, -2f, -2f, 0 }, BufferTarget.ArrayBuffer, VBO<float>.PointerType.vertex); squareElems = new VBO<ushort>(new ushort[] { 0, 1, 2, 3 }, BufferTarget.ElementArrayBuffer, VBO<ushort>.PointerType.element); this.coronaShader = new ShaderProgram(File.ReadAllText("content/shaders/coronaShader.vert"), File.ReadAllText("content/shaders/coronaShader.frag"), "coronaShader"); Console.WriteLine(coronaShader.ProgramInfoLog); coronaShader.setUniform("proj", Form1.projectionMatrix); coronaShader.setUniform("model", Matrix4.Identity); this.billboardShader = new ShaderProgram(File.ReadAllText("content/shaders/billboardShader.vert"), File.ReadAllText("content/shaders/billboardShader.frag"), "billboardShader"); Console.WriteLine(billboardShader.ProgramInfoLog); billboardShader.setUniform("proj", Form1.projectionMatrix); billboardShader.setUniform("model", Matrix4.Identity); frameBufferTime = 0; bufferResolution = new Vector2(1024, 1024); bufferTexture = GL.GenTexture(); GL.BindTexture(TextureTarget.Texture2D, bufferTexture); GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, (int)bufferResolution.X, (int)bufferResolution.Y, 0, PixelFormat.Rgba, PixelType.UnsignedByte, IntPtr.Zero); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear); frameBuffer = GL.GenFramebuffer(); GL.BindFramebuffer(FramebufferTarget.Framebuffer, frameBuffer); GL.FramebufferTexture2D(FramebufferTarget.Framebuffer, FramebufferAttachment.ColorAttachment0, TextureTarget.Texture2D, bufferTexture, 0); GL.BindFramebuffer(FramebufferTarget.Framebuffer, 0); // make sure to set the framebuffer back to the default, or else bugs, //bugs that take two hours to debug }
public Earth(string dataBaseName, PlanetParameters param, Planet parent, MeshVBOs vbos, Texture diffuse, Texture specular, Texture night, Texture normal, Texture clouds, ShaderProgram earthShader, ShaderProgram lineShader) : base(dataBaseName, param, parent, vbos, diffuse, earthShader, lineShader) { this.specularT = specular; this.nightT = night; this.normalT = normal; this.cloudsT = clouds; this.cloudsSphereScale = Matrix4.CreateScale(1.005f); cloudShader = new ShaderProgram(File.ReadAllText("content/shaders/defaultShader.vert"), File.ReadAllText("content/shaders/cloudShader.frag"), "cloudShader"); Console.WriteLine(cloudShader.ProgramInfoLog); cloudShader.setUniform("proj", Form1.projectionMatrix); }
public Earth(string dataBaseName, PlanetParameters param, Planet parent, VAO vbos, Texture diffuse, Texture specular, Texture night, Texture normal, Texture clouds) : base(dataBaseName, param, parent, vbos, diffuse) { this.specularT = specular; this.nightT = night; this.normalT = normal; this.cloudsT = clouds; //cloudShader = new ShaderProgram( // @"E:\Visual Studio 2015\Projects\Solar_System\Solar_System\content\shaders\default.vert", // @"E:\Visual Studio 2015\Projects\Solar_System\Solar_System\content\shaders\cloudShader.frag", // "cloudShader"); }
public SolarSystemScene(PlanetParameters planetParams, Dictionary<Enums.MeshVBOs, MeshVBOs> VBOs, Dictionary<Enums.Textures, Texture> textures, Dictionary<Enums.Shaders, ShaderProgram> shaders, double hoursPerSecond, bool zAxisLine, GLControl pannel) { this.hoursPerSecond = hoursPerSecond; this.ZAxisLine = zAxisLine; this.defaultShader = shaders[Enums.Shaders.default_]; this.sunShader = shaders[Enums.Shaders.sun]; this.lineShader = shaders[Enums.Shaders.line]; this.earthShader = shaders[Enums.Shaders.earth]; this.setProjectionMatrix(pannel); this.loadContent(planetParams, VBOs, textures); }
private void loadContent(PlanetParameters planetParams, ContentManager content) { this.planets = new List <Planet>(); this.rings = new List <PlanetRing>(); VAO planetVao = content.GetVao("sphere"); skybox = new SkyBox("content/textures/skybox"); sun = new Sun("sun", planetParams, null, planetVao, content.getTexture("sun")); Planet mercury = new Planet("mercury", planetParams, sun, planetVao, content.getTexture("mercury")); Planet venus = new Planet("venus", planetParams, sun, planetVao, content.getTexture("venus")); earth = new Earth("earth", planetParams, sun, planetVao, content.getTexture("earth"), content.getTexture("earth_spec"), content.getTexture("earth_night"), content.getTexture("earth_normal"), content.getTexture("earth_clouds")); Planet moon = new Planet("moon", planetParams, earth, planetVao, content.getTexture("moon")); Planet mars = new Planet("mars", planetParams, sun, planetVao, content.getTexture("mars")); Planet jupiter = new Planet("jupiter", planetParams, sun, planetVao, content.getTexture("jupiter")); Planet saturn = new Planet("saturn", planetParams, sun, planetVao, content.getTexture("saturn")); Planet uranus = new Planet("uranus", planetParams, sun, planetVao, content.getTexture("uranus")); Planet neptune = new Planet("neptune", planetParams, sun, planetVao, content.getTexture("neptune")); Planet pluto = new Planet("pluto", planetParams, sun, planetVao, content.getTexture("pluto")); //PlanetRing saturnRings = new PlanetRing(content.GetVao("saturnRings"), content.getTexture("saturnRings.png"), saturn); //PlanetRing uranusRings = new PlanetRing(content.GetVao("uranusRings"), content.getTexture("uranusRings.png"), uranus); planets.Add(mercury); planets.Add(venus); planets.Add(moon); planets.Add(mars); planets.Add(jupiter); planets.Add(saturn); planets.Add(uranus); planets.Add(neptune); planets.Add(pluto); //rings.Add(saturnRings); //rings.Add(uranusRings); }
public SolarSystemScene(GameWindow gw, PlanetParameters planetParams, ContentManager contentManager) { this.contentManager = contentManager; this.hoursPerSecond = 1; this.defaultShader = contentManager.GetShader("default"); this.sunShader = contentManager.GetShader("sunShader"); this.lineShader = contentManager.GetShader("lineShader"); this.earthShader = contentManager.GetShader("earth"); this.buffer = new Framebuffer(gw.Width, gw.Height); buffer.AttachColorBuffer(internalFormat: PixelInternalFormat.Rgba16f, type: PixelType.Float); buffer.AttachColorBuffer(internalFormat: PixelInternalFormat.Rgba16f, type: PixelType.Float); buffer.AttachDepthStencilBuffer(); blur = new GaussianBlur((int)gw.Size.Width / 1, (int)gw.Size.Height / 1); frame = FrameRenderer.Instance; finalShader = contentManager.LoadShader("final"); finalShader.Initialize = () => { finalShader.Bind(); finalShader.SetUniform("frame", 0); finalShader.SetUniform("bloom", 1); }; finalShader.Init(); cam = new Camera(60); cam.MaxDepth = 600; cam.LightPos = new Vector3(0, 0, 0); cam.Projection = Matrix4.CreatePerspectiveFieldOfView(MathHelper.DegreesToRadians(70), gw.Width / (float)gw.Height, .1f, 100000f); this.loadContent(planetParams, contentManager); cam.SetFocus(earth); #region Gui guiManager = new GuiManager(gw); panel = new Panel() { Size = new System.Drawing.Size(200, gw.Height), BackgroundColor = new Vector4(36f / 255, 36f / 255, 36f / 255, 1), BorderColor = new Vector4(1, 1, 1, 1), Location = new System.Drawing.Point(-201, 0), }; var titleLabel = new Label() { Size = new System.Drawing.Size(200, 50), Location = new System.Drawing.Point(0, 10), Font = new System.Drawing.Font("Arial", 20, System.Drawing.FontStyle.Underline), TextColor = new Vector4(1, 1, 1, 1), Text = "Options" }; int y = 70; var label = new Label() { Size = new System.Drawing.Size(120, 25), Location = new System.Drawing.Point(10, y), TextColor = new Vector4(1, 1, 1, 1), Text = "Axial Tilt" }; var @switch = new Switch() { Location = new System.Drawing.Point(130, y), On = true }; @switch.OnToggle += (o, e) => { this.setAxialTiltDraw(((Switch)o).On); }; panel.Controls.Add(titleLabel, label, @switch); y += 30; label = new Label() { Size = new System.Drawing.Size(120, 25), Location = new System.Drawing.Point(10, y), TextColor = new Vector4(1, 1, 1, 1), Text = "Orbits" }; @switch = new Switch() { Location = new System.Drawing.Point(130, y), On = true }; @switch.OnToggle += (o, e) => { this.setOrbitDraw(((Switch)o).On); }; panel.Controls.Add(label, @switch); y += 30; label = new Label() { Size = new System.Drawing.Size(120, 25), Location = new System.Drawing.Point(10, y), TextColor = new Vector4(1, 1, 1, 1), Text = "Bloom Buffer" }; @switch = new Switch() { Location = new System.Drawing.Point(130, y) }; @switch.OnToggle += (o, e) => { this.showBloomBuffer = ((Switch)o).On; }; panel.Controls.Add(label, @switch); y += 30; label = new Label() { Size = new System.Drawing.Size(120, 25), Location = new System.Drawing.Point(10, y), TextColor = new Vector4(1, 1, 1, 1), Text = "Bloom" }; @switch = new Switch() { Location = new System.Drawing.Point(130, y), On = true }; @switch.OnToggle += (o, e) => { this.bloom = ((Switch)o).On; }; panel.Controls.Add(label, @switch); guiManager.Controls.Add(panel); #endregion }
private void LoadContent() { Stopwatch watch = new Stopwatch(); watch.Start(); scenes = new List <Scene>(); ContentManager contentManager = new ContentManager($@"{Environment.CurrentDirectory}\content\"); contentManager.ShaderFolder = @"shaders\"; contentManager.TextureFolder = @"textures\"; contentManager.MeshFolder = @"models\"; //loading the shaders ShaderProgram defaultShader = contentManager.LoadShader("default"); defaultShader.Initialize = () => { defaultShader.Bind(); defaultShader.SetUniform("lightPos", new Vector3(0, 0, 0)); defaultShader.SetUniform("ambientCoefficient", .01f); defaultShader.SetUniform("lightIntensities", Vector3.One); }; defaultShader.Init(); //s = defaultShader; ShaderProgram earthShader = contentManager.LoadShader("earth"); earthShader.Initialize = () => { earthShader.Bind(); //earthShader.SetUniform("lightIntensities", Vector3.One); earthShader.SetUniform("texture", 0); earthShader.SetUniform("specularTexture", 1); earthShader.SetUniform("nightTexture", 2); //earthShader.SetUniform("normalTexture", 3); //earthShader.SetUniform("cloudsTexture", 4); }; earthShader.Init(); ShaderProgram sunShader = contentManager.LoadShader("sunShader"); ShaderProgram lineShader = contentManager.LoadShader("lineShader"); Console.WriteLine($"loaded shaders: {watch.ElapsedMilliseconds}"); watch.Restart(); //loading models PlanetParameters planetParams = PlanetParameters.readFromFile("content/planetInfo.txt"); contentManager.LoadVao("saturnRings"); contentManager.LoadVao("sphere"); contentManager.LoadVao("uranusRings"); Console.WriteLine($"loaded meshes: {watch.ElapsedMilliseconds}"); watch.Restart(); //loading the textures contentManager.LoadTexture("sun4096g.jpg", "sun"); contentManager.LoadTexture("mercury4096.jpg", "mercury"); contentManager.LoadTexture("venus4096.jpg", "venus"); contentManager.LoadTexture("earth4096.jpg", "earth"); contentManager.LoadTexture("earth_Spec4096.png", "earth_spec"); contentManager.LoadTexture("earth_Night4096.jpg", "earth_night"); contentManager.LoadTexture("earth_Normal4096.jpg", "earth_normal"); contentManager.LoadTexture("earth_Clouds4096.jpg", "earth_clouds"); contentManager.LoadTexture("moon4096.jpg", "moon"); contentManager.LoadTexture("mars4096.jpg", "mars"); contentManager.LoadTexture("jupiter4096.jpg", "jupiter"); contentManager.LoadTexture("saturn2048.jpg", "saturn"); contentManager.LoadTexture("uranus2048.png", "uranus"); contentManager.LoadTexture("neptune1024.png", "neptune"); contentManager.LoadTexture("pluto1024.jpg", "pluto"); //contentManager.LoadTexture("saturnRings.png"); //contentManager.LoadTexture("uranusRings.png"); Console.WriteLine($"loaded textures: {watch.ElapsedMilliseconds}"); watch.Restart(); var solarSystemScene = new SolarSystemScene(this, planetParams, contentManager); //var planetSizeScene = new PlanetSIzeScene(context, planetParams, contentManager, 1); scenes.Add(solarSystemScene); // _scenes.Add(planetSizeScene); currentScene = scenes[0]; Console.WriteLine($"created scenes: {watch.ElapsedMilliseconds}"); watch.Stop(); }
public Sun(string dataBaseName, PlanetParameters param, Planet parent, VAO vao, Texture t) : base(dataBaseName, param, parent, vao, t) { this.DrawAxisTilt = false; this.DrawOrbit = false; }
private void loadContent(PlanetParameters planetParams, Dictionary<Enums.MeshVBOs, MeshVBOs> VBOs, Dictionary<Enums.Textures, Texture> textures) { this.planets = new List<Planet>();; this.rings = new List<PlanetRing>();; this.stars = new Mesh(VBOs[Enums.MeshVBOs.planet], textures[Enums.Textures.starsT], defaultShader); stars.Scale = 4500f; MeshVBOs planetVBOs = VBOs[Enums.MeshVBOs.planet]; sun = new Sun("sun", planetParams, null, planetVBOs, textures[Enums.Textures.sunT], sunShader, lineShader); Planet mercury = new Planet("mercury", planetParams, sun, planetVBOs, textures[Enums.Textures.mercury], defaultShader, lineShader); Planet venus = new Planet("venus", planetParams, sun, planetVBOs, textures[Enums.Textures.venusT], defaultShader, lineShader); Earth earth = new Earth("earth", planetParams, sun, planetVBOs, textures[Enums.Textures.earthT], textures[Enums.Textures.earth_SpecT], textures[Enums.Textures.earth_NightT], textures[Enums.Textures.earth_NormalT], textures[Enums.Textures.earty_CloudsT], earthShader, lineShader); Planet moon = new Planet("moon", planetParams, earth, planetVBOs, textures[Enums.Textures.moonT], defaultShader, lineShader); Planet mars = new Planet("mars", planetParams, sun, planetVBOs, textures[Enums.Textures.marsT], defaultShader, lineShader); Planet jupiter = new Planet("jupiter", planetParams, sun, planetVBOs, textures[Enums.Textures.jupiterT], defaultShader, lineShader); Planet saturn = new Planet("saturn", planetParams, sun, planetVBOs, textures[Enums.Textures.saturnT], defaultShader, lineShader); Planet uranus = new Planet("uranus", planetParams, sun, planetVBOs, textures[Enums.Textures.uranusT], defaultShader, lineShader); Planet neptune = new Planet("neptune", planetParams, sun, planetVBOs, textures[Enums.Textures.neptuneT], defaultShader, lineShader); Planet pluto = new Planet("pluto", planetParams, sun, planetVBOs, textures[Enums.Textures.plutoT], defaultShader, lineShader); PlanetRing saturnRings = new PlanetRing(VBOs[Enums.MeshVBOs.saturnRings], textures[Enums.Textures.saturn_RingsT], saturn); PlanetRing uranusRings = new PlanetRing(VBOs[Enums.MeshVBOs.uranusRings], textures[Enums.Textures.uranus_RingsT], uranus); planets.Add(sun); planets.Add(mercury); planets.Add(venus); planets.Add(earth); planets.Add(moon); planets.Add(mars); planets.Add(jupiter); planets.Add(saturn); planets.Add(uranus); planets.Add(neptune); planets.Add(pluto); rings.Add(saturnRings); rings.Add(uranusRings); cam = new Camera(); cam.setFocus(sun); foreach (Planet p in planets) { p.DrawOrbit = true; p.DrawAxisTilt = true; } }