Esempio n. 1
0
        public virtual void Update()
        {
            if (disabled)
            {
                return;
            }

            Constrain();

            velocity = Vector2.Add(velocity, acceleration);
            velocity = Vector2.Multiply(velocity, dampening);
            velocity = Vectorizer.Limit(velocity, maxSpeed);
            position = Vector2.Add(position, velocity);
        }
Esempio n. 2
0
        /*
         * Get a low resolution version of this grid for displaying
         */
        private List <Vector2> CalculateLowResolution()
        {
            List <Vector2> positions = new List <Vector2>();

            //Loop through low resolution version
            for (int i = 0; i < lowResFieldSize.X; i++)
            {
                for (int j = 0; j < lowResFieldSize.Y; j++)
                {
                    //Loop through the high resolution version, but only within the current low-res range
                    Vector2 start = new Vector2(i * lowResScale, j * lowResScale);
                    Vector2 end   = new Vector2(
                        Math.Min(start.X + lowResScale, fieldSize.X),
                        Math.Min(start.Y + lowResScale, fieldSize.Y));

                    Vector2 sum = Vector2.Zero;

                    for (int w = (int)start.X; w < end.X; w++)
                    {
                        for (int h = (int)start.Y; h < end.Y; h++)
                        {
                            int index = ConvertCoordinatesToIndex(w, h);
                            sum = Vector2.Add(sum, field[index]);
                        }
                    }

                    Vector2 pos = ConvertLowResFieldToScreenPos(i, j);
                    sum = Vector2.Multiply(sum, drawDampening);
                    sum = Vectorizer.Limit(sum, lowResMaxForce);

                    positions.Add(Vector2.Add(pos, sum));
                }
            }

            return(positions);
        }