Пример #1
0
        /// <summary>
        /// A percentageArray with only one value
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static PercentageArray <T> Singleton(T value)
        {
            PercentageArray <T> array = new PercentageArray <T>(1);

            array[0] = new PercentageElement <T>(0, value);
            return(array);
        }
Пример #2
0
        public PercentageArray <T> Clone()
        {
            PercentageArray <T> clone = new PercentageArray <T>(this.array.Length);

            for (int i = 0; i < clone.Length; i++)
            {
                clone[i] = this.array[i].Clone();
            }
            return(clone);
        }
Пример #3
0
        /// <summary>
        /// A percentage array with certain values. The percentages are evenly spaced.
        /// </summary>
        /// <param name="values"></param>
        /// <returns></returns>
        public static PercentageArray <T> FromArray(T[] values)
        {
            PercentageArray <T> array = new PercentageArray <T>(values.Length);

            for (int i = 0; i < values.Length; i++)
            {
                array[i] = new PercentageElement <T>(100 * i / (values.Length - 1), values[i]);
            }
            return(array);
        }
Пример #4
0
        /// <summary>
        /// A percentage array with percentages and values
        /// </summary>
        /// <param name="values">Params in the form: Pct, Value, Pct, Value, ...</param>
        /// <returns></returns>
        public static PercentageArray <T> FromParams(object[] values)
        {
            PercentageArray <T> array = new PercentageArray <T>(values.Length / 2);

            for (int i = 0; i < values.Length; i += 2)
            {
                array[i / 2] = new PercentageElement <T>((float)values[i], (T)values[i + 1]);
            }
            return(array);
        }
Пример #5
0
 public virtual void Initialize(Vector3 position, Vector3 velocity, Vector3 acceleration, float lifeTime,
                                PercentageArray <Color> colorPs, PercentageArray <float> scalePs, PercentageArray <float> alphaPs, Geo geo)
 {
     this.position         = position;
     this.velocity         = velocity;
     this.acceleration     = acceleration;
     this.timeLeft         = this.lifeTime = lifeTime;
     this.colorPercentages = colorPs;
     this.scalePercentages = scalePs;
     this.alphaPercentages = alphaPs;
     this.geometry         = geo;
 }
Пример #6
0
        protected virtual ParticleT createParticle(float elepsedS)
        {
            float percentage = this.calculateEmitterPercentage();

            // Calculate the lifetime
            float lifetime = 1f;

            if (this.AverageLifetimes.Length == 1)
            {
                lifetime = this.AverageLifetimes[0].Value;
            }
            else
            {
                int i = this.AverageLifetimes.GetToIndex(percentage);
                lifetime = GameMath.Lerp(this.AverageLifetimes[i - 1].Value, this.AverageLifetimes[i].Value, AverageLifetimes.GetLerpFactor(i, percentage));
            }
            lifetime = (float)GlobalRandom.Rand(this.Distribution, lifetime, this.LifeTimeDeviation);

            // Adjust the scales
            PercentageArray <float> scales = this.ScalePercentages.Clone();

            if (ScaleDiesToo)
            {
                float factor = lifetime / this.AverageLifetimes[0].Value;
                for (int i = 0; i < scales.Length; i++)
                {
                    scales[i].Value = scales[i].Value * factor;
                }
            }

            // Adjust the alphas
            PercentageArray <float> alphas = this.AlphaPercentages.Clone();

            if (AlphaDiesToo)
            {
                float factor = lifetime / this.AverageLifetimes[0].Value;
                for (int i = 0; i < alphas.Length; i++)
                {
                    alphas[i].Value = alphas[i].Value * factor;
                }
            }

            // Create the particle
            ParticleT particle = this.createParticle(elepsedS, lifetime, scales, alphas);

            return(particle);
        }
