Exemplo n.º 1
0
        public RaceTrackCurve(float terrainWidth, Vector3 terrainScale)
        {
            float nodecenter = 1.0f * terrainWidth / 4f;
            float variation = 1.0f, strength = .6f;

            int direction = 2 * UniversalRandom.GetInstance().Next(2) - 1;

            float height = .14f;
            //float height = (float)UniversalRandom.GetInstance().NextDouble() / 3f;

            //nodes.Add(new CurveNode()
            //{
            //    Position = terrainScale * new Vector3(0, height, -nodecenter),
            //    Tangent = Vector3.Transform(terrainScale * new Vector3(nodecenter, 0, 0), Matrix.CreateRotationY(MathHelper.PiOver4 * (float)(2 * UniversalRandom.GetInstance().NextDouble() - 1) / 2))
            //});

            float step = MathHelper.TwoPi / 5f;

            for (float i = 0; i < MathHelper.TwoPi; i += step)
            {
                height = (float)(.15 + .2 * (UniversalRandom.GetInstance().NextDouble() - .5));
                nodes.Add(new CurveNode()
                {
                    Position = terrainScale * Vector3.Transform(new Vector3(nodecenter, height, 0), Matrix.CreateRotationY(direction * i)),
                    Tangent  = Vector3.Transform(terrainScale * new Vector3(0, 0, -direction * strength * nodecenter),
                                                 Matrix.CreateRotationY(direction * (i + (float)(variation * UniversalRandom.GetInstance().NextDouble()))))
                });
            }


            //nodes.Add(new CurveNode()
            //{
            //    Position = terrainScale * new Vector3(nodecenter, height, -nodecenter / 2),
            //    //Tangent = Vector3.Transform(terrainScale * new Vector3(nodecenter, 0, 0), Matrix.CreateRotationY(MathHelper.PiOver4 * (float)(2 * UniversalRandom.GetInstance().NextDouble() - 1) / 2))
            //    Tangent = Vector3.Transform(terrainScale * new Vector3(variation * nodecenter/2, 0, variation * nodecenter), Matrix.CreateRotationY(MathHelper.PiOver4 * (float)(2 * UniversalRandom.GetInstance().NextDouble() - 1)))
            //});

            //nodes.Add(new CurveNode()
            //{
            //    Position = terrainScale * new Vector3(nodecenter / 2, height, nodecenter),
            //    //Tangent = Vector3.Transform(terrainScale * new Vector3(-nodecenter, 0, 0), Matrix.CreateRotationY(MathHelper.PiOver4 * (float)(2 * UniversalRandom.GetInstance().NextDouble() - 1) / 2))
            //    Tangent = Vector3.Transform(terrainScale * new Vector3(variation * -nodecenter / 2, 0, variation * nodecenter), Matrix.CreateRotationY(MathHelper.PiOver4 * (float)(2 * UniversalRandom.GetInstance().NextDouble() - 1)))
            //});
            //nodes.Add(new CurveNode()
            //{
            //    Position = terrainScale * new Vector3(-nodecenter / 2, height, nodecenter),
            //    //Tangent = Vector3.Transform(terrainScale * new Vector3(-nodecenter, 0, 0), Matrix.CreateRotationY(MathHelper.PiOver4 * (float)(2 * UniversalRandom.GetInstance().NextDouble() - 1) / 2))
            //    Tangent = Vector3.Transform(terrainScale * new Vector3(variation * -nodecenter, 0, variation * nodecenter / 2), Matrix.CreateRotationY(MathHelper.PiOver4 * (float)(2 * UniversalRandom.GetInstance().NextDouble() - 1)))
            //});
            //nodes.Add(new CurveNode()
            //{
            //    Position = terrainScale * new Vector3(-nodecenter, height, -nodecenter / 2),
            //    //Tangent = Vector3.Transform(terrainScale * new Vector3(nodecenter, 0, 0), Matrix.CreateRotationY(MathHelper.PiOver4 * (float)(2 * UniversalRandom.GetInstance().NextDouble() - 1) / 2))
            //    Tangent = Vector3.Transform(terrainScale * new Vector3(0, 0, variation * -nodecenter), Matrix.CreateRotationY(MathHelper.PiOver4 * (float)(2 * UniversalRandom.GetInstance().NextDouble() - 1)))
            //});
        }
 private void InitGradients()
 {
     for (int i = 0; i < GradientSizeTable; i++)
     {
         float z     = 1f - 2f * (float)UniversalRandom.GetInstance().NextDouble();
         float r     = (float)Math.Sqrt(1f - z * z);
         float theta = 2 * (float)Math.PI * (float)UniversalRandom.GetInstance().NextDouble();
         _gradients[i * 3]     = r * (float)Math.Cos(theta);
         _gradients[i * 3 + 1] = r * (float)Math.Sin(theta);
         _gradients[i * 3 + 2] = z;
     }
 }
        /// <summary>
        /// Adds a new particle to the system.
        /// </summary>
        public void AddParticle(Vector3 position, Vector3 velocity)
        {
            // Figure out where in the circular queue to allocate the new particle.
            int nextFreeParticle = firstFreeParticle + 1;

            if (nextFreeParticle >= settings.MaxParticles)
            {
                nextFreeParticle = 0;
            }

            // If there are no free particles, we just have to give up.
            if (nextFreeParticle == firstRetiredParticle)
            {
                return;
            }

            // Adjust the input velocity based on how much
            // this particle system wants to be affected by it.
            velocity *= settings.EmitterVelocitySensitivity;

            // Add in some random amount of horizontal velocity.
            float horizontalVelocity = MathHelper.Lerp(settings.MinHorizontalVelocity,
                                                       settings.MaxHorizontalVelocity,
                                                       (float)UniversalRandom.GetInstance().NextDouble());

            double horizontalAngle = UniversalRandom.GetInstance().NextDouble() * MathHelper.TwoPi;

            velocity.X += horizontalVelocity * (float)Math.Cos(horizontalAngle);
            velocity.Z += horizontalVelocity * (float)Math.Sin(horizontalAngle);

            // Add in some random amount of vertical velocity.
            velocity.Y += MathHelper.Lerp(settings.MinVerticalVelocity,
                                          settings.MaxVerticalVelocity,
                                          (float)UniversalRandom.GetInstance().NextDouble());

            // Choose four random control values. These will be used by the vertex
            // shader to give each particle a different size, rotation, and color.
            Color randomValues = new Color((byte)UniversalRandom.GetInstance().Next(255),
                                           (byte)UniversalRandom.GetInstance().Next(255),
                                           (byte)UniversalRandom.GetInstance().Next(255),
                                           (byte)UniversalRandom.GetInstance().Next(255));

            // Fill in the particle vertex structure.
            for (int i = 0; i < 4; i++)
            {
                particles[firstFreeParticle * 4 + i].Position = position;
                particles[firstFreeParticle * 4 + i].Velocity = velocity;
                particles[firstFreeParticle * 4 + i].Random   = randomValues;
                particles[firstFreeParticle * 4 + i].Time     = currentTime;
            }

            firstFreeParticle = nextFreeParticle;
        }
