Esempio n. 1
0
        public Moon(Vector3 Position, float Scale, float ParentMass)
            : base()
        {
            Body.CreateUVSphere(16, 16, out ModelVertices, out ModelIndices);
            effect = Manager.TexturedEffect;

            Color[] StaticNoise = Manager.GenerateStaticNoise(5, 5);
            NoiseMap = new Texture2D(MyGame.graphics.GraphicsDevice, 5, 5);
            NoiseMap.SetData <Color>(StaticNoise);
            NoiseMap    = Manager.SphericalWrap(NoiseMap);
            StaticNoise = Manager.GenerateStaticNoise(5, 5);
            ColorMap    = new Texture2D(MyGame.graphics.GraphicsDevice, 5, 5);
            ColorMap.SetData <Color>(StaticNoise);

            RotationAxis    = Manager.GetRandomNormal();
            RotationTime    = (float)MyGame.random.NextDouble();
            Bounds          = new BoundingSphere(Position, Scale);
            this.Transforms = new ScalePositionRotation(
                Scale
                , Position
                , Matrix.CreateFromAxisAngle(RotationAxis, RotationTime));
            Mass = (float)(4.0 / 3.0 * Math.PI * Math.Pow(Transforms.Scale, 3.0));

            //Set the initial velocity
            Velocity = Body.GetRandomInitialOrbitVelocity(Transforms.Position, null
                                                          , ParentMass, Mass);
        }
Esempio n. 2
0
        public Planet(Vector3 Position, float Scale, float ParentMass, Vector3 OrbitalPlaneNormal)
            : base()
        {
            Body.CreateUVSphere(32, 32, out ModelVertices, out ModelIndices);
            effect = Manager.TexturedEffect;

            NoiseMap = Manager.WrappedNoiseTextures[MyGame.random.Next(Manager.WrappedNoiseTextures.Length)];
            Color[] StaticNoise = Manager.GenerateStaticNoise(5, 5);
            for (int i = 0; i < StaticNoise.Length; i++)
            {
                StaticNoise[i] = Color.Lerp(planetColors[MyGame.random.Next(planetColors.Length)]
                                            , StaticNoise[i]
                                            , 0.1f * (float)MyGame.random.NextDouble());
            }
            ColorMap = new Texture2D(MyGame.graphics.GraphicsDevice, 5, 5);
            ColorMap.SetData <Color>(StaticNoise);

            RotationAxis    = Manager.GetRandomNormal();
            RotationTime    = (float)MyGame.random.NextDouble();
            Bounds          = new BoundingSphere(Position, 2.0f * Scale);
            this.Transforms = new ScalePositionRotation(
                Scale
                , Position
                , Matrix.CreateFromAxisAngle(RotationAxis, RotationTime));
            Mass = 10.0f * (float)(4.0 / 3.0 * Math.PI * Math.Pow(Transforms.Scale, 3.0));

            this.Velocity = Body.GetRandomInitialOrbitVelocity(Position, OrbitalPlaneNormal, ParentMass, Mass);
        }
Esempio n. 3
0
 protected override void InitializeNestedBodies()
 {
     if (NestedBodies.Count == 0)
     {
         //Add the other parts of the SolarSystem
         Vector3 OrbitalPlaneNormal = Manager.GetRandomNormal();
         int     NumPlanets         = MyGame.random.Next(7, 10);
         for (int i = 0; i < NumPlanets; i++)
         {
             NestedBodies.Add(new Planet(Manager.GetRandomNormal() * (float)(Transforms.Scale + 0.9 * MyGame.random.NextDouble())
                                         , Transforms.Scale * 0.1f * (float)MyGame.random.NextDouble()
                                         , Mass
                                         , OrbitalPlaneNormal));
         }
         int NumAsteroids = MyGame.random.Next(1, 4);
         for (int i = 0; i < NumAsteroids; i++)
         {
             NestedBodies.AddRange(
                 Asteroid.CreateBelt(
                     Transforms.Scale + 0.9f * (float)MyGame.random.NextDouble()
                     , Transforms.Scale * (0.5f + 0.5f * (float)MyGame.random.NextDouble())
                     , Transforms.Scale * (0.1f + 0.1f * (float)MyGame.random.NextDouble())
                     , Manager.GetRandomNormal()
                     , MyGame.random.Next(1, 4)
                     , Mass));
         }
     }
 }
