Пример #1
0
        public Rockets()
        {
            Name = "Rockets";
            MaxNumberOfParticles = 10;

            // The RocketEffector will add child particle systems.
            Children = new ParticleSystemCollection();

            Parameters.AddUniform <float>(ParticleParameterNames.Lifetime).DefaultValue = 2;

            Effectors.Add(new StreamEmitter
            {
                DefaultEmissionRate = 2,
            });

            Parameters.AddVarying <Vector3>(ParticleParameterNames.Position);
            Effectors.Add(new StartPositionEffector
            {
                Parameter    = ParticleParameterNames.Position,
                Distribution = new BoxDistribution {
                    MinValue = new Vector3(-5, 0, -5), MaxValue = new Vector3(5, 0, 0)
                },
            });

            Parameters.AddVarying <Vector3>(ParticleParameterNames.Direction);
            Effectors.Add(new StartDirectionEffector
            {
                Parameter    = ParticleParameterNames.Direction,
                Distribution = new DirectionDistribution {
                    Deviation = 0.5f, Direction = Vector3.UnitY
                },
            });

            Parameters.AddVarying <float>(ParticleParameterNames.LinearSpeed);
            Effectors.Add(new StartValueEffector <float>
            {
                Parameter    = ParticleParameterNames.LinearSpeed,
                Distribution = new UniformDistributionF(2, 6),
            });

            Effectors.Add(new LinearVelocityEffector());

            Parameters.AddUniform <Vector3>(ParticleParameterNames.LinearAcceleration).DefaultValue = new Vector3(0, -2f, 0);
            Effectors.Add(new LinearAccelerationEffector());

            Parameters.AddUniform <float>(ParticleParameterNames.Alpha).DefaultValue = 0;

            // The RocketEffector creates and controls nested particle systems for the rocket trails
            // and explosions.
            Effectors.Add(new RocketEffector());

            ParticleSystemValidator.Validate(this);
        }
