示例#1
0
        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
        }
示例#2
0
        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);
        }
示例#3
0
 public PlanetRing(MeshVBOs vbos, Texture t, Planet p)
 {
     this.vbos = vbos;
     this.texture = t;
     this.parent = p;
     this.transform = parent.Transform;
 }
示例#4
0
 public Camera()
 {
     this.LookAt = new Vector3(0, 0, 0);
     this.Position = new Vector3(0, 0, 0);
     this.offset = new Vector3(0, 0, 0);
     this.Depth = 60;
     this.focus = null;
 }
示例#5
0
        public Orbit(Planet parent, Vector3 center, double radius, int sides, ShaderProgram shader, double ia, double lan, double lp, double ecc)
        {
            this.eccentricAnomaly = 0;
            this.shader = shader;
            this.parent = parent;
            this.Positon = center;
            this.Radius = (float)radius;
            this.Sides = sides;

            this.inclinationAngleRadians = MathHelper.DegreesToRadians(ia);
            this.longitudeAscendingNodeRadians = MathHelper.DegreesToRadians(lan);
            this.longitudePerihelionRadians = MathHelper.DegreesToRadians(lp);
            this.eccentricity = ecc;

            float step = MathHelper.DegreesToRadians(360f / sides);

            List<float> verts = new List<float>();
            List<float> angles = new List<float>();
            List<ushort> elements = new List<ushort>();

            float alpha = (float)longitudePerihelionRadians;
            ushort count = 0;
            while (alpha < Math.PI * 2f + longitudePerihelionRadians)
            {
                if (alpha < Math.PI + longitudePerihelionRadians)
                    this.eccentricAnomaly += step;
                if (alpha > Math.PI + longitudePerihelionRadians)
                    this.eccentricAnomaly -= step;
                this.newRadius = (float)((radius / (1 - this.eccentricity)) * (1 - (this.eccentricity * Math.Cos(this.eccentricAnomaly))));
                //verts.Add((float)Math.Cos(alpha) * Radius + center.X);
                //verts.Add(0f + center.Y);
                //verts.Add((float)Math.Sin(alpha) * Radius + center.Z);
                //verts.Add(Radius * ((float)Math.Cos(alpha + longitudeAscendingNodeRadians) - (float)Math.Sin(alpha + longitudeAscendingNodeRadians) * (float)Math.Cos(inclinationAngleRadians)) + center.Z);
                //verts.Add(Radius * ((float)Math.Sin(alpha + longitudeAscendingNodeRadians) * (float)Math.Sin(inclinationAngleRadians)) + center.Y);
                //verts.Add(Radius * ((float)Math.Sin(alpha + longitudeAscendingNodeRadians) + (float)Math.Cos(alpha + longitudeAscendingNodeRadians) * (float)Math.Cos(inclinationAngleRadians)) + center.X);

                //verts.Add(newRadius * ((float)Math.Cos(alpha) * (float)Math.Cos(longitudeAscendingNodeRadians) - (float)Math.Sin(longitudeAscendingNodeRadians) * (float)Math.Sin(alpha) * (float)Math.Sin(inclinationAngleRadians) ) + center.X);
                //verts.Add(newRadius * ((float)Math.Sin(alpha) * (float)Math.Sin(inclinationAngleRadians)) + center.Y);
                //verts.Add(newRadius * ((float)Math.Sin(alpha) * (float)Math.Cos(longitudeAscendingNodeRadians) + (float)Math.Cos(longitudeAscendingNodeRadians) * (float)Math.Sin(alpha) * (float)Math.Cos(inclinationAngleRadians)) + center.Z);

                verts.Add(newRadius * (float)Math.Cos(alpha) + center.X);
                verts.Add(newRadius * (float)inclinationAngleRadians * (float)Math.Sin(alpha - longitudeAscendingNodeRadians) + center.Y);
                verts.Add(newRadius * (float)Math.Sin(alpha) + center.Z);

                elements.Add(count);
                angles.Add(alpha);
                alpha += step;
                count++;
            }

            float[] vertsf = verts.ToArray();
            float[] anglesf = angles.ToArray();
            ushort[] elementsf = elements.ToArray();

            this.vertsBuffer = new VBO<float>(vertsf, BufferTarget.ArrayBuffer, VBO<float>.PointerType.vertex);
            this.anglesBuffer = new VBO<float>(anglesf, BufferTarget.ArrayBuffer, VBO<float>.PointerType.color);
            this.elementsBuffer = new VBO<ushort>(elementsf, BufferTarget.ElementArrayBuffer, VBO<ushort>.PointerType.element);
        }
示例#6
0
        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);
        }