Esempio n. 4
0
        public SolarSystem(Vector3 Position)
            : base()
        {
            Body.CreateUVSphere(64, 64, out ModelVertices, out ModelIndices);
            effect = Manager.TexturedEffect;

            NoiseMap = Manager.WrappedNoiseTextures[MyGame.random.Next(Manager.WrappedNoiseTextures.Length)];
            Color[] StaticNoise = Manager.GenerateStaticNoise(5, 5);
            for (int i = 0; i < StaticNoise.Length; i++)
            {
                StaticNoise[i] = Color.Lerp(starColors[MyGame.random.Next(starColors.Length)]
                                            , StaticNoise[i]
                                            , 0.1f * (float)MyGame.random.NextDouble());
            }
            ColorMap = new Texture2D(MyGame.graphics.GraphicsDevice, 5, 5);
            ColorMap.SetData <Color>(StaticNoise);

            RotationAxis    = Manager.GetRandomNormal();
            RotationTime    = (float)MyGame.random.NextDouble();
            Bounds          = new BoundingSphere(Position, 1.0f);
            this.Transforms = new ScalePositionRotation(
                (float)(0.04 + 0.06 * MyGame.random.NextDouble())
                , Position
                , Matrix.CreateFromAxisAngle(RotationAxis, RotationTime));
            Mass = 100.0f * (float)(4.0 / 3.0 * Math.PI * Math.Pow(Transforms.Scale, 3.0));

            //Initialize the glow
            int glowSpikes = MyGame.random.Next(25, 50);

            Glow      = new VertexPositionColor[1 + glowSpikes * 2];
            GlowIndex = new int[glowSpikes * 9];
            Glow[0]   = new VertexPositionColor(Vector3.Zero, new Color(Color.White, 0.0f));
            for (int i = 0; i < glowSpikes; i++)
            {
                Glow[1 + i] = new VertexPositionColor(
                    new Vector3((float)Math.Sin(i * MathHelper.TwoPi / glowSpikes)
                                , (float)Math.Cos(i * MathHelper.TwoPi / glowSpikes)
                                , (float)MyGame.random.NextDouble() * MathHelper.TwoPi)
                    , new Color(StaticNoise[MyGame.random.Next(StaticNoise.Length)]
                                , 0.1f + 0.15f * (float)MyGame.random.NextDouble()));
                GlowIndex[i * 9]         = 0;
                GlowIndex[i * 9 + 1]     = 1 + i;
                GlowIndex[i * 9 + 2]     = 2 + i;
                Glow[1 + glowSpikes + i] = new VertexPositionColor(
                    Glow[1 + i].Position * (2.0f + 3.0f * (float)MyGame.random.NextDouble())
                    , new Color(Glow[1 + i].Color, 0.0f));
                Glow[1 + glowSpikes + i].Position.Z = Glow[1 + i].Position.Z;
                GlowIndex[i * 9 + 3] = 1 + i;
                GlowIndex[i * 9 + 4] = 1 + glowSpikes + i;
                GlowIndex[i * 9 + 5] = 2 + glowSpikes + i;
                GlowIndex[i * 9 + 6] = 1 + i;
                GlowIndex[i * 9 + 7] = 2 + glowSpikes + i;
                GlowIndex[i * 9 + 8] = 2 + i;
            }
            GlowIndex[(glowSpikes - 1) * 9 + 2] = 1;
            GlowIndex[(glowSpikes - 1) * 9 + 5] = 1 + glowSpikes;
            GlowIndex[(glowSpikes - 1) * 9 + 7] = 1 + glowSpikes;
            GlowIndex[(glowSpikes - 1) * 9 + 8] = 1;
            GlowDeclaration = new VertexDeclaration(MyGame.graphics.GraphicsDevice, VertexPositionColor.VertexElements);
        }