Пример #2
0
        private RocketTrail(ContentManager contentManager)
        {
            MaxNumberOfParticles = 200;

            Parameters.AddVarying <float>(ParticleParameterNames.Lifetime);
            Effectors.Add(new StartValueEffector <float>
            {
                Parameter    = ParticleParameterNames.Lifetime,
                Distribution = new UniformDistributionF(1, 2),
            });

            Parameters.AddUniform <float>(ParticleParameterNames.EmissionRate);
            Effectors.Add(new StartValueEffector <float>
            {
                Parameter    = ParticleParameterNames.EmissionRate,
                DefaultValue = 60,
            });
            Effectors.Add(new StreamEmitter
            {
                EmissionRateParameter = ParticleParameterNames.EmissionRate,
            });

            Parameters.AddVarying <Vector3F>(ParticleParameterNames.Position);
            Effectors.Add(new StartPositionEffector
            {
                Parameter = ParticleParameterNames.Position,
            });

            Parameters.AddVarying <Vector3F>(ParticleParameterNames.Direction);
            Effectors.Add(new StartDirectionEffector
            {
                Parameter    = ParticleParameterNames.Direction,
                Distribution = new DirectionDistribution {
                    Deviation = ConstantsF.Pi, Direction = Vector3F.UnitY
                },
            });

            Parameters.AddVarying <float>(ParticleParameterNames.LinearSpeed);
            Effectors.Add(new StartValueEffector <float>
            {
                Parameter    = ParticleParameterNames.LinearSpeed,
                Distribution = new UniformDistributionF(0.1f, 0.3f),
            });

            // The StartVelocityBiasEffector adds a velocity to new particles. We use this to add
            // the rocket velocity (stored in the parameter "EmitterVelocity") to the start velocities
            // of the particles.
            Parameters.AddUniform <Vector3F>(ParticleParameterNames.EmitterVelocity);
            Effectors.Add(new StartVelocityBiasEffector {
                Strength = 0.1f
            });

            Effectors.Add(new LinearVelocityEffector());

            Parameters.AddVarying <float>(ParticleParameterNames.Angle);
            Effectors.Add(new StartValueEffector <float>
            {
                Parameter    = ParticleParameterNames.Angle,
                Distribution = new UniformDistributionF(-ConstantsF.Pi, ConstantsF.Pi),
            });

            Parameters.AddVarying <float>(ParticleParameterNames.AngularSpeed);
            Effectors.Add(new StartValueEffector <float>
            {
                Parameter    = ParticleParameterNames.AngularSpeed,
                Distribution = new UniformDistributionF(-1, 1),
            });
            Effectors.Add(new AngularVelocityEffector());

            Parameters.AddVarying <float>("StartSize");
            Effectors.Add(new StartValueEffector <float>
            {
                Parameter    = "StartSize",
                Distribution = new UniformDistributionF(0.2f, 0.5f),
            });

            Parameters.AddVarying <float>("EndSize");
            Effectors.Add(new StartValueEffector <float>
            {
                Parameter    = "EndSize",
                Distribution = new UniformDistributionF(0.5f, 1f),
            });

            Parameters.AddVarying <float>(ParticleParameterNames.Size);
            Effectors.Add(new SingleLerpEffector
            {
                ValueParameter = ParticleParameterNames.Size,
                StartParameter = "StartSize",
                EndParameter   = "EndSize",
            });

            Parameters.AddVarying <Vector3F>(ParticleParameterNames.Color);
            Effectors.Add(new StartValueEffector <Vector3F>
            {
                Parameter    = ParticleParameterNames.Color,
                Distribution = new LineSegmentDistribution {
                    Start = new Vector3F(0.5f, 0.4f, 0.25f), End = new Vector3F(0.7f, 0.6f, 0.5f)
                },
            });

            Parameters.AddVarying <float>(ParticleParameterNames.Alpha);
            Effectors.Add(new FuncEffector <float, float>
            {
                InputParameter  = ParticleParameterNames.NormalizedAge,
                OutputParameter = ParticleParameterNames.Alpha,
                Func            = age => 6.7f * age * (1 - age) * (1 - age),
            });


            Parameters.AddUniform <Texture2D>(ParticleParameterNames.Texture).DefaultValue =
                contentManager.Load <Texture2D>("Particles/Smoke");

            // Draw behind explosion.
            Parameters.AddUniform <int>(ParticleParameterNames.DrawOrder).DefaultValue = -100;

            // The ParticleSystemRecycler recycles this instance into the specified resource
            // pool when all particles are dead.
            Effectors.Add(new ParticleSystemRecycler
            {
                ResourcePool = Pool,

                // Set a minimum life-time to avoid that the particle system is recycled too early.
                // (The rocket trail might need a few frames before particles are created.)
                MinRuntime = TimeSpan.FromSeconds(0.05f),
            });

            ParticleSystemValidator.Validate(this);
        }
        public RocketExplosionSmoke(ContentManager contentManager)
        {
            MaxNumberOfParticles = 200;

            Parameters.AddVarying <float>(ParticleParameterNames.Lifetime);
            Effectors.Add(new StartValueEffector <float>
            {
                Parameter    = ParticleParameterNames.Lifetime,
                Distribution = new UniformDistributionF(2, 4),
            });

            // 30 particles are created instantly, and then no more particles.
            Effectors.Add(new StreamEmitter
            {
                DefaultEmissionRate = 30 * 60,
                EmissionLimit       = 30,
            });

            Parameters.AddVarying <Vector3>(ParticleParameterNames.Position);
            Effectors.Add(new StartPositionEffector());

            Parameters.AddVarying <Vector3>(ParticleParameterNames.Direction);
            Effectors.Add(new StartDirectionEffector
            {
                Parameter    = ParticleParameterNames.Direction,
                Distribution = new DirectionDistribution {
                    Deviation = ConstantsF.TwoPi, Direction = Vector3.UnitY
                },
            });

            Parameters.AddVarying <float>(ParticleParameterNames.LinearSpeed);
            Effectors.Add(new StartValueEffector <float>
            {
                Parameter    = ParticleParameterNames.LinearSpeed,
                Distribution = new UniformDistributionF(1, 6),
            });

            // The StartVelocityBiasEffector adds a velocity to new particles. We use this to add
            // the rocket velocity (stored in the parameter "EmitterVelocity") to the start velocities
            // of the particles.
            Effectors.Add(new StartVelocityBiasEffector
            {
                BiasVelocityParameter = ParticleParameterNames.EmitterVelocity,
                Strength = 1
            });

            Effectors.Add(new LinearVelocityEffector());

            Parameters.AddUniform <Vector3>(ParticleParameterNames.LinearAcceleration).DefaultValue = new Vector3(0, -2.0f, 0);
            Effectors.Add(new LinearAccelerationEffector());

            Parameters.AddUniform <float>(ParticleParameterNames.Damping).DefaultValue = 2.0f;
            Effectors.Add(new SingleDampingEffector());

            Parameters.AddVarying <float>(ParticleParameterNames.Angle);
            Effectors.Add(new StartValueEffector <float>
            {
                Parameter    = ParticleParameterNames.Angle,
                Distribution = new UniformDistributionF(-ConstantsF.Pi, ConstantsF.Pi),
            });

            Parameters.AddVarying <float>(ParticleParameterNames.AngularSpeed);
            Effectors.Add(new StartValueEffector <float>
            {
                Parameter    = ParticleParameterNames.AngularSpeed,
                Distribution = new UniformDistributionF(-1, 1),
            });
            Effectors.Add(new AngularVelocityEffector());

            Parameters.AddVarying <float>(ParticleParameterNames.Alpha);
            Effectors.Add(new FuncEffector <float, float>
            {
                InputParameter  = ParticleParameterNames.NormalizedAge,
                OutputParameter = ParticleParameterNames.Alpha,
                Func            = age => 6.7f * age * (1 - age) * (1 - age),
            });

            Parameters.AddVarying <float>("StartSize");
            Effectors.Add(new StartValueEffector <float>
            {
                Parameter    = "StartSize",
                Distribution = new UniformDistributionF(1, 3),
            });

            Parameters.AddVarying <float>("EndSize");
            Effectors.Add(new StartValueEffector <float>
            {
                Parameter    = "EndSize",
                Distribution = new UniformDistributionF(5, 10),
            });

            Parameters.AddVarying <float>(ParticleParameterNames.Size);
            Effectors.Add(new SingleLerpEffector
            {
                ValueParameter = ParticleParameterNames.Size,
                StartParameter = "StartSize",
                EndParameter   = "EndSize",
            });

            Parameters.AddVarying <Vector3>(ParticleParameterNames.Color);
            Effectors.Add(new StartValueEffector <Vector3>
            {
                Parameter    = ParticleParameterNames.Color,
                Distribution = new LineSegmentDistribution {
                    Start = new Vector3(0.8f, 0.8f, 0.8f), End = new Vector3(1, 1, 1)
                },
            });

            Parameters.AddUniform <Texture2D>(ParticleParameterNames.Texture).DefaultValue =
                contentManager.Load <Texture2D>("Particles/Smoke");
        }