示例#7
0
 void Default()
 {
     back = Image.FromFile(@"Images\Background.jpg");
     Sun = new Planet(0, "Sun", Image.FromFile(@"Images\Sun.png"), 0, 0);
     Mercury = new Planet(10, "Mercury", Image.FromFile(@"Images\Mercury.png"), 50, 0.9F);
     Venus = new Planet(9, "Venus", Image.FromFile(@"Images\Venus.png"), 90, 0.75F);
     Earth = new Planet(8, "Earth", Image.FromFile(@"Images\Earth.png"), 130, 0.5F);
     Mars = new Planet(7, "Mars", Image.FromFile(@"Images\Mars.png"), 170, 0.45F);
     Jupiter = new Planet(6, "Jupiter", Image.FromFile(@"Images\Jupiter.png"), 210, 0.3F);
     Saturn = new Planet(5, "Saturn", Image.FromFile(@"Images\Saturn.png"), 250, 0.25F);
     Uranus = new Planet(4, "Uranus", Image.FromFile(@"Images\Uranus.png"), 290, 0.2F);
     Neptune = new Planet(3, "Neptune", Image.FromFile(@"Images\Neptune.png"), 330, 0.15F);
     Pluto = new Planet(2, "Plutoe", Image.FromFile(@"Images\Pluto.png"), 370, 0.1F);
 }
示例#8
0
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            cam = new Camera(GraphicsDevice.Viewport.AspectRatio)
            {
                Position = Vector3.Backward * 15,
            };

            Texture2D tex=Content.Load<Texture2D>("Textures\\Default\\TEX_Default");
            planet1 = new Planet(GraphicsDevice, 10)
            {
                Diameter = 50f,
            };

            planet1.Orbit.Radius = 500f;
            planet1.Orbit.OriginPosition = Vector3.Zero;

            sun = new Star(GraphicsDevice);
            sun.Diameter = 500f;
        }
示例#9
0
 PointF NewCrd(Planet q, double angle, double z)
 {
     double x = centerPoint.X - q.Image.Size.Width / z + Math.Cos((float)(angle * q.Angle)) * q.Rad;
     double y = centerPoint.Y - q.Image.Size.Height + Math.Sin((float)(angle * q.Angle)) * q.Rad;
     return new PointF((float)x, (float)y);
 }
示例#10
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            AsteroidManager.Create(this, 900, 150000, 200000, -10000, 60000);

            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            Texture2D earthTexture = Content.Load<Texture2D>("textures/earthmap");
            Texture2D moon = Content.Load<Texture2D>("textures/meteor1");
            Texture2D sun = Content.Load<Texture2D>("textures/sun");
            Texture2D mercury = Content.Load<Texture2D>("textures/mercury");
            Texture2D venus = Content.Load<Texture2D>("textures/venus");
            Texture2D mars = Content.Load<Texture2D>("textures/mars");
            Texture2D stars = Content.Load<Texture2D>("textures/stars");

            // Sun, Mercury, Venus, Earth + Moon, Mars,  Asteroids

            // Initialize the lists
            Drawn = new List<ANode>();
            Updated = new List<Planet>();

            // Sun
            Planet planet = new Planet(this)
            {
                Scale = new Vector3(1.5f, 1.5f, 1.5f),
                Texture = sun,

                Orbit = new Vector3(0.5f, 0, 0),
                Spin = new Vector3(0.5f, 0, 0),
            };

            Drawn.Add(planet);
            Updated.Add(planet);

            // Mercury
            planet = new Planet(this)
            {
                Scale = new Vector3(0.4f),
                Texture = mercury,

                Orbit = new Vector3(0.7f, 0, 0),
                Spin = new Vector3(0.7f, 0, 0),

                Origin = new Vector3(7.0f, 0, 0),
            };

            Drawn.Add(planet);
            Updated.Add(planet);

            // Venus
            planet = new Planet(this)
            {
                Scale = new Vector3(0.6f),
                Texture = venus,

                Spin = new Vector3(0.4f, 0, 0),
                Orbit = new Vector3(0.4f, 0, 0),

                Origin = new Vector3(8.0f, 0, 0),
            };

            Drawn.Add(planet);
            Updated.Add(planet);

            // Create the Earth and moon
            Planet earth = new Planet(this)
            {
                Scale = new Vector3(0.6f),
                Texture = earthTexture,

                Spin = new Vector3(0.6f, 0, 0),
                Orbit = new Vector3(0.6f, 0, 0),

                Origin = new Vector3(12.0f, 0, 0),
            };

            Drawn.Add(earth);
            Updated.Add(earth);

            planet = new Planet(this)
            {
                Scale = new Vector3(0.2f),
                Texture = moon,
                Orbit = new Vector3(2.0f, 0, 0),

                Origin = new Vector3(10.0f, 0, 0),
            };

            earth.Satellites.Add(planet);

            // Mars
            planet = new Planet(this)
            {
                Scale = new Vector3(0.4f),
                Texture = mars,

                Spin = new Vector3(0.30f, 0, 0),
                Orbit = new Vector3(0.30f, 0, 0),

                Origin = new Vector3(28.0f, 0, 0),
            };

            Drawn.Add(planet);
            Updated.Add(planet);

            // Stars
            planet = new Planet(this)
            {
                Scale = new Vector3(-100.0f, 100, 100),
                Texture = stars,

                Spin = new Vector3(0.01f, 0.02f, 0.03f),
            };

            Drawn.Add(planet);
            Updated.Add(planet);
        }
