Пример #1
0
        /// <summary>
        ///     Allows the game to perform any initialization it needs to before starting to run.
        ///     This is where it can query for any required services and load any non-graphic
        ///     related content.  Calling base.Initialize will enumerate through any components
        ///     and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            metaballTarget = new RenderTarget2D(GraphicsDevice, GraphicsDevice.Viewport.Width,
                                                GraphicsDevice.Viewport.Height);

            controller = new ParticleHydrodynamics2Controller(2.0f, 2048);
            world.Add(controller);

            base.Initialize();
        }
Пример #2
0
        private void HandleInput()
        {
            input.Update();
            if (input.Pad.Is.Press(Buttons.Back) || input.Key.Is.Press(Keys.Escape))
            {
                Exit();
            }
            if (input.Key.Is.Press(Keys.R))
            {
                Reset(Preset.Lava());
            }
            if (input.Key.Is.Press(Keys.T))
            {
                Reset(Preset.Water());
            }
            if (input.Key.Is.Press(Keys.G))
            {
                isGravity = !isGravity;
                if (isGravity)
                {
                    world.Remove(controller);
                    controller = new ParticleHydrodynamics2Controller(2.0f, 2048);
                    world.Add(controller);
                    foreach (var metaball in metaballs)
                    {
                        controller.AddParticle(metaball.Position, metaball.Trajectory * metaball.Velocity);
                    }
                }
            }

            bool valModified = false;

            preset.GlowFactor = HandleFloatInput(Keys.Q, Keys.W, .1f, preset.GlowFactor, ref valModified).Clamp(0f, 1f);
            numberOfMetaballs = HandleIntInput(Keys.A, Keys.S, 1, numberOfMetaballs, ref valModified)
                                .Clamp(0, int.MaxValue);

            bool textureModified = false;

            preset.Glow          = HandleColorInput(Keys.NumPad7, Keys.NumPad8, Keys.NumPad9, preset.Glow, ref textureModified);
            preset.GradientInner = HandleColorInput(Keys.NumPad4, Keys.NumPad5, Keys.NumPad6, preset.GradientInner,
                                                    ref textureModified);
            preset.GradientOuter = HandleColorInput(Keys.NumPad1, Keys.NumPad2, Keys.NumPad3, preset.GradientOuter,
                                                    ref textureModified);
            preset.MaxDistance =
                HandleFloatInput(Keys.Y, Keys.X, .01f, preset.MaxDistance, ref textureModified, true).Clamp(0f, 1f);
            preset.ScalingFactor =
                HandleFloatInput(Keys.C, Keys.V, .01f, preset.ScalingFactor, ref textureModified, true).Clamp(0f, 1f);
            preset.Size = HandleIntInput(Keys.B, Keys.N, 1, preset.Size, ref textureModified, true)
                          .Clamp(0, int.MaxValue);
            if (textureModified)
            {
                RecreateTexture();
            }
            AdjustNumberOfMetaballs();
        }