Пример #4
0
        public RocketExplosionCore(ContentManager contentManager)
        {
            MaxNumberOfParticles = 200;

            Parameters.AddUniform <float>(ParticleParameterNames.Lifetime).DefaultValue = 1;

            Effectors.Add(new StreamEmitter
            {
                DefaultEmissionRate = 20 * 60,
                EmissionLimit       = 20,
            });

            Parameters.AddVarying <Vector3>(ParticleParameterNames.Position);
            Effectors.Add(new StartPositionEffector());

            Parameters.AddVarying <Vector3>(ParticleParameterNames.Direction);
            Effectors.Add(new StartDirectionEffector
            {
                Parameter    = ParticleParameterNames.Direction,
                Distribution = new DirectionDistribution {
                    Deviation = ConstantsF.TwoPi, Direction = Vector3.UnitY
                },
            });

            Parameters.AddVarying <float>(ParticleParameterNames.LinearSpeed);
            Effectors.Add(new StartValueEffector <float>
            {
                Parameter    = ParticleParameterNames.LinearSpeed,
                Distribution = new UniformDistributionF(0.5f, 2),
            });

            // The StartVelocityBiasEffector adds a velocity to new particles. We use this to add
            // the rocket velocity (stored in the parameter "EmitterVelocity") to the start velocities
            // of the particles.
            Effectors.Add(new StartVelocityBiasEffector {
                Strength = 1
            });

            Effectors.Add(new LinearVelocityEffector());

            Parameters.AddVarying <float>(ParticleParameterNames.Angle);
            Effectors.Add(new StartValueEffector <float>
            {
                Parameter    = ParticleParameterNames.Angle,
                Distribution = new UniformDistributionF(-ConstantsF.Pi, ConstantsF.Pi),
            });

            Parameters.AddVarying <float>(ParticleParameterNames.AngularSpeed);
            Effectors.Add(new StartValueEffector <float>
            {
                Parameter    = ParticleParameterNames.AngularSpeed,
                Distribution = new UniformDistributionF(-1, 1),
            });
            Effectors.Add(new AngularVelocityEffector());

            Parameters.AddVarying <float>("TargetAlpha");
            Effectors.Add(new StartValueEffector <float>
            {
                Parameter    = "TargetAlpha",
                Distribution = new UniformDistributionF(0.3f, 0.5f),
            });

            Parameters.AddVarying <float>(ParticleParameterNames.Alpha);
            Effectors.Add(new SingleFadeEffector
            {
                ValueParameter       = ParticleParameterNames.Alpha,
                TargetValueParameter = "TargetAlpha",
                FadeInStart          = 0f,
                FadeInEnd            = 0.3f,
                FadeOutStart         = 0.3f,
                FadeOutEnd           = 1f,
            });

            Parameters.AddUniform <float>("StartSize").DefaultValue = 3;
            Parameters.AddUniform <float>("EndSize").DefaultValue   = 5;
            Parameters.AddVarying <float>(ParticleParameterNames.Size);
            Effectors.Add(new SingleLerpEffector
            {
                ValueParameter = ParticleParameterNames.Size,
                StartParameter = "StartSize",
                EndParameter   = "EndSize",
            });

            Parameters.AddVarying <Vector3>(ParticleParameterNames.Color);
            Effectors.Add(new StartValueEffector <Vector3>
            {
                Parameter    = ParticleParameterNames.Color,
                Distribution = new LineSegmentDistribution {
                    Start = new Vector3(0.5f), End = new Vector3(0.66f)
                },
            });

            Parameters.AddUniform <Texture2D>(ParticleParameterNames.Texture).DefaultValue =
                contentManager.Load <Texture2D>("Particles/Explosion");

            Parameters.AddUniform <float>(ParticleParameterNames.BlendMode).DefaultValue = 0;

            // Draw on top of smoke.
            Parameters.AddUniform <int>(ParticleParameterNames.DrawOrder).DefaultValue = 100;
        }