Esempio n. 5
0
        private Asteroid(Vector3 Position, float Scale, Vector3 OrbitalPlaneNormal, float ParentMass)
            : base()
        {
            AsteroidVertices = null;

            //Create a unique asteroid Model
            //First establish the 6 Vertices of the tetrahedron
            Vertices.Add(new Vertex(new Vector3(0, 0.5f + (float)MyGame.random.NextDouble(), 0), 0));
            Vertices.Add(new Vertex(new Vector3(0.5f + (float)MyGame.random.NextDouble(), 0, 0), 1));
            Vertices.Add(new Vertex(new Vector3(0, 0, 0.5f + (float)MyGame.random.NextDouble()), 2));
            Vertices.Add(new Vertex(new Vector3(-0.5f - (float)MyGame.random.NextDouble(), 0, 0), 3));
            Vertices.Add(new Vertex(new Vector3(0, 0, -0.5f - (float)MyGame.random.NextDouble()), 4));
            Vertices.Add(new Vertex(new Vector3(0, -0.5f - (float)MyGame.random.NextDouble(), 0), 5));
            //Next establish the 12 Edges of the tetrahedron
            Edges.Add(new Edge(Vertices[0], Vertices[1]));
            Edges.Add(new Edge(Vertices[0], Vertices[2]));
            Edges.Add(new Edge(Vertices[0], Vertices[3]));
            Edges.Add(new Edge(Vertices[0], Vertices[4]));
            Edges.Add(new Edge(Vertices[1], Vertices[2]));
            Edges.Add(new Edge(Vertices[2], Vertices[3]));
            Edges.Add(new Edge(Vertices[3], Vertices[4]));
            Edges.Add(new Edge(Vertices[4], Vertices[1]));
            Edges.Add(new Edge(Vertices[1], Vertices[5]));
            Edges.Add(new Edge(Vertices[2], Vertices[5]));
            Edges.Add(new Edge(Vertices[3], Vertices[5]));
            Edges.Add(new Edge(Vertices[4], Vertices[5]));
            //Next establish the 8 Faces/Triangles of the tetrahedron
            Triangles.Add(new Triangle(Edges[0], Edges[1], Edges[4]));
            Triangles.Add(new Triangle(Edges[1], Edges[2], Edges[5]));
            Triangles.Add(new Triangle(Edges[2], Edges[3], Edges[6]));
            Triangles.Add(new Triangle(Edges[3], Edges[0], Edges[7]));
            Triangles.Add(new Triangle(Edges[8], Edges[9], Edges[4]));
            Triangles.Add(new Triangle(Edges[9], Edges[10], Edges[5]));
            Triangles.Add(new Triangle(Edges[10], Edges[11], Edges[6]));
            Triangles.Add(new Triangle(Edges[11], Edges[8], Edges[7]));

            int DetailLevel = MyGame.random.Next(4, 5);

            for (int i = 0; i < DetailLevel; i++)
            {
                IncreaseVertexCount();
            }

            ConvertPartsToPrimitive(Color.Brown);
            ModelDeclaration = new VertexDeclaration(MyGame.graphics.GraphicsDevice, VertexPositionNormalColor.VertexElements);

            RotationAxis    = Manager.GetRandomNormal();
            RotationTime    = (float)MyGame.random.NextDouble();
            Bounds          = new BoundingSphere(Position, Scale);
            this.Transforms = new ScalePositionRotation(
                Scale
                , Position
                , Matrix.CreateFromAxisAngle(RotationAxis, RotationTime));
            Mass = (float)(4.0 / 3.0 * Math.PI * Math.Pow(Transforms.Scale, 3.0));

            this.Velocity = Body.GetRandomInitialOrbitVelocity(Position, OrbitalPlaneNormal, ParentMass, Mass);
        }
 /// <summary>
 /// Re-randomizes the stars drawn in the far area
 /// </summary>
 void RefreshBackground(int numStars)
 {
     if (numStars > Stars.Length / 4)
     {
         int PreviousStarNumber = Stars.Length / 4;
         Array.Resize <VertexPositionColorTexture>(ref Stars, numStars * 4);
         Array.Resize <int>(ref StarIndex, numStars * 6);
         for (int i = PreviousStarNumber; i < numStars; i++)
         {
             Vector3 position = Manager.GetRandomNormal()
                                * (0.6f + 0.4f * (float)MyGame.random.NextDouble());
             Vector2 texture = new Vector2(0.1f * MyGame.random.Next(10), 0.1f * MyGame.random.Next(10));
             Stars[i * 4] = new VertexPositionColorTexture(
                 position
                 , Manager.GetRandomColor(true)
                 , texture);
             Stars[i * 4 + 1] = new VertexPositionColorTexture(
                 position
                 , Manager.GetRandomColor(true)
                 , texture + Vector2.UnitX * 0.099f);
             Stars[i * 4 + 2] = new VertexPositionColorTexture(
                 position
                 , Manager.GetRandomColor(true)
                 , texture + Vector2.UnitY * 0.099f);
             Stars[i * 4 + 3] = new VertexPositionColorTexture(
                 position
                 , Manager.GetRandomColor(true)
                 , texture + Vector2.One * 0.099f);
             StarIndex[i * 6]     = i * 4;
             StarIndex[i * 6 + 1] = i * 4 + 1;
             StarIndex[i * 6 + 2] = i * 4 + 3;
             StarIndex[i * 6 + 3] = i * 4;
             StarIndex[i * 6 + 4] = i * 4 + 3;
             StarIndex[i * 6 + 5] = i * 4 + 2;
         }
     }
     else if (numStars < Stars.Length / 4)
     {
         Array.Resize <int>(ref StarIndex, numStars * 6);
         //Randomize the order of stars a bit
         int numChanges = Stars.Length / 4 - numStars;
         for (int i = 0; i < numChanges; i++)
         {
             int OtherIndex = MyGame.random.Next(Stars.Length / 4);
             VertexPositionColorTexture temp;
             for (int j = 0; j < 4; j++)
             {
                 temp                      = Stars[i * 4 + j];
                 Stars[i * 4 + j]          = Stars[OtherIndex * 4 + j];
                 Stars[OtherIndex * 4 + j] = temp;
             }
         }
         Array.Resize <VertexPositionColorTexture>(ref Stars, numStars * 4);
     }
 }