Пример #7
0
        //protected abstract ParticleT createParticle(float elepsedS, float lifetime, PercentageArray<float> scales, byte alpha);
        protected virtual ParticleT createParticle(float elepsedS, float lifetime, PercentageArray <float> scales, PercentageArray <float> alphas)
        {
            Vector3   velocity = this.Velocity.Create();
            ParticleT particle = new ParticleT();

            particle.Initialize(
                this.Position + velocity * elepsedS * (GlobalRandom.Next(4) + 1f) / 4f,
                velocity,
                this.Acceleration.Create(),
                lifetime,
                this.ColorPercentages,
                scales,
                alphas,
                this.Geometry
                );
            return(particle);
        }
Пример #8
0
 /// <summary>
 /// Set the percentages and alpha values (in [0,1]) (in the form: pct, alpha, pct, alpha, ...)
 /// </summary>
 /// <param name="percentageAlphaValues"></param>
 public void SetPercentageAlphas(params object[] percentageAlphaValues)
 {
     this.AlphaPercentages = PercentageArray <float> .FromParams(percentageAlphaValues);
 }
Пример #9
0
 /// <summary>
 /// Set the alpha values (in [0,1]) (and interpolate the percentages linearely)
 /// </summary>
 /// <param name="scales"></param>
 public void SetAlphas(params float[] scales)
 {
     this.AlphaPercentages = PercentageArray <float> .FromArray(scales);
 }
Пример #10
0
 /// <summary>
 /// Set the percentages and scales (in the form: pct, scale, pct, scale, ...)
 /// </summary>
 /// <param name="percentageScales"></param>
 public void SetPercentageScales(params object[] percentageScales)
 {
     this.ScalePercentages = PercentageArray <float> .FromParams(percentageScales);
 }
Пример #11
0
 /// <summary>
 /// Set the scales (and interpolate the percentages linearely)
 /// </summary>
 /// <param name="scales"></param>
 public void SetScales(params float[] scales)
 {
     this.ScalePercentages = PercentageArray <float> .FromArray(scales);
 }
Пример #12
0
 /// <summary>
 /// Set the colours (and interpolate the percentages linearely)
 /// </summary>
 /// <param name="colors"></param>
 public void SetColors(params Color[] colors)
 {
     this.ColorPercentages = PercentageArray <Color> .FromArray(colors);
 }
Пример #13
0
 /// <summary>
 /// Set the percentages and lifetimes (in the form: pct, time, pct, time, ...) (in s)
 /// </summary>
 /// <param name="percentageLifetimes"></param>
 public void SetPercentageAverageLifetimes(params object[] percentageLifetimes)
 {
     this.AverageLifetimes = PercentageArray <float> .FromParams(percentageLifetimes);
 }
Пример #14
0
        protected override TextParticle3D createParticle(float elepsedS, float lifetime, PercentageArray <float> scales, PercentageArray <float> alphas)
        {
            TextParticle3D particle = base.createParticle(elepsedS, lifetime, scales, alphas);

            particle.SetText(this.text);
            return(particle);
        }
Пример #15
0
 /// <summary>
 /// Set the lifetimes (and interpolate the percentages linearely) (in s)
 /// </summary>
 /// <param name="lifetimes"></param>
 public void SetAverageLifetimes(params float[] lifetimes)
 {
     this.AverageLifetimes = PercentageArray <float> .FromArray(lifetimes);
 }
Пример #16
0
        public override void Initialize(Vector3 position, Vector3 velocity, Vector3 acceleration, float lifeTime, PercentageArray <Color> colorPs, PercentageArray <float> scalePs, PercentageArray <float> alphaPs, Sprite2DGeometry geo)
        {
            base.Initialize(position, velocity, acceleration, lifeTime, colorPs, scalePs, alphaPs, geo);

            this.position.Z     = 0;
            this.velocity.Z     = 0;
            this.acceleration.Z = 0;
        }
Пример #17
0
 /// <summary>
 /// Set the percentages and colours (in the form: pct, color, pct, color, ...)
 /// </summary>
 /// <param name="percentageColors"></param>
 public void SetPercentageColors(params object[] percentageColors)
 {
     this.ColorPercentages = PercentageArray <Color> .FromParams(percentageColors);
 }