示例#11
0
        /// <summary>
        /// Create the asteroid manager using the following parameters.
        /// </summary>
        /// <param name="game">
        /// The instantiating game.
        /// </param>
        /// <param name="number">
        /// The total number of asteroids to spawn.
        /// </param>
        /// <param name="minDist">
        /// The minimum distance from the center of the universe for our generation.
        /// </param>
        /// <param name="maxDist">
        /// The maximum distance from the center of the universe for our generation.
        /// </param>
        /// <param name="minHeight">
        /// The minimum possible height to use for our asteroids.
        /// </param>
        /// <param name="maxHeight">
        /// The maximum possible height to use for our asteroids.
        /// </param>
        public static void Create(Game1 game, int number, float minDist, float maxDist, float minHeight, float maxHeight)
        {
            Asteroids = new List<Planet>();

            Texture2D texture = game.Content.Load<Texture2D>("Textures/meteor1");

            for (int iteration = 0; iteration < number; iteration++)
            {
                // First, determine a random angle between 0 and 2pi and a random height
                float height = RandomHelper.RandomFloat(minHeight, maxHeight);

                float distanceX = RandomHelper.RandomFloat(minDist, maxDist);
                float distanceZ = RandomHelper.RandomFloat(minDist, maxDist);

                // Determine a base angle from iteration then add a variance
                float variance = RandomHelper.RandomFloat(0, 100) / 100.0f;
                float angle = (float)(iteration % 20);
                angle += variance;

                Planet asteroid = new Planet(game, "Models/asteroid" + RandomHelper.RandomInt(1, 2))
                {
                    Texture = texture,
                    Scale = new Vector3(0.00008f),

                    Origin = new Vector3((float)Math.Cos(angle) * distanceX, height, (float)Math.Sin(angle) * distanceZ),
                    Spin = new Vector3(RandomHelper.RandomFloat(0, 2.0f * 3.14f),
                    RandomHelper.RandomFloat(0, 2.0f * 3.14f), RandomHelper.RandomFloat(0, 2.0f * 3.14f)),
                    Orbit = new Vector3(1.0f, 0, 0),
                };

                Console.WriteLine(asteroid.Origin);

                Asteroids.Add(asteroid);
            }
        }
示例#12
0
 public void setFocus(Planet p)
 {
     this.focus = p;
     float size = (float) focus.Scale;
     this.Depth = size * 4f;
     this.MinDepath = size * 2f;
     this.MaxDepth = size * 10f;
 }
示例#13
0
 public Sun(string dataBaseName, PlanetParameters param, Planet parent, VAO vao, Texture t)
     : base(dataBaseName, param, parent, vao, t)
 {
     this.DrawAxisTilt = false;
     this.DrawOrbit    = false;
 }
示例#14
0
        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;
            }
        }
示例#15
0
        static void Main(string[] args)
        {
            Planet Earth = new Planet("Earth");

            Earth.Mass = 34;
            //Satellite Moon = new Satellite("Moon");
            //Earth.SetSatellites(Moon);



            test[] items = new test[4];

            //test first = new test { x = "Jupiter", y = 2 };
            //test second = new test { x = "Saturn", y = 0 };

            items[0] = new test {
                x = "Jupiter", y = 2
            };
            items[1] = new test {
                x = "Saturn", y = 0
            };
            items[2] = new test {
                x = "Jungo", y = 3
            };
            items[3] = new test {
                x = "Pluto", y = 0
            };

            var filteredNames  = items.OrderBy(n => n.y);
            int min            = filteredNames.First().y;
            var filteredNames2 = items.Where(n => n.y == min);

            //Console.WriteLine(filteredNames.First().y);
            foreach (test name in filteredNames2)
            {
                Console.WriteLine(name.x + " " + name.y);
            }

            Moon first  = new Moon("First", 20, 34.9);
            Moon second = new Moon("Second", 24, 35.8);
            Moon third  = new Moon("Third", 11, 5.8);

            List <Moon> Moons = new List <Moon>();

            Moons.Add(first);
            Moons.Add(second);
            Moons.Add(third);

            Moons.Sort();


            Planet Neptune = new Planet("Neptune");

            List <Moon> MoonsOfNeptune = Neptune.GetListOfMoons();

            MoonsOfNeptune.Sort();

            foreach (var item in MoonsOfNeptune)
            {
                Console.WriteLine(item.ToString());
            }
        }