Esempio n. 7
0
 protected override void InitializeNestedBodies()
 {
     if (NestedBodies.Count == 0)
     {
         int NumSystems = MyGame.random.Next(7, 13);
         NestedBodies.Add(new SolarSystem(Vector3.Zero));
         for (int i = 1; i < NumSystems; i++)
         {
             NestedBodies.Add(new SolarSystem(75.0f * Manager.GetRandomNormal() * (float)MyGame.random.NextDouble()));
         }
     }
 }
Esempio n. 8
0
 protected override void InitializeNestedBodies()
 {
     if (NestedBodies.Count == 0)
     {
         //Add some Moons
         int NumMoons = MyGame.random.Next(2, 5);
         for (int i = 0; i < NumMoons; i++)
         {
             NestedBodies.Add(new Moon(Manager.GetRandomNormal() * (float)(Transforms.Scale + Transforms.Scale * MyGame.random.NextDouble())
                                       , (float)(Transforms.Scale * 0.1 * MyGame.random.NextDouble())
                                       , Mass));
         }
     }
 }
Esempio n. 9
0
        /// <summary>
        /// Returns the the velocity of a perfectly circular orbit
        /// </summary>
        /// <param name="relativePosition">Relative to the orbital center</param>
        /// <param name="orbitalPlaneNormal">Null for random</param>
        /// <param name="gravityWell">Scale in Kilometers (SolarSystem.ScaleInKilometers)</param>
        /// <param name="scale">Scale in Kilometers (Planet radius * PlanetDatum.RadiusModifier)</param>
        public static Vector3 GetRandomInitialOrbitVelocity(Vector3 relativePosition, Vector3?orbitalPlaneNormal
                                                            , float ParentMass, float ChildMass)
        {
            Vector3 direction;

            if (orbitalPlaneNormal.HasValue)
            {
                direction = Vector3.Normalize(Vector3.Cross(relativePosition, orbitalPlaneNormal.Value));
            }
            else
            {
                direction = Vector3.Normalize(Vector3.Cross(relativePosition, Manager.GetRandomNormal()));
            }
            float velocity = (float)Math.Pow(GetGravitationalForce(relativePosition, ParentMass, ChildMass) * relativePosition.Length(), 0.5);

            return(velocity * direction);
        }
