Ejemplo n.º 1
0
        /// <summary>
        /// Subdivide this QuadTree and move it's children into the appropriate Quads where applicable.
        /// </summary>
        private void Subdivide()
        {
            // We've reached capacity, subdivide...
            PrecisePoint size = new PrecisePoint(rect.Width / 2.0d, rect.Height / 2.0d);
            PrecisePoint mid  = new PrecisePoint(rect.X + size.X, rect.Y + size.Y);

            childTL = new QuadTreeNode <T>(this, new PreciseRectangle(rect.Left, rect.Top, size.X, size.Y));
            childTR = new QuadTreeNode <T>(this, new PreciseRectangle(mid.X, rect.Top, size.X, size.Y));
            childBL = new QuadTreeNode <T>(this, new PreciseRectangle(rect.Left, mid.Y, size.X, size.Y));
            childBR = new QuadTreeNode <T>(this, new PreciseRectangle(mid.X, mid.Y, size.X, size.Y));

            // If they're completely contained by the quad, bump objects down
            for (int i = 0; i < objects.Count; i++)
            {
                QuadTreeNode <T> destTree = GetDestinationTree(objects[i]);

                if (destTree != this)
                {
                    // Insert to the appropriate tree, remove the object, and back up one in the loop
                    destTree.Insert(objects[i]);
                    Remove(objects[i]);
                    i--;
                }
            }
        }
Ejemplo n.º 2
0
 private void reScale(PrecisePoint scale)
 {
     if (scale.X != _scale.X || scale.Y != _scale.Y)
     {
         LocalTransform.Scale((float)scale.X, (float)scale.Y, (float)_offset.X, (float)_offset.Y);
         _scale.X = scale.X;
         _scale.Y = scale.Y;
     }
 }
Ejemplo n.º 3
0
        private PrecisePoint unScale()
        {
            PrecisePoint oldScale = new PrecisePoint(_scale.X, _scale.Y);

            if (_scale.X != 1.0d || _scale.Y != 1.0d)
            {
                LocalTransform.Scale((float)(1.0d / _scale.X), (float)(1.0d / _scale.Y), (float)_offset.X, (float)_offset.Y);
                _scale.X = 1.0d;
                _scale.Y = 1.0d;
            }
            return(oldScale);
        }
Ejemplo n.º 4
0
        protected override void OnUpdate(double deltaTime)
        {
            if (inputEngine.Keyboard.IsAnyKeyDown(leftKeys))
            {
                sprite.X        -= sprite.Speed * deltaTime;
                sprite.Rotation -= sprite.Speed * deltaTime;
            }
            if (inputEngine.Keyboard.IsAnyKeyDown(rightKeys))
            {
                sprite.X        += sprite.Speed * deltaTime;
                sprite.Rotation += sprite.Speed * deltaTime;
            }

            if (inputEngine.Controllers.NumControllers > 0)
            {
                PrecisePoint left = inputEngine.Controllers.GetStickPosition(0, XboxStickSide.Left);
                if (left.Length > inputEngine.Controllers.StickDeadZone)
                {
                    sprite.X        += left.X * sprite.Speed * deltaTime;
                    sprite.Rotation += left.X * sprite.Speed * deltaTime;
                }
            }
        }
Ejemplo n.º 5
0
        private void LineTool(int x1, int y1, int x2, int y2, Color c)
        {
            if (!(x1 < 0 || x1 > Pixels[0].Length - 1 || y1 < 0 || y1 > Pixels[0].Length - 1)) Pixels[x1][y1].Color = c;
            if (!(x2 < 0 || x2 > Pixels[0].Length - 1 || y2 < 0 || y2 > Pixels[0].Length - 1)) Pixels[x2][y2].Color = c;
            PrecisePoint slope = new PrecisePoint() { x = -1, y = -1 };
            int xdistance = Math.Abs(x2 - x1);
            int ydistance = Math.Abs(y2 - y1);

            // Right or left quadrants
            if (xdistance >= ydistance && xdistance != 0)
            {

                slope.x = Math.Sign(x2 - x1);
                slope.y = (double)(y2 - y1) / (double)Math.Abs(x2 - x1);
                double y = y1 + 0.5 + slope.y;
                for (int x = x1 + (int)slope.x; (x2 - x1 > 0 && x < x2) || (x2 - x1 < 0 && x > x2); x += (int)slope.x)
                {
                    if (!(x < 0 || x > Pixels.Length - 1 || (int)y < 0 || (int)y > Pixels[0].Length - 1))
                        Pixels[x][(int)y].Color = c;
                    y += slope.y;
                }
            }
            // Top or bottom quadrants
            else
            {
                slope.y = Math.Sign(y2 - y1);
                slope.x = (double)(x2 - x1) / (double)Math.Abs(y2 - y1);
                double x = x1 + 0.5 + slope.x;
                for (int y = y1 + (int)slope.y; (y2 - y1 > 0 && y < y2) || (y2 - y1 < 0 && y > y2); y += (int)slope.y)
                {
                    if (!((int)x < 0 || (int)x > Pixels.Length - 1 || y < 0 || y > Pixels[0].Length - 1))
                        Pixels[(int)x][y].Color = c;
                    x += slope.x;
                }
            }
        }
Ejemplo n.º 6
0
 //constructor
 public StickEventArgs(XboxStickCode code, PrecisePoint position)
 {
     _code     = code;
     _position = position;
 }