예제 #1
0
        /// <summary>
        /// Gives a float array of specified attribute of particles in a specified rectangular area.
        /// </summary>
        /// <param name="rectX">Together with `rectY`: origin for a rectangular area which contains particles.</param>
        /// <param name="rectY"></param>
        /// <param name="rectWidth">Width of that area</param>
        /// <param name="rectHeight">Height of that area</param>
        /// <param name="partatt">Attribute whose array will be given. Only one attribute can be specified and "All" cannot be specified.</param>
        public float[] GetParticles(int rectX, int rectY, int rectWidth, int rectHeight, ParticleAttribute partatt)
        {
            float[] result = new float[1];

            bool xh = false, xv = false, xa = false, xs = false, xf = false;

            if ((int)partatt == 1 || (int)partatt == 2 || (int)partatt == 4 || (int)partatt == 8 || (int)partatt == 16)
            {
                if (rectX < 0)
                {
                    rectX = 0;
                }

                if (rectY < 0)
                {
                    rectY = 0;
                }

                if (rectWidth + rectX > size)
                {
                    rectWidth -= (int)(rectX + rectWidth) - size;
                }

                if (rectHeight + rectY > size)
                {
                    rectHeight -= (int)(rectY + rectHeight) - size;
                }

                result = new float[rectWidth * rectHeight];

                if (partatt == ParticleAttribute.Height)
                {
                    xh = true;
                }
                if (partatt == ParticleAttribute.Velocity)
                {
                    xv = true;
                }
                if (partatt == ParticleAttribute.Acceleration)
                {
                    xa = true;
                }
                if (partatt == ParticleAttribute.Sustainability)
                {
                    xs = true;
                }
                if (partatt == ParticleAttribute.Fixity)
                {
                    xf = true;
                }

                int r = 0;
                for (int y = rectY * size; y < rectY * size + rectHeight * size; y += size)
                {
                    for (int x = rectX; x < rectX + rectWidth; x++)
                    {
                        if (xh)
                        {
                            result[r] = vd[x + y];
                        }
                        if (xv)
                        {
                            result[r] = vdv[x + y];
                        }
                        if (xa)
                        {
                            result[r] = vda[x + y];
                        }
                        if (xs)
                        {
                            result[r] = vds[x + y];
                        }
                        if (xf)
                        {
                            result[r] = Convert.ToSingle(vd_static[x + y]);
                        }
                        r += 1;
                    }
                }
            }

            return(result);
        }
예제 #2
0
        /// <summary>
        /// Sets particles' specified attribute(s) to a specified value in a specified rectangular area.
        /// </summary>
        /// <param name="rectX">Together with `rectY`: origin for a rectangular area which contains particles.</param>
        /// <param name="rectY"></param>
        /// <param name="rectWidth">Width of that area</param>
        /// <param name="rectHeight">Height of that area</param>
        /// <param name="value">Value to set the particles to.</param>
        /// <param name="partatt">Attribute(s) that will be set.</param>
        public void SetParticles(int rectX, int rectY, int rectWidth, int rectHeight, float value, ParticleAttribute partatt)
        {
            if (rectX < 0)
            {
                rectX = 0;
            }

            if (rectY < 0)
            {
                rectY = 0;
            }

            if (rectWidth + rectX > size)
            {
                rectWidth -= (rectX + rectWidth) - size;
            }

            if (rectHeight + rectY > size)
            {
                rectHeight -= (rectY + rectHeight) - size;
            }

            bool xh = false, xv = false, xa = false, xs = false, xf = false;

            // Let's see which attributes we are gonna deal with.
            if ((ParticleAttribute.All & partatt) == ParticleAttribute.All)
            {
                xh = true; xv = true; xa = true; xs = true; xf = true;
            }
            else
            {
                if ((ParticleAttribute.Height & partatt) == ParticleAttribute.Height)
                {
                    xh = true;
                }
                if ((ParticleAttribute.Velocity & partatt) == ParticleAttribute.Velocity)
                {
                    xv = true;
                }
                if ((ParticleAttribute.Acceleration & partatt) == ParticleAttribute.Acceleration)
                {
                    xa = true;
                }
                if ((ParticleAttribute.Sustainability & partatt) == ParticleAttribute.Sustainability)
                {
                    xs = true;
                }
                if ((ParticleAttribute.Fixity & partatt) == ParticleAttribute.Fixity)
                {
                    xf = true;
                }
            }

            for (int y = rectY * size; y < rectY * size + rectHeight * size; y += size)
            {
                for (int x = rectX; x < rectX + rectWidth; x++)
                {
                    if (xh)
                    {
                        vd[x + y] = value;
                    }
                    if (xv)
                    {
                        vdv[x + y] = value;
                    }
                    if (xa)
                    {
                        vda[x + y] = value;
                    }
                    if (xs)
                    {
                        vds[x + y] = value;
                    }
                    if (xf)
                    {
                        vd_static[x + y] = Convert.ToBoolean(value);
                    }
                }
            }
        }