Esempio n. 10
0
        public Nebula(Vector3 Position)
            : base()
        {
            Body.CreateUVSphere(32, 32, out ModelVertices, out ModelIndices);
            effect = Manager.TexturedEffect;

            NoiseMap = Manager.WrappedNoiseTextures[MyGame.random.Next(Manager.WrappedNoiseTextures.Length)];
            Color[] StaticNoise = Manager.GenerateStaticNoise(5, 5);
            ColorMap = new Texture2D(MyGame.graphics.GraphicsDevice, 5, 5);
            ColorMap.SetData <Color>(StaticNoise);

            RotationAxis    = Manager.GetRandomNormal();
            RotationTime    = (float)MyGame.random.NextDouble();
            Bounds          = new BoundingSphere(Position, 100.0f);
            this.Transforms = new ScalePositionRotation(
                100.0f
                , Position
                , Matrix.CreateFromAxisAngle(RotationAxis, RotationTime));
            Mass = 1000.0f * (float)(4.0 / 3.0 * Math.PI * Math.Pow(Transforms.Scale, 3.0));
        }
Esempio n. 11
0
        public Galaxy(Vector3 Position)
            : base()
        {
            Body.CreateUVSphere(32, 32, out ModelVertices, out ModelIndices);
            effect = Manager.TexturedEffect;

            GalaxyTexture = Manager.GeneratePerlinNoise(MyGame.random.Next(10, 25));
            GalaxyTexture = Manager.SpiralWarp(GalaxyTexture);
            Color[] colorScheme = Manager.GenerateStaticNoise(5, 5);
            ColorMap = new Texture2D(MyGame.graphics.GraphicsDevice
                                     , 5
                                     , 5);
            ColorMap.SetData <Color>(colorScheme);

            RotationAxis    = Manager.GetRandomNormal();
            RotationTime    = (float)MyGame.random.NextDouble();
            Bounds          = new BoundingSphere(Position, 10000.0f);
            this.Transforms = new ScalePositionRotation(
                100.0f
                , Position
                , Matrix.CreateFromAxisAngle(RotationAxis, RotationTime));
            Mass = 1000.0f * (float)(4.0 / 3.0 * Math.PI * Math.Pow(Transforms.Scale, 3.0));
        }
Esempio n. 12
0
        public static List <Body> CreateBelt(float Radius, float RadiusModulus
                                             , float MaximumScale
                                             , Vector3 OrbitalPlaneNormal
                                             , int Quantity
                                             , float ParentMass)
        {
            List <Body> asteroids = new List <Body>();

            for (int i = 0; i < Quantity; i++)
            {
                asteroids.Add(new Asteroid(
                                  Vector3.Normalize(
                                      Vector3.Cross(OrbitalPlaneNormal
                                                    , Manager.GetRandomNormal()))
                                  * Radius
                                  + Manager.GetRandomNormal()
                                  * RadiusModulus * 4
                                  * (float)MyGame.random.NextDouble()
                                  , MaximumScale * (0.1f + 0.9f * (float)MyGame.random.NextDouble())
                                  , OrbitalPlaneNormal
                                  , ParentMass));
            }
            return(asteroids);
        }