Exemplo n.º 4
0
 public Stone(GameManager game)
     : base()
 {
     this.game = game;
     Model     = stoneVariants[UniversalRandom.GetInstance().Next(stoneVariants.Count)];
 }
Exemplo n.º 5
0
        public BirdCurve()
        {
            float nodecenter = 1000;
            float variation  = .8f;

            nodes.Add(new CurveNode()
            {
                Position = new Vector3(0, 5000f, -nodecenter),
                Tangent  = Vector3.Transform(new Vector3(variation * nodecenter, 0, 0), Matrix.CreateRotationY(MathHelper.PiOver4 * (float)(2 * UniversalRandom.GetInstance().NextDouble() - 1)))
            });
            nodes.Add(new CurveNode()
            {
                Position = new Vector3(nodecenter, 5000f, 0),
                Tangent  = Vector3.Transform(new Vector3(0, 0, variation * nodecenter), Matrix.CreateRotationY(MathHelper.PiOver4 * (float)(2 * UniversalRandom.GetInstance().NextDouble() - 1)))
            });
            nodes.Add(new CurveNode()
            {
                Position = new Vector3(0, 5000f, nodecenter),
                Tangent  = Vector3.Transform(new Vector3(variation * -nodecenter, 0, 0), Matrix.CreateRotationY(MathHelper.PiOver4 * (float)(2 * UniversalRandom.GetInstance().NextDouble() - 1)))
            });
            nodes.Add(new CurveNode()
            {
                Position = new Vector3(-nodecenter, 5000f, 0),
                Tangent  = Vector3.Transform(new Vector3(0, 0, variation * -nodecenter), Matrix.CreateRotationY(MathHelper.PiOver4 * (float)(2 * UniversalRandom.GetInstance().NextDouble() - 1)))
            });
        }
        public override void Update(GameTime gameTime)
        {
            if (spawn)
            {
                spawn = false;
                flash = 1;
                Game.GetService <CameraComponent>().CurrentCamera.Shake();

                List <SubBolt> branches = new List <SubBolt>();

                branches.Add(new SubBolt()
                {
                    position = startPosition + new Vector3(
                        5000 * ((float)UniversalRandom.GetInstance().NextDouble() - .5f), 0,
                        5000 * ((float)UniversalRandom.GetInstance().NextDouble() - .5f)),
                    target = endPosition + new Vector3(
                        20000 * ((float)UniversalRandom.GetInstance().NextDouble() - .5f), 0,
                        20000 * ((float)UniversalRandom.GetInstance().NextDouble() - .5f))
                });

                while (branches.Count > 0)
                {
                    for (int i = 0; i < branches.Count; i++)
                    {
                        Vector3 dTarget  = branches[i].target - branches[i].position;
                        float   distance = dTarget.Length();

                        // Remove
                        if (distance < 150)
                        {
                            branches.RemoveAt(i--);
                            continue;
                        }

                        // Add
                        if (UniversalRandom.GetInstance().NextDouble() < .002 && i == 0)
                        {
                            var newBolt = branches[i].Clone();

                            newBolt.target = newBolt.position + Vector3.Transform(dTarget,
                                                                                  Matrix.CreateFromYawPitchRoll(
                                                                                      rotationSeed * ((float)UniversalRandom.GetInstance().NextDouble() - .5f),
                                                                                      rotationSeed * ((float)UniversalRandom.GetInstance().NextDouble() - .5f),
                                                                                      rotationSeed * ((float)UniversalRandom.GetInstance().NextDouble() - .5f)));
                            newBolt.target = Vector3.Lerp(newBolt.target, branches[0].target, .4f);
                            branches.Add(newBolt);
                        }

                        branches[i].minDist = distance;
                        dTarget.Normalize();


                        // Offset dTarget
                        Vector3 offset = Vector3.Transform(2f * dTarget,
                                                           Matrix.CreateFromYawPitchRoll(
                                                               rotationSeed * ((float)UniversalRandom.GetInstance().NextDouble() - .5f),
                                                               rotationSeed * ((float)UniversalRandom.GetInstance().NextDouble() - .5f),
                                                               rotationSeed * ((float)UniversalRandom.GetInstance().NextDouble() - .5f)));

                        for (int j = 0; j < 2; j++)
                        {
                            particleSystem.AddParticle(branches[i].position, Vector3.Zero);
                            branches[i].position += 10 * j * offset;
                        }
                    }
                }
            }
            if (flash > 0)
            {
                flash = Math.Max(flash - .01f, 0);
            }

            Game.GetService <DirectionalLight>().Ambient = flash * flashColor;

            base.Update(gameTime);
        }
Exemplo n.º 7
0
 public BirchTree(GameManager game)
     : base()
 {
     this.game = game;
     Model     = birchTreesVariants[UniversalRandom.GetInstance().Next(birchTreesVariants.Count)];
 }