Example #1
0
        int Index(QRectangle r)
        {
            int    i         = -1;
            double vMidpoint = bounds.X + bounds.Width / 2.0;
            double hMidpoint = bounds.Y + bounds.Height / 2.0;

            bool topQuad = r.Y < hMidpoint && r.Y + r.Height < hMidpoint;
            bool botQuad = r.Y > hMidpoint;

            if (r.X < vMidpoint && r.X + r.Width < vMidpoint)
            {
                if (topQuad)
                {
                    i = 1;
                }
                else if (botQuad)
                {
                    i = 2;
                }
            }
            else if (r.X > vMidpoint)
            {
                if (topQuad)
                {
                    i = 0;
                }
                else if (botQuad)
                {
                    i = 3;
                }
            }

            return(i);
        }
Example #2
0
 public QQuad(QRectangle pBounds)
 {
     level   = 0;
     objects = new List <QRectangle>();
     bounds  = pBounds;
     nodes   = new QQuad[4];
 }
Example #3
0
 QQuad(int plevel, QRectangle pBounds)
 {
     level   = plevel;
     objects = new List <QRectangle>();
     bounds  = pBounds;
     nodes   = new QQuad[4];
 }
Example #4
0
        public QTexture GetPartialTexture(QRectangle source)
        {
            Texture2D t = new Texture2D(_texture.GraphicsDevice, source.Width, source.Height);

            QColor[] colors = new QColor[t.Width * t.Height];
            _texture.GetData(0, source, colors, 0, colors.Length);
            t.SetData(0, source, colors, 0, colors.Length);
            return(new QTexture(Manager, t));
        }
Example #5
0
        public List <QRectangle> Retrieve(List <QRectangle> returnObjects, QRectangle rectangle)
        {
            int index = Index(rectangle);

            if (index != -1 && nodes[0] != null)
            {
                nodes[index].Retrieve(returnObjects, rectangle);
            }

            returnObjects.AddRange(objects);

            return(returnObjects);
        }
Example #6
0
        public void Insert(QRectangle r)
        {
            if (nodes[0] != null)
            {
                int index = Index(r);

                if (index != -1)
                {
                    nodes[index].Insert(r);
                }

                return;
            }

            objects.Add(r);

            if (objects.Count > MAX_OBJECTS && level < MAX_LEVELS)
            {
                if (nodes[0] == null)
                {
                    Split();
                }

                int i = 0;
                while (i < objects.Count)
                {
                    int index = Index(objects[i]);
                    if (index != -1)
                    {
                        nodes[index].Insert(objects[i]);
                        objects.RemoveAt(i);
                    }
                    else
                    {
                        i++;
                    }
                }
            }
        }
Example #7
0
 public QTiles(QVector2 pos, QRectangle source)
 {
     Position = pos;
     Source   = source;
 }
Example #8
0
 public QFrame(QRectangle r, float d)
 {
     SourceRectangle = r;
     Duration        = d;
 }
Example #9
0
 /// <summary>
 /// Adds a frame to the animation at the end
 /// </summary>
 /// <param name="rectangle"></param>
 /// <param name="time"></param>
 public void Add(QRectangle rectangle, float time)
 {
     _frames.Add(new QFrame(rectangle